Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup / faster builds #168

Closed
wants to merge 12 commits into from
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ doc/*.css
doc/*.html
doc/*.png
doc/edoc-info
include/compile_flags.hrl
.directory
.eunit
.rebar
33 changes: 22 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
sudo: false
language: erlang
script: "make all"
script:
- |
~/rebar3 compile
REBAR=~/rebar3 make all
- |
rm -rf _build
./configure --use-sfmt
make fast && cd deps/sfmt && make && cd -
make all

otp_release:
- 20.3
- 20.0
- 19.3
- 19.0
- 18.3
- 18.1
- 17.4
- 17.0
- 20.3
- 20.0
- 19.3
- 19.0
- 18.3
- 18.1
- 17.4
- 17.0

# coverage tests
matrix:
Expand Down Expand Up @@ -42,5 +50,8 @@ matrix:
- bash <(curl -s https://codecov.io/bash)

cache:
directories:
- .plt
directories:
- .plt

install:
- curl -#fSLo ~/rebar3 https://s3.amazonaws.com/rebar3/rebar3 && chmod +x ~/rebar3
22 changes: 12 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,57 @@
# Author(s): Manolis Papadakis, Kostis Sagonas
# Description: Instructions for make

.PHONY: default fast all get-deps compile dialyzer check_escripts tests doc clean distclean rebuild retest
.PHONY: default fast all get-deps compile dialyzer check_escripts tests doc clean distclean rebuild retest cover

ifneq (,$(findstring Windows,$(OS)))
SEP := $(strip \)
else
SEP := $(strip /)
endif

REBAR := .$(SEP)rebar
REBAR ?= .$(SEP)rebar
REBAR3 ?= rebar3

default: fast

fast: get-deps compile

all: fast dialyzer doc tests

include/compile_flags.hrl: write_compile_flags
./write_compile_flags $@

get-deps:
$(REBAR) get-deps

compile: include/compile_flags.hrl
compile:
$(REBAR) compile

dialyzer: .plt/proper_plt compile
dialyzer -n -nn --plt $< -Wunmatched_returns ebin $(find . -path 'deps/*/ebin/*.beam')
dialyzer -n -nn --plt $< -Wunmatched_returns $(wildcard ebin deps/*/ebin _build/default/lib/*/ebin)

.plt/proper_plt: .plt
dialyzer --build_plt --output_plt $@ --apps erts kernel stdlib compiler crypto syntax_tools

check_escripts:
./check_escripts.sh make_doc write_compile_flags
./check_escripts.sh make_doc

tests: compile
$(REBAR) eunit

doc: compile
./make_doc

cover:
# Show compilation warnings then run tests then display coverage info
$(REBAR3) do compile, cover --reset, eunit --cover, cover --verbose

clean:
./clean_temp.sh

distclean: clean
$(RM) -r .eunit .rebar
$(RM) include/compile_flags.hrl .plt/proper_plt
$(RM) .plt/proper_plt
$(REBAR) clean

rebuild: distclean include/compile_flags.hrl
rebuild: distclean
$(REBAR) compile

retest: compile
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ Quickstart guide
a `make all` call; in that case, you are going to need the `syntax_tools`
application and a recent version of `EDoc`).
Optionally, sfmt-erlang can be selected as an alternative random number
generator using `./configure --use-sfmt` before running `make`.
generator using `./configure --use-sfmt` before running `make`, or with rebar3:
```erlang
{deps, [proper,sfmt]}.
{overrides, [{override, proper, [{erl_opts, [{d, 'RNG', sfmt}]}]}]}.
```
* Add PropEr's base directory to your Erlang library path, using one of the
following methods:
1. `ERL_LIBS` environment variable: Add the following line to your shell
Expand Down
41 changes: 30 additions & 11 deletions include/proper_internal.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,48 @@
%%% @doc Internal header file: This header is included in all PropEr source
%%% files.

-include("compile_flags.hrl").
-include("proper_common.hrl").


%%------------------------------------------------------------------------------
%% Random generator selection
%%------------------------------------------------------------------------------

-ifdef(USE_SFMT).
-define(RANDOM_MOD, sfmt).
-define(SEED_NAME, sfmt_seed).
-ifndef(RNG).
- ifndef(USE_SFMT).
- ifndef(USE_EXSPLUS).
- ifndef(USE_RANDOM).
- ifdef(AT_LEAST_19).
%% for 19.x use 'rand' module
- define(USE_EXSPLUS, true).
- else.
%% for 18.x and older use 'random' module
- define(USE_RANDOM, true).
- endif.
- endif.
- endif.
- endif.
-endif.

-else.
-ifdef(USE_EXSPLUS).
-define(RNG, rand).
-define(RNG_SET_SEED(Seed), ?RNG:seed(exsplus,Seed)).
-endif.

-ifdef(AT_LEAST_19).
-define(RANDOM_MOD, rand). %% for 19.x use the 'rand' module
-define(SEED_NAME, rand_seed).
-else.
-define(RANDOM_MOD, random).
-define(SEED_NAME, random_seed).
-ifdef(USE_SFMT).
-define(RNG, sfmt).
-endif.

-ifdef(USE_RANDOM).
-define(RNG, random).
-endif.

-define(SEED_NAME, list_to_atom(atom_to_list(?RNG)++"_seed")).
-ifndef(USE_EXSPLUS).
-define(RNG_SET_SEED(Seed), ?RNG:seed(Seed)).
-endif.
-define(RNG_UNIFORM(), ?RNG:uniform()).
-define(RNG_UNIFORM(UpperBound), ?RNG:uniform(UpperBound)).

%%------------------------------------------------------------------------------
%% Line annotations
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Proper.Mixfile do
end

defp package do
[files: ~w(src include rebar.config configure Makefile COPYING README.md THANKS check_escripts.sh clean_doc.sh clean_temp.sh write_compile_flags mix.exs),
[files: ~w(src include rebar.config configure Makefile COPYING README.md THANKS check_escripts.sh clean_doc.sh clean_temp.sh mix.exs),
maintainers: ["Manolis Papadakis", "Eirini Arvaniti", "Kostis Sagonas"],
licenses: ["GPL"],
links: %{"GitHub" => "https://github.com/manopapad/proper"}]
Expand Down
23 changes: 19 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
%% WARNING: Our version of rebar does NOT automatically report warnings,
%% nor does it add erl_opts to eunit_compile_opts.

{minimum_otp_vsn, "17.0"}.

{erl_first_files, ["src/vararg.erl"]}.
{eunit_first_files, ["src/vararg.erl",
"src/proper_transformer.erl",
Expand All @@ -35,9 +37,22 @@
{erl_opts, [debug_info,
report_warnings, {warn_format,1}, warn_export_vars,
warn_obsolete_guard, warn_unused_import,
warn_missing_spec, warn_untyped_record]}.
warn_missing_spec, warn_untyped_record,
warn_unused_vars,
{platform_define, "^17", 'USE_ERL_SCAN_LINE'},
{platform_define, "^19|^2", 'AT_LEAST_19'},
{platform_define, "^2", 'AT_LEAST_20'},
{platform_define, "^2[1-9]", 'AT_LEAST_21'}]}.

{pre_hooks, [{"(linux|darwin|gnu)", compile, "make include/compile_flags.hrl"},
{"(freebsd|netbsd|openbsd|solaris|dragonfly)", compile, "gmake include/compile_flags.hrl"},
{"win32", compile, "escript.exe write_compile_flags include/compile_flags.hrl"}]}.
{post_hooks, [{clean, "./clean_doc.sh"}]}.

{profiles, [{test, [{erl_opts, [nowarn_missing_spec
%% TODO: remove most of these:
,nowarn_export_all
,nowarn_untyped_record
]}]}]}.

{dialyzer, [{warnings, [unmatched_returns
]}
,{plt_extra_apps, [erts, kernel, stdlib, compiler, crypto, syntax_tools]}
]}.
1 change: 1 addition & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[].
52 changes: 15 additions & 37 deletions src/proper_arith.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
safe_any/2, safe_zip/2, tuple_map/2, cut_improper_tail/1,
head_length/1, find_first/2, filter/2, partition/2, remove/2, insert/3,
unflatten/2]).
-export([rand_start/1, rand_restart/1, rand_reseed/0, rand_stop/0,
-export([rand_restart/1, rand_reseed/0, rand_stop/0,
rand_int/1, rand_int/2, smart_rand_int/3, rand_non_neg_int/1,
rand_float/1, rand_float/2, rand_non_neg_float/1,
distribute/2, jumble/1, rand_choose/1, freq_choose/1]).
Expand Down Expand Up @@ -221,47 +221,25 @@ remove_n(N, {List,Acc}) ->
%% Random functions
%%-----------------------------------------------------------------------------

%% @doc Seeds the random number generator. This function should be run before
%% calling any random function from this module.
-spec rand_start(seed()) -> 'ok'.
-ifdef(AT_LEAST_19).
rand_start(Seed) ->
_ = rand:seed(exsplus, Seed),
ok.
-else.
rand_start(Seed) ->
_ = ?RANDOM_MOD:seed(Seed),
%% TODO: read option for RNG bijections here
ok.
-endif.

%% @doc Conditionally seeds the random number generator. This function should
%% be run before calling any random function from this module.
-spec rand_restart(seed()) -> 'ok'.
rand_restart(Seed) ->
case get(?SEED_NAME) of
undefined ->
rand_start(Seed);
_ ->
ok
end.
_ = undefined == get(?SEED_NAME)
%% TODO: read option for RNG bijections here
andalso ?RNG_SET_SEED(Seed),
ok.

-spec rand_reseed() -> 'ok'.
-ifdef(AT_LEAST_19).
rand_reseed() ->
_ = rand:seed(exsplus, os:timestamp()),
ok.
-else.
%% TODO: This should use the pid of the process somehow, in case two
%% spawned functions call it simultaneously?
rand_reseed() ->
%% TODO: This should use the pid of the process somehow, in case two
%% spawned functions call it simultaneously?
_ = ?RANDOM_MOD:seed(os:timestamp()),
_ = ?RNG_SET_SEED(os:timestamp()),
ok.
-endif.

-spec rand_stop() -> 'ok'.
rand_stop() ->
erase(?SEED_NAME),
_ = erase(?SEED_NAME),
ok.

-spec rand_int(non_neg_integer()) -> integer().
Expand All @@ -283,7 +261,7 @@ bounded_rand_non_neg_int(Const, Lim) when is_integer(Lim), Lim >= 0 ->

-spec rand_int(integer(), integer()) -> integer().
rand_int(Low, High) when is_integer(Low), is_integer(High), Low =< High ->
Low + ?RANDOM_MOD:uniform(High - Low + 1) - 1.
Low + ?RNG_UNIFORM(High - Low + 1) - 1.

%% When the range is large, skew the distribution to be more like that of an
%% unbounded random integer.
Expand All @@ -301,29 +279,29 @@ wide_range_rand_int(Const, Low, High) when Low >= 0 ->
wide_range_rand_int(Const, Low, High) when High =< 0 ->
High - bounded_rand_non_neg_int(Const, High - Low);
wide_range_rand_int(Const, Low, High) ->
case ?RANDOM_MOD:uniform(2) of
case ?RNG_UNIFORM(2) of
1 -> smart_rand_int(Const, 0, High);
2 -> smart_rand_int(Const, Low, 0)
end.

-spec rand_float(non_neg_integer()) -> float().
rand_float(Const) ->
X = rand_non_neg_float(Const),
case ?RANDOM_MOD:uniform(2) of
case ?RNG_UNIFORM(2) of
1 -> X;
2 -> -X
end.

-spec rand_non_neg_float(non_neg_integer()) -> float().
rand_non_neg_float(Const) when is_integer(Const), Const >= 0 ->
case ?RANDOM_MOD:uniform() of
case ?RNG_UNIFORM() of
1.0 -> rand_non_neg_float(Const);
X -> Const * zero_one_to_zero_inf(X)
end.

-spec rand_float(float(), float()) -> float().
rand_float(Low, High) when is_float(Low), is_float(High), Low =< High ->
Low + ?RANDOM_MOD:uniform() * (High - Low).
Low + ?RNG_UNIFORM() * (High - Low).

-spec zero_one_to_zero_inf(float()) -> float().
%% This function must return only non-negative values and map 0.0 to 0.0, but
Expand Down Expand Up @@ -351,7 +329,7 @@ distribute_tr(CreditsLeft, PeopleLeft, AccList) ->
-spec jumble([T]) -> [T].
%% @doc Produces a random permutation of a list.
jumble(List) ->
[X || {_, X} <- lists:sort([{?RANDOM_MOD:uniform(), X} || X <- List])].
[X || {_, X} <- lists:sort([{?RNG_UNIFORM(), X} || X <- List])].

-spec rand_choose([T,...]) -> {position(),T}.
rand_choose(Choices) when Choices =/= [] ->
Expand Down
17 changes: 1 addition & 16 deletions src/proper_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -626,23 +626,8 @@ function_body(Args, RetType, {Seed1,Seed2}) ->
RetType;
_ ->
SavedSeed = get(?SEED_NAME),
update_seed({Seed1,Seed2,erlang:phash2(Args,?SEED_RANGE)}),
_ = ?RNG_SET_SEED({Seed1, Seed2, erlang:phash2(Args,?SEED_RANGE)}),
Ret = clean_instance(generate(RetType)),
put(?SEED_NAME, SavedSeed),
proper_symb:internal_eval(Ret)
end.

-ifdef(USE_SFMT).
update_seed(Seed) ->
_ = sfmt:seed(Seed),
ok.
-else.
-ifdef(AT_LEAST_19).
update_seed(Seed) ->
_ = rand:seed(exsplus, Seed),
ok.
-else.
update_seed(Seed) ->
put(?SEED_NAME, Seed).
-endif.
-endif.
Loading