Skip to content

Commit

Permalink
Stick TASTy reading behind a -Ytasty-reader flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Nov 2, 2020
1 parent 56ac9d6 commit 3743cad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/internal/tastyreader.md
Expand Up @@ -8,6 +8,8 @@ TASTy is an intermediate representation of a Scala program after type checking a

### Compiler flags

- `-Ytasty-reader` enables the support for reading Scala 3's TASTy files.

- `-Ydebug-tasty` enables rich output when traversing tasty files, important for tracing the history of events when diagnosing errors.

- `-Ytasty-no-annotations` ignores all annotations on tasty symbols, may be useful for ignoring complex annotations that are unsupported, but will prevent safety checks for pattern matching.
Expand Down
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Expand Up @@ -261,6 +261,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
val YmacroFresh = BooleanSetting ("-Ymacro-global-fresh-names", "Should fresh names in macros be unique across all compilation units")
val YmacroAnnotations = BooleanSetting ("-Ymacro-annotations", "Enable support for macro annotations, formerly in macro paradise.")
val YtastyNoAnnotations = BooleanSetting("-Ytasty-no-annotations", "Disable support for reading annotations from TASTy, this will prevent safety features such as pattern match exhaustivity and reachability analysis.")
val YtastyReader = BooleanSetting("-Ytasty-reader", "Enable support for reading Scala 3's TASTy files, allowing consumption of libraries compiled with Scala 3 (provided they don't use any Scala 3 only features).")
val Yreplclassbased = BooleanSetting ("-Yrepl-class-based", "Use classes to wrap REPL snippets instead of objects", default = true)
val YreplMagicImport = BooleanSetting ("-Yrepl-use-magic-imports", "In the code that wraps REPL snippets, use magic imports rather than nesting wrapper object/classes", default = true)
val Yreploutdir = StringSetting ("-Yrepl-outdir", "path", "Write repl-generated classfiles to given output directory (use \"\" to generate a temporary dir)" , "")
Expand Down
Expand Up @@ -81,6 +81,7 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
protected def moduleClass: Symbol = staticModule.moduleClass
protected val TASTYUUIDLength: Int = 16
private var sawPrivateConstructor = false
private var YtastyReader = false

private def ownerForFlags(jflags: JavaAccFlags) = if (jflags.isStatic) moduleClass else clazz

Expand Down Expand Up @@ -160,6 +161,7 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
this.clazz = clazz
this.staticModule = module
this.isScala = false
this.YtastyReader = settings.YtastyReader

val magic = in.getInt(in.bp)
if (magic != JAVA_MAGIC && file.name.endsWith(".sig")) {
Expand Down Expand Up @@ -1114,6 +1116,8 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
case tpnme.ScalaATTR =>
isScalaRaw = true
i = numAttrs
case tpnme.TASTYATTR if !YtastyReader =>
MissingRequirementError.signal(s"Add -Ytasty-reader to scalac options to parse the TASTy in $file")
case tpnme.TASTYATTR =>
isTASTY = true
TASTYAttrLen = attrLen
Expand Down
4 changes: 2 additions & 2 deletions src/tastytest/scala/tools/tastytest/TastyTest.scala
Expand Up @@ -60,7 +60,7 @@ object TastyTest {

private def scalacPos(out: String, sourceRoot: String, additionalSettings: Seq[String], sources: String*): Try[Unit] = {
println(s"compiling sources in ${yellow(sourceRoot)} with scalac.")
successWhen(Scalac.scalac(out, additionalSettings, sources:_*))("scalac failed to compile sources.")
successWhen(Scalac.scalac(out, "-Ytasty-reader" +: additionalSettings, sources:_*))("scalac failed to compile sources.")
}

private def scalacNeg(out: String, additionalSettings: Seq[String], files: String*): Try[Unit] = {
Expand Down Expand Up @@ -89,7 +89,7 @@ object TastyTest {
}
val compiled = Console.withErr(byteArrayStream) {
Console.withOut(byteArrayStream) {
Scalac.scalac(out, additionalSettings, source)
Scalac.scalac(out, "-Ytasty-reader" +: additionalSettings, source)
}
}
byteArrayStream.flush()
Expand Down

0 comments on commit 3743cad

Please sign in to comment.