Repository navigation
Only run trait specialization passes when compilation units contain inline traits - #26842
Conversation
|
I think you need to also do this for |
1b5e9dc to
09f5b52
Compare
|
It's better now but You can get a flame graph by following instructions here: https://github.com/lampepfl/scala3-benchmarks/tree/main#using-jmhs-profilers To publish a compiler from a commit, run |
|
@jmesyou will you have time to do this soon? it really should be in 3.10-RC1 which will be released soon |
|
Yes, I'm actively working on this right now, I should have an update today update: Sorry for the delay, I ended up doing a small refactor. We were doing some checks for whether programs using inline or specialized traits were valid inside trait Foo[T: Specialized]so when the pass didn't run, some negative test cases failed. Combined with the fact we also do some semantic checks in w.r.t to the profiles, I wanted to make a note of what methods were hot for the record.
I profiled this change on a few benchmarks and the previous problematic methods no longer show up in the profiles but I did not do a full benchmark run. flamegraph for reference. There are some regressions on ScalaJS from the CI, I'm not sure if they are related to this change but I will take a look. |
09f5b52 to
d3d961e
Compare
d3d961e to
c6c7d15
Compare
e492506 to
a38082a
Compare
|
Only 1 remaining failure in |
|
also bat signal @sjrd for why a single Scala.js test fails? |
|
No idea. Does |
Not particularly ): I don't believe |
a38082a to
794e0d7
Compare
|
There's now a cyclic error in community_build_b as well, so it seems something's not right |
086be47 to
ac01a54
Compare
|
|
|
@SolalPirelli There's a remaining failure I am not able to reproduce locally |
bb607c2 to
fb3d4ba
Compare
|
I just merged a PR to delete that test (and filed an issue to resurrect it), it wasn't related to this. |
SolalPirelli
left a comment
There was a problem hiding this comment.
Perf and flamegraph look good locally. Thanks!
|
The remaining failure is due to us running out of space to encode phase IDs in period IDs... I'll open a PR to fix it |
Needed for #26842 ## Have you relied on LLM-based tools in this contribution? No ## How was the solution tested? Covered by existing tests (this is a refactoring)
e266069 to
c99c5c9
Compare
This commit adds a new field to CompilationUnits to check whether the unit contains an inline trait. This property is then used by inline trait specific passes to determine whether or not they need to run. There is an additional refactor that reorganized semantic checks for inline and specialized traits into its own pass as they were previously in transform passes. Because these transform passes do not run anymore, these checks need to be relocated elsewhere.
c99c5c9 to
4cfa4d9
Compare
|
CI failure from HTTP 502 error from downloading a dependency ): |
- Run the `-Yqualified-types-anf` variants of the qualified-types pos and run tests as their own `posQualifiedTypesAnf` and `runQualifiedTypesAnf` tests. Compiling the same files twice in one group writes them to the same output directories, which now fails with `FileAlreadyExistsException` (scala#27311), and `aggregateTests` now requires all aggregated tests to share one group (scala#26911). - Update `tests/printing/qualified-types-anf/anf.check`: the inline-trait phases no longer run on units without inline traits (scala#26842), so the tree printed after `qualifiedTypesANF` is no longer rebuilt, wrapped in `package <empty>`, nor printed with `x.type` singletons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The library projects passed their own source directories as -sourcepath so that `Definitions#init`, which runs before any compilation unit is entered, finds package `scala` on a from-scratch build. That only needs the package to exist: with -verbose, init lists `scala` and forces no library source. On incremental builds the real sourcepath is harmful. SymbolLoaders pairs sources with classfiles by name, so a file like `IArray.scala`, whose only class is `IArray$package`, is always entered from source instead of read from the output directory. Since scala#26842 the Namer completer of the source-entered opaque type `IArray` first runs during erasure, where it cycles: CyclicReference: Cyclic reference involving type IArray Any comment-only edit to a file in package `scala` triggered it, in both scala-library-nonbootstrapped and scala-library-bootstrapped. With 3.10.0-RC1 the same setup crashed differently, with a ClassCastException in ExtractDependencies. Point -sourcepath at a checked-in directory containing only an empty `scala` package instead. A clean build produces the same classfiles apart from the source-table order in the TASTy of `scala.*:`, and incremental recompiles of language.scala, StringContext.scala, IArray.scala and TrieMap.scala now succeed. The underlying compiler bug (completing a sourcepath-entered opaque type at or after ElimOpaque) is reproducible outside the stdlib and should be reported separately. Investigated, implemented and tested with Claude Code (LLM).
The library projects passed their own source directories as -sourcepath so that `Definitions#init`, which runs before any compilation unit is entered, finds package `scala` on a from-scratch build. That only needs the package to exist: with -verbose, init lists `scala` and forces no library source. On incremental builds the real sourcepath is harmful. SymbolLoaders pairs sources with classfiles by name, so a file like `IArray.scala`, whose only class is `IArray$package`, is always entered from source instead of read from the output directory. Since scala#26842 the Namer completer of the source-entered opaque type `IArray` first runs during erasure, where it cycles: CyclicReference: Cyclic reference involving type IArray Any comment-only edit to a file in package `scala` triggered it, in both scala-library-nonbootstrapped and scala-library-bootstrapped. With 3.10.0-RC1 the same setup crashed differently, with a ClassCastException in ExtractDependencies. Point -sourcepath at a checked-in directory containing only an empty `scala` package instead. A clean build produces the same classfiles apart from the source-table order in the TASTy of `scala.*:`, and incremental recompiles of language.scala, StringContext.scala, IArray.scala and TrieMap.scala now succeed. An empty sourcepath also keeps the build closer to typical Zinc usage, since a populated -sourcepath under Zinc is likely un- or under-tested. The underlying compiler bug, completing a sourcepath-entered opaque type at or after ElimOpaque, reproduces outside the stdlib and is reported as scala#27408. Investigated, implemented and tested with Claude Code (LLM).
The library projects passed their own source directories as -sourcepath so that `Definitions#init`, which runs before any compilation unit is entered, finds package `scala` on a from-scratch build. That only needs the package to exist: with -verbose, init lists `scala` and forces no library source. On incremental builds the real sourcepath is harmful. SymbolLoaders pairs sources with classfiles by name, so a file like `IArray.scala`, whose only class is `IArray$package`, is always entered from source instead of read from the output directory. Since scala#26842 the Namer completer of the source-entered opaque type `IArray` first runs during erasure, where it cycles: CyclicReference: Cyclic reference involving type IArray Any comment-only edit to a file in package `scala` triggered it, in both scala-library-nonbootstrapped and scala-library-bootstrapped. With 3.10.0-RC1 the same setup crashed differently, with a ClassCastException in ExtractDependencies. Point -sourcepath at a checked-in directory containing only an empty `scala` package instead. A clean build produces the same classfiles apart from the source-table order in the TASTy of `scala.*:`, and incremental recompiles of language.scala, StringContext.scala, IArray.scala and TrieMap.scala now succeed. An empty sourcepath also keeps the build closer to typical Zinc usage, since a populated -sourcepath under Zinc is likely un- or under-tested. The underlying compiler bug, completing a sourcepath-entered opaque type at or after ElimOpaque, reproduces outside the stdlib and is reported as scala#27408. Investigated, implemented and tested with Claude Code (LLM).
Needed for scala#26842 ## Have you relied on LLM-based tools in this contribution? No ## How was the solution tested? Covered by existing tests (this is a refactoring) [Cherry-picked f03673c]
…nline traits (scala#26842) This commit adds a new field to the CompilationUnit to check whether the unit contains an inline trait. This property is then used by inline trait specific passes to determine whether or not they need to run. Fixes a compiler performance regression caused by unnecessarily running compiler passes when no inline traits are present. *will add benchmarking results as soon as they are available* <!-- where #XYZ is the issue number; create as draft if this is not in a reviewable state yet; do not paste LLM output here, describe the PR in your own words; if in doubt about your contribution, refer to: https://github.com/scala/scala3/blob/main/CONTRIBUTING.md; don't forget to sign the CLA: https://cla.scala-lang.org/scala/scala3 --> ## Have you relied on LLM-based tools in this contribution? No ## How was the solution tested? Covered by existing tests [Cherry-picked 63666da]

This commit adds a new field to the CompilationUnit to check whether the unit contains an inline trait. This property is then used by inline trait specific passes to determine whether or not they need to run.
Fixes a compiler performance regression caused by unnecessarily running compiler passes when no inline traits are present.
will add benchmarking results as soon as they are available
Have you relied on LLM-based tools in this contribution?
No
How was the solution tested?
Covered by existing tests