Skip to content

Commit 2738524

Browse files
committed
add some traces
1 parent 10d79ff commit 2738524

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

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

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import transform.ContextFunctionResults.*
1313
import unpickleScala2.Scala2Erasure
1414
import Decorators.*
1515
import Definitions.MaxImplementedFunctionArity
16+
import dotty.tools.dotc.reporting.trace
17+
1618
import scala.annotation.tailrec
1719

1820
/** The language in which the definition being erased was written. */
@@ -820,7 +822,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
820822
case tp1 =>
821823
this(tp1)
822824

823-
private def eraseDerivedValueClass(tp: Type)(using Context): Type = {
825+
private def eraseDerivedValueClass(tp: Type)(using Context): Type = trace.force(i"eraseDerivedValueClass $tp") {
824826
val cls = tp.classSymbol.asClass
825827
val unbox = valueClassUnbox(cls)
826828
if unbox.exists then
@@ -830,30 +832,33 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
830832
// The underlying part of an ErasedValueType cannot be an ErasedValueType itself
831833
val erase = erasureFn(sourceLanguage, semiEraseVCs = false, isConstructor, isSymbol, inSigName)
832834
val erasedUnderlying = erase(underlying)
833-
if erasedUnderlying.isInstanceOf[WildcardType] then return WildcardType
834-
835-
// Ideally, we would just use `erasedUnderlying` as the erasure of `tp`, but to
836-
// be binary-compatible with Scala 2 we need two special cases for polymorphic
837-
// value classes:
838-
// - Given `class Foo[A](x: A) extends AnyVal`, `Foo[X]` should erase like
839-
// `X`, except if its a primitive in which case it erases to the boxed
840-
// version of this primitive.
841-
// - Given `class Bar[A](x: Array[A]) extends AnyVal`, `Bar[X]` will be
842-
// erased like `Array[A]` as seen from its definition site, no matter
843-
// the `X` (same if `A` is bounded).
844-
//
845-
// The binary compatibility is checked by sbt-test/scala2-compat/i8001
846-
val erasedValueClass =
847-
if erasedUnderlying.isPrimitiveValueType && !genericUnderlying.isPrimitiveValueType then
848-
defn.boxedType(erasedUnderlying)
849-
else if genericUnderlying.derivesFrom(defn.ArrayClass) then
850-
erasure(genericUnderlying)
851-
else erasedUnderlying
852-
853-
if erasedValueClass.exists then ErasedValueType(cls.typeRef, erasedValueClass)
854-
else
855-
assert(ctx.reporter.errorsReported, i"no erasure for $underlying")
856-
NoType
835+
if erasedUnderlying.isInstanceOf[WildcardType] then WildcardType
836+
else {
837+
838+
// Ideally, we would just use `erasedUnderlying` as the erasure of `tp`, but to
839+
// be binary-compatible with Scala 2 we need two special cases for polymorphic
840+
// value classes:
841+
// - Given `class Foo[A](x: A) extends AnyVal`, `Foo[X]` should erase like
842+
// `X`, except if its a primitive in which case it erases to the boxed
843+
// version of this primitive.
844+
// - Given `class Bar[A](x: Array[A]) extends AnyVal`, `Bar[X]` will be
845+
// erased like `Array[A]` as seen from its definition site, no matter
846+
// the `X` (same if `A` is bounded).
847+
//
848+
// The binary compatibility is checked by sbt-test/scala2-compat/i8001
849+
val erasedValueClass = trace.force(i"erasedValueClass of erasedUnderlying $erasedUnderlying and genericUnderlying $genericUnderlying") {
850+
if erasedUnderlying.isPrimitiveValueType && !genericUnderlying.isPrimitiveValueType then
851+
defn.boxedType(erasedUnderlying)
852+
else if genericUnderlying.derivesFrom(defn.ArrayClass) then
853+
erasure(genericUnderlying)
854+
else erasedUnderlying
855+
}
856+
857+
if erasedValueClass.exists then ErasedValueType(cls.typeRef, erasedValueClass)
858+
else
859+
assert(ctx.reporter.errorsReported, i"no erasure for $underlying")
860+
NoType
861+
}
857862
else NoType
858863
}
859864

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ object Erasure {
270270
def constant(tree: Tree, const: Tree)(using Context): Tree =
271271
(if (isPureExpr(tree)) const else Block(tree :: Nil, const)).withSpan(tree.span)
272272

273-
final def box(tree: Tree, target: => String = "")(using Context): Tree = trace(i"boxing ${tree.showSummary()}: ${tree.tpe} into $target") {
273+
final def box(tree: Tree, target: => String = "")(using Context): Tree = trace.force(i"boxing ${tree.showSummary()}: ${tree.tpe} into $target") {
274274
tree.tpe.widen match {
275275
case ErasedValueType(tycon, _) =>
276276
New(tycon, cast(tree, underlyingOfValueClass(tycon.symbol.asClass)) :: Nil) // todo: use adaptToType?
@@ -290,7 +290,7 @@ object Erasure {
290290
}
291291
}
292292

293-
def unbox(tree: Tree, pt: Type)(using Context): Tree = trace(i"unboxing ${tree.showSummary()}: ${tree.tpe} as a $pt") {
293+
def unbox(tree: Tree, pt: Type)(using Context): Tree = trace.force(i"unboxing ${tree.showSummary()}: ${tree.tpe} as a $pt") {
294294
pt match {
295295
case ErasedValueType(tycon, underlying) =>
296296
def unboxedTree(t: Tree) =

0 commit comments

Comments
 (0)