Skip to content

Commit 0e00420

Browse files
authored
Do not remove inline method implementations until PruneErasedDefs (#17408)
This way, the tree in the inline method will pass through all checks after first transform.
2 parents 77f5378 + 82236ae commit 0e00420

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class CrossStageSafety extends TreeMapWithStages {
9090
if level != 0 then cpy.Apply(tree)(cpy.TypeApply(tree.fun)(fun, transformedBody :: Nil), quotes :: Nil)
9191
else tpd.Quote(transformedBody).select(nme.apply).appliedTo(quotes).withSpan(tree.span)
9292

93+
case _: DefDef if tree.symbol.isInlineMethod =>
94+
tree
95+
9396
case _ if !inQuoteOrSpliceScope =>
9497
checkAnnotations(tree) // Check quotes in annotations
9598
super.transform(tree)
@@ -117,8 +120,6 @@ class CrossStageSafety extends TreeMapWithStages {
117120
// propagate healed types
118121
tree1.withType(tree1.tpt.tpe.appliedTo(tree1.args.map(_.tpe)))
119122
case tree1 => tree1
120-
case tree: DefDef if tree.symbol.is(Inline) && level > 0 =>
121-
EmptyTree // Remove inline defs in quoted code. Already fully inlined.
122123
case tree: ValOrDefDef =>
123124
checkAnnotations(tree)
124125
healInfo(tree, tree.tpt.srcPos)

compiler/src/dotty/tools/dotc/transform/FirstTransform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import NameKinds.OuterSelectName
1818
import StdNames._
1919
import TypeUtils.isErasedValueType
2020
import config.Feature
21+
import inlines.Inlines.inInlineMethod
2122

2223
object FirstTransform {
2324
val name: String = "firstTransform"

compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ class PickleQuotes extends MacroTransform {
103103
val pickled = PickleQuotes.pickle(quote1, quotes, contents)
104104
transform(pickled) // pickle quotes that are in the contents
105105
case tree: DefDef if !tree.rhs.isEmpty && tree.symbol.isInlineMethod =>
106-
// Shrink size of the tree. The methods have already been inlined.
107-
// TODO move to FirstTransform to trigger even without quotes
108-
cpy.DefDef(tree)(rhs = defaultValue(tree.rhs.tpe))
106+
tree
109107
case _ =>
110108
super.transform(tree)
111109
}

compiler/src/dotty/tools/dotc/transform/Staging.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.dotc.core.Decorators._
88
import dotty.tools.dotc.core.Flags._
99
import dotty.tools.dotc.core.Symbols._
1010
import dotty.tools.dotc.core.Types._
11+
import dotty.tools.dotc.inlines.Inlines
1112
import dotty.tools.dotc.util.SrcPos
1213
import dotty.tools.dotc.transform.SymUtils._
1314
import dotty.tools.dotc.staging.StagingLevel.*
@@ -56,7 +57,8 @@ class Staging extends MacroTransform {
5657
checker.transform(tree)
5758
case _ =>
5859
}
59-
60+
}
61+
if !Inlines.inInlineMethod then
6062
tree match {
6163
case tree: RefTree =>
6264
assert(level != 0 || tree.symbol != defn.QuotedTypeModule_of,
@@ -72,7 +74,7 @@ class Staging extends MacroTransform {
7274
case _ =>
7375
// OK
7476
}
75-
}
77+
end checkPostCondition
7678

7779
override def run(using Context): Unit =
7880
if (ctx.compilationUnit.needsStaging) super.run

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class BootstrappedOnlyCompilationTests {
110110
aggregateTests(
111111
compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")),
112112
compileFile("tests/pos-macros/i9570.scala", defaultOptions.and("-Xfatal-warnings")),
113+
compileFile("tests/pos-macros/macro-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-deprecation")),
114+
compileFile("tests/pos-macros/macro-experimental.scala", defaultOptions.and("-Yno-experimental")),
113115
).checkExpectedErrors()
114116
}
115117

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.quoted.*
2+
3+
inline def f = ${ impl } // error
4+
@deprecated def impl(using Quotes) = '{1}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted.*
2+
import scala.annotation.experimental
3+
4+
inline def f = ${ impl } // error
5+
@experimental def impl(using Quotes) = '{1}

0 commit comments

Comments
 (0)