Skip to content

Inline Traits & Specialized Traits#26156

Draft
starswap wants to merge 325 commits into
scala:mainfrom
starswap:specialized-inline-traits
Draft

Inline Traits & Specialized Traits#26156
starswap wants to merge 325 commits into
scala:mainfrom
starswap:specialized-inline-traits

Conversation

@starswap
Copy link
Copy Markdown
Contributor

@starswap starswap commented May 25, 2026

Final year master's project at EPFL. Introduces specialization for Scala 3 as an experimental feature, via:

The latest specification for each of these is included in docs accompanying the PR. To see a demo of the generated code and speed gain offered, try tools/benchmarks/SpecializedTraitsBenchmark.scala

How much have you relied on LLM-based tools in this contribution?

Moderately, for debugging.

How was the solution tested?

New automated tests

starswap added 30 commits March 30, 2026 13:23
…s from the parent traits later so they need to live in the children
… the bodies of methods defined inside inline traits
@starswap starswap force-pushed the specialized-inline-traits branch from 78aec78 to afd9b33 Compare June 5, 2026 14:46
starswap added 7 commits June 5, 2026 16:46
Opaque types can appear in inline traits. This is not the case for inline methods, so we run into the new case that a LazyBodyAnnotation contains an inline trait. This causes a problem because the LazyBodyAnnotation and the ordinary code both complete the opaque type's LazyRefs which causes us to throw a CyclicReference. It turns out that this CyclicReference throw was originally created for a test case which we no longer reject (typer evolved and we now accept tests/pos/i9052. Therefore we conclude that this CyclicReference is no longer really needed. Removing it allows us to support opaque types in inline traits but it does change the error behaviour of two other tests (modified in this commit). I claim that the resulting errors are acceptable for both of these cases. In particular, the issues they correspond to were both crashes, and we still don't crash without the cyclic reference error. The errors we throw are modified but I think reasonable; feel free to check for yourself.

// Because opaque types can appear in inline traits and these are only allowed to be completed once (otherwise cyclic reference error)
// we need to force the body stats now if we have an inline trait so that we don't complete them twice, once in the LazyBodyAnnot and once
// in the main code.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Check: Is this ok? I'm not sure if we can do this because maybe it is actually necessary to read the contents of the body annotation in the context of the body annotation. It seems to pass tests but I'm not sure if it's ok. Also this code was copied from the inline methods case so it is possible not all of it is needed for inline traits.

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.

1 participant