Skip to content
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
merged 9 commits into from
Oct 1, 2018

Conversation

bjorng
Copy link
Contributor

@bjorng 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.

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.
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.
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.
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.
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.
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.
The only caller of bif_to_test/3 is beam_ssa_codegen.
Moving away this optimization makes beam_block do one thing
and one thing only -- creating blocks.
@bjorng bjorng added team:VM Assigned to OTP team VM enhancement labels Sep 26, 2018
@bjorng bjorng self-assigned this Sep 26, 2018
@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Sep 27, 2018
@bjorng bjorng merged commit ba7e9c3 into erlang:master Oct 1, 2018
@bjorng bjorng deleted the bjorn/compiler/misc-cleanups branch October 1, 2018 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant