Skip to content

Commit fc91da8

Browse files
Apply suggestions from code review
Co-authored-by: Nicolas Stucki <[email protected]>
1 parent 1d7ae0c commit fc91da8

File tree

12 files changed

+18
-27
lines changed

12 files changed

+18
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
7676
override def isType: Boolean = body.isType
7777
}
7878

79-
/** A function type or closure with `implicit`, `erased`, or `given` modifiers */
79+
/** A function type or closure with `implicit` or `given` modifiers and information on which parameters are `erased` */
8080
class FunctionWithMods(args: List[Tree], body: Tree, val mods: Modifiers, val erasedParams: List[Boolean])(implicit @constructorOnly src: SourceFile)
8181
extends Function(args, body) {
8282
assert(args.length == erasedParams.length)

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21182118
case nil =>
21192119
formals2.isEmpty
21202120
}
2121-
// Check if methods are erased, then the erased parameters match
2122-
val erasedValid =
2123-
if tp1.hasErasedParams && tp2.hasErasedParams then
2124-
tp1.erasedParams == tp2.erasedParams
2125-
else !tp1.hasErasedParams && !tp2.hasErasedParams
2121+
// If methods have erased parameters, then the erased parameters must match
2122+
val erasedValid = (!tp1.hasErasedParams && !tp2.hasErasedParams) || (tp1.erasedParams == tp2.erasedParams)
21262123

21272124
erasedValid && loop(tp1.paramInfos, tp2.paramInfos)
21282125
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ object Types {
14731473

14741474
/** Dealias, and if result is a dependent function type, drop the `apply` refinement. */
14751475
final def dropDependentRefinement(using Context): Type = dealias match {
1476-
case RefinedType(parent, nme.apply, mt) if !defn.isErasedFunctionType(parent) => parent
1476+
case RefinedType(parent, nme.apply, mt) if defn.isNonRefinedFunction(parent) => parent
14771477
case tp => tp
14781478
}
14791479

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ class TastyPrinter(bytes: Array[Byte]) {
136136
case METHODtype | POLYtype | TYPELAMBDAtype =>
137137
printTree()
138138
while (currentAddr.index < end.index && !isModifierTag(nextByte)) { printTree(); printName(); }
139-
// read tags
140139
printTrees()
141140
case PARAMtype =>
142141
printNat(); printNat()

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3294,7 +3294,6 @@ object Parsers {
32943294
val firstParamMod =
32953295
var mods = EmptyModifiers
32963296
if isErased then mods = addModifier(mods)
3297-
// if in.name == nme.inline then mods = addModifier(mods)
32983297
mods
32993298
if givenOnly && !impliedMods.is(Given) then
33003299
syntaxError(em"`using` expected")

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
129129
* (hence with `GlobalPrec` precedence).
130130
*/
131131
protected def argsText(args: List[Type]): Text =
132-
atPrec(GlobalPrec) { Text(args.map(argText(_)), ", ") }
132+
atPrec(GlobalPrec) { Text(args.map(arg => argText(arg) ), ", ") }
133133

134134
/** The longest sequence of refinement types, starting at given type
135135
* and following parents.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 defn.ContextFunctionType(_, resTpe, erasedParams) => erasedParams.forall(_ == true) && allErased(resTpe)
61+
case defn.ContextFunctionType(_, resTpe, erasedParams) => !erasedParams.contains(false) && allErased(resTpe)
6262
case _ => true
6363
contextResultCount(sym) > 0 && allErased(sym.info.finalResultType)
6464

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,10 @@ object Erasure {
829829
val Apply(fun, args) = tree
830830
val origFun = fun.asInstanceOf[tpd.Tree]
831831
val origFunType = origFun.tpe.widen(using preErasureCtx)
832-
val erasedCompanion = if origFunType.hasErasedParams then
833-
Some(origFunType.asInstanceOf[MethodType].erasedParams)
834-
else None
835-
val ownArgs = erasedCompanion.map { isErased =>
836-
args.zip(isErased).collect { case (arg, isErased) if !isErased => arg }
837-
}.getOrElse(args)
832+
val ownArgs = origFunType match
833+
case mt: MethodType if mt.hasErasedParams =>
834+
args.zip(mt.erasedParams).collect { case (arg, false) => arg }
835+
case _ => args
838836
val fun1 = typedExpr(fun, AnyFunctionProto)
839837
fun1.tpe.widen match
840838
case mt: MethodType =>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ object GenericSignatures {
312312
// erased method parameters do not make it to the bytecode.
313313
def effectiveParamInfoss(t: Type)(using Context): List[List[Type]] = t match {
314314
case t: MethodType if t.hasErasedParams =>
315-
t.paramInfos.zip(t.erasedParams)
316-
.flatMap((i, e) => if e then None else Some(i))
315+
t.paramInfos.zip(t.erasedParams).collect{ case (i, false) => i }
317316
:: effectiveParamInfoss(t.resType)
318317
case t: MethodType => t.paramInfos :: effectiveParamInfoss(t.resType)
319318
case _ => Nil

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
3939
else sym.copySymDenotation(initFlags = sym.flags | Private)
4040

4141
override def transformApply(tree: Apply)(using Context): Tree =
42-
if !tree.fun.tpe.widen.hasErasedParams then tree
43-
else
44-
val erasedParams = tree.fun.tpe.widen.asInstanceOf[MethodType].erasedParams
45-
cpy.Apply(tree)(tree.fun, tree.args.zip(erasedParams).map((a, e) => if e then trivialErasedTree(a) else a))
42+
tree.fun.tpe.widen match
43+
case mt: MethodType if mt.hasErasedParams =>
44+
cpy.Apply(tree)(tree.fun, tree.args.zip(mt.erasedParams).map((a, e) => if e then trivialErasedTree(a) else a))
45+
case _ =>
46+
tree
4647

4748
override def transformValDef(tree: ValDef)(using Context): Tree =
4849
checkErasedInExperimental(tree.symbol)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SpecializeFunctions extends MiniPhase {
7070
/** Dispatch to specialized `apply`s in user code when available */
7171
override def transformApply(tree: Apply)(using Context) =
7272
tree match {
73-
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 && fun.symbol.exists && fun.symbol.owner.isType =>
73+
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 && fun.symbol.maybeOwner.isType =>
7474
val argTypes = fun.tpe.widen.firstParamTypes.map(_.widenSingleton.dealias)
7575
val retType = tree.tpe.widenSingleton.dealias
7676
val isSpecializable =

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12481248
val pt1 = pt.strippedDealias.normalized
12491249
if (pt1 ne pt1.dropDependentRefinement)
12501250
&& defn.isContextFunctionType(pt1.nonPrivateMember(nme.apply).info.finalResultType)
1251-
&& pt1.nonPrivateMember(nme.apply).info.asInstanceOf[MethodType].isResultDependent
12521251
then
12531252
report.error(
12541253
em"""Implementation restriction: Expected result type $pt1
@@ -1364,8 +1363,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
13641363
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
13651364
val typeArgs = appDef.termParamss.head.map(_.tpt) :+ resTpt
13661365
val core =
1367-
if mt.hasErasedParams
1368-
then TypeTree(defn.ErasedFunctionClass.typeRef)
1366+
if mt.hasErasedParams then TypeTree(defn.ErasedFunctionClass.typeRef)
13691367
else
13701368
val funSym = defn.FunctionSymbol(numArgs, isContextual, isImpure)
13711369
val tycon = TypeTree(funSym.typeRef)

0 commit comments

Comments
 (0)