-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
nicolasstucki
merged 1 commit into
scala:main
from
dotty-staging:add-experimental-checks
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) | ||
|
||
|
||
@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) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.