Skip to content

Commit 118b395

Browse files
committed
Bring back part of pruneErasedDefs
Do make erased symbols private. This is needed so that we don't get false overriding relationships for effectively erased symbols.
1 parent 665f6d7 commit 118b395

File tree

6 files changed

+69
-20
lines changed

6 files changed

+69
-20
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ 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 UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`
95+
List(new PruneErasedDefs, // Make erased symbols private
96+
new UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`
9697
new InlinePatterns, // Remove placeholders of inlined patterns
9798
new VCInlineMethods, // Inlines calls to value class methods
9899
new SeqLiterals, // Express vararg arguments as arrays
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package dotty.tools.dotc
2+
package transform
3+
4+
import core.*
5+
import Contexts.*
6+
import DenotTransformers.SymTransformer
7+
import Flags.*
8+
import SymDenotations.*
9+
import Symbols.*
10+
import typer.RefChecks
11+
import MegaPhase.MiniPhase
12+
13+
/** This phase makes all erased term members of classes private so that they cannot
14+
* conflict with non-erased members. This is needed so that subsequent phases like
15+
* ResolveSuper that inspect class members work correctly and so that we do not
16+
* generate bridges for such members. See pos/i23451.scala for a test case.
17+
*/
18+
class PruneErasedDefs extends MiniPhase with SymTransformer:
19+
override def phaseName: String = PruneErasedDefs.name
20+
21+
override def description: String = PruneErasedDefs.description
22+
23+
override def changesMembers: Boolean = true // makes erased members private
24+
25+
override def runsAfterGroupsOf: Set[String] = Set(RefChecks.name, ExplicitOuter.name)
26+
27+
override def transformSym(sym: SymDenotation)(using Context): SymDenotation =
28+
if !sym.is(Private) && sym.isEffectivelyErased && sym.isTerm && sym.owner.isClass
29+
then sym.copySymDenotation(initFlags = sym.flags | Private)
30+
else sym
31+
32+
object PruneErasedDefs:
33+
val name: String = "pruneErasedDefs"
34+
val description: String = "drop erased definitions and simplify erased expressions"
35+
end PruneErasedDefs

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ 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.
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
4142

4243
override def changesMembers: Boolean = true // the phase adds super accessors
4344

sbt-bridge/test/xsbt/CompileProgressSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CompileProgressSpecification {
6363
"staging",
6464
"splicing",
6565
"pickleQuotes",
66-
"MegaPhase{uninitialized,...,arrayConstructors}",
66+
"MegaPhase{pruneErasedDefs,...,arrayConstructors}",
6767
"erasure",
6868
"constructors",
6969
"genBCode"

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,6 @@
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-
3821
1
3922
macro-late-suspend/VisitorMacros.scala
4023
example
@@ -86,3 +69,20 @@ false
8669
false
8770
mkVisitorType[Test]
8871

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+

tests/pos/i23451.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Inliner[A]:
2+
inline def apply[T]: A
3+
4+
class SummonInliner[F[_]] extends Inliner[ForSome[F]]:
5+
inline def apply[T]: ForSome[F] = ForSome(compiletime.summonInline[F[T]])
6+
7+
type ForSome[F[_]] = ForSome.Type[F]
8+
object ForSome:
9+
type Type[F[_]] = Unwrap[F, ?]
10+
class Unwrap[F[_], A](val unwrap: F[A]) extends AnyVal
11+
12+
inline def apply[F[_], A](v: F[A]): Type[F] = Unwrap(v)

0 commit comments

Comments
 (0)