Apply type optimizations across local function calls#2100
Merged
jhogberg merged 8 commits intoJan 24, 2019
Conversation
A switch is equivalent to a series of '=:=', so we have to subtract each value individually from the type. Subtracting a join risks removing too much type information, and managed to narrow "number" into "float" in the attached test case.
If the match instruction was already marked as a skip, we'd ruin its argument list.
Contributor
Author
|
9daffa0 revealed some funny side-effects from propagating the 'none' type across functions. I'm working on fixing them but it might take some time. |
9c8b886 to
95a4452
Compare
bjorng
approved these changes
Jan 24, 2019
This serves as a base for the upcoming module-level type optimization, but may come in handy for other passes like beam_ssa_funs and beam_ssa_bsm that have their own ad-hoc implementations.
This commit lets the type optimization pass work across functions, tracking return and argument types to eliminate redundant tests.
95a4452 to
294d66a
Compare
bjorng
added a commit
to bjorng/otp
that referenced
this pull request
Feb 26, 2021
The `error_handler` module in the Kernel application has a call to the
`int` module in the Debugger application. That call is only there to
make the Debugger work. To avoid that Xref sees Debugger as a
dependency for Kernel, the call to the `int` module is obfuscated in
the following way:
breakpoint(Module, Func, Args) ->
(int()):eval(Module, Func, Args).
int() -> int.
That is, the call will show up as a call to an unknown module in
Xref.
With the improved whole-module type analysis introduced in
294d66a (erlang#2100), the compiler sees through the obfuscation
and rewrites the code to:
breakpoint(Module, Func, Args) ->
int:eval(Module, Func, Args).
It would be fun to solve this issue by introducing further obfuscations,
but such tricks could stop working in the future when the compiler is
improved. Instead, turn off whole-module type analysis by compiling
the module with the `no_module_opt` option.
Resolves erlang#4546
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current type pass works on a per-function level and assumes that every argument and return value could be anything, which means they have to be type-checked before they're used. This is a bit inefficient as most functions always return something of the same type, and their argument types seldom differ.
This PR makes the type pass track the return and argument types of local functions, letting us eliminate many redundant type checks.