Skip to content

Commit 7e7b3f9

Browse files
committed
Add option to avoid intersections for class refinements
Add an option to avoid the type intersection when we do a select of a parameter accessor that is mentioned in a class refinement type. It seems to give us a little bit if performance, but nothing significant. So the option is off by default.
1 parent 7ac9c7b commit 7e7b3f9

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ object ccConfig:
2727
*/
2828
inline val allowUnsoundMaps = false
2929

30+
/** If true, when computing the memberinfo of a refined type created
31+
* by addCaptureRefinements take the refineInfo directly without intersecting
32+
* with the parent info.
33+
*/
34+
inline val optimizedRefinements = false
35+
3036
/** If true, use existential capture set variables */
3137
def useExistentials(using Context) =
3238
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.5`)

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import CaptureSet.{CompareResult, IdempotentCaptRefMap, IdentityCaptRefMap}
4343

4444
import scala.annotation.internal.sharable
4545
import scala.annotation.threadUnsafe
46+
import dotty.tools.dotc.cc.ccConfig
4647

4748
object Types extends TypeUtils {
4849

@@ -865,19 +866,23 @@ object Types extends TypeUtils {
865866
}
866867
else
867868
val isRefinedMethod = rinfo.isInstanceOf[MethodOrPoly]
868-
val joint = pdenot.meet(
869-
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),
870-
pre,
871-
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
872-
joint match
873-
case joint: SingleDenotation
874-
if isRefinedMethod
875-
&& (rinfo <:< joint.info
876-
|| name == nme.apply && defn.isFunctionType(tp.parent)) =>
877-
// use `rinfo` to keep the right parameter names for named args. See i8516.scala.
878-
joint.derivedSingleDenotation(joint.symbol, rinfo, pre, isRefinedMethod)
869+
rinfo match
870+
case CapturingType(_, refs: CaptureSet.RefiningVar) if ccConfig.optimizedRefinements =>
871+
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, rinfo)
879872
case _ =>
880-
joint
873+
val joint = pdenot.meet(
874+
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),
875+
pre,
876+
safeIntersection = ctx.base.pendingMemberSearches.contains(name))
877+
joint match
878+
case joint: SingleDenotation
879+
if isRefinedMethod
880+
&& (rinfo <:< joint.info
881+
|| name == nme.apply && defn.isFunctionType(tp.parent)) =>
882+
// use `rinfo` to keep the right parameter names for named args. See i8516.scala.
883+
joint.derivedSingleDenotation(joint.symbol, rinfo, pre, isRefinedMethod)
884+
case _ =>
885+
joint
881886
}
882887

883888
def goApplied(tp: AppliedType, tycon: HKTypeLambda) =

0 commit comments

Comments
 (0)