File 3271-beam_validator-No-longer-support-old-tuple-creation-.patch of Package erlang
From e455e719c54846f2f0f157b8585b1642e448ff69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Mon, 14 Nov 2022 06:54:42 +0100
Subject: [PATCH] beam_validator: No longer support old tuple creation
instructions
The last release that emitted the `put_tuple` and `put` instructions
was OTP 21, which is no longer supported.
---
lib/compiler/src/beam_validator.erl | 27 ---------
lib/compiler/test/beam_validator_SUITE.erl | 15 ++---
.../beam_validator_SUITE_data/bad_tuples.S | 55 +------------------
.../no_exception_in_catch.S | 26 ++-------
.../receive_stacked.S | 32 +++--------
5 files changed, 22 insertions(+), 133 deletions(-)
diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl
index f98bbe894f..6d5964c1d1 100644
--- a/lib/compiler/src/beam_validator.erl
+++ b/lib/compiler/src/beam_validator.erl
@@ -630,33 +630,6 @@ vi({put_tuple2,Dst,{list,Elements}}, Vst0) ->
end, {#{}, 1}, Elements),
Type = #t_tuple{exact=true,size=Size,elements=Es},
create_term(Type, put_tuple2, [], Dst, Vst);
-vi({put_tuple,Sz,Dst}, Vst0) when is_integer(Sz) ->
- Vst1 = eat_heap(1, Vst0),
- Vst = create_term(#t_abstract{kind=unfinished_tuple}, put_tuple, [],
- Dst, Vst1),
- #vst{current=St0} = Vst,
- St = St0#st{puts_left={Sz,{Dst,Sz,#{}}}},
- Vst#vst{current=St};
-vi({put,Src}, Vst0) ->
- assert_term(Src, Vst0),
- Vst = eat_heap(1, Vst0),
- #vst{current=St0} = Vst,
- case St0 of
- #st{puts_left=none} ->
- error(not_building_a_tuple);
- #st{puts_left={1,{Dst,Sz,Es0}}} ->
- ElementType = get_term_type(Src, Vst0),
- Es = beam_types:set_tuple_element(Sz, ElementType, Es0),
- St = St0#st{puts_left=none},
- Type = #t_tuple{exact=true,size=Sz,elements=Es},
- create_term(Type, put_tuple, [], Dst, Vst#vst{current=St});
- #st{puts_left={PutsLeft,{Dst,Sz,Es0}}} when is_integer(PutsLeft) ->
- Index = Sz - PutsLeft + 1,
- ElementType = get_term_type(Src, Vst0),
- Es = beam_types:set_tuple_element(Index, ElementType, Es0),
- St = St0#st{puts_left={PutsLeft-1,{Dst,Sz,Es}}},
- Vst#vst{current=St}
- end;
vi({set_tuple_element,Src,Tuple,N}, Vst) ->
%% This instruction never fails, though it may be invalid in some contexts;
%% see validate_mutation/2
diff --git a/lib/compiler/test/beam_validator_SUITE.erl b/lib/compiler/test/beam_validator_SUITE.erl
index ee43c81a2f..b76426e596 100644
--- a/lib/compiler/test/beam_validator_SUITE.erl
+++ b/lib/compiler/test/beam_validator_SUITE.erl
@@ -321,7 +321,7 @@ state_after_fault_in_catch(Config) when is_list(Config) ->
no_exception_in_catch(Config) when is_list(Config) ->
Errors = do_val(no_exception_in_catch, Config),
[{{no_exception_in_catch,nested_of_1,4},
- {{try_case_end,{x,0}},180,ambiguous_catch_try_state}}] = Errors,
+ {{try_case_end,{x,0}},166,ambiguous_catch_try_state}}] = Errors,
ok.
undef_label(Config) when is_list(Config) ->
@@ -519,13 +519,8 @@ destroy_reg({Tag,N}) ->
bad_tuples(Config) ->
Errors = do_val(bad_tuples, Config),
[{{bad_tuples,heap_overflow,1},
- {{put,{x,0}},9,{heap_overflow,{left,0},{wanted,1}}}},
- {{bad_tuples,long,2},
- {{put,{atom,too_long}},9,not_building_a_tuple}},
- {{bad_tuples,self_referential,1},
- {{put,{x,1}},8,{unfinished_tuple,{x,1}}}},
- {{bad_tuples,short,1},
- {{move,{x,1},{x,0}},8,{unfinished_tuple,{x,1}}}}] = Errors,
+ {{put_tuple2,{x,0},{list,[{atom,ok},{x,0}]}},6,
+ {heap_overflow,{left,2},{wanted,3}}}}] = Errors,
ok.
@@ -552,7 +547,7 @@ receive_stacked(Config) ->
{{test_heap,3,0},11,{fragile_message_reference,{y,_}}}},
{{receive_stacked,f5,0},
{{loop_rec_end,{f,23}},
- 24,
+ 22,
{fragile_message_reference,{y,_}}}},
{{receive_stacked,f6,0},
{{gc_bif,byte_size,{f,29},0,[{y,_}],{x,0}},
@@ -572,7 +567,7 @@ receive_stacked(Config) ->
{fragile_message_reference,{y,_}}}},
{{receive_stacked,m2,0},
{{loop_rec_end,{f,48}},
- 34,
+ 32,
{fragile_message_reference,{y,_}}}}] = Errors,
%% Compile the original source code as a smoke test.
diff --git a/lib/compiler/test/beam_validator_SUITE_data/bad_tuples.S b/lib/compiler/test/beam_validator_SUITE_data/bad_tuples.S
index 7980241c37..81b52757b8 100644
--- a/lib/compiler/test/beam_validator_SUITE_data/bad_tuples.S
+++ b/lib/compiler/test/beam_validator_SUITE_data/bad_tuples.S
@@ -1,69 +1,20 @@
{module, bad_tuples}. %% version = 0
{exports, [{heap_overflow,1},
- {long,2},
{module_info,0},
- {module_info,1},
- {self_referential,1},
- {short,1}]}.
+ {module_info,1}]}.
{attributes, []}.
{labels, 13}.
-
-{function, short, 1, 2}.
- {label,1}.
- {line,[{location,"bad_tuples.erl",4}]}.
- {func_info,{atom,bad_tuples},{atom,short},1}.
- {label,2}.
- {test_heap,3,1}.
- {put_tuple,2,{x,1}}.
- {put,{atom,ok}}.
- {move,{x,1},{x,0}}.
- return.
-
-
-{function, long, 2, 4}.
- {label,3}.
- {line,[{location,"bad_tuples.erl",7}]}.
- {func_info,{atom,bad_tuples},{atom,long},2}.
- {label,4}.
- {test_heap,6,2}.
- {put_tuple,2,{x,2}}.
- {put,{x,0}}.
- {put,{x,1}}.
- {put,{atom,too_long}}.
- {put_tuple,2,{x,0}}.
- {put,{atom,ok}}.
- {put,{x,2}}.
- return.
-
-
{function, heap_overflow, 1, 6}.
{label,5}.
{line,[{location,"bad_tuples.erl",10}]}.
{func_info,{atom,bad_tuples},{atom,heap_overflow},1}.
{label,6}.
- {test_heap,3,1}.
- {put_tuple,2,{x,1}}.
- {put,{atom,ok}}.
- {put,{x,0}}.
- {put,{x,0}}.
- {move,{x,1},{x,0}}.
- return.
-
-
-{function, self_referential, 1, 8}.
- {label,7}.
- {line,[{location,"bad_tuples.erl",13}]}.
- {func_info,{atom,bad_tuples},{atom,self_referential},1}.
- {label,8}.
- {test_heap,3,1}.
- {put_tuple,2,{x,1}}.
- {put,{atom,ok}}.
- {put,{x,1}}.
- {move,{x,1},{x,0}}.
+ {test_heap,2,1}.
+ {put_tuple2,{x,0},{list,[{atom,ok},{x,0}]}}.
return.
diff --git a/lib/compiler/test/beam_validator_SUITE_data/no_exception_in_catch.S b/lib/compiler/test/beam_validator_SUITE_data/no_exception_in_catch.S
index 1a5b417a5f..b6304d00cc 100644
--- a/lib/compiler/test/beam_validator_SUITE_data/no_exception_in_catch.S
+++ b/lib/compiler/test/beam_validator_SUITE_data/no_exception_in_catch.S
@@ -47,9 +47,7 @@
{move,{y,12},{x,0}}.
{call,1,{f,17}}.
{test_heap,3,1}.
- {put_tuple,2,{x,1}}.
- {put,{atom,value1}}.
- {put,{x,0}}.
+ {put_tuple2,{x,1},{list,[{atom,value1},{x,0}]}}.
{move,{x,1},{x,0}}.
{jump,{f,5}}.
{label,3}.
@@ -69,9 +67,7 @@
{move,{y,12},{x,0}}.
{call,1,{f,17}}.
{test_heap,3,1}.
- {put_tuple,2,{x,1}}.
- {put,{atom,caught1}}.
- {put,{x,0}}.
+ {put_tuple2,{x,1},{list,[{atom,caught1},{x,0}]}}.
{move,{x,1},{x,0}}.
{jump,{f,5}}.
{label,4}.
@@ -142,20 +138,14 @@
{label,10}.
{try_end,{y,7}}.
{test_heap,3,1}.
- {put_tuple,2,{x,1}}.
- {put,{atom,value}}.
- {put,{x,0}}.
+ {put_tuple2,{x,1},{list,[{atom,value},{x,0}]}}.
{move,{x,1},{x,0}}.
{jump,{f,12}}.
{label,11}.
{try_case,{y,7}}.
{test_heap,6,3}.
- {put_tuple,2,{x,3}}.
- {put,{x,0}}.
- {put,{x,1}}.
- {put_tuple,2,{x,0}}.
- {put,{atom,caught}}.
- {put,{x,3}}.
+ {put_tuple2,{x,3},{list,[{x,0},{x,1}]}}.
+ {put_tuple2,{x,0},{list,[{atom,caught},{x,3}]}}.
{'%live',1}.
{label,12}.
{try_end,{y,8}}.
@@ -189,11 +179,7 @@
{move,{atom,nested},{x,0}}.
{call_ext,1,{extfunc,erlang,erase,1}}.
{test_heap,5,1}.
- {put_tuple,4,{x,1}}.
- {put,{y,14}}.
- {put,{y,13}}.
- {put,{y,12}}.
- {put,{x,0}}.
+ {put_tuple2,{x,1},{list,[{y,14},{y,13},{y,12},{x,0}]}}.
{move,{x,1},{x,0}}.
{deallocate,15}.
return.
diff --git a/lib/compiler/test/beam_validator_SUITE_data/receive_stacked.S b/lib/compiler/test/beam_validator_SUITE_data/receive_stacked.S
index a878204d16..d4597f088e 100644
--- a/lib/compiler/test/beam_validator_SUITE_data/receive_stacked.S
+++ b/lib/compiler/test/beam_validator_SUITE_data/receive_stacked.S
@@ -55,16 +55,12 @@
{test,is_nil,{f,9},[{x,0}]}.
{test_heap,3,0}.
remove_message.
- {put_tuple,2,{y,0}}.
- {put,{atom,ok}}.
- {put,{y,1}}.
+ {put_tuple2,{y,0},{list,[{atom,ok},{y,1}]}}.
{move,{integer,42},{x,0}}.
{line,[{location,"receive_stacked.erl",26}]}.
{call,1,{f,52}}.
{test_heap,3,0}.
- {put_tuple,2,{x,0}}.
- {put,{y,0}}.
- {put,{y,1}}.
+ {put_tuple2,{x,0},{list,[{y,0},{y,1}]}}.
{deallocate,2}.
return.
{label,9}.
@@ -86,16 +82,12 @@
{test,is_integer,{f,14},[{y,1}]}.
{test_heap,3,0}.
remove_message.
- {put_tuple,2,{y,0}}.
- {put,{atom,ok}}.
- {put,{y,1}}.
+ {put_tuple2,{y,0},{list,[{atom,ok},{y,1}]}}.
{move,{integer,42},{x,0}}.
{line,[{location,"receive_stacked.erl",34}]}.
{call,1,{f,52}}.
{test_heap,3,0}.
- {put_tuple,2,{x,0}}.
- {put,{y,0}}.
- {put,{y,1}}.
+ {put_tuple2,{x,0},{list,[{y,0},{y,1}]}}.
{deallocate,2}.
return.
{label,14}.
@@ -117,16 +109,12 @@
{test,is_list,{f,19},[{y,1}]}.
{test_heap,3,0}.
remove_message.
- {put_tuple,2,{y,0}}.
- {put,{atom,ok}}.
- {put,{y,1}}.
+ {put_tuple2,{y,0},{list,[{atom,ok},{y,1}]}}.
{move,{integer,42},{x,0}}.
{line,[{location,"receive_stacked.erl",42}]}.
{call,1,{f,52}}.
{test_heap,3,0}.
- {put_tuple,2,{x,0}}.
- {put,{y,0}}.
- {put,{y,1}}.
+ {put_tuple2,{x,0},{list,[{y,0},{y,1}]}}.
{deallocate,2}.
return.
{label,19}.
@@ -153,9 +141,7 @@
{line,[{location,"receive_stacked.erl",50}]}.
{call,1,{f,52}}.
{test_heap,3,0}.
- {put_tuple,2,{x,0}}.
- {put,{y,0}}.
- {put,{y,1}}.
+ {put_tuple2,{x,0},{list,[{y,0},{y,1}]}}.
{deallocate,2}.
return.
{label,24}.
@@ -350,9 +336,7 @@
{line,[{location,"receive_stacked.erl",87}]}.
{call,1,{f,52}}.
{test_heap,3,0}.
- {put_tuple,2,{x,0}}.
- {put,{y,1}}.
- {put,{y,0}}.
+ {put_tuple2,{x,0},{list,[{y,1},{y,0}]}}.
{deallocate,4}.
return.
{label,49}.
--
2.35.3