Skip to content

Commit 5f52768

Browse files
author
Erlang/OTP
committed
Merge branch 'john/compiler/revert-container-type-subtraction/ERIERL-650/OTP-17386' into maint-23
* john/compiler/revert-container-type-subtraction/ERIERL-650/OTP-17386: Revert "Merge branch 'john/compiler/validator-container-type-subtraction/GH-4774/OTP-17357' into maint-23"
2 parents da391d9 + 4b4c2fd commit 5f52768

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

lib/compiler/src/beam_validator.erl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ update_type(Merge, With, #value_ref{}=Ref, Vst0) ->
20932093
none ->
20942094
throw({type_conflict, Current, With});
20952095
Type ->
2096-
Vst = update_container_type(Merge, With, Ref, Vst0),
2096+
Vst = update_container_type(Type, Ref, Vst0),
20972097
set_type(Type, Ref, Vst)
20982098
end;
20992099
update_type(Merge, With, {Kind,_}=Reg, Vst) when Kind =:= x; Kind =:= y ->
@@ -2108,19 +2108,13 @@ update_type(Merge, With, Literal, Vst) ->
21082108
end.
21092109

21102110
%% Updates the container the given value was extracted from, if any.
2111-
update_container_type(Merge, With, Ref, #vst{current=#st{vs=Vs}}=Vst) ->
2111+
update_container_type(Type, Ref, #vst{current=#st{vs=Vs}}=Vst) ->
21122112
case Vs of
21132113
#{ Ref := #value{op={bif,element},
21142114
args=[{integer,Index},Tuple]} } when Index >= 1 ->
2115-
case beam_types:set_tuple_element(Index, With, #{}) of
2116-
#{ Index := _ }=Es ->
2117-
TupleType = #t_tuple{size=Index,elements=Es},
2118-
update_type(Merge, TupleType, Tuple, Vst);
2119-
#{} ->
2120-
%% Index was above the element limit; subtract/2 won't be
2121-
%% safe and meet/2 won't do anything.
2122-
Vst
2123-
end;
2115+
Es = beam_types:set_tuple_element(Index, Type, #{}),
2116+
TupleType = #t_tuple{size=Index,elements=Es},
2117+
update_type(fun meet/2, TupleType, Tuple, Vst);
21242118
#{} ->
21252119
Vst
21262120
end.

lib/compiler/test/beam_type_SUITE.erl

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@
2525
cons/1,tuple/1,record_float/1,binary_float/1,float_compare/1,
2626
arity_checks/1,elixir_binaries/1,find_best/1,
2727
test_size/1,cover_lists_functions/1,list_append/1,bad_binary_unit/1,
28-
none_argument/1,success_type_oscillation/1,type_subtraction/1,
29-
container_subtraction/1]).
30-
31-
%% Force id/1 to return 'any'.
32-
-export([id/1]).
28+
none_argument/1,success_type_oscillation/1,type_subtraction/1]).
3329

3430
suite() -> [{ct_hooks,[ts_install_cth]}].
3531

@@ -57,8 +53,7 @@ groups() ->
5753
bad_binary_unit,
5854
none_argument,
5955
success_type_oscillation,
60-
type_subtraction,
61-
container_subtraction
56+
type_subtraction
6257
]}].
6358

6459
init_per_suite(Config) ->
@@ -638,23 +633,5 @@ ts_23(_x@1) ->
638633
2
639634
end.
640635

641-
%% GH-4774: The validator didn't update container contents on type subtraction.
642-
container_subtraction(Config) when is_list(Config) ->
643-
A = id(baz),
644-
645-
cs_1({foo,[]}),
646-
cs_1({bar,A}),
647-
cs_2({bar,A}),
648-
649-
ok.
650-
651-
cs_1({_,[]}) ->
652-
ok;
653-
cs_1({_,_}=Other) ->
654-
cs_2(Other).
655-
656-
cs_2({bar,baz}) ->
657-
ok.
658-
659636
id(I) ->
660637
I.

0 commit comments

Comments
 (0)