From 6b2ef640624646fa9f02fe9cf137c7f07c3e15a2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 1 May 2020 15:17:18 +0200 Subject: [PATCH 1/2] Fix #8856: Keep transparent flag --- compiler/src/dotty/tools/dotc/ast/untpd.scala | 2 +- compiler/src/dotty/tools/dotc/core/Flags.scala | 5 ++++- compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala | 2 -- .../dotc/tastyreflect/ReflectionCompilerInterface.scala | 1 + compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 +- compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala | 6 +++--- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- library/src/scala/tasty/Reflection.scala | 3 +++ library/src/scala/tasty/reflect/CompilerInterface.scala | 1 + library/src/scala/tasty/reflect/SourceCodePrinter.scala | 1 + tasty/src/dotty/tools/tasty/TastyFormat.scala | 2 +- 11 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index bb8da0d59d72..78b8cba20415 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -196,7 +196,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { case class Inline()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Inline) - case class Transparent()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.EmptyFlags) + case class Transparent()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Transparent) } /** Modifiers and annotations for definitions diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 1bb664b63673..783041921615 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -347,8 +347,11 @@ object Flags { /** Labeled with `erased` modifier (erased value) */ val (_, Erased @ _, _) = newFlags(42, "erased") + /** Labelled with `transparent` modifier */ + val (Transparent @ _, _, _) = newFlags(43, "transparent") + /** An opaque type alias or a class containing one */ - val (Opaque @ _, _, _) = newFlags(43, "opaque") + val (Opaque @ _, _, _) = newFlags(44, "opaque") // ------------ Flags following this one are not pickled ---------------------------------- diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 98d231de643c..1141a1c2dd31 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -865,8 +865,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { if (rawFlags.is(Param)) flagMask = flagMask &~ Given val flags = rawFlags & flagMask var flagsText = toTextFlags(sym, flags) - if mods.hasMod(classOf[untpd.Mod.Transparent]) then - flagsText = "transparent " ~ flagsText val annotations = if (sym.exists) sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(_.tree) else mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol)) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index c2bb1173aced..e733dd2e04c5 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -1847,6 +1847,7 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def Flags_Lazy: Flags = core.Flags.Lazy def Flags_Override: Flags = core.Flags.Override def Flags_Inline: Flags = core.Flags.Inline + def Flags_Transparent: Flags = core.Flags.Transparent def Flags_Macro: Flags = core.Flags.Macro def Flags_Static: Flags = core.Flags.JavaStatic def Flags_JavaDefined: Flags = core.Flags.JavaDefined diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 9c6e83af0522..3a5e6a8529d3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -866,7 +866,7 @@ class Namer { typer: Typer => case original: untpd.DefDef if sym.isInlineMethod => def rhsToInline(using Context): tpd.Tree = val mdef = typedAheadExpr(original).asInstanceOf[tpd.DefDef] - PrepareInlineable.wrapRHS(original, mdef.tpt, mdef.rhs) + PrepareInlineable.wrapRHS(sym, mdef.tpt, mdef.rhs) PrepareInlineable.registerInlineInfo(sym, rhsToInline)(using localContext(sym)) case _ => } diff --git a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala index cf7286be340f..352e4134fe5f 100644 --- a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala +++ b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala @@ -204,9 +204,9 @@ object PrepareInlineable { def isLocal(sym: Symbol, inlineMethod: Symbol)(using Context): Boolean = isLocalOrParam(sym, inlineMethod) && !(sym.is(Param) && sym.owner == inlineMethod) - /** The type ascription `rhs: tpt`, unless `original` is `transparent`. */ - def wrapRHS(original: untpd.DefDef, tpt: Tree, rhs: Tree)(using Context): Tree = - if original.mods.hasMod(classOf[untpd.Mod.Transparent]) then rhs + /** The type ascription `rhs: tpt`, unless `sym` is `transparent`. */ + def wrapRHS(sym: Symbol, tpt: Tree, rhs: Tree)(using Context): Tree = + if sym.is(Transparent) then rhs else Typed(rhs, tpt) /** Register inline info for given inlineable method `sym`. diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9c4ba0b47128..2c2f8fa0d63b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1865,7 +1865,7 @@ class Typer extends Namer if (sym.isInlineMethod) rhsCtx.addMode(Mode.InlineableBody) val rhs1 = typedExpr(ddef.rhs, tpt1.tpe.widenExpr)(using rhsCtx) - val rhsToInline = PrepareInlineable.wrapRHS(ddef, tpt1, rhs1) + val rhsToInline = PrepareInlineable.wrapRHS(sym, tpt1, rhs1) if (sym.isInlineMethod) PrepareInlineable.registerInlineInfo(sym, rhsToInline) diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index d3f6e63719b7..0cbc8f57cf64 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -2607,6 +2607,9 @@ class Reflection(private[scala] val internal: CompilerInterface) { self => /** Is this symbol `inline` */ def Inline: Flags = internal.Flags_Inline + /** Is this symbol a `transparent` */ + def Transparent: Flags = internal.Flags_Transparent + /** Is this symbol marked as a macro. An inline method containing toplevel splices */ def Macro: Flags = internal.Flags_Macro diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index 93bffe1b72cf..c602a8e8d919 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -1397,6 +1397,7 @@ trait CompilerInterface { def Flags_Lazy: Flags def Flags_Override: Flags def Flags_Inline: Flags + def Flags_Transparent: Flags def Flags_Macro: Flags def Flags_Static: Flags def Flags_JavaDefined: Flags diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index 75da3d55750b..504e6cc2e37a 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -34,6 +34,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig if (flags.is(Flags.Lazy)) flagList += "lazy" if (flags.is(Flags.Override)) flagList += "override" if (flags.is(Flags.Inline)) flagList += "inline" + if (flags.is(Flags.Transparent)) flagList += "transparent" if (flags.is(Flags.Macro)) flagList += "macro" if (flags.is(Flags.JavaDefined)) flagList += "javaDefined" if (flags.is(Flags.Static)) flagList += "javaStatic" diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index f330254e4ff2..6b8a71b28328 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -248,7 +248,7 @@ Standard Section: "Comments" Comment* object TastyFormat { final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F) - val MajorVersion: Int = 22 + val MajorVersion: Int = 23 val MinorVersion: Int = 0 /** Tags used to serialize names, should update [[nameTagToString]] if a new constant is added */ From 204ad43bf40de5260508e63f97c9649eb13beca0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 1 May 2020 18:14:20 +0200 Subject: [PATCH 2/2] Pickle transparent flag --- compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala | 1 + .../src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 1 + library/src/scala/tasty/reflect/SourceCodePrinter.scala | 1 + tasty/src/dotty/tools/tasty/TastyFormat.scala | 6 +++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 95dbaeb10267..50300a05b716 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -664,6 +664,7 @@ class TreePickler(pickler: TastyPickler) { if (flags.is(Case)) writeModTag(CASE) if (flags.is(Override)) writeModTag(OVERRIDE) if (flags.is(Inline)) writeModTag(INLINE) + if (flags.is(Transparent)) writeModTag(TRANSPARENT) if (flags.is(InlineProxy)) writeModTag(INLINEPROXY) if (flags.is(Macro)) writeModTag(MACRO) if (flags.is(JavaStatic)) writeModTag(STATIC) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index c81982ba77fd..47e380c8f4d8 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -632,6 +632,7 @@ class TreeUnpickler(reader: TastyReader, case LAZY => addFlag(Lazy) case OVERRIDE => addFlag(Override) case INLINE => addFlag(Inline) + case TRANSPARENT => addFlag(Transparent) case INLINEPROXY => addFlag(InlineProxy) case MACRO => addFlag(Macro) case OPAQUE => addFlag(Opaque) diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index 504e6cc2e37a..a13a1175dc9e 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -296,6 +296,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig val flags = ddef.symbol.flags if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Transparent)) this += highlightKeyword("transparent ") if (flags.is(Flags.Inline)) this += highlightKeyword("inline ") if (flags.is(Flags.Override)) this += highlightKeyword("override ") if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index 6b8a71b28328..13f71f930037 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -182,6 +182,7 @@ Standard-Section: "ASTs" TopLevelStat* LAZY -- lazy OVERRIDE -- override OPAQUE -- opaque, also used for classes containing opaque aliases + TRANSPARENT -- transparent INLINE -- inline MACRO -- Inline method containing toplevel splices INLINEPROXY -- Symbol of binding with an argument to an inline method as rhs (TODO: do we still need this?) @@ -354,6 +355,7 @@ object TastyFormat { final val OPEN = 40 final val PARAMEND = 41 final val PARAMalias = 42 + final val TRANSPARENT = 43 // Cat. 2: tag Nat @@ -467,7 +469,7 @@ object TastyFormat { /** Useful for debugging */ def isLegalTag(tag: Int): Boolean = - firstSimpleTreeTag <= tag && tag <= PARAMalias || + firstSimpleTreeTag <= tag && tag <= TRANSPARENT || firstNatTreeTag <= tag && tag <= RENAMED || firstASTTreeTag <= tag && tag <= BOUNDED || firstNatASTTreeTag <= tag && tag <= NAMEDARG || @@ -493,6 +495,7 @@ object TastyFormat { | INLINEPROXY | MACRO | OPAQUE + | TRANSPARENT | STATIC | OBJECT | TRAIT @@ -553,6 +556,7 @@ object TastyFormat { case INLINEPROXY => "INLINEPROXY" case MACRO => "MACRO" case OPAQUE => "OPAQUE" + case TRANSPARENT => "TRANSPARENT" case STATIC => "STATIC" case OBJECT => "OBJECT" case TRAIT => "TRAIT"