Skip to content

Commit 740e11b

Browse files
committed
make TyperState#test take an IFT argument
1 parent c85f708 commit 740e11b

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object Contexts {
315315
/** Run `op` as if it was run in a fresh explore typer state, but possibly
316316
* optimized to re-use the current typer state.
317317
*/
318-
final def test[T](op: Context => T): T = typerState.test(op)(this)
318+
final def test[T](op: given Context => T): T = typerState.test(op)(this)
319319

320320
/** Is this a context for the members of a class definition? */
321321
def isClassDefContext: Boolean =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ class TyperState(private val previous: TyperState /* | Null */) {
9696
* typerstate. If it is unshared, run `op` in current typerState, restoring typerState
9797
* to previous state afterwards.
9898
*/
99-
def test[T](op: Context => T)(implicit ctx: Context): T =
99+
def test[T](op: given Context => T)(implicit ctx: Context): T =
100100
if (isShared)
101-
op(ctx.fresh.setExploreTyperState())
101+
op given ctx.fresh.setExploreTyperState()
102102
else {
103103
val savedConstraint = myConstraint
104104
val savedReporter = myReporter
@@ -114,7 +114,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
114114
testReporter.inUse = true
115115
testReporter
116116
}
117-
try op(ctx)
117+
try op given ctx
118118
finally {
119119
testReporter.inUse = false
120120
resetConstraintTo(savedConstraint)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,20 +1153,20 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
11531153
def isApplicableMethodRef(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type, keepConstraint: Boolean)(implicit ctx: Context): Boolean = {
11541154
def isApp(implicit ctx: Context): Boolean =
11551155
new ApplicableToTrees(methRef, targs, args, resultType).success
1156-
if (keepConstraint) isApp else ctx.test(implicit ctx => isApp)
1156+
if (keepConstraint) isApp else ctx.test(isApp)
11571157
}
11581158

11591159
/** Is given method reference applicable to type arguments `targs` and argument trees `args` without inferring views?
11601160
* @param resultType The expected result type of the application
11611161
*/
11621162
def isDirectlyApplicableMethodRef(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context): Boolean =
1163-
ctx.test(implicit ctx => new ApplicableToTreesDirectly(methRef, targs, args, resultType).success)
1163+
ctx.test(new ApplicableToTreesDirectly(methRef, targs, args, resultType).success)
11641164

11651165
/** Is given method reference applicable to argument types `args`?
11661166
* @param resultType The expected result type of the application
11671167
*/
11681168
def isApplicableMethodRef(methRef: TermRef, args: List[Type], resultType: Type)(implicit ctx: Context): Boolean =
1169-
ctx.test(implicit ctx => new ApplicableToTypes(methRef, args, resultType).success)
1169+
ctx.test(new ApplicableToTypes(methRef, args, resultType).success)
11701170

11711171
/** Is given type applicable to type arguments `targs` and argument trees `args`,
11721172
* possibly after inserting an `apply`?
@@ -1287,7 +1287,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
12871287
case tp2: MethodType => true // (3a)
12881288
case tp2: PolyType if tp2.resultType.isInstanceOf[MethodType] => true // (3a)
12891289
case tp2: PolyType => // (3b)
1290-
ctx.test(implicit ctx => isAsSpecificValueType(tp1, constrained(tp2).resultType))
1290+
ctx.test(isAsSpecificValueType(tp1, constrained(tp2).resultType))
12911291
case _ => // (3b)
12921292
isAsSpecificValueType(tp1, tp2)
12931293
}
@@ -1481,9 +1481,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
14811481
* do they prune much, on average.
14821482
*/
14831483
def adaptByResult(chosen: TermRef, alts: List[TermRef]) = pt match {
1484-
case pt: FunProto if !ctx.test(implicit ctx => resultConforms(chosen.symbol, chosen, pt.resultType)) =>
1484+
case pt: FunProto if !ctx.test(resultConforms(chosen.symbol, chosen, pt.resultType)) =>
14851485
val conformingAlts = alts.filter(alt =>
1486-
(alt ne chosen) && ctx.test(implicit ctx => resultConforms(alt.symbol, alt, pt.resultType)))
1486+
(alt ne chosen) && ctx.test(resultConforms(alt.symbol, alt, pt.resultType)))
14871487
conformingAlts match {
14881488
case Nil => chosen
14891489
case alt2 :: Nil => alt2

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ object Implicits {
102102
else if (mt.paramInfos.lengthCompare(1) == 0 && {
103103
var formal = widenSingleton(mt.paramInfos.head)
104104
if (approx) formal = wildApprox(formal)
105-
ctx.test(implicit ctx => argType relaxed_<:< formal.widenExpr)
105+
ctx.test(argType relaxed_<:< formal.widenExpr)
106106
})
107107
Candidate.Conversion
108108
else
@@ -216,7 +216,7 @@ object Implicits {
216216
val nestedCtx = ctx.fresh.addMode(Mode.TypevarsMissContext)
217217

218218
def matchingCandidate(ref: ImplicitRef): Option[Candidate] =
219-
nestedCtx.test(implicit ctx => candidateKind(ref.underlyingRef)) match {
219+
nestedCtx.test(candidateKind(ref.underlyingRef)) match {
220220
case Candidate.None => None
221221
case ckind => Some(new Candidate(ref, ckind, level))
222222
}
@@ -808,7 +808,7 @@ trait Implicits { self: Typer =>
808808
if (canComparePredefined(arg1, arg2)
809809
||
810810
!strictEquality &&
811-
ctx.test(implicit ctx => validEqAnyArgs(arg1, arg2)))
811+
ctx.test(validEqAnyArgs(arg1, arg2)))
812812
ref(defn.Eql_eqlAny).appliedToTypes(args).withSpan(span)
813813
else EmptyTree
814814
case _ =>
@@ -1391,7 +1391,7 @@ trait Implicits { self: Typer =>
13911391
def compareCandidate(prev: SearchSuccess, ref: TermRef, level: Int): Int =
13921392
if (prev.ref eq ref) 0
13931393
else if (prev.level != level) prev.level - level
1394-
else nestedContext().test(implicit ctx => compare(prev.ref, ref))
1394+
else nestedContext().test(compare(prev.ref, ref))
13951395

13961396
/** If `alt1` is also a search success, try to disambiguate as follows:
13971397
* - If alt2 is preferred over alt1, pick alt2, otherwise return an

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object ProtoTypes {
5656
normalizedCompatible(tp, pt, keepConstraint = false)
5757
case _ => testCompat
5858
}
59-
else ctx.test(implicit ctx => testCompat)
59+
else ctx.test(testCompat)
6060
}
6161

6262
private def disregardProto(pt: Type)(implicit ctx: Context): Boolean = pt.dealias match {

0 commit comments

Comments
 (0)