Skip to content

Simplify and correctify calculation of the InnerClass attribute #15153

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

Merged
merged 2 commits into from
May 18, 2022

Conversation

WojciechMazur
Copy link
Contributor

This PR is a part of porting the backend improvements introduced in Scala 2 #14912 and corresponds to scala/scala#4807
Original PR description:

The InnerClass attribute needs to contain an entry for every nested
class that is defined or referenced in a class. Details are in a
doc comment in BTypes.scala.

Instead of collecting ClassBTypes of nested classes into a hash map
during code generation, traverse the class before writing it out to
disk. The previous approach was incorrect as soon as the generated
bytecode was modified by the optimzier (DCE, inlining).

Fixes https://github.com/scala/scala-dev/issues/21.

Similarly to the original repo CoreBTypes naming convention has been unified and cleaned up from not used references.
The original collection of nested classes signatures was replaced with extended version of NestedClassesCollector present in the current Scala 2 main branch https://github.com/scala/scala/blob/724be0e9425b9ad07c244d25efdad695d75abbcf/src/compiler/scala/tools/nsc/backend/jvm/analysis/BackendUtils.scala#L790
Generation of ClassBType for mirrors has been added by porting implementation from Scala 2 and definitions of MethodHandles has been updated to make sure that given ClassBTypes are loaded and reachable. This is needed since in Scala 3 we only use ClassBTypes created from Symbols, whereas in Scala 2 their instances could have been also loaded from Classfiles.

The InnerClass attribute needs to contain an entry for every nested
class that is defined or referenced in a class. Details are in a
doc comment in BTypes.scala.

Instead of collecting ClassBTypes of nested classes into a hash map
during code generation, traverse the class before writing it out to
disk. The previous approach was incorrect as soon as the generated
bytecode was modified by the optimzier (DCE, inlining).
@WojciechMazur WojciechMazur force-pushed the backport/scala-pr-4807 branch from bda8508 to 0aa184d Compare May 10, 2022 11:00
@WojciechMazur WojciechMazur requested a review from Kordyjan May 10, 2022 14:32
@Kordyjan Kordyjan merged commit 72352dc into scala:main May 18, 2022
@WojciechMazur WojciechMazur deleted the backport/scala-pr-4807 branch May 18, 2022 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants