Skip to content

Commit f692b67

Browse files
committed
Remove the need to pass erased parameter boolean lists around
with `MethodTypeCompanion`s not needing `erasedParams` anymore, we can simplify some of the parts previously made to return the array just to construct the companion.
1 parent 824c763 commit f692b67

File tree

11 files changed

+32
-37
lines changed

11 files changed

+32
-37
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11341134

11351135
def etaExpandCFT(using Context): Tree =
11361136
def expand(target: Tree, tp: Type)(using Context): Tree = tp match
1137-
case defn.ContextFunctionType(argTypes, resType, erasedParams) =>
1137+
case defn.ContextFunctionType(argTypes, resType, _) =>
11381138
val anonFun = newAnonFun(
11391139
ctx.owner,
1140-
MethodType.companion(isContextual = true, erasedParams = erasedParams)(argTypes, resType),
1140+
MethodType.companion(isContextual = true)(argTypes, resType),
11411141
coord = ctx.owner.coord)
11421142
def lambdaBody(refss: List[List[Tree]]) =
11431143
expand(target.select(nme.apply).appliedToArgss(refss), resType)(

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ class CheckCaptures extends Recheck, SymTransformer:
336336
mapArgUsing(_.forceBoxStatus(false))
337337
else if meth == defn.Caps_unsafeBoxFunArg then
338338
mapArgUsing {
339-
case defn.FunctionOf(paramtpe :: Nil, restpe, isContectual, erasedParams) =>
340-
defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContectual, erasedParams)
339+
case defn.FunctionOf(paramtpe :: Nil, restpe, isContectual) =>
340+
defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContectual)
341341
}
342342
else
343343
super.recheckApply(tree, pt) match
@@ -430,7 +430,7 @@ class CheckCaptures extends Recheck, SymTransformer:
430430
block match
431431
case closureDef(mdef) =>
432432
pt.dealias match
433-
case defn.FunctionOf(ptformals, _, _, _)
433+
case defn.FunctionOf(ptformals, _, _)
434434
if ptformals.nonEmpty && ptformals.forall(_.captureSet.isAlwaysEmpty) =>
435435
// Redo setup of the anonymous function so that formal parameters don't
436436
// get capture sets. This is important to avoid false widenings to `*`
@@ -598,18 +598,18 @@ class CheckCaptures extends Recheck, SymTransformer:
598598
//println(i"check conforms $actual1 <<< $expected1")
599599
super.checkConformsExpr(actual1, expected1, tree)
600600

601-
private def toDepFun(args: List[Type], resultType: Type, isContextual: Boolean, erasedParams: List[Boolean])(using Context): Type =
602-
MethodType.companion(isContextual = isContextual, erasedParams = erasedParams)(args, resultType)
601+
private def toDepFun(args: List[Type], resultType: Type, isContextual: Boolean)(using Context): Type =
602+
MethodType.companion(isContextual = isContextual)(args, resultType)
603603
.toFunctionType(isJava = false, alwaysDependent = true)
604604

605605
/** Turn `expected` into a dependent function when `actual` is dependent. */
606606
private def alignDependentFunction(expected: Type, actual: Type)(using Context): Type =
607607
def recur(expected: Type): Type = expected.dealias match
608608
case expected @ CapturingType(eparent, refs) =>
609609
CapturingType(recur(eparent), refs, boxed = expected.isBoxed)
610-
case expected @ defn.FunctionOf(args, resultType, isContextual, erasedParams)
610+
case expected @ defn.FunctionOf(args, resultType, isContextual)
611611
if defn.isNonRefinedFunction(expected) && defn.isFunctionType(actual) && !defn.isNonRefinedFunction(actual) =>
612-
val expected1 = toDepFun(args, resultType, isContextual, erasedParams)
612+
val expected1 = toDepFun(args, resultType, isContextual)
613613
expected1
614614
case _ =>
615615
expected
@@ -675,7 +675,7 @@ class CheckCaptures extends Recheck, SymTransformer:
675675

676676
try
677677
val (eargs, eres) = expected.dealias.stripCapturing match
678-
case defn.FunctionOf(eargs, eres, _, _) => (eargs, eres)
678+
case defn.FunctionOf(eargs, eres, _) => (eargs, eres)
679679
case expected: MethodType => (expected.paramInfos, expected.resType)
680680
case expected @ RefinedType(_, _, rinfo: MethodType) if defn.isFunctionType(expected) => (rinfo.paramInfos, rinfo.resType)
681681
case _ => (aargs.map(_ => WildcardType), WildcardType)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ extends tpd.TreeTraverser:
3838
private def depFun(tycon: Type, argTypes: List[Type], resType: Type)(using Context): Type =
3939
MethodType.companion(
4040
isContextual = defn.isContextFunctionClass(tycon.classSymbol),
41-
erasedParams = defn.erasedFunctionParameters(tycon)
4241
)(argTypes, resType)
4342
.toFunctionType(isJava = false, alwaysDependent = true)
4443

@@ -260,7 +259,7 @@ extends tpd.TreeTraverser:
260259
private def expandThrowsAlias(tp: Type)(using Context) = tp match
261260
case AppliedType(tycon, res :: exc :: Nil) if tycon.typeSymbol == defn.throwsAlias =>
262261
// hard-coded expansion since $throws aliases in stdlib are defined with `?=>` rather than `?->`
263-
defn.FunctionOf(defn.CanThrowClass.typeRef.appliedTo(exc) :: Nil, res, isContextual = true, erasedParams = List(true))
262+
defn.FunctionOf(defn.CanThrowClass.typeRef.appliedTo(exc) :: Nil, res, isContextual = true)
264263
case _ => tp
265264

266265
private def expandThrowsAliases(using Context) = new TypeMap:

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ class Definitions {
134134
val resParamRef = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls).typeRef
135135
val methodType = MethodType.companion(
136136
isContextual = name.isContextFunction,
137-
isImplicit = false,
138-
erasedParams = List())
137+
isImplicit = false)
139138
decls.enter(newMethod(cls, nme.apply, methodType(argParamRefs, resParamRef), Deferred))
140139
denot.info =
141140
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: Nil, decls)
@@ -1086,23 +1085,22 @@ class Definitions {
10861085
sym.owner.linkedClass.typeRef
10871086

10881087
object FunctionOf {
1089-
def apply(args: List[Type], resultType: Type, isContextual: Boolean = false, erasedParams: List[Boolean] = List())(using Context): Type =
1090-
assert(erasedParams.size == 0 || args.size == erasedParams.size)
1091-
if erasedParams.contains(true) then
1092-
val mt = MethodType.companion(isContextual, false, erasedParams.padTo(args.size, false))(args, resultType)
1088+
def apply(args: List[Type], resultType: Type, isContextual: Boolean = false)(using Context): Type =
1089+
val mt = MethodType.companion(isContextual, false)(args, resultType)
1090+
if mt.hasErasedParams then
10931091
RefinedType(ErasedFunctionClass.typeRef, nme.apply, mt)
10941092
else
10951093
FunctionType(args.length, isContextual).appliedTo(args ::: resultType :: Nil)
1096-
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean, List[Boolean])] = {
1094+
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
10971095
ft.dealias match
10981096
case RefinedType(parent, nme.apply, mt: MethodType) if isErasedFunctionType(parent) =>
1099-
Some(mt.paramInfos, mt.resType, mt.isContextualMethod, mt.erasedParams)
1097+
Some(mt.paramInfos, mt.resType, mt.isContextualMethod)
11001098
case _ =>
11011099
val tsym = ft.dealias.typeSymbol
11021100
if isFunctionSymbol(tsym) && ft.isRef(tsym) then
11031101
val targs = ft.dealias.argInfos
11041102
if (targs.isEmpty) None
1105-
else Some(targs.init, targs.last, tsym.name.isContextFunction, List.fill(targs.init.size) { false })
1103+
else Some(targs.init, targs.last, tsym.name.isContextFunction)
11061104
else None
11071105
}
11081106
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ object NamerOps:
4242
case Nil =>
4343
resultType
4444
case TermSymbols(params) :: paramss1 =>
45-
val (isContextual, isImplicit, erasedParams) =
46-
if params.isEmpty then (false, false, List())
47-
else (params.head.is(Given), params.head.is(Implicit), params.map(_.is(Erased)))
48-
val make = MethodType.companion(isContextual = isContextual, isImplicit = isImplicit, erasedParams = erasedParams)
45+
val (isContextual, isImplicit) =
46+
if params.isEmpty then (false, false)
47+
else (params.head.is(Given), params.head.is(Implicit))
48+
val make = MethodType.companion(isContextual = isContextual, isImplicit = isImplicit)
4949
if isJava then
5050
for param <- params do
5151
if param.info.isDirectRef(defn.ObjectClass) then param.info = defn.AnyType

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,14 +1844,13 @@ object Types {
18441844
case mt: MethodType if !mt.isParamDependent =>
18451845
val formals1 = if (dropLast == 0) mt.paramInfos else mt.paramInfos dropRight dropLast
18461846
val isContextual = mt.isContextualMethod && !ctx.erasedTypes
1847-
val erasedParams = (if !ctx.erasedTypes then mt.erasedParams else List.fill(mt.paramInfos.size) { false }).dropRight(dropLast)
18481847
val result1 = mt.nonDependentResultApprox match {
18491848
case res: MethodType => res.toFunctionType(isJava)
18501849
case res => res
18511850
}
18521851
val funType = defn.FunctionOf(
18531852
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1854-
result1, isContextual, erasedParams)
1853+
result1, isContextual)
18551854
if alwaysDependent || mt.isResultDependent then RefinedType(funType, nme.apply, mt)
18561855
else funType
18571856
}
@@ -4033,8 +4032,7 @@ object Types {
40334032
}
40344033

40354034
object MethodType extends MethodTypeCompanion("MethodType") {
4036-
def companion(isContextual: Boolean = false, isImplicit: Boolean = false, erasedParams: List[Boolean] = Nil): MethodTypeCompanion =
4037-
val hasErased = erasedParams.contains(true)
4035+
def companion(isContextual: Boolean = false, isImplicit: Boolean = false): MethodTypeCompanion =
40384036
if (isContextual) ContextualMethodType
40394037
else if (isImplicit) ImplicitMethodType
40404038
else MethodType

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object PickleQuotes {
315315
defn.QuotedExprClass.typeRef.appliedTo(defn.AnyType)),
316316
args =>
317317
val cases = termSplices.map { case (splice, idx) =>
318-
val defn.FunctionOf(argTypes, defn.FunctionOf(quotesType :: _, _, _, _), _, _) = splice.tpe: @unchecked
318+
val defn.FunctionOf(argTypes, defn.FunctionOf(quotesType :: _, _, _), _) = splice.tpe: @unchecked
319319
val rhs = {
320320
val spliceArgs = argTypes.zipWithIndex.map { (argType, i) =>
321321
args(1).select(nme.apply).appliedTo(Literal(Constant(i))).asInstance(argType)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ trait Applications extends Compatibility {
19681968
val formals = ref.widen.firstParamTypes
19691969
if formals.length > idx then
19701970
formals(idx) match
1971-
case defn.FunctionOf(args, _, _, _) => args.length
1971+
case defn.FunctionOf(args, _, _) => args.length
19721972
case _ => -1
19731973
else -1
19741974

@@ -2052,7 +2052,7 @@ trait Applications extends Compatibility {
20522052
if isDetermined(alts2) then alts2
20532053
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
20542054

2055-
case defn.FunctionOf(args, resultType, _, _) =>
2055+
case defn.FunctionOf(args, resultType, _) =>
20562056
narrowByTypes(alts, args, resultType)
20572057

20582058
case pt =>
@@ -2215,7 +2215,7 @@ trait Applications extends Compatibility {
22152215
val formalsForArg: List[Type] = altFormals.map(_.head)
22162216
def argTypesOfFormal(formal: Type): List[Type] =
22172217
formal.dealias match {
2218-
case defn.FunctionOf(args, result, isImplicit, isErased) => args
2218+
case defn.FunctionOf(args, result, isImplicit) => args
22192219
case defn.PartialFunctionOf(arg, result) => arg :: Nil
22202220
case _ => Nil
22212221
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ object ProtoTypes {
372372

373373
private def isUndefined(tp: Type): Boolean = tp match {
374374
case _: WildcardType => true
375-
case defn.FunctionOf(args, result, _, _) => args.exists(isUndefined) || isUndefined(result)
375+
case defn.FunctionOf(args, result, _) => args.exists(isUndefined) || isUndefined(result)
376376
case _ => false
377377
}
378378

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
103103
def functionTypeEqual(baseFun: Type, actualArgs: List[Type],
104104
actualRet: Type, expected: Type) =
105105
expected =:= defn.FunctionOf(actualArgs, actualRet,
106-
defn.isContextFunctionType(baseFun), List() /* erased functions not supported */)
106+
defn.isContextFunctionType(baseFun))
107107
val arity: Int =
108108
if defn.isErasedFunctionType(fun) then -1 // TODO support?
109109
else if defn.isFunctionType(fun) then

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15901590
|because it has internal parameter dependencies""")
15911591
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
15921592
// Note implicitness of function in target type since there are no method parameters that indicate it.
1593-
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true, erasedParams = List()))
1593+
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true))
15941594
else if hasCaptureConversionArg(mt.resType) then
15951595
errorTree(tree,
15961596
em"""cannot turn method type $mt into closure
@@ -3036,7 +3036,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
30363036
tree
30373037

30383038
protected def makeContextualFunction(tree: untpd.Tree, pt: Type)(using Context): Tree = {
3039-
val defn.FunctionOf(formals, _, true, _) = pt.dropDependentRefinement: @unchecked
3039+
val defn.FunctionOf(formals, _, true) = pt.dropDependentRefinement: @unchecked
30403040

30413041
// The getter of default parameters may reach here.
30423042
// Given the code below

0 commit comments

Comments
 (0)