Skip to content

Remove Macro flag from Dotty macros #4855

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
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 bench/tests/power-macro/PowerMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object PowerMacro {

def powerCode(n: Long, x: Expr[Double]): Expr[Double] =
if (n == 0) '(1.0)
else if (n % 2 == 0) '{ { val y = ~x * ~x; ~powerCode(n / 2, '(y)) } }
else if (n % 2 == 0) '{ val y = ~x * ~x; ~powerCode(n / 2, '(y)) }
else '{ ~x * ~powerCode(n - 1, x) }

}
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ object Flags {
/** A Scala 2.12 or higher trait */
final val Scala_2_12_Trait = typeFlag(58, "<scala_2_12_trait>")

/** A macro */
/** A Scala 2 macro */
final val Macro = commonFlag(59, "<macro>")

/** A method that is known to have inherited default parameters */
Expand Down Expand Up @@ -608,9 +608,6 @@ object Flags {
/** Is a default parameter in Scala 2*/
final val DefaultParameter = allOf(Param, DefaultParameterized)

/** A Scala 2 Macro */
final val Scala2Macro = allOf(Macro, Scala2x)

/** A trait that does not need to be initialized */
final val NoInitsTrait = allOf(Trait, NoInits)

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
val abs = sym.is(Abstract) || sym.is(Deferred) || absOver
val over = sym.is(Override) || absOver
new api.Modifiers(abs, over, sym.is(Final), sym.is(Sealed),
sym.is(Implicit), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor)
sym.is(Implicit), sym.is(Lazy), false, sym.isSuperAccessor)
}

def apiAnnotations(s: Symbol): List[api.Annotation] = {
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class FlagSet(flags: Flags.FlagSet) extends scala.tasty.FlagSet {
def isLazy: Boolean = flags.is(Lazy)
def isOverride: Boolean = flags.is(Override)
def isTransparent: Boolean = flags.is(Transparent)
def isMacro: Boolean = flags.is(Macro)
def isStatic: Boolean = flags.is(JavaStatic)
def isObject: Boolean = flags.is(Module)
def isTrait: Boolean = flags.is(Trait)
Expand Down Expand Up @@ -46,7 +45,6 @@ class FlagSet(flags: Flags.FlagSet) extends scala.tasty.FlagSet {
if (isLazy) flags += "lazy"
if (isOverride) flags += "override"
if (isTransparent) flags += "transparent"
if (isMacro) flags += "macro"
if (isStatic) flags += "javaStatic"
if (isObject) flags += "object"
if (isTrait) flags += "trait"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { s
}

object Inlined extends InlinedExtractor {
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[Statement], Term)] = x match {
def unapply(x: Term)(implicit ctx: Context): Option[(Option[Term], List[Statement], Term)] = x match {
case x: tpd.Inlined @unchecked =>
Some((x.call, x.bindings, x.expansion))
Some((optional(x.call), x.bindings, x.expansion))
case _ => None
}
}
Expand Down
12 changes: 2 additions & 10 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase

def markAsMacro(c: Context): Unit =
if (c.owner eq c.outer.owner) markAsMacro(c.outer)
else if (c.owner.isTransparentMethod) {
c.owner.setFlag(Macro)
c.owner.resetFlag(Erased) // FIXME: Macros should be Erased, but that causes problems right now
}
else if (c.owner.isTransparentMethod) () // OK
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)

if (sym.isSplice || sym.isQuote) {
Expand Down Expand Up @@ -245,12 +242,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
// be duplicated
// 2. To enable correct pickling (calls can share symbols with the inlined code, which
// would trigger an assertion when pickling).
// In the case of macros we keep the call to be able to reconstruct the parameters that
// are passed to the macro. This same simplification is applied in ReifiedQuotes when the
// macro splices are evaluated.
val callTrace =
if (call.symbol.is(Macro)) call
else Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
val callTrace = Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(inlineContext(call)))
case tree: Template =>
withNoCheckNews(tree.parents.flatMap(newPart)) {
Expand Down
Loading