Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:25
erlang
2171-compiler-Add-type-info-for-bs_init_writabl...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2171-compiler-Add-type-info-for-bs_init_writable.patch of Package erlang
From 93ee923900c39caf367d9d96613c4b0b410dfb35 Mon Sep 17 00:00:00 2001 From: Frej Drejhammar <frej.drejhammar@gmail.com> Date: Mon, 20 Jun 2022 10:24:16 +0200 Subject: [PATCH] compiler: Add type info for bs_init_writable The SSA instruction bs_init_writable is not known to the SSA type analysis pass, nor is its result type known to the BEAM validator. This patch adds type information for bs_init_writable and as it allows the SSA type pass to elide is_bitstring tests, it also extends the BEAM validator to consider the result of bs_init_writable to be a bitstring. --- lib/compiler/src/beam_ssa_type.erl | 2 + lib/compiler/src/beam_validator.erl | 3 ++ lib/compiler/test/compile_SUITE.erl | 20 ++++++++- .../compile_SUITE_data/bs_init_writable.erl | 45 +++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 lib/compiler/test/compile_SUITE_data/bs_init_writable.erl diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl index f96d4c521e..c35ae6c717 100644 --- a/lib/compiler/src/beam_ssa_type.erl +++ b/lib/compiler/src/beam_ssa_type.erl @@ -2148,6 +2148,8 @@ type(update_tuple, [Src | Updates], _Anno, Ts, _Ds) -> type(wait_timeout, [#b_literal{val=infinity}], _Anno, _Ts, _Ds) -> %% Waits forever, never reaching the 'after' block. beam_types:make_atom(false); +type(bs_init_writable, [_Size], _, _, _) -> + beam_types:make_type_from_value(<<>>); type(_, _, _, _, _) -> any. diff --git a/lib/compiler/src/beam_validator.erl b/lib/compiler/src/beam_validator.erl index 649382bd93..0323fd384c 100644 --- a/lib/compiler/src/beam_validator.erl +++ b/lib/compiler/src/beam_validator.erl @@ -3279,6 +3279,9 @@ join_tuple_elements(I, Tuple, Type0) -> call_types({extfunc,M,F,A}, A, Vst) -> Args = get_call_args(A, Vst), beam_call_types:types(M, F, Args); +call_types(bs_init_writable, A, Vst) -> + T = beam_types:make_type_from_value(<<>>), + {T, get_call_args(A, Vst), false}; call_types(_, A, Vst) -> {any, get_call_args(A, Vst), false}. diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl index 648137259a..b2b3f65d6a 100644 --- a/lib/compiler/test/compile_SUITE.erl +++ b/lib/compiler/test/compile_SUITE.erl @@ -38,7 +38,7 @@ warnings/1, pre_load_check/1, env_compiler_options/1, bc_options/1, deterministic_include/1, deterministic_paths/1, compile_attribute/1, message_printing/1, other_options/1, - transforms/1, erl_compile_api/1, types_pp/1 + transforms/1, erl_compile_api/1, types_pp/1, bs_init_writable/1 ]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -58,7 +58,7 @@ all() -> env_compiler_options, custom_debug_info, bc_options, custom_compile_info, deterministic_include, deterministic_paths, compile_attribute, message_printing, other_options, transforms, - erl_compile_api, types_pp]. + erl_compile_api, types_pp, bs_init_writable]. groups() -> []. @@ -2063,6 +2063,22 @@ get_result_types([CallLine|Lines], TypeLine, Acc) -> [_,Callee,_] = string:split(CallLine, "`", all), get_result_types(Lines, Acc#{ Callee => TypeLine }). +%% Check that the beam_ssa_type pass knows about bs_init_writable. +bs_init_writable(Config) -> + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + InFile = filename:join(DataDir, "bs_init_writable.erl"), + OutDir = filename:join(PrivDir, "bs_init_writable"), + OutFile = filename:join(OutDir, "bs_init_writable.S"), + ok = file:make_dir(OutDir), + {ok,bs_init_writable} = compile:file(InFile, ['S',{outdir,OutDir}]), + {ok,Listing} = file:read_file(OutFile), + Os = [global,multiline,{capture,all_but_first,list}], + %% The is_bitstr test should be optimized away. + nomatch = re:run(Listing, "({test,is_bitstr,.+})", Os), + %% The is_bitstr test should be optimized away. + nomatch = re:run(Listing, "({test,is_binary,.+})", Os), + ok = file:del_dir_r(OutDir). %%% diff --git a/lib/compiler/test/compile_SUITE_data/bs_init_writable.erl b/lib/compiler/test/compile_SUITE_data/bs_init_writable.erl new file mode 100644 index 0000000000..a9e061645f --- /dev/null +++ b/lib/compiler/test/compile_SUITE_data/bs_init_writable.erl @@ -0,0 +1,45 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2022. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +-module(bs_init_writable). + +-export([do/0]). + +do() -> + Val = ex:foo(), + X = << <<B:1>> || B <- Val >>, + should_not_have_bitstring_test(X), + Y = << <<B:8>> || B <- Val >>, + should_not_have_binary_test(Y). + + +%% If the beam_ssa_type pass does its job, +%% should_not_have_bitstring_test/1 should not contain a is_bitstr test. +should_not_have_bitstring_test(X) when is_bitstring(X) -> + bitstring; +should_not_have_bitstring_test(_) -> + something_else. + +%% If the beam_ssa_type pass does its job, +%% should_not_have_binary_test/1 should not contain a is_binary test. +should_not_have_binary_test(X) when is_binary(X) -> + binary; +should_not_have_binary_test(_) -> + something_else. -- 2.35.3
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