Permalink
Browse files

Reduce PropEr's memory consumption

  • Loading branch information...
1 parent ad76dc0 commit 872d81c7eac4e3f1102161b09aef9970f41e8c3f @thomasc thomasc committed Apr 16, 2012
Showing with 237 additions and 96 deletions.
  1. +35 −9 src/proper_gen.erl
  2. +2 −2 src/proper_shrink.erl
  3. +200 −85 src/proper_types.erl
View
@@ -68,11 +68,28 @@
%% @private_type
-type sized_generator() :: fun((size()) -> imm_instance()).
%% @private_type
+-type typed_sized_generator() :: {typed,
+ fun((proper_types:type(),size()) ->
+ imm_instance())}.
+%% @private_type
-type nosize_generator() :: fun(() -> imm_instance()).
%% @private_type
--type generator() :: sized_generator() | nosize_generator().
+-type typed_nosize_generator() :: {typed,
+ fun((proper_types:type()) ->
+ imm_instance())}.
+%% @private_type
+-type generator() :: sized_generator()
+ | typed_sized_generator()
+ | nosize_generator()
+ | typed_nosize_generator().
+%% @private_type
+-type plain_reverse_gen() :: fun((instance()) -> imm_instance()).
%% @private_type
--type reverse_gen() :: fun((instance()) -> imm_instance()).
+-type typed_reverse_gen() :: {typed,
+ fun((proper_types:type(),instance()) ->
+ imm_instance())}.
+%% @private_type
+-type reverse_gen() :: plain_reverse_gen() | typed_reverse_gen().
%% @private_type
-type combine_fun() :: fun((instance()) -> imm_instance()).
%% @private_type
@@ -272,10 +289,17 @@ contains_fun(_Term) ->
%% @private
-spec normal_gen(proper_types:type()) -> imm_instance().
normal_gen(Type) ->
- Gen = proper_types:get_prop(generator, Type),
- if
- is_function(Gen, 0) -> Gen();
- is_function(Gen, 1) -> Gen(proper:get_size(Type))
+ case proper_types:get_prop(generator, Type) of
+ {typed, Gen} ->
+ if
+ is_function(Gen, 1) -> Gen(Type);
+ is_function(Gen, 2) -> Gen(Type, proper:get_size(Type))
+ end;
+ Gen ->
+ if
+ is_function(Gen, 0) -> Gen();
+ is_function(Gen, 1) -> Gen(proper:get_size(Type))
+ end
end.
%% @private
@@ -488,9 +512,11 @@ loose_tuple_gen(Size, ElemType) ->
loose_tuple_rev(Tuple, ElemType) ->
CleanList = tuple_to_list(Tuple),
List = case proper_types:find_prop(reverse_gen, ElemType) of
- {ok,ReverseGen} -> [ReverseGen(X) || X <- CleanList];
- error -> CleanList
- end,
+ {ok,{typed, ReverseGen}} ->
+ [ReverseGen(ElemType,X) || X <- CleanList];
+ {ok,ReverseGen} -> [ReverseGen(X) || X <- CleanList];
+ error -> CleanList
+ end,
{'$used', List, Tuple}.
%% @private
View
@@ -345,7 +345,7 @@ remove_shrinker(Instance, Type, {shrunk,1,{indices,Checked,_ToCheck}}) ->
%% compares elements with == instead of =:=, that could cause us to
%% miss some elements in some cases
GetIndices = proper_types:get_prop(get_indices, Type),
- Indices = ordsets:from_list(GetIndices(Instance)),
+ Indices = ordsets:from_list(GetIndices(Type, Instance)),
NewToCheck = ordsets:subtract(Indices, Checked),
remove_shrinker(Instance, Type, {indices,Checked,NewToCheck}).
@@ -369,7 +369,7 @@ elements_shrinker(Instance, Type, init) ->
proper_types:get_prop(internal_types, Type),
fun(I) -> Retrieve(I, InnerTypes) end
end,
- Indices = GetIndices(Instance),
+ Indices = GetIndices(Type, Instance),
elements_shrinker(Instance, Type, {inner,Indices,GetElemType,init});
_ ->
{[], done}
Oops, something went wrong.

0 comments on commit 872d81c

Please sign in to comment.