Skip to content

Add a test to track @experimental definitions #14944

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 1 commit into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import scala.quoted.*
import scala.tasty.inspector.*

val experimentalDefinitionInLibrary = Set(

// README
// - Definitions should be grouped under a language feature or API
// - API definitions that must be stabilized at the same time should be added in the same line
// - Language definitions are assumed to be stabilized all at once unless stated otherwise


//// New feature: Safe Exceptions
// Can be stabilized when safe exeptions language feature is stabilized.
"scala.CanThrow",
"scala.unsafeExceptions", "scala.unsafeExceptions$",
"scala.runtime.$throws$package$.$throws",

//// New feature: Tupled Functions
// Can be stabilized when language feature is stabilized.
// Needs user feedback.
// Needs generalization to polymorphic types (at least proof of concept that shows that that design is compatible).
"scala.runtime.TupledFunctions",
"scala.runtime.TupledFunctions$",
"scala.util.TupledFunction",
"scala.util.TupledFunction$",

//// New feature: main annotation generalization
// Can be stabilized when language feature is stabilized.
// Needs user feedback.
// Should argGetter/varargGetter be simplified?
// Should we have better support for main annotation macros?
"scala.annotation.MainAnnotation",
"scala.annotation.MainAnnotation$",

//// New APIs: compiletime.ops
// Can be stabilized in 3.3.0 or later.
// Needs user feedback
"scala.compiletime.ops.any$.IsConst",
"scala.compiletime.ops.any$.ToString",
"scala.compiletime.ops.double", "scala.compiletime.ops.double$",
"scala.compiletime.ops.float",
"scala.compiletime.ops.float$",
"scala.compiletime.ops.int$.NumberOfLeadingZeros",
"scala.compiletime.ops.int$.ToDouble",
"scala.compiletime.ops.int$.ToFloat",
"scala.compiletime.ops.int$.ToLong",
"scala.compiletime.ops.long", "scala.compiletime.ops.long$",
"scala.compiletime.ops.string$.Length",
"scala.compiletime.ops.string$.Matches",
"scala.compiletime.ops.string$.Substring",

//// New APIs: Mirror
// Can be stabilized in 3.2.0 or later.
"scala.deriving.Mirror$.fromTuple", // Probably for 3.2.0
"scala.deriving.Mirror$.fromProductTyped", // This API is a bit convoluted. We may need some more feedback before we can stabilize it.

//// New APIs: Tuples
// Should be stabilized in 3.2.0.
"scala.Tuple.:*", "scala.Tuple$.Append", "scala.runtime.Tuples$.append",
"scala.NonEmptyTuple.init", "scala.Tuple$.Init", "scala.runtime.Tuples$.init",
"scala.Tuple$.Last", "scala.NonEmptyTuple.last", "scala.runtime.Tuples$.last",

//// New APIs: Quotes
// Should be stabilized in 3.2.0.
"scala.quoted.Quotes.reflectModule.AppliedTypeModule.apply",
"scala.quoted.Quotes.reflectModule.SymbolMethods.asQuotes",
"scala.quoted.Quotes.reflectModule.SymbolMethods.termRef",
"scala.quoted.Quotes.reflectModule.SymbolMethods.typeRef",
"scala.quoted.Quotes.reflectModule.TypeReprMethods.substituteTypes",
"scala.quoted.Quotes.reflectModule.TypeReprMethods.typeArgs",
"scala.quoted.Quotes.reflectModule.TypeTreeModule.ref",
// Can be stabilized in 3.2.0 (unsure) or later
"scala.quoted.Quotes.reflectModule.CompilationInfoModule.XmacroSettings",
// Cant be stabilized yet.
// Need newClass variant that can add constructor parameters.
// Need experimental annotation macros to check that design works.
"scala.quoted.Quotes.reflectModule.ClassDefModule.apply",
"scala.quoted.Quotes.reflectModule.SymbolModule.newClass",
Comment on lines +74 to +78
Copy link
Member

Choose a reason for hiding this comment

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

I guess this will need to be discussed, but if we want Scala 3.2 to be an LTS, we'll want to have these APIs stabilized by then. I don't think they preclude future additions that will benefit annotation macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these comments are subject to change in the LTS discussions. I just added the constraints/concerns we had discussed so far so that I am not the only one that knows them.

)


@main def Test = {
val inspector = new Inspector {
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit = {
import quotes.reflect.*
val experimentalAnnot = Symbol.requiredClass("scala.annotation.experimental")
object AccumulateExperimentalDefs extends TreeAccumulator[Set[Symbol]]:
def foldTree(expDefs: Set[Symbol], tree: Tree)(owner: Symbol): Set[Symbol] =
tree match
case tree: Definition if tree.symbol.hasAnnotation(experimentalAnnot) => foldOverTree(expDefs + tree.symbol, tree)(owner)
case _ => foldOverTree(expDefs, tree)(owner)

val experimentalDefinitionsSyms = tastys.foldLeft(Set.empty[Symbol]) { (acc, tasty) =>
AccumulateExperimentalDefs.foldTree(acc, tasty.ast)(Symbol.spliceOwner)
}
val experimentalDefinitions = experimentalDefinitionsSyms.map(_.fullName)
val missingFromList = experimentalDefinitions -- experimentalDefinitionInLibrary
val missingInLibrary = experimentalDefinitionInLibrary -- experimentalDefinitions
assert(missingFromList.isEmpty,
s"""Failed @experimental definitions check
|
|Found @experimental definition in library not listed:
|${missingFromList.toSeq.sorted.mkString("\n")}
|
|If added new experimental defintions to the library, add them to the list in tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala
|
|Test only: sbt "scala3-bootstrapped/testCompilation tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala"
|""".stripMargin
)
assert(missingInLibrary.isEmpty,
s"""Failed @experimental definitions check
|
|Listed @experimental definition was not found in the library
|${missingInLibrary.toSeq.sorted.mkString("\n")}
|
|If experimental definition was removed or stabilized, remove from the list in tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala
|
|Test only: sbt "scala3-bootstrapped/testCompilation tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala"
|""".stripMargin
)
}
}

// Artefact of the current test infrastructure
// TODO improve infrastructure to avoid needing this code on each test
val libJarClasspath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(x => x.contains("scala3-library-bootstrapped") && x.endsWith(".jar")).get

TastyInspector.inspectTastyFilesInJar(libJarClasspath)(inspector)
}