Skip to content

Commit 1c5b8a4

Browse files
committed
Make ElimOpaque a DenotTransformer
1 parent 0fadbe3 commit 1c5b8a4

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

compiler/src/dotty/tools/dotc/core/DenotTransformers.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ object DenotTransformers {
5757
protected def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = true
5858
}
5959

60-
/** A transformer that only transforms SymDenotations */
60+
/** A transformer that only transforms SymDenotations.
61+
* Note: Infos of non-sym denotations are left as is. So the transformer should
62+
* be used before erasure only if this is not a problem. After erasure, all
63+
* denotations are SymDenotations, so SymTransformers can be used freely.
64+
*/
6165
trait SymTransformer extends DenotTransformer {
6266

63-
/** Tramsform the info of a denotation that is not a Symdenotation */
64-
def transformNonSymInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = tp
65-
6667
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation
6768

6869
def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = ref match {
6970
case ref: SymDenotation => transformSym(ref)
70-
case _ => ref.derivedSingleDenotation(ref.symbol, transformNonSymInfo(ref.info, ref.symbol))
71+
case _ => ref
7172
}
7273
}
7374

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Types._
88
import Contexts.Context
99
import Symbols._
1010
import Decorators._
11+
import Denotations.SingleDenotation
1112
import SymDenotations.SymDenotation
1213
import DenotTransformers._
1314
import TypeUtils._
@@ -17,7 +18,7 @@ object ElimOpaque {
1718
}
1819

1920
/** Rewrites opaque type aliases to normal alias types */
20-
class ElimOpaque extends MiniPhase with SymTransformer {
21+
class ElimOpaque extends MiniPhase with DenotTransformer {
2122

2223
override def phaseName: String = ElimOpaque.name
2324

@@ -27,14 +28,15 @@ class ElimOpaque extends MiniPhase with SymTransformer {
2728
// base types of opaque aliases change
2829
override def changesBaseTypes = true
2930

30-
override def transformNonSymInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type =
31-
if (sym.isOpaqueHelper) TypeAlias(tp.extractOpaqueAlias) else tp
32-
33-
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation =
34-
if (sym.isOpaqueHelper) {
35-
sym.copySymDenotation(
36-
info = TypeAlias(sym.opaqueAlias),
37-
initFlags = sym.flags &~ (Opaque | Deferred))
31+
def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation =
32+
if (ref.symbol.isOpaqueHelper)
33+
ref match {
34+
case sym: SymDenotation =>
35+
sym.copySymDenotation(
36+
info = TypeAlias(sym.opaqueAlias),
37+
initFlags = sym.flags &~ (Opaque | Deferred))
38+
case _ =>
39+
ref.derivedSingleDenotation(ref.symbol, TypeAlias(ref.info.extractOpaqueAlias))
3840
}
39-
else sym
41+
else ref
4042
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class Getters extends MiniPhase with SymTransformer {
6565
d.copySymDenotation(
6666
initFlags = d.flags | maybeStable | AccessorCreationFlags,
6767
info = ExprType(d.info))
68+
// Note: This change will only affect the SymDenotation itself, not
69+
// SingleDenotations referring to a getter. In this case it does not
70+
// seem to be a problem since references to a getter don't care whether
71+
// it's a `T` or a `=> T`
6872
}
6973
else d
7074

0 commit comments

Comments
 (0)