Skip to content

Commit

Permalink
Do not remove inline method implementations until PruneErasedDefs (sc…
Browse files Browse the repository at this point in the history
…ala#17408)

This way, the tree in the inline method will pass through all checks
after first transform.
  • Loading branch information
smarter authored May 4, 2023
2 parents 77f5378 + 82236ae commit 0e00420
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class CrossStageSafety extends TreeMapWithStages {
if level != 0 then cpy.Apply(tree)(cpy.TypeApply(tree.fun)(fun, transformedBody :: Nil), quotes :: Nil)
else tpd.Quote(transformedBody).select(nme.apply).appliedTo(quotes).withSpan(tree.span)

case _: DefDef if tree.symbol.isInlineMethod =>
tree

case _ if !inQuoteOrSpliceScope =>
checkAnnotations(tree) // Check quotes in annotations
super.transform(tree)
Expand Down Expand Up @@ -117,8 +120,6 @@ class CrossStageSafety extends TreeMapWithStages {
// propagate healed types
tree1.withType(tree1.tpt.tpe.appliedTo(tree1.args.map(_.tpe)))
case tree1 => tree1
case tree: DefDef if tree.symbol.is(Inline) && level > 0 =>
EmptyTree // Remove inline defs in quoted code. Already fully inlined.
case tree: ValOrDefDef =>
checkAnnotations(tree)
healInfo(tree, tree.tpt.srcPos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import NameKinds.OuterSelectName
import StdNames._
import TypeUtils.isErasedValueType
import config.Feature
import inlines.Inlines.inInlineMethod

object FirstTransform {
val name: String = "firstTransform"
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ class PickleQuotes extends MacroTransform {
val pickled = PickleQuotes.pickle(quote1, quotes, contents)
transform(pickled) // pickle quotes that are in the contents
case tree: DefDef if !tree.rhs.isEmpty && tree.symbol.isInlineMethod =>
// Shrink size of the tree. The methods have already been inlined.
// TODO move to FirstTransform to trigger even without quotes
cpy.DefDef(tree)(rhs = defaultValue(tree.rhs.tpe))
tree
case _ =>
super.transform(tree)
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Staging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.inlines.Inlines
import dotty.tools.dotc.util.SrcPos
import dotty.tools.dotc.transform.SymUtils._
import dotty.tools.dotc.staging.StagingLevel.*
Expand Down Expand Up @@ -56,7 +57,8 @@ class Staging extends MacroTransform {
checker.transform(tree)
case _ =>
}

}
if !Inlines.inInlineMethod then
tree match {
case tree: RefTree =>
assert(level != 0 || tree.symbol != defn.QuotedTypeModule_of,
Expand All @@ -72,7 +74,7 @@ class Staging extends MacroTransform {
case _ =>
// OK
}
}
end checkPostCondition

override def run(using Context): Unit =
if (ctx.compilationUnit.needsStaging) super.run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class BootstrappedOnlyCompilationTests {
aggregateTests(
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
compileFile("tests/pos-macros/i9570.scala", defaultOptions.and("-Xfatal-warnings")),
compileFile("tests/pos-macros/macro-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
compileFile("tests/pos-macros/macro-experimental.scala", defaultOptions.and("-Yno-experimental")),
).checkExpectedErrors()
}

Expand Down
4 changes: 4 additions & 0 deletions tests/pos-macros/macro-deprecation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scala.quoted.*

inline def f = ${ impl } // error
@deprecated def impl(using Quotes) = '{1}
5 changes: 5 additions & 0 deletions tests/pos-macros/macro-experimental.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted.*
import scala.annotation.experimental

inline def f = ${ impl } // error
@experimental def impl(using Quotes) = '{1}

0 comments on commit 0e00420

Please sign in to comment.