Skip to content

Commit 4c807c5

Browse files
committed
Roll the isAlwaysEmpty optimisation into capturing
1 parent efe28db commit 4c807c5

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -2613,11 +2613,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
26132613
val refs2 = tp2.captureSet
26142614
if subCaptures(refs2, refs1, frozen = true).isOK
26152615
&& tp1.isBoxedCapturing == tp2.isBoxedCapturing
2616-
then
2617-
if refs2.isAlwaysEmpty then parent1 & tp2
2618-
else (parent1 & tp2).capturing(refs2)
2619-
else
2620-
tp1.derivedCapturingType(parent1 & tp2, refs1)
2616+
then (parent1 & tp2).capturing(refs2)
2617+
else tp1.derivedCapturingType(parent1 & tp2, refs1)
26212618
case tp1: AnnotatedType if !tp1.isRefining =>
26222619
tp1.underlying & tp2
26232620
case _ =>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ object Types {
19401940
* the two capture sets are combined.
19411941
*/
19421942
def capturing(cs: CaptureSet)(using Context): Type =
1943-
if cs.isConst && cs.subCaptures(captureSet, frozen = true).isOK then this
1943+
if cs.isAlwaysEmpty || cs.isConst && cs.subCaptures(captureSet, frozen = true).isOK then this
19441944
else this match
19451945
case CapturingType(parent, cs1) => parent.capturing(cs1 ++ cs)
19461946
case _ => CapturingType(this, cs)

0 commit comments

Comments
 (0)