-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Avoid null checks when emitting "".== and SomeModule.== #2954
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
Conversation
Will be somewhat leaner after the next commit.
Although the same the code would be later optimized by -Yconst-opt, we can offer the same lean byte code to those compiling without that option by being more discerning when translating ==. This helps people using bytecode based code coverage tools such as jacoco that would emit "branch not covered" warnings for the impossible null check.
For which we can also elide the null check, and will in the next commit.
I'm happy to rework the tests a little, it will be a bit less brittle if we assert the absence of null check instructions. |
@retronym: rewriting those tests to test the specific property we care about would be very welcome. Also, please reopen once test failures are addressed. |
For the same reasons outlined in the previous commits.
- Directly count null checks, rather than diffing the textual bytecode of the entire method - Add a test to show that the LHS needs to be a direct module reference, not just a tree with a module type, to elide the null check.
@gkossakowski The latest push does both of those things :) I left the bytcode-diffing tests in the history as they might be easier to review, the the last commit switches to counting null check instructions. |
LGTM! I like the tests. |
LGTM as well! I'll hold the merge until build bot comes back and can verify this branch. |
Here are green builds for each commit 2bb960 https://scala-webapps.epfl.ch/jenkins/job/pr-scala/2632/ |
Avoid null checks when emitting "".== and SomeModule.==
Avoid null checks for "someLiteral".== and SomeModule.==. This has been implemented in GenICode in scala#2954. Introduces a trait to share code between GenICode and GenBCode. This is just a start, more such refactorings will come quite certainly.
Avoid null checks for "someLiteral".== and SomeModule.==. This has been implemented in GenICode in scala#2954. Introduces a trait to share code between GenICode and GenBCode. This is just a start, more such refactorings will come quite certainly.
The optimization is not correct for modules, https://issues.scala-lang.org/browse/SI-9655 |
Do we care? I mean, code where a module load returns FTR Scala.js considers this UB. |
well, define broken :) the example prints null, and behaves as specified
i'd love to make the assumption that module loads are always non-null. maybe we can, but it definitely changes program semantics. |
Although the same the code would be later optimized by -Yconst-opt,
we can offer the same lean byte code to those compiling without that
option by being more discerning when translating ==.
This helps people using bytecode based code coverage tools
such as jacoco that would emit "branch not covered" warnings
for the impossible null check.
Before:
After:
Review by @gkossakowski or @JamesIry, /cc @dragos