Skip to content

Commit 5659aaf

Browse files
committed
Optimize boxedUnlessFun
1 parent b9a559e commit 5659aaf

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension (tp: Type)
6868
//.showing(i"boxedUF $tp in $tycon = $result")
6969

7070
/** The boxed capture set of a type */
71-
def boxedCaptured(using Context): CaptureSet =
71+
def boxedCaptureSet(using Context): CaptureSet =
7272
def getBoxed(tp: Type): CaptureSet = tp match
7373
case tp @ CapturingType(parent, refs) =>
7474
val pcs = getBoxed(parent)
@@ -80,7 +80,7 @@ extension (tp: Type)
8080
case _ => CaptureSet.empty
8181
getBoxed(tp)
8282

83-
def isBoxedCapturing(using Context) = !tp.boxedCaptured.isAlwaysEmpty
83+
def isBoxedCapturing(using Context) = !tp.boxedCaptureSet.isAlwaysEmpty
8484

8585
def stripCapturing(using Context): Type = tp.dealiasKeepAnnots match
8686
case CapturingType(parent, _) =>
@@ -133,3 +133,9 @@ extension (tp: AnnotatedType)
133133
case ann: CaptureAnnotation => ann.boxed
134134
case _ => false
135135

136+
extension (ts: List[Type])
137+
def boxedUnlessFun(tycon: Type)(using Context) =
138+
if ctx.phase != Phases.checkCapturesPhase || defn.isFunctionClass(tycon.typeSymbol)
139+
then ts
140+
else ts.mapconserve(_.boxed)
141+

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,9 @@ class TypeApplications(val self: Type) extends AnyVal {
494494
* otherwise return Nil.
495495
* Existential types in arguments are returned as TypeBounds instances.
496496
*/
497-
final def argInfos(using Context): List[Type] = self.stripped match {
498-
case AppliedType(tycon, args) => args.mapconserve(_.boxedUnlessFun(tycon))
497+
final def argInfos(using Context): List[Type] = self.stripped match
498+
case AppliedType(tycon, args) => args.boxedUnlessFun(tycon)
499499
case _ => Nil
500-
}
501500

502501
/** Argument types where existential types in arguments are disallowed */
503502
def argTypes(using Context): List[Type] = argInfos mapConserve noBounds

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CheckCaptures extends Recheck, SymTransformer:
187187
includeIn(curEnv.outer)
188188

189189
def includeBoxedCaptures(tp: Type, pos: SrcPos)(using Context): Unit =
190-
includeBoxedCaptures(tp.boxedCaptured, pos)
190+
includeBoxedCaptures(tp.boxedCaptureSet, pos)
191191

192192
def includeBoxedCaptures(refs: CaptureSet, pos: SrcPos)(using Context): Unit =
193193
if curEnv.isOpen then
@@ -213,9 +213,9 @@ class CheckCaptures extends Recheck, SymTransformer:
213213
*/
214214
def addResultBoxes(tp: Type)(using Context): Type =
215215
def includeBoxed(res: Type) =
216-
//if !res.boxedCaptured.isAlwaysEmpty then
217-
// println(i"add boxed $tp from ${res.boxedCaptured}")
218-
tp.capturing(res.boxedCaptured)
216+
//if !res.boxedCaptureSet.isAlwaysEmpty then
217+
// println(i"add boxed $tp from ${res.boxedCaptureSet}")
218+
tp.capturing(res.boxedCaptureSet)
219219
val tp1 = tp.dealias
220220
val boxedTp = tp1 match
221221
case tp1 @ AppliedType(_, args) if defn.isNonRefinedFunction(tp1) =>

0 commit comments

Comments
 (0)