Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17d954c

Browse files
committedFeb 7, 2023
Change isFunctionType to only recognize synthesized Function traits
Poly and Erased functions are recognized in `isRefinedFunctionType`. Comments are updated to reflect this.
1 parent fc91da8 commit 17d954c

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed
 

‎compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,9 +960,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
960960
&& tree.isTerm
961961
&& {
962962
val qualType = tree.qualifier.tpe
963-
hasRefinement(qualType) &&
964-
!qualType.derivesFrom(defn.PolyFunctionClass) &&
965-
!defn.isErasedFunctionType(qualType)
963+
hasRefinement(qualType) && !defn.isRefinedFunctionType(qualType)
966964
}
967965
def loop(tree: Tree): Boolean = tree match
968966
case TypeApply(fun, _) =>

‎compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ class CheckCaptures extends Recheck, SymTransformer:
739739
case actual @ AppliedType(tycon, args) if defn.isNonRefinedFunction(actual) =>
740740
adaptFun(actual, args.init, args.last, expected, covariant, insertBox,
741741
(aargs1, ares1) => actual.derivedAppliedType(tycon, aargs1 :+ ares1))
742-
case actual @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(actual) =>
742+
case actual @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionOrPolyType(actual) =>
743743
// TODO Find a way to combine handling of generic and dependent function types (here and elsewhere)
744744
adaptFun(actual, rinfo.paramInfos, rinfo.resType, expected, covariant, insertBox,
745745
(aargs1, ares1) =>
@@ -962,7 +962,7 @@ class CheckCaptures extends Recheck, SymTransformer:
962962
case CapturingType(parent, refs) =>
963963
healCaptureSet(refs)
964964
traverse(parent)
965-
case tp @ RefinedType(parent, rname, rinfo: MethodType) if defn.isFunctionType(tp) =>
965+
case tp @ RefinedType(parent, rname, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
966966
traverse(rinfo)
967967
case tp: TermLambda =>
968968
val saved = allowed

‎compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extends tpd.TreeTraverser:
5454
val boxedRes = recur(res)
5555
if boxedRes eq res then tp
5656
else tp1.derivedAppliedType(tycon, args.init :+ boxedRes)
57-
case tp1 @ RefinedType(_, _, rinfo) if defn.isFunctionType(tp1) =>
57+
case tp1 @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionOrPolyType(tp1) =>
5858
val boxedRinfo = recur(rinfo)
5959
if boxedRinfo eq rinfo then tp
6060
else boxedRinfo.toFunctionType(isJava = false, alwaysDependent = true)
@@ -231,7 +231,7 @@ extends tpd.TreeTraverser:
231231
tp.derivedAppliedType(tycon1, args1 :+ res1)
232232
else
233233
tp.derivedAppliedType(tycon1, args.mapConserve(arg => this(arg)))
234-
case tp @ RefinedType(core, rname, rinfo) if defn.isFunctionType(tp) =>
234+
case tp @ RefinedType(core, rname, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
235235
val rinfo1 = apply(rinfo)
236236
if rinfo1 ne rinfo then rinfo1.toFunctionType(isJava = false, alwaysDependent = true)
237237
else tp
@@ -327,7 +327,7 @@ extends tpd.TreeTraverser:
327327
args.last, CaptureSet.empty, currentCs ++ outerCs)
328328
tp.derivedAppliedType(tycon1, args1 :+ resType1)
329329
tp1.capturing(outerCs)
330-
case tp @ RefinedType(parent, nme.apply, rinfo: MethodType) if defn.isFunctionType(tp) =>
330+
case tp @ RefinedType(parent, nme.apply, rinfo: MethodType) if defn.isFunctionOrPolyType(tp) =>
331331
propagateDepFunctionResult(mapOver(tp), currentCs ++ outerCs)
332332
.capturing(outerCs)
333333
case _ =>

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,6 @@ class Definitions {
14831483

14841484
/** Is any function class where
14851485
* - FunctionXXL
1486-
* - ErasedFunction
14871486
* - FunctionN for N >= 0
14881487
* - ContextFunctionN for N >= 0
14891488
*/
@@ -1684,12 +1683,25 @@ class Definitions {
16841683
skipRefined = false)
16851684
end isNonRefinedFunction
16861685

1687-
/** Is `tp` a representation of a (possibly dependent) function type or an alias of such? */
1686+
/** Returns whether `tp` is an instance or a refined instance of:
1687+
* - scala.FunctionN
1688+
* - scala.ContextFunctionN
1689+
*/
16881690
def isFunctionType(tp: Type)(using Context): Boolean =
1689-
isNonRefinedFunction(tp.dropDependentRefinement) || isErasedFunctionType(tp)
1691+
isNonRefinedFunction(tp.dropDependentRefinement)
1692+
1693+
/** Is `tp` a specialized, refined function type? Either an `ErasedFunction` or a `PolyFunction`. */
1694+
def isRefinedFunctionType(tp: Type)(using Context): Boolean =
1695+
tp.derivesFrom(defn.PolyFunctionClass) || isErasedFunctionType(tp)
16901696

1697+
/** Returns whether `tp` is an instance or a refined instance of:
1698+
* - scala.FunctionN
1699+
* - scala.ContextFunctionN
1700+
* - ErasedFunction
1701+
* - PolyFunction
1702+
*/
16911703
def isFunctionOrPolyType(tp: Type)(using Context): Boolean =
1692-
isFunctionType(tp) || (tp.typeSymbol eq defn.PolyFunctionClass)
1704+
isFunctionType(tp) || isRefinedFunctionType(tp)
16931705

16941706
private def withSpecMethods(cls: ClassSymbol, bases: List[Name], paramTypes: Set[TypeRef]) =
16951707
for base <- bases; tp <- paramTypes do

‎compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,10 @@ object NameOps {
225225
private def checkedFunArity(suffixStart: Int)(using Context): Int =
226226
if isFunctionPrefix(suffixStart) then funArity(suffixStart) else -1
227227

228-
/** Is a function name, i.e one of FunctionXXL, FunctionN, ContextFunctionN, ErasedFunctionN, ErasedContextFunctionN for N >= 0
228+
/** Is a function name, i.e one of FunctionXXL, FunctionN, ContextFunctionN, ImpureFunctionN, ImpureContextFunctionN for N >= 0
229229
*/
230230
def isFunction(using Context): Boolean =
231231
(name eq tpnme.FunctionXXL)
232-
|| (name eq tpnme.ErasedFunction)
233232
|| checkedFunArity(functionSuffixStart) >= 0
234233

235234
/** Is a function name
@@ -248,8 +247,6 @@ object NameOps {
248247
/** Is a synthetic function name, i.e. one of
249248
* - FunctionN for N > 22
250249
* - ContextFunctionN for N >= 0
251-
* - ErasedFunctionN for N >= 0
252-
* - ErasedContextFunctionN for N >= 0
253250
*/
254251
def isSyntheticFunction(using Context): Boolean =
255252
val suffixStart = functionSuffixStart

0 commit comments

Comments
 (0)
Please sign in to comment.