Skip to content

Fix #8856: Keep transparent flag #8857

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions library/src/scala/tasty/reflect/SourceCodePrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -295,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 ")
Expand Down
8 changes: 6 additions & 2 deletions tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down Expand Up @@ -248,7 +249,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 */
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 ||
Expand All @@ -493,6 +495,7 @@ object TastyFormat {
| INLINEPROXY
| MACRO
| OPAQUE
| TRANSPARENT
| STATIC
| OBJECT
| TRAIT
Expand Down Expand Up @@ -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"
Expand Down