Skip to content

Only run trait specialization passes when compilation units contain inline traits - #26842

Merged
SolalPirelli merged 1 commit into
scala:mainfrom
jmesyou:feature/specialization/hasSpecializations
Sep 8, 2026
Merged

SolalPirelli merged 1 commit into
scala:mainfrom
jmesyou:feature/specialization/hasSpecializations

Conversation

@jmesyou

@jmesyou jmesyou commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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

@SolalPirelli

Copy link
Copy Markdown
Contributor

I think you need to also do this for PruneInlinedMethods and PruneInlineTraits, I see a lot of time spent there in a flame graph compiling the helloWorld benchmark

@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch from 1b5e9dc to 09f5b52 Compare August 18, 2026 07:54
@SolalPirelli

Copy link
Copy Markdown
Contributor

It's better now but PruneInlineTraits is still being called to transform symbols.

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 BENCHMARKBUILD=yes sbt clean community-build/prepareCommunityBuild

@Gedochao Gedochao added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Aug 18, 2026
@Gedochao Gedochao added this to the 3.10.0 milestone Aug 18, 2026
@SolalPirelli

Copy link
Copy Markdown
Contributor

@jmesyou will you have time to do this soon? it really should be in 3.10-RC1 which will be released soon

@jmesyou

jmesyou commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor Author

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 DesugarSpecializedTraits:

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 PostTyper, I decided to create a new MiniPhase CheckInlineTraits that consolidate these checks and updates the hasSpecializations for the compilation unit. I think there is enough code both DesugarSpecializedTraits and PostTyper to justify this.

w.r.t to the profiles, I wanted to make a note of what methods were hot for the record.
In desugarSpecializedTraits, collectReferencedSpecializations was the hottest method so that may warrant a look later but currently we just don't transform the unit if there are no specializations present in this change.

isEraseable was also fairly slow in PruneInlineTraits but reordered the conditions to short circuit fixed that.

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.
areWeFastYet.html

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.

@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch from 09f5b52 to d3d961e Compare August 20, 2026 16:23
@jmesyou
jmesyou marked this pull request as draft August 20, 2026 16:29
@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch from d3d961e to c6c7d15 Compare August 21, 2026 20:50
@jmesyou
jmesyou marked this pull request as ready for review August 22, 2026 18:35
@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch 3 times, most recently from e492506 to a38082a Compare August 25, 2026 22:27
@jmesyou

jmesyou commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Only 1 remaining failure in scalajs, tests/run/transparent. Still unsure why this fails

@SolalPirelli

Copy link
Copy Markdown
Contributor

Good progress, it's clearly faster than main. PruneInlinedMethods.transform still takes a fair amount of time for helloWorld. Looks like it needs an override of infoMayChange ?

image

@SolalPirelli

Copy link
Copy Markdown
Contributor

also bat signal @sjrd for why a single Scala.js test fails?

@sjrd

sjrd commented Aug 26, 2026

Copy link
Copy Markdown
Member

No idea. Does -explain help?

@jmesyou

jmesyou commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

@sjrd

checking tests/run/transparent/inlines_1.scala after phase MegaPhase{pruneErasedDefs, uninitialized, inlinePatterns, vcInlineMethods, seqLiterals, intercepted, getters, specializeFunctions, specializeTuples, collectNullableFields, elimOuterSelect, resolveSuper, functionXXLForwarders, paramForwarding, genericTuples, letOverApply, arrayConstructors, simplifySynchronized}
[[syntax trees at end of                    Ycheck]] // tests/run/transparent/inlines_1.scala: unchanged since MegaPhase{pruneErasedDefs, uninitialized, inlinePatterns, vcInlineMethods, seqLiterals, intercepted, getters, specializeFunctions, specializeTuples, collectNullableFields, elimOuterSelect, resolveSuper, functionXXLForwarders, paramForwarding, genericTuples, letOverApply, arrayConstructors, simplifySynchronized}
-- [E046] Cyclic Error: tests/run/transparent/inlines_1.scala:11:13 ----------------------------------------------------
11 |  val hits = new mutable.HashMap[String, Int] {
   |             ^
   |Cyclic reference involving class AbstractIterator
   |
   |The error occurred while trying to compute the base classes of class HashMapIterator
   |  which required to compute the base classes of class AbstractIterator
   |  which required to compute the base classes of class GroupedIterator
   |  which required to compute the base classes of class AbstractIterator
   |
   |Stacktrace:
   |    dotty.tools.dotc.core.CyclicReference$.apply(TypeErrors.scala:152)
   |    dotty.tools.dotc.core.SymDenotations$BaseDataImpl.apply(SymDenotations.scala:3125)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseData(SymDenotations.scala:2083)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseClasses(SymDenotations.scala:2090)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.traverse$1(SymDenotations.scala:2111)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeBaseData(SymDenotations.scala:2136)
   |    dotty.tools.dotc.core.SymDenotations$BaseDataImpl.apply(SymDenotations.scala:3129)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseData(SymDenotations.scala:2083)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseClassSet(SymDenotations.scala:2099)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.derivesFrom(SymDenotations.scala:2143)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.isValueClass(SymDenotations.scala:2182)
   |    dotty.tools.dotc.core.SymUtils.isDerivedValueClass(SymUtils.scala:85)
   |    dotty.tools.dotc.transform.ExtensionMethods.transform(ExtensionMethods.scala:59)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:840)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:127)
   |    dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:121)
   |    dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:112)
   |    dotty.tools.dotc.transform.sjs.ExplicitJSClasses.isJSClass(ExplicitJSClasses.scala:269)
   |    dotty.tools.dotc.transform.sjs.ExplicitJSClasses.$anonfun$2(ExplicitJSClasses.scala:340)
   |    dotty.tools.dotc.core.Scopes$Scope.filter(Scopes.scala:102)
   |    dotty.tools.dotc.transform.sjs.ExplicitJSClasses.transformInfo(ExplicitJSClasses.scala:340)
   |    dotty.tools.dotc.core.DenotTransformers$InfoTransformer.transform(DenotTransformers.scala:44)
   |    dotty.tools.dotc.core.DenotTransformers$InfoTransformer.transform$(DenotTransformers.scala:36)
   |    dotty.tools.dotc.transform.sjs.ExplicitJSClasses.transform(ExplicitJSClasses.scala:395)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:840)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:127)
   |    dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:121)
   |    dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:112)
   |    dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:128)
   |    dotty.tools.dotc.core.Types$Type.isProvisional(Types.scala:153)
   |    dotty.tools.dotc.core.Types$AppliedType.superType(Types.scala:4688)
   |    dotty.tools.dotc.core.Types$Type.classSymbol(Types.scala:634)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.traverse$1(SymDenotations.scala:2110)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeBaseData(SymDenotations.scala:2136)
   |    dotty.tools.dotc.core.SymDenotations$BaseDataImpl.apply(SymDenotations.scala:3129)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseData(SymDenotations.scala:2083)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseClasses(SymDenotations.scala:2090)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.traverse$1(SymDenotations.scala:2111)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeBaseData(SymDenotations.scala:2136)
   |    dotty.tools.dotc.core.SymDenotations$BaseDataImpl.apply(SymDenotations.scala:3129)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseData(SymDenotations.scala:2083)
   |    dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseClasses(SymDenotations.scala:2090)
   |    dotty.tools.dotc.core.SymUtils.directlyInheritedTraits(SymUtils.scala:35)
   |    dotty.tools.dotc.core.SymUtils.mixins(SymUtils.scala:49)
   |    dotty.tools.dotc.transform.ExplicitOuter$.dotty$tools$dotc$transform$ExplicitOuter$$$needsOuterAlways(ExplicitOuter.scala:221)
   |    dotty.tools.dotc.transform.ExplicitOuter.transformInfo(ExplicitOuter.scala:51)
   |    dotty.tools.dotc.core.DenotTransformers$InfoTransformer.transform(DenotTransformers.scala:44)
   |    dotty.tools.dotc.core.DenotTransformers$InfoTransformer.transform$(DenotTransformers.scala:36)
   |    dotty.tools.dotc.transform.ExplicitOuter.transform(ExplicitOuter.scala:37)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:840)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:857)
   |    dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:886)
   |    dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:127)
   |    dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:121)
   |    dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:112)
   |    dotty.tools.dotc.transform.OverridingPairs$Cursor.fillDecls$1(OverridingPairs.scala:63)
   |    dotty.tools.dotc.transform.OverridingPairs$Cursor.fillDecls$1(OverridingPairs.scala:60)
   |    dotty.tools.dotc.transform.OverridingPairs$Cursor.<init>(OverridingPairs.scala:70)
   |    dotty.tools.dotc.transform.Bridges$BridgesCursor.<init>(Bridges.scala:26)
   |    dotty.tools.dotc.transform.Bridges.add(Bridges.scala:186)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1136)
   |    dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3533)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1114)
   |    dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3938)
   |    dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3942)
   |    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:4044)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4127)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4132)
   |    dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:4154)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1138)
   |    dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1591)
   |    dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1595)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedBlock(Erasure.scala:836)
   |    dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3958)
   |    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:4045)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4127)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4132)
   |    dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:4244)
   |    dotty.tools.dotc.typer.Typer.$anonfun$68(Typer.scala:3198)
   |    dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:3198)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:989)
   |    dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3932)
   |    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:4044)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4127)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4132)
   |    dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:4154)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1138)
   |    dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3533)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1114)
   |    dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3938)
   |    dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3942)
   |    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:4044)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4127)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4132)
   |    dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:4154)
   |    dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1138)
   |    dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3712)
   |    dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3984)
   |    dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:4045)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4127)
   |    dotty.tools.dotc.typer.Typer.typed(Typer.scala:4132)
   |    dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:4244)
   |    dotty.tools.dotc.transform.Erasure.run(Erasure.scala:144)
   |    dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:411)
   |    scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
   |    scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
   |    scala.collection.immutable.List.foreach(List.scala:331)
   |    dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:403)
   |    dotty.tools.dotc.Run.runPhases$1(Run.scala:420)
   |    dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:462)
   |    dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:462)
   |    dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:525)
   |    dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:475)
   |    dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
   |    dotty.tools.dotc.Run.compileUnits(Run.scala:475)
   |    dotty.tools.dotc.Run.compileSources(Run.scala:348)
   |    dotty.tools.dotc.Run.compile(Run.scala:333)
   |    dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
   |    dotty.tools.dotc.Driver.process(Driver.scala:216)
   |    dotty.tools.dotc.Driver.process(Driver.scala:184)
   |    dotty.tools.vulpix.ParallelTesting$Test.compile(ParallelTesting.scala:574)
   |    dotty.tools.vulpix.ParallelTesting$CompilationLogic.compileTestSource$$anonfun$1$$anonfun$1(ParallelTesting.scala:263)
   |    scala.collection.immutable.List.map(List.scala:244)
   |    dotty.tools.vulpix.ParallelTesting$CompilationLogic.compileTestSource$$anonfun$1(ParallelTesting.scala:261)
   |    scala.util.Try$.apply(Try.scala:256)
   |    dotty.tools.vulpix.ParallelTesting$CompilationLogic.dotty$tools$vulpix$ParallelTesting$CompilationLogic$$compileTestSource(ParallelTesting.scala:266)
   |    dotty.tools.vulpix.ParallelTesting$$anon$4.checkTestSource$$anonfun$1(ParallelTesting.scala:297)
   |    dotty.tools.vulpix.ParallelTesting$$anon$4.checkTestSource$$anonfun$adapted$1(ParallelTesting.scala:300)
   |    scala.Function0.apply$mcV$sp(Function0.scala:42)
   |    dotty.tools.vulpix.ParallelTesting$Test.tryCompile(ParallelTesting.scala:484)
   |    dotty.tools.vulpix.ParallelTesting$$anon$4.checkTestSource(ParallelTesting.scala:300)
   |    dotty.tools.vulpix.ParallelTesting$Test$LoggedRunnable.run(ParallelTesting.scala:380)
   |    dotty.tools.vulpix.ParallelTesting$Test$LoggedRunnable.run$(ParallelTesting.scala:362)
   |    dotty.tools.vulpix.ParallelTesting$$anon$4.run(ParallelTesting.scala:295)
   |    java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1375)
   |    java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
   |    java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
   |    java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
   |    java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
   |    java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
   |--------------------------------------------------------------------------------------------------------------------
   | Explanation (enabled by `-explain`)
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   | class AbstractIterator is declared as part of a cycle which makes it impossible for the
   | compiler to decide upon AbstractIterator's type.
   | To avoid this error, try giving AbstractIterator an explicit type.

Not particularly ): I don't believe AbstractIterator is actually part of a cycle. Appending -Ylog:all makes this problem go away, which is unusual.

@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch from a38082a to 794e0d7 Compare August 27, 2026 06:12
@SolalPirelli

Copy link
Copy Markdown
Contributor

There's now a cyclic error in community_build_b as well, so it seems something's not right

@jmesyou

jmesyou commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

cyclic compilation issue fixed. community build b still exhibiting a cyclic issue but the scalaJS issue is fixed

@WojciechMazur WojciechMazur linked an issue Sep 5, 2026 that may be closed by this pull request
@jmesyou

jmesyou commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@SolalPirelli There's a remaining failure I am not able to reproduce locally tests/neg/stackoverflowmacro, it's related to fuel and perhaps related to the same set of cyclic denotation issues, could you take a look?

@SolalPirelli
SolalPirelli force-pushed the feature/specialization/hasSpecializations branch from bb607c2 to fb3d4ba Compare September 8, 2026 09:04
@SolalPirelli

Copy link
Copy Markdown
Contributor

I just merged a PR to delete that test (and filed an issue to resurrect it), it wasn't related to this.

@SolalPirelli SolalPirelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf and flamegraph look good locally. Thanks!

@SolalPirelli

Copy link
Copy Markdown
Contributor

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

SolalPirelli added a commit that referenced this pull request Sep 8, 2026
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)
@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch from e266069 to c99c5c9 Compare September 8, 2026 15:17
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.
@jmesyou
jmesyou force-pushed the feature/specialization/hasSpecializations branch from c99c5c9 to 4cfa4d9 Compare September 8, 2026 15:17
@jmesyou

jmesyou commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

CI failure from HTTP 502 error from downloading a dependency ):

@SolalPirelli
SolalPirelli merged commit 63666da into scala:main Sep 8, 2026
77 of 78 checks passed
@WojciechMazur WojciechMazur added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels Sep 8, 2026
WojciechMazur added a commit that referenced this pull request Sep 9, 2026
… contain inline traits" to 3.10.0 (#27021)

Backports #26842 to the 3.10.0-RC2.

PR submitted by the release tooling.
@WojciechMazur WojciechMazur added backport:done This PR was successfully backported. and removed backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Sep 9, 2026
mbovel added a commit to mbovel/dotty that referenced this pull request Oct 21, 2026
- 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>
retronym added a commit to retronym/scala3 that referenced this pull request Oct 26, 2026
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).
retronym added a commit to retronym/scala3 that referenced this pull request Oct 26, 2026
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).
retronym added a commit to retronym/scala3 that referenced this pull request Nov 3, 2026
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).
alexarchambault pushed a commit to plasmon-scala/scala3 that referenced this pull request Nov 4, 2026
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]
alexarchambault pushed a commit to plasmon-scala/scala3 that referenced this pull request Nov 4, 2026
…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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:done This PR was successfully backported.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in circe/circe

5 participants