Skip to content

Commit cfa1f88

Browse files
committed
Improve code based on review
1 parent e8fb429 commit cfa1f88

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Types.Type
77

88
/** Phantom erasure erases:
99
*
10-
* - Parameters/arguments are erased removed from the function definition/call in `PhantomArgumentEval`.
10+
* - Parameters/arguments are removed from the function definition/call in `PhantomArgumentEval`.
1111
* If the evaluation of the phantom arguments may produce a side effect, these are evaluated and stored in
1212
* local `val`s and then the non phantoms are used in the Apply. Phantom `val`s are then erased to
1313
* `val ev$i: ErasedPhantom = myPhantom` intended to be optimized away by local optimizations. `myPhantom` could be

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
401401
def paramErasure(tpToErase: Type) =
402402
erasureFn(tp.isJava, semiEraseVCs, isConstructor, wildcardOK)(tpToErase)
403403
val (names, formals0) =
404-
if (tp.paramInfos.forall(!_.isPhantom)) (tp.paramNames, tp.paramInfos)
405-
else tp.paramNames.iterator.zip(tp.paramInfos.iterator).filterNot(_._2.isPhantom).toList.unzip
404+
if (tp.paramInfos.exists(_.isPhantom)) tp.paramNames.zip(tp.paramInfos).filterNot(_._2.isPhantom).unzip
405+
else (tp.paramNames, tp.paramInfos)
406406
val formals = formals0.mapConserve(paramErasure)
407407
eraseResult(tp.resultType) match {
408408
case rt: MethodType =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ object Erasure extends TypeTestsCasts{
477477
.withType(defn.ArrayOf(defn.ObjectType))
478478
args0 = bunchedArgs :: Nil
479479
}
480+
// Arguments are phantom if an only if the parameters are phantom, guaranteed by the separation of type lattices
480481
val args1 = args0.filterConserve(arg => !wasPhantom(arg.typeOpt)).zipWithConserve(mt.paramInfos)(typedExpr)
481482
untpd.cpy.Apply(tree)(fun1, args1) withType mt.resultType
482483
case _ =>

0 commit comments

Comments
 (0)