Skip to content

Commit b9a559e

Browse files
committed
Don't box type arguments in Setup
They will be boxed anyway when they are accessed.
1 parent 7006bea commit b9a559e

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,19 @@ extends tpd.TreeTraverser:
4545
else tp1.derivedLambdaType(resType = boxedRes)
4646
case _ => tp
4747

48-
private def addBoxes(using Context) = new TypeMap:
49-
def apply(t: Type) = mapOver(t) match
50-
case t1 @ AppliedType(tycon, args) if !defn.isNonRefinedFunction(t1) =>
51-
t1.derivedAppliedType(tycon, args.mapConserve(box))
52-
case t1: AliasingBounds =>
53-
t1.derivedAlias(t1.alias)
54-
case t1 @ TypeBounds(lo, hi) =>
55-
t1.derivedTypeBounds(box(lo), box(hi))
56-
case t1 =>
57-
t1
58-
override def mapCapturingType(tp: Type, parent: Type, refs: CaptureSet, v: Int): Type =
59-
tp.derivedCapturingType(this(parent), refs)
60-
end addBoxes
61-
6248
/** Expand some aliases of function types to the underlying functions.
6349
* Right now, these are only $throws aliases, but this could be generalized.
6450
*/
65-
def expandInlineAlias(tp: Type)(using Context) = tp match
51+
def expandThrowsAlias(tp: Type)(using Context) = tp match
6652
case AppliedType(tycon, res :: exc :: Nil) if tycon.typeSymbol == defn.throwsAlias =>
6753
// hard-coded expansion since $throws aliases in stdlib are defined with `?=>` rather than `?->`
6854
defn.FunctionOf(defn.CanThrowClass.typeRef.appliedTo(exc) :: Nil, res, isContextual = true, isErased = true)
6955
case _ => tp
7056

71-
private def expandInlineAliases(using Context) = new TypeMap:
57+
private def expandThrowsAliases(using Context) = new TypeMap:
7258
def apply(t: Type) = t match
7359
case _: AppliedType =>
74-
val t1 = expandInlineAlias(t)
60+
val t1 = expandThrowsAlias(t)
7561
if t1 ne t then apply(t1) else mapOver(t)
7662
case _: LazyRef =>
7763
t
@@ -208,7 +194,7 @@ extends tpd.TreeTraverser:
208194
try ts.mapConserve(this) finally isTopLevel = saved
209195

210196
def apply(t: Type) =
211-
val tp = expandInlineAlias(t)
197+
val tp = expandThrowsAlias(t)
212198
val tp1 = tp match
213199
case AnnotatedType(parent, annot) if annot.symbol == defn.RetainsAnnot =>
214200
apply(parent)
@@ -296,9 +282,7 @@ extends tpd.TreeTraverser:
296282
if boxed then box(tp1) else tp1
297283

298284
private def transformExplicitType(tp: Type, boxed: Boolean)(using Context): Type =
299-
var tp1 = addBoxes(tp)
300-
if boxed then tp1 = box(tp1)
301-
tp1 = expandInlineAliases(tp1)
285+
val tp1 = expandThrowsAliases(if boxed then box(tp) else tp)
302286
if tp1 ne tp then capt.println(i"expanded: $tp --> $tp1")
303287
if ctx.settings.YccNoAbbrev.value then tp1
304288
else expandAbbreviations(tp1)

0 commit comments

Comments
 (0)