aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2016-05-16 09:51:09 +0200
committerHans Bolinder <[email protected]>2016-05-16 09:51:09 +0200
commite81b0af5c95e776794f8a6f39e3bc0d577c3947c (patch)
tree180682db919870584c0d5391b884dc5276320ac4
parentf45c3aa375bc8925366a0844195d8bb0b26879f5 (diff)
parent43b99183a5cdd7efbbfda8d991752e7065f9e109 (diff)
downloadotp-e81b0af5c95e776794f8a6f39e3bc0d577c3947c.tar.gz
otp-e81b0af5c95e776794f8a6f39e3bc0d577c3947c.tar.bz2
otp-e81b0af5c95e776794f8a6f39e3bc0d577c3947c.zip
Merge branch 'kostis/dialyzer/opaque_type/OTP-13586/PR-1047'
* kostis/dialyzer/opaque_type/OTP-13586/PR-1047: Declare the erl_types:var_table() type as opaque
-rw-r--r--lib/dialyzer/src/dialyzer_contracts.erl16
-rw-r--r--lib/hipe/cerl/erl_types.erl16
2 files changed, 23 insertions, 9 deletions
diff --git a/lib/dialyzer/src/dialyzer_contracts.erl b/lib/dialyzer/src/dialyzer_contracts.erl
index 116260778c..d1ffa07706 100644
--- a/lib/dialyzer/src/dialyzer_contracts.erl
+++ b/lib/dialyzer/src/dialyzer_contracts.erl
@@ -479,7 +479,8 @@ initialize_constraints([], _MFA, _RecDict, _ExpTypes, _AllRecords, Acc) ->
initialize_constraints([Constr|Rest], MFA, RecDict, ExpTypes, AllRecords, Acc) ->
case Constr of
{type, _, constraint, [{atom, _, is_subtype}, [Type1, Type2]]} ->
- T1 = final_form(Type1, ExpTypes, MFA, AllRecords, maps:new()),
+ VarTable = erl_types:var_table__new(),
+ T1 = final_form(Type1, ExpTypes, MFA, AllRecords, VarTable),
Entry = {T1, Type2},
initialize_constraints(Rest, MFA, RecDict, ExpTypes, AllRecords, [Entry|Acc]);
{type, _, constraint, [{atom,_,Name}, List]} ->
@@ -489,8 +490,9 @@ initialize_constraints([Constr|Rest], MFA, RecDict, ExpTypes, AllRecords, Acc) -
end.
constraints_fixpoint(Constrs, MFA, RecDict, ExpTypes, AllRecords) ->
+ VarTable = erl_types:var_table__new(),
VarDict =
- constraints_to_dict(Constrs, MFA, RecDict, ExpTypes, AllRecords, maps:new()),
+ constraints_to_dict(Constrs, MFA, RecDict, ExpTypes, AllRecords, VarTable),
constraints_fixpoint(VarDict, MFA, Constrs, RecDict, ExpTypes, AllRecords).
constraints_fixpoint(OldVarDict, MFA, Constrs, RecDict, ExpTypes, AllRecords) ->
@@ -498,11 +500,11 @@ constraints_fixpoint(OldVarDict, MFA, Constrs, RecDict, ExpTypes, AllRecords) ->
constraints_to_dict(Constrs, MFA, RecDict, ExpTypes, AllRecords, OldVarDict),
case NewVarDict of
OldVarDict ->
- DictFold =
+ Fun =
fun(Key, Value, Acc) ->
[{subtype, erl_types:t_var(Key), Value}|Acc]
end,
- FinalConstrs = maps:fold(DictFold, [], NewVarDict),
+ FinalConstrs = maps:fold(Fun, [], NewVarDict),
{FinalConstrs, NewVarDict};
_Other ->
constraints_fixpoint(NewVarDict, MFA, Constrs, RecDict, ExpTypes, AllRecords)
@@ -512,12 +514,12 @@ final_form(Form, ExpTypes, MFA, AllRecords, VarDict) ->
from_form_with_check(Form, ExpTypes, MFA, AllRecords, VarDict).
from_form_with_check(Form, ExpTypes, MFA, AllRecords) ->
- from_form_with_check(Form, ExpTypes, MFA, AllRecords, maps:new()).
+ VarTable = erl_types:var_table__new(),
+ from_form_with_check(Form, ExpTypes, MFA, AllRecords, VarTable).
from_form_with_check(Form, ExpTypes, MFA, AllRecords, VarDict) ->
Site = {spec, MFA},
- erl_types:t_check_record_fields(Form, ExpTypes, Site, AllRecords,
- VarDict),
+ erl_types:t_check_record_fields(Form, ExpTypes, Site, AllRecords, VarDict),
erl_types:t_from_form(Form, ExpTypes, Site, AllRecords, VarDict).
constraints_to_dict(Constrs, MFA, RecDict, ExpTypes, AllRecords, VarDict) ->
diff --git a/lib/hipe/cerl/erl_types.erl b/lib/hipe/cerl/erl_types.erl
index 84addcc105..b037a4360c 100644
--- a/lib/hipe/cerl/erl_types.erl
+++ b/lib/hipe/cerl/erl_types.erl
@@ -220,6 +220,7 @@
is_opaque_type/2,
is_erl_type/1,
atom_to_string/1,
+ var_table__new/0,
map_pairwise_merge/3
]).
@@ -236,7 +237,7 @@
-export([t_is_identifier/1]).
-endif.
--export_type([erl_type/0, opaques/0, type_table/0]).
+-export_type([erl_type/0, opaques/0, type_table/0, var_table/0]).
%%-define(DEBUG, true).
@@ -380,7 +381,7 @@
-type type_table() :: dict:dict(record_key() | type_key(),
record_value() | type_value()).
--type var_table() :: #{atom() => erl_type()}.
+-opaque var_table() :: #{atom() => erl_type()}.
%%-----------------------------------------------------------------------------
%% Unions
@@ -5464,6 +5465,17 @@ family(L) ->
sofs:to_external(F).
%%=============================================================================
+%%
+%% Interface functions for abstract data types defined in this module
+%%
+%%=============================================================================
+
+-spec var_table__new() -> var_table().
+
+var_table__new() ->
+ maps:new().
+
+%%=============================================================================
%% Consistency-testing function(s) below
%%=============================================================================