New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanups and bug fixes of the compiler #1965

merged 9 commits into from Oct 1, 2018


None yet
1 participant

bjorng commented Sep 26, 2018

This pull request introduces several minor cleanups, bug fixes, and improvements in the compiler. See the individual commit messages for details.

bjorng added some commits Sep 20, 2018

Move optimization of 'move' from beam_flatten to beam_ssa_codegen
The purpose of beam_flatten is to eliminate the blocks created by
beam_block, but it also does a few optimizations because at the
time the optimizations were added, beam_flatten was the most
convenient place.

Move the optimization that places `{move,Something,{x,0}}` before
`call` instructions from beam_flatten to beam_ssa_codegen.

This change will very slightly improve compilation times, and it
will also apply the optimization in more places. In particular,
a `{move,Literal,{x,0}}` would never be moved passed a `trim`
instruction before this change. Now it will.
Move allocation combining from beam_flatten to beam_ssa_codegen
Continuing the simplification of beam_flatten, move the optimization
that eliminates a test_heap instruction following a binary construction
by incorporating the allocation of the heap space into the bs_init*
instruction itself.

This change does not change the generated code in any way.

Also remove beam_utils:combine_heap_needs/2, because beam_flatten
was the last user of it.
Remove the last optimization from beam_flatten
It is not necessary to combine get_hd and get_tl instruction to
a get_list instruction. It will be done in beam_z.

After this change, beam_flatten does nothing more than eliminating
the blocks.
beam_clean: Use maps and cerl_sets instead of dict and sets
Using maps and cerl_sets instead of dict and sets will slightly
speed up the beam_clean pass for modules with many functions
and/or calls to local functions.
beam_ssa_pre_codegen: Fix bug in sanitization of get_map_element
The source map for `get_map_element` is not supposed to be a literal,
and the sanitization code is supposed to ensure that.

The sanitization incorrectly translated this code:

    Map = get_tuple_element literal {ok,#{key=>value}}, literal 1
    Var = get_map_element Map, literal {a,key}

To this code:

    Var = get_map_element literal #{key=>value}, literal {a,key}

Make sure to substitute the arguments for `get_map_element` before
looking for a literal source map.
beam_validator: Disallow literal arguments for certain instructions
Disallow a literal map source for get_map_elements. There is currently
runtime support for get_map with a literal map source, but by
forbidding it in OTP 22, the runtime support could be removed in a
future release (perhaps OTP 24).

Also verify that the source arguments for get_list, get_hd, get_tl,
and get_tuple_element are not literals. Literals are not supported for
those instructions in the runtime system; verifying it in
beam_validator is a convenience so that this kind of bug will
be detected already during compilation.
Move bif_to_test/3 from beam_utils to beam_ssa_codegen
The only caller of bif_to_test/3 is beam_ssa_codegen.
Move peephole optimization from beam_block to beam_a
Moving away this optimization makes beam_block do one thing
and one thing only -- creating blocks.

@bjorng bjorng self-assigned this Sep 26, 2018

@bjorng bjorng added the testing label Sep 27, 2018

@bjorng bjorng merged commit ba7e9c3 into erlang:master Oct 1, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
license/cla Contributor License Agreement is signed.

@bjorng bjorng deleted the bjorng:bjorn/compiler/misc-cleanups branch Oct 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment