Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
2009-dialyzer_typesig-Test-for-foldable-terms-i...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2009-dialyzer_typesig-Test-for-foldable-terms-in-a-cheape.patch of Package erlang
From a5a7f719b16a91f5f859b818064a31a6b84b984b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Tue, 14 Sep 2021 08:11:41 +0200 Subject: [PATCH 09/20] dialyzer_typesig: Test for foldable terms in a cheaper way When testing wheter a term can be folded into a literal, avoid reconstructing the term. --- lib/dialyzer/src/dialyzer_typesig.erl | 16 +++++++--------- lib/dialyzer/src/dialyzer_utils.erl | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/dialyzer/src/dialyzer_typesig.erl b/lib/dialyzer/src/dialyzer_typesig.erl index 66c6e2ec3e..f392665864 100644 --- a/lib/dialyzer/src/dialyzer_typesig.erl +++ b/lib/dialyzer/src/dialyzer_typesig.erl @@ -309,7 +309,7 @@ traverse(Tree, DefinedVars, State) -> Hd = cerl:cons_hd(Tree), Tl = cerl:cons_tl(Tree), {State1, [HdVar, TlVar]} = traverse_list([Hd, Tl], DefinedVars, State), - case cerl:is_literal(fold_literal_maybe_match(Tree, State)) of + case is_foldable(Tree, State) of true -> %% We do not need to do anything more here. {State, t_cons(HdVar, TlVar)}; @@ -446,7 +446,7 @@ traverse(Tree, DefinedVars, State) -> Elements = cerl:tuple_es(Tree), {State1, EVars} = traverse_list(Elements, DefinedVars, State), {State2, TupleType} = - case cerl:is_literal(fold_literal_maybe_match(Tree, State1)) of + case is_foldable(Tree, State) of true -> %% We do not need to do anything more here. {State, t_tuple(EVars)}; @@ -3308,14 +3308,12 @@ find_constraint(Tuple, [#constraint_list{list = List}|Cs]) -> find_constraint(Tuple, [_|Cs]) -> find_constraint(Tuple, Cs). --spec fold_literal_maybe_match(cerl:cerl(), state()) -> cerl:cerl(). +%% Test whether the term can be folded into a literal. If `State` +%% indicates that we are in a match, folding is not possible if any +%% literal in the term contains a map. -fold_literal_maybe_match(Tree0, State) -> - Tree1 = cerl:fold_literal(Tree0), - case state__is_in_match(State) of - false -> Tree1; - true -> dialyzer_utils:refold_pattern(Tree1) - end. +is_foldable(Tree, State) -> + dialyzer_utils:is_foldable(Tree, state__is_in_match(State)). lookup_record(State, Tag, Arity) -> #state{module = M, mod_records = ModRecs, cserver = CServer} = State, diff --git a/lib/dialyzer/src/dialyzer_utils.erl b/lib/dialyzer/src/dialyzer_utils.erl index d81799b301..292c01f7aa 100644 --- a/lib/dialyzer/src/dialyzer_utils.erl +++ b/lib/dialyzer/src/dialyzer_utils.erl @@ -31,6 +31,7 @@ get_record_and_type_info/1, get_spec_info/3, get_fun_meta_info/3, + is_foldable/2, is_suppressed_fun/2, is_suppressed_tag/3, is_compiler_generated/1, @@ -990,6 +991,32 @@ segs_from_bitstring(Bitstring) -> %%------------------------------------------------------------------------------ + +%% Test whether the term can be folded into a literal. +%% If the boolean `InMatch` indicates that the term is used in a +%% match, folding is not possible if any literal in the term +%% contains a map. + +-spec is_foldable(cerl:cerl(), boolean()) -> boolean(). + +is_foldable(Tree, InMatch) -> + case cerl:type(Tree) of + cons -> + is_foldable(cerl:cons_hd(Tree), InMatch) andalso + is_foldable(cerl:cons_tl(Tree), InMatch); + tuple -> + is_foldable_list(cerl:tuple_es(Tree), InMatch); + literal -> + not (InMatch andalso find_map(cerl:concrete(Tree))); + _ -> + false + end. + +is_foldable_list([E|Es], InMatch) -> + is_foldable(E, InMatch) andalso is_foldable_list(Es, InMatch); +is_foldable_list([], _InMatch) -> + true. + -spec refold_pattern(cerl:cerl()) -> cerl:cerl(). refold_pattern(Pat) -> -- 2.31.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor