Skip to content

Commit c13c1c9

Browse files
committed
Rename ContextFunctionType to ContextFunctionOf
For homogeneouity with `FunctionOf` and `PolyFunctionOf`.
1 parent fdbc86b commit c13c1c9

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11491149

11501150
def etaExpandCFT(using Context): Tree =
11511151
def expand(target: Tree, tp: Type)(using Context): Tree = tp match
1152-
case defn.ContextFunctionType(argTypes, resType) =>
1152+
case defn.ContextFunctionOf(argTypes, resType) =>
11531153
val anonFun = newAnonFun(
11541154
ctx.owner,
11551155
MethodType.companion(isContextual = true)(argTypes, resType),

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,24 @@ class Definitions {
11291129
}
11301130
}
11311131

1132+
/** An extractor for context function types `As ?=> B`, possibly with
1133+
* dependent refinements. Optionally returns a triple consisting of the argument
1134+
* types `As`, the result type `B` and a whether the type is an erased context function.
1135+
*/
1136+
object ContextFunctionOf:
1137+
def unapply(tp: Type)(using Context): Option[(List[Type], Type)] =
1138+
if ctx.erasedTypes then
1139+
atPhase(erasurePhase)(unapply(tp))
1140+
else
1141+
asContextFunctionType(tp) match
1142+
case PolyFunctionOf(mt: MethodType) =>
1143+
Some((mt.paramInfos, mt.resType))
1144+
case tp1 if tp1.exists =>
1145+
val args = tp1.functionArgInfos
1146+
val erasedParams = List.fill(functionArity(tp1)) { false }
1147+
Some((args.init, args.last))
1148+
case _ => None
1149+
11321150
object PolyFunctionOf {
11331151

11341152
/** Creates a refined `PolyFunction` with an `apply` method with the given info. */
@@ -1867,24 +1885,6 @@ class Definitions {
18671885
def isContextFunctionType(tp: Type)(using Context): Boolean =
18681886
asContextFunctionType(tp).exists
18691887

1870-
/** An extractor for context function types `As ?=> B`, possibly with
1871-
* dependent refinements. Optionally returns a triple consisting of the argument
1872-
* types `As`, the result type `B` and a whether the type is an erased context function.
1873-
*/
1874-
object ContextFunctionType:
1875-
def unapply(tp: Type)(using Context): Option[(List[Type], Type)] =
1876-
if ctx.erasedTypes then
1877-
atPhase(erasurePhase)(unapply(tp))
1878-
else
1879-
asContextFunctionType(tp) match
1880-
case PolyFunctionOf(mt: MethodType) =>
1881-
Some((mt.paramInfos, mt.resType))
1882-
case tp1 if tp1.exists =>
1883-
val args = tp1.functionArgInfos
1884-
val erasedParams = List.fill(functionArity(tp1)) { false }
1885-
Some((args.init, args.last))
1886-
case _ => None
1887-
18881888
/** A whitelist of Scala-2 classes that are known to be pure */
18891889
def isAssuredNoInits(sym: Symbol): Boolean =
18901890
(sym `eq` SomeClass) || isTupleClass(sym)

compiler/src/dotty/tools/dotc/transform/Bridges.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
129129
assert(ctx.typer.isInstanceOf[Erasure.Typer])
130130
ctx.typer.typed(untpd.cpy.Apply(ref)(ref, args), member.info.finalResultType)
131131
else
132-
val defn.ContextFunctionType(argTypes, resType) = tp: @unchecked
132+
val defn.ContextFunctionOf(argTypes, resType) = tp: @unchecked
133133
val erasedParams = defn.erasedFunctionParams(tp)
134134
val anonFun = newAnonFun(ctx.owner,
135135
MethodType(

compiler/src/dotty/tools/dotc/transform/ContextFunctionResults.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object ContextFunctionResults:
2020
*/
2121
def annotateContextResults(mdef: DefDef)(using Context): Unit =
2222
def contextResultCount(rhs: Tree, tp: Type): Int = tp match
23-
case defn.ContextFunctionType(_, resTpe) =>
23+
case defn.ContextFunctionOf(_, resTpe) =>
2424
rhs match
2525
case closureDef(meth) => 1 + contextResultCount(meth.rhs, resTpe)
2626
case _ => 0
@@ -58,7 +58,7 @@ object ContextFunctionResults:
5858
*/
5959
def contextResultsAreErased(sym: Symbol)(using Context): Boolean =
6060
def allErased(tp: Type): Boolean = tp.dealias match
61-
case ft @ defn.ContextFunctionType(_, resTpe) =>
61+
case ft @ defn.ContextFunctionOf(_, resTpe) =>
6262
!defn.erasedFunctionParams(ft).contains(false) && allErased(resTpe)
6363
case _ => true
6464
contextResultCount(sym) > 0 && allErased(sym.info.finalResultType)
@@ -73,7 +73,7 @@ object ContextFunctionResults:
7373
integrateContextResults(rt, crCount)
7474
case tp: MethodOrPoly =>
7575
tp.derivedLambdaType(resType = integrateContextResults(tp.resType, crCount))
76-
case defn.ContextFunctionType(argTypes, resType) =>
76+
case defn.ContextFunctionOf(argTypes, resType) =>
7777
MethodType(argTypes, integrateContextResults(resType, crCount - 1))
7878

7979
/** The total number of parameters of method `sym`, not counting
@@ -84,7 +84,7 @@ object ContextFunctionResults:
8484
def contextParamCount(tp: Type, crCount: Int): Int =
8585
if crCount == 0 then 0
8686
else
87-
val defn.ContextFunctionType(params, resTpe) = tp: @unchecked
87+
val defn.ContextFunctionOf(params, resTpe) = tp: @unchecked
8888
val erasedParams = defn.erasedFunctionParams(tp)
8989
val rest = contextParamCount(resTpe, crCount - 1)
9090
if erasedParams.contains(true) then erasedParams.count(_ == false) + rest else params.length + rest
@@ -105,7 +105,7 @@ object ContextFunctionResults:
105105
def recur(tp: Type, n: Int): Type =
106106
if n == 0 then tp
107107
else tp match
108-
case defn.ContextFunctionType(_, resTpe) => recur(resTpe, n - 1)
108+
case defn.ContextFunctionOf(_, resTpe) => recur(resTpe, n - 1)
109109
recur(meth.info.finalResultType, depth)
110110

111111
/** Should selection `tree` be eliminated since it refers to an `apply`
@@ -120,7 +120,7 @@ object ContextFunctionResults:
120120
case Select(qual, name) =>
121121
if name == nme.apply then
122122
qual.tpe match
123-
case defn.ContextFunctionType(_, _) =>
123+
case defn.ContextFunctionOf(_, _) =>
124124
integrateSelect(qual, n + 1)
125125
case _ if defn.isContextFunctionClass(tree.symbol.maybeOwner) => // for TermRefs
126126
integrateSelect(qual, n + 1)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ object ErrorReporting {
167167
val normPt = normalize(pt, pt)
168168

169169
def contextFunctionCount(tp: Type): Int = tp.stripped match
170-
case defn.ContextFunctionType(_, restp) => 1 + contextFunctionCount(restp)
170+
case defn.ContextFunctionOf(_, restp) => 1 + contextFunctionCount(restp)
171171
case _ => 0
172172
def strippedTpCount = contextFunctionCount(tree.tpe) - contextFunctionCount(normTp)
173173
def strippedPtCount = contextFunctionCount(pt) - contextFunctionCount(normPt)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ class Namer { typer: Typer =>
18931893
val originalTp = defaultParamType
18941894
val approxTp = wildApprox(originalTp)
18951895
approxTp.stripPoly match
1896-
case atp @ defn.ContextFunctionType(_, resType)
1896+
case atp @ defn.ContextFunctionOf(_, resType)
18971897
if !defn.isNonRefinedFunction(atp) // in this case `resType` is lying, gives us only the non-dependent upper bound
18981898
|| resType.existsPart(_.isInstanceOf[WildcardType], StopAt.Static, forceLazy = false) =>
18991899
originalTp

0 commit comments

Comments
 (0)