Skip to content

Commit 7313691

Browse files
committed
TypeErasure: change the meaning of isSemi and simplify the code
- isSemi is still unimplemented but its meaning is changed: before, isSemi = false meant that a value class should be erased to its underlying type, now it means that it should be erased like a normal class. These two cases are the one we actually need in Erasure. - Fix the documentation of the TypeErasure class which was wrong. - Remove intermediate functions scalaErasureFn, scalaSigFn, javaSigFn and semiErasureFn. It's clearer to just use erasureFn directly instead. - Add an optional parameter isSemi to erasure which will be used in Erasure when we need to disable semi-erasure.
1 parent 7ce7d95 commit 7313691

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,35 +71,26 @@ object TypeErasure {
7171
} erasures(erasureIdx(isJava, isSemi, isConstructor, wildcardOK)) =
7272
new TypeErasure(isJava, isSemi, isConstructor, wildcardOK)
7373

74-
/** Produces an erasure function.
75-
* @param isJava Arguments should be treated the way Java does it
76-
* @param isSemi Value classes are mapped in an intermediate step to
77-
* ErasedValueClass types, instead of going directly to
78-
* the erasure of the underlying type.
79-
* @param isConstructor Argument forms part of the type of a constructor
80-
* @param wildcardOK Wildcards are acceptable (true when using the erasure
81-
* for computing a signature name).
74+
/** Produces an erasure function. See the documentation of the class `TypeErasure`
75+
* for a description of each parameter.
8276
*/
8377
private def erasureFn(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wildcardOK: Boolean): TypeErasure =
8478
erasures(erasureIdx(isJava, isSemi, isConstructor, wildcardOK))
8579

86-
private val scalaErasureFn = erasureFn(isJava = false, isSemi = false, isConstructor = false, wildcardOK = false)
87-
private val scalaSigFn = erasureFn(isJava = false, isSemi = false, isConstructor = false, wildcardOK = true)
88-
private val javaSigFn = erasureFn(isJava = true, isSemi = false, isConstructor = false, wildcardOK = true)
89-
private val semiErasureFn = erasureFn(isJava = false, isSemi = true, isConstructor = false, wildcardOK = false)
90-
9180
/** The current context with a phase no later than erasure */
9281
private def erasureCtx(implicit ctx: Context) =
9382
if (ctx.erasedTypes) ctx.withPhase(ctx.erasurePhase).addMode(Mode.FutureDefsOK) else ctx
9483

95-
def erasure(tp: Type)(implicit ctx: Context): Type = scalaErasureFn(tp)(erasureCtx)
96-
def semiErasure(tp: Type)(implicit ctx: Context): Type = semiErasureFn(tp)(erasureCtx)
84+
def erasure(tp: Type, isSemi: Boolean = true)(implicit ctx: Context): Type =
85+
erasureFn(isJava = false, isSemi, isConstructor = false, wildcardOK = false)(tp)(erasureCtx)
86+
9787
def sigName(tp: Type, isJava: Boolean)(implicit ctx: Context): TypeName = {
9888
val seqClass = if(isJava) defn.ArrayClass else defn.SeqClass
9989
val normTp =
10090
if (tp.isRepeatedParam) tp.translateParameterized(defn.RepeatedParamClass, seqClass)
10191
else tp
102-
(if (isJava) javaSigFn else scalaSigFn).sigName(normTp)(erasureCtx)
92+
val erase = erasureFn(isJava, isSemi = false, isConstructor = false, wildcardOK = true)
93+
erase.sigName(normTp)(erasureCtx)
10394
}
10495

10596
/** The erasure of a top-level reference. Differs from normal erasure in that
@@ -228,10 +219,13 @@ object TypeErasure {
228219
import TypeErasure._
229220

230221
/**
231-
* This is used as the Scala erasure during the erasure phase itself
232-
* It differs from normal erasure in that value classes are erased to ErasedValueTypes which
233-
* are then later converted to the underlying parameter type in phase posterasure.
234-
*
222+
* @param isJava Arguments should be treated the way Java does it
223+
* @param isSemi If true, value classes are mapped in an intermediate
224+
* step to ErasedValueClass types, otherwise they're
225+
* erased like normal classes.
226+
* @param isConstructor Argument forms part of the type of a constructor
227+
* @param wildcardOK Wildcards are acceptable (true when using the erasure
228+
* for computing a signature name).
235229
*/
236230
class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wildcardOK: Boolean) extends DotClass {
237231

0 commit comments

Comments
 (0)