Skip to content

Commit 5c9c61c

Browse files
committed
Do not remove inline method implementations until PruneErasedDefs
1 parent 8a055d6 commit 5c9c61c

File tree

7 files changed

+32
-19
lines changed

7 files changed

+32
-19
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: 16 additions & 14 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.*
@@ -57,21 +58,22 @@ class Staging extends MacroTransform {
5758
case _ =>
5859
}
5960

60-
tree match {
61-
case tree: RefTree =>
62-
assert(level != 0 || tree.symbol != defn.QuotedTypeModule_of,
63-
"scala.quoted.Type.of at level 0 should have been replaced with Quote AST in staging phase")
64-
case _ =>
65-
}
61+
if !Inlines.inInlineMethod then
62+
tree match {
63+
case tree: RefTree =>
64+
assert(level != 0 || tree.symbol != defn.QuotedTypeModule_of,
65+
"scala.quoted.Type.of at level 0 should have been replaced with Quote AST in staging phase")
66+
case _ =>
67+
}
6668

67-
tree.tpe match {
68-
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol.isTypeSplice =>
69-
// Type splices must have a know term ref, usually to an implicit argument
70-
// This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T`
71-
assert(prefix.isInstanceOf[TermRef] || prefix.isInstanceOf[ThisType], prefix)
72-
case _ =>
73-
// OK
74-
}
69+
tree.tpe match {
70+
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol.isTypeSplice =>
71+
// Type splices must have a know term ref, usually to an implicit argument
72+
// This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T`
73+
assert(prefix.isInstanceOf[TermRef] || prefix.isInstanceOf[ThisType], prefix)
74+
case _ =>
75+
// OK
76+
}
7577
}
7678

7779
override def run(using Context): Unit =

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)