Skip to content

Commit 6d0595d

Browse files
committed
Drop PruneErasedDefs
The motivation for the phase was always unclear to me. No tests broke after the change. Piggybacked on the phase was the unrelated "anonymous class in inline method" warning. I moved it in changed form to FirstTransform. It is more efficient now since it does not need an auxiliary tree traversal.
1 parent 2d11d4c commit 6d0595d

File tree

6 files changed

+34
-42
lines changed

6 files changed

+34
-42
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ class Compiler {
9292
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
9393
new StringInterpolatorOpt, // Optimizes raw and s and f string interpolators by rewriting them to string concatenations or formats
9494
new DropBreaks) :: // Optimize local Break throws by rewriting them
95-
List(new PruneErasedDefs, // Drop erased definitions from scopes and simplify erased expressions
96-
new UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`
95+
List(new UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`
9796
new InlinePatterns, // Remove placeholders of inlined patterns
9897
new VCInlineMethods, // Inlines calls to value class methods
9998
new SeqLiterals, // Express vararg arguments as arrays

compiler/src/dotty/tools/dotc/cc/ccConfig.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ object ccConfig:
5656

5757
/** Not used currently. Handy for trying out new features */
5858
def newScheme(using ctx: Context): Boolean =
59-
ctx.settings.XdropComments.value
59+
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.7`)
6060

6161
end ccConfig

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import StdNames.*
2020
import config.Feature
2121
import inlines.Inlines.inInlineMethod
2222
import util.Property
23+
import inlines.Inlines
24+
import reporting.InlinedAnonClassWarning
2325

2426
object FirstTransform {
2527
val name: String = "firstTransform"
@@ -207,6 +209,11 @@ class FirstTransform extends MiniPhase with SymTransformer { thisPhase =>
207209
case _ => tree
208210
}
209211

212+
override def transformTypeDef(tree: TypeDef)(using Context): Tree =
213+
if tree.symbol.isAnonymousClass && Inlines.inInlineMethod then
214+
report.warning(InlinedAnonClassWarning(), tree.symbol.sourcePos)
215+
tree
216+
210217
/** Perform one of the following simplification if applicable:
211218
*
212219
* true && y ==> y

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -414,26 +414,13 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
414414
checkUsableAsValue(tree) match
415415
case tree1: Select => transformSelect(tree1, Nil)
416416
case tree1 => tree1
417-
case tree: Apply =>
418-
val methType = tree.fun.tpe.widen.asInstanceOf[MethodType]
419-
val app =
420-
if (methType.hasErasedParams)
421-
tpd.cpy.Apply(tree)(
422-
tree.fun,
423-
tree.args.zip(methType.erasedParams).map((arg, isErased) =>
424-
if !isErased then arg
425-
else
426-
if methType.isResultDependent then
427-
Checking.checkRealizable(arg.tpe, arg.srcPos, "erased argument")
428-
if (methType.isImplicitMethod && arg.span.isSynthetic)
429-
arg match
430-
case _: RefTree | _: Apply | _: TypeApply if arg.symbol.is(Erased) =>
431-
dropInlines.transform(arg)
432-
case _ =>
433-
PruneErasedDefs.trivialErasedTree(arg)
434-
else dropInlines.transform(arg)))
435-
else
436-
tree
417+
case app: Apply =>
418+
val methType = app.fun.tpe.widen.asInstanceOf[MethodType]
419+
if (methType.hasErasedParams)
420+
for (arg, isErased) <- app.args.lazyZip(methType.erasedParams) do
421+
if isErased then
422+
if methType.isResultDependent then
423+
Checking.checkRealizable(arg.tpe, arg.srcPos, "erased argument")
437424
def app1 =
438425
// reverse order of transforming args and fun. This way, we get a chance to see other
439426
// well-formedness errors before reporting errors in possible inferred type args of fun.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class ResolveSuper extends MiniPhase with IdentityDenotTransformer { thisPhase =
3737

3838
override def description: String = ResolveSuper.description
3939

40-
override def runsAfter: Set[String] = Set(ElimByName.name, // verified empirically, need to figure out what the reason is.
41-
PruneErasedDefs.name) // Erased decls make `isCurrent` work incorrectly
40+
override def runsAfter: Set[String] = Set(ElimByName.name) // verified empirically, need to figure out what the reason is.
4241

4342
override def changesMembers: Boolean = true // the phase adds super accessors
4443

tests/coverage/pos/macro-late-suspend/test.scoverage.check

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@
1818
# - description (can be multi-line)
1919
# ' ' sign
2020
# ------------------------------------------
21+
0
22+
macro-late-suspend/UsesTest.scala
23+
example
24+
UsesTest$package
25+
Object
26+
example.UsesTest$package
27+
<init>
28+
22
29+
22
30+
3
31+
<none>
32+
Literal
33+
true
34+
0
35+
false
36+
37+
2138
1
2239
macro-late-suspend/VisitorMacros.scala
2340
example
@@ -69,20 +86,3 @@ false
6986
false
7087
mkVisitorType[Test]
7188

72-
4
73-
macro-late-suspend/UsesTest.scala
74-
example
75-
UsesTest$package
76-
Object
77-
example.UsesTest$package
78-
<init>
79-
22
80-
22
81-
3
82-
<none>
83-
Literal
84-
true
85-
0
86-
false
87-
88-

0 commit comments

Comments
 (0)