Skip to content

Port the Scala2 optimizer#25165

Draft
SolalPirelli wants to merge 31 commits intoscala:mainfrom
dotty-staging:port-optimizer
Draft

Port the Scala2 optimizer#25165
SolalPirelli wants to merge 31 commits intoscala:mainfrom
dotty-staging:port-optimizer

Conversation

@SolalPirelli
Copy link
Contributor

@SolalPirelli SolalPirelli commented Feb 2, 2026

Fixes #22667
Depends on #25187

Review commit by commit, the history has been heavily rewritten to facilitate that, individual commits mostly don't build. Commits until the tests are just porting stuff.

Noteworthy changes:

  • InlineInfo is now computed lazily, creating a ClassInfo only requires data necessary for this lazy computation. This avoids circular dependencies between some components.
  • SAM detection for inlining is now a lot simpler as we don't bother hardcoding known Java SAMs or detecting @FunctionalInterface, since it's just for inlining decisions it's OK if we are slightly off as long as reasonable cases behave reasonably

@SolalPirelli SolalPirelli force-pushed the port-optimizer branch 7 times, most recently from 4a50a97 to 61fef76 Compare February 12, 2026 15:57
@SolalPirelli SolalPirelli force-pushed the port-optimizer branch 4 times, most recently from 76ec8dc to b412ff9 Compare February 16, 2026 10:37
SolalPirelli added a commit that referenced this pull request Feb 16, 2026
Prerequisite for #25165, extracting the stuff that touches the backend
without actually being the optimizer, and cleaning up the overall
architecture so it can be layered (this is especially important when
adding back the optimizer so it's understandable...)

I realize this PR is a little larger than is reasonable, sorry about
that. Part of the point of the refactoring was that by following the
code flow and simplifying it I got an understanding of how the JVM
backend works...

Main changes:
- `BType` and its implementations are top-level now, no longer members
of a module-like class
- `CoreBTypes` is passed explicitly where needed
- `BTypesFromSymbols` integrated into `CoreBTypesFromSymbols` (since its
parent `BTypes` no longer exists)
- `CoreBTypesFromSymbols` moved to its own file
- `DottyBackendInterface` is an `object` only, the stateful stuff it did
has been inlined where it was needed
- (Most) classes now take their dependencies as constructor parameters,
instead of "magically" importing what they need from
`bTypes`/`int`/`postProcessor`. This makes dependencies explicit, and
allowed me to remove some unneeded cycles in the object graph
(especially in the next PR which is the optimizer)
- `BackendReporting` moved to its own file
- The `io` package no longer has a dependency on the `backend/jvm`
package (!!!)
- Cleanups of unnecessary parentheses etc.

There's a lot of extra cleanup that could be done, and that I'd like to
do once the optimizer is in, since we have many "utility" classes that
could be either a single class or split in a way that makes sense (e.g.,
`AsmUtils` is currently just about... logging). From what I understand
some of this dates back to the porting of the JVM backend to Dotty,
which introduced "temporary" interfaces to the rest of the compiler.

And more generally the overall state of the backend is spread across
many classes that often touch what should be each other's internals
(this is especially pronounced with the call graph, which will be added
with the optimizer), and it's not easy to follow the data flow.

 But that's for later.
@SolalPirelli SolalPirelli force-pushed the port-optimizer branch 5 times, most recently from 87b314c to c84b017 Compare February 18, 2026 08:11
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.

Port the Scala 2 bytecode-optimizer to Dotty

1 participant

Comments