Skip to content

Commit 39cacda

Browse files
committed
Rename erasedParams to paramErasureStatuses
# Conflicts: # compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
1 parent 522454b commit 39cacda

File tree

11 files changed

+38
-19
lines changed

11 files changed

+38
-19
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
301301
assert(vparams.hasSameLengthAs(tp.paramNames) && vparams.head.isTerm)
302302
(vparams.asInstanceOf[List[TermSymbol]], remaining1)
303303
case nil =>
304-
(tp.paramNames.lazyZip(tp.paramInfos).lazyZip(tp.erasedParams).map(valueParam), Nil)
304+
(tp.paramNames.lazyZip(tp.paramInfos).lazyZip(tp.paramErasureStatuses).map(valueParam), Nil)
305305
val (rtp, paramss) = recur(tp.instantiate(vparams.map(_.termRef)), remaining1)
306306
(rtp, vparams :: paramss)
307307
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
23872387
formals2.isEmpty
23882388
}
23892389
// If methods have erased parameters, then the erased parameters must match
2390-
val erasedValid = (!tp1.hasErasedParams && !tp2.hasErasedParams) || (tp1.erasedParams == tp2.erasedParams)
2390+
val erasedValid = (!tp1.hasErasedParams && !tp2.hasErasedParams) || (tp1.paramErasureStatuses == tp2.paramErasureStatuses)
23912391

23922392
erasedValid && loop(tp1.paramInfos, tp2.paramInfos)
23932393
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
697697
val (names, formals0) = if tp.hasErasedParams then
698698
tp.paramNames
699699
.zip(tp.paramInfos)
700-
.zip(tp.erasedParams)
700+
.zip(tp.paramErasureStatuses)
701701
.collect{ case (param, isErased) if !isErased => param }
702702
.unzip
703703
else (tp.paramNames, tp.paramInfos)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,7 +3931,7 @@ object Types extends TypeUtils {
39313931
case tp: MethodType =>
39323932
val params = if (hasErasedParams)
39333933
tp.paramInfos
3934-
.zip(tp.erasedParams)
3934+
.zip(tp.paramErasureStatuses)
39353935
.collect { case (param, isErased) if !isErased => param }
39363936
else tp.paramInfos
39373937
resultSignature.prependTermParams(params, sourceLanguage)
@@ -4163,7 +4163,7 @@ object Types extends TypeUtils {
41634163
final override def isContextualMethod: Boolean =
41644164
companion.eq(ContextualMethodType)
41654165

4166-
def erasedParams(using Context): List[Boolean] =
4166+
def paramErasureStatuses(using Context): List[Boolean] =
41674167
paramInfos.map(p => p.hasAnnotation(defn.ErasedParamAnnot))
41684168

41694169
def nonErasedParamCount(using Context): Int =

compiler/src/dotty/tools/dotc/quoted/Interpreter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ class Interpreter(pos: SrcPos, classLoader0: ClassLoader)(using Context):
127127
case fnType: MethodType =>
128128
val argTypes = fnType.paramInfos
129129
assert(argss.head.size == argTypes.size)
130-
val nonErasedArgs = argss.head.lazyZip(fnType.erasedParams).collect { case (arg, false) => arg }.toList
131-
val nonErasedArgTypes = fnType.paramInfos.lazyZip(fnType.erasedParams).collect { case (arg, false) => arg }.toList
130+
val nonErasedArgs = argss.head.lazyZip(fnType.paramErasureStatuses).collect { case (arg, false) => arg }.toList
131+
val nonErasedArgTypes = fnType.paramInfos.lazyZip(fnType.paramErasureStatuses).collect { case (arg, false) => arg }.toList
132132
assert(nonErasedArgs.size == nonErasedArgTypes.size)
133133
interpretArgsGroup(nonErasedArgs, nonErasedArgTypes) ::: interpretArgs(argss.tail, fnType.resType)
134134
case fnType: AppliedType if defn.isContextFunctionType(fnType) =>

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,17 @@ object Erasure {
583583
checkNotErasedClass(tree)
584584
end checkNotErased
585585

586+
def checkPureErased(tree: untpd.Tree, isArgument: Boolean)(using Context): Unit =
587+
if false then inContext(preErasureCtx):
588+
if tpd.isPureExpr(tree.asInstanceOf[tpd.Tree]) then
589+
val tree1 = tree.asInstanceOf[tpd.Tree]
590+
println(i"$tree1 is pure, ${tree1.tpe.widen}")
591+
else
592+
def what =
593+
if isArgument then "argument to erased parameter"
594+
else "right-hand-side of erased value"
595+
report.error(em"$what fails to be a pure expression", tree.srcPos)
596+
586597
private def checkNotErasedClass(tp: Type, tree: untpd.Tree)(using Context): Unit = tp match
587598
case JavaArrayType(et) =>
588599
checkNotErasedClass(et, tree)
@@ -848,7 +859,12 @@ object Erasure {
848859
val origFunType = origFun.tpe.widen(using preErasureCtx)
849860
val ownArgs = origFunType match
850861
case mt: MethodType if mt.hasErasedParams =>
851-
args.zip(mt.erasedParams).collect { case (arg, false) => arg }
862+
args.lazyZip(mt.paramErasureStatuses).flatMap: (arg, isErased) =>
863+
if isErased then
864+
checkPureErased(arg, isArgument = true)
865+
Nil
866+
else
867+
arg :: Nil
852868
case _ => args
853869
val fun1 = typedExpr(fun, AnyFunctionProto)
854870
fun1.tpe.widen match
@@ -916,7 +932,9 @@ object Erasure {
916932
}
917933

918934
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =
919-
if (sym.isEffectivelyErased) erasedDef(sym)
935+
if sym.isEffectivelyErased then
936+
checkPureErased(vdef.rhs, isArgument = false)
937+
erasedDef(sym)
920938
else
921939
checkNotErasedClass(sym.info, vdef)
922940
super.typedValDef(untpd.cpy.ValDef(vdef)(
@@ -928,6 +946,7 @@ object Erasure {
928946
*/
929947
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(using Context): Tree =
930948
if sym.isEffectivelyErased || sym.name.is(BodyRetainerName) then
949+
checkPureErased(ddef.rhs, isArgument = false)
931950
erasedDef(sym)
932951
else
933952
checkNotErasedClass(sym.info.finalResultType, ddef)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
408408
case app: Apply =>
409409
val methType = app.fun.tpe.widen.asInstanceOf[MethodType]
410410
if (methType.hasErasedParams)
411-
for (arg, isErased) <- app.args.lazyZip(methType.erasedParams) do
411+
for (arg, isErased) <- app.args.lazyZip(methType.paramErasureStatuses) do
412412
if isErased then
413413
if methType.isResultDependent then
414414
Checking.checkRealizable(arg.tpe, arg.srcPos, "erased argument")
@@ -475,15 +475,15 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
475475
case tree: ValDef =>
476476
annotateExperimentalCompanion(tree.symbol)
477477
registerIfHasMacroAnnotations(tree)
478-
checkErasedDef(tree)
478+
//checkErasedDef(tree)
479479
Checking.checkPolyFunctionType(tree.tpt)
480480
val tree1 = cpy.ValDef(tree)(tpt = makeOverrideTypeDeclared(tree.symbol, tree.tpt))
481481
if tree1.removeAttachment(desugar.UntupledParam).isDefined then
482482
checkStableSelection(tree.rhs)
483483
processValOrDefDef(super.transform(tree1))
484484
case tree: DefDef =>
485485
registerIfHasMacroAnnotations(tree)
486-
checkErasedDef(tree)
486+
//checkErasedDef(tree)
487487
Checking.checkPolyFunctionType(tree.tpt)
488488
annotateContextResults(tree)
489489
val tree1 = cpy.DefDef(tree)(tpt = makeOverrideTypeDeclared(tree.symbol, tree.tpt))

compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ object EtaExpansion extends LiftImpure {
300300
val body = Apply(lifted, ids)
301301
if (mt.isContextualMethod) body.setApplyKind(ApplyKind.Using)
302302
val fn =
303-
if (mt.isContextualMethod) new untpd.FunctionWithMods(params, body, Modifiers(Given), mt.erasedParams)
304-
else if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(Implicit), mt.erasedParams)
305-
else if (mt.hasErasedParams) new untpd.FunctionWithMods(params, body, Modifiers(), mt.erasedParams)
303+
if (mt.isContextualMethod) new untpd.FunctionWithMods(params, body, Modifiers(Given), mt.paramErasureStatuses)
304+
else if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(Implicit), mt.paramErasureStatuses)
305+
else if (mt.hasErasedParams) new untpd.FunctionWithMods(params, body, Modifiers(), mt.paramErasureStatuses)
306306
else untpd.Function(params, body)
307307
if (defs.nonEmpty) untpd.Block(defs.toList map (untpd.TypedSplice(_)), fn) else fn
308308
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
17611761
if (mt.isParamDependent)
17621762
report.error(em"$mt is an illegal function type because it has inter-parameter dependencies", tree.srcPos)
17631763
// Restart typechecking if there are erased classes that we want to mark erased
1764-
if mt.erasedParams.zip(mt.paramInfos.map(_.isErasedClass)).exists((paramErased, classErased) => classErased && !paramErased) then
1764+
if mt.paramErasureStatuses.zip(mt.paramInfos.map(_.isErasedClass)).exists((paramErased, classErased) => classErased && !paramErased) then
17651765
val newParams = params3.zipWithConserve(mt.paramInfos.map(_.isErasedClass)) { (arg, isErasedClass) =>
17661766
if isErasedClass then arg.withAddedFlags(Erased) else arg
17671767
}
@@ -3788,7 +3788,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
37883788
}
37893789

37903790
val erasedParams = pt match {
3791-
case defn.PolyFunctionOf(mt: MethodType) => mt.erasedParams
3791+
case defn.PolyFunctionOf(mt: MethodType) => mt.paramErasureStatuses
37923792
case _ => paramTypes.map(_ => false)
37933793
}
37943794

compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class QuoteMatcher(debug: Boolean) {
448448
def matchErasedParams(sctype: Type, pttype: Type): optional[MatchingExprs] =
449449
(sctype, pttype) match
450450
case (sctpe: MethodType, pttpe: MethodType) =>
451-
if sctpe.erasedParams.sameElements(pttpe.erasedParams) then
451+
if sctpe.paramErasureStatuses.sameElements(pttpe.paramErasureStatuses) then
452452
matchErasedParams(sctpe.resType, pttpe.resType)
453453
else
454454
notMatched

0 commit comments

Comments
 (0)