From e5472f905c2042fc547611dfd0669f9bbb5cbab0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 21 Aug 2023 14:46:12 +0200 Subject: [PATCH] Add default arguments to `derivedRefinedType` --- compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala | 4 ++-- compiler/src/dotty/tools/dotc/cc/Setup.scala | 4 ++-- .../dotty/tools/dotc/core/ConstraintHandling.scala | 2 +- .../src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- compiler/src/dotty/tools/dotc/core/Types.scala | 12 +++++++----- .../dotc/core/unpickleScala2/Scala2Unpickler.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 +- .../src/dotty/tools/dotc/typer/Inferencing.scala | 2 +- .../src/dotty/tools/dotc/typer/Synthesizer.scala | 4 ++-- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index 66a7899a6bd0..57fbab46e7bf 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -303,7 +303,7 @@ class CheckCaptures extends Recheck, SymTransformer: case _ => val t1 = t match case t @ defn.RefinedFunctionOf(rinfo: MethodType) => - t.derivedRefinedType(t.parent, t.refinedName, this(rinfo)) + t.derivedRefinedType(refinedInfo = this(rinfo)) case _ => mapOver(t) if variance > 0 then t1 @@ -859,7 +859,7 @@ class CheckCaptures extends Recheck, SymTransformer: adaptTypeFun(actual, rinfo.resType, expected, covariant, insertBox, ares1 => val rinfo1 = rinfo.derivedLambdaType(rinfo.paramNames, rinfo.paramInfos, ares1) - val actual1 = actual.derivedRefinedType(actual.parent, actual.refinedName, rinfo1) + val actual1 = actual.derivedRefinedType(refinedInfo = rinfo1) actual1 ) case _ => diff --git a/compiler/src/dotty/tools/dotc/cc/Setup.scala b/compiler/src/dotty/tools/dotc/cc/Setup.scala index b66b9f2b2277..e8062bf70042 100644 --- a/compiler/src/dotty/tools/dotc/cc/Setup.scala +++ b/compiler/src/dotty/tools/dotc/cc/Setup.scala @@ -447,8 +447,8 @@ object Setup: * an embedded capture set variable from a part of `tp`. */ def decorate(tp: Type, addedSet: Type => CaptureSet)(using Context): Type = tp match - case tp @ RefinedType(parent @ CapturingType(parent1, refs), rname, rinfo) => - CapturingType(tp.derivedRefinedType(parent1, rname, rinfo), refs, parent.isBoxed) + case tp @ RefinedType(parent @ CapturingType(parent1, refs), _, _) => + CapturingType(tp.derivedRefinedType(parent = parent1), refs, parent.isBoxed) case tp: RecType => tp.parent match case parent @ CapturingType(parent1, refs) => diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala index 7d2f51381d5a..c7ceada9884b 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala @@ -689,7 +689,7 @@ trait ConstraintHandling { case tp: AndType => tp.derivedAndType(tp.tp1.hardenUnions, tp.tp2.hardenUnions) case tp: RefinedType => - tp.derivedRefinedType(tp.parent.hardenUnions, tp.refinedName, tp.refinedInfo) + tp.derivedRefinedType(parent = tp.parent.hardenUnions) case tp: RecType => tp.rebind(tp.parent.hardenUnions) case tp: HKTypeLambda => diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index de40ac7232b7..16f29d90da89 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1814,7 +1814,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling private def fixRecs(anchor: SingletonType, tp: Type): Type = { def fix(tp: Type): Type = tp.stripTypeVar match { case tp: RecType => fix(tp.parent).substRecThis(tp, anchor) - case tp @ RefinedType(parent, rname, rinfo) => tp.derivedRefinedType(fix(parent), rname, rinfo) + case tp: RefinedType => tp.derivedRefinedType(parent = fix(tp.parent)) case tp: TypeParamRef => fixOrElse(bounds(tp).hi, tp) case tp: TypeProxy => fixOrElse(tp.superType, tp) case tp: AndType => tp.derivedAndType(fix(tp.tp1), fix(tp.tp2)) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 15b7695202e1..e9e87ca75a54 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1348,7 +1348,7 @@ object Types { case tp: AndType => tp.derivedAndType(tp.tp1.widenUnionWithoutNull, tp.tp2.widenUnionWithoutNull) case tp: RefinedType => - tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo) + tp.derivedRefinedType(parent = tp.parent.widenUnion) case tp: RecType => tp.rebind(tp.parent.widenUnion) case tp: HKTypeLambda => @@ -3195,7 +3195,9 @@ object Types { def checkInst(using Context): this.type = this // debug hook - def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(using Context): Type = + final def derivedRefinedType + (parent: Type = this.parent, refinedName: Name = this.refinedName, refinedInfo: Type = this.refinedInfo) + (using Context): Type = if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this else RefinedType(parent, refinedName, refinedInfo) @@ -4101,7 +4103,7 @@ object Types { case tp @ AppliedType(tycon, args) if defn.isFunctionNType(tp) => wrapConvertible(tp.derivedAppliedType(tycon, args.init :+ addInto(args.last))) case tp @ defn.RefinedFunctionOf(rinfo) => - wrapConvertible(tp.derivedRefinedType(tp.parent, tp.refinedName, addInto(rinfo))) + wrapConvertible(tp.derivedRefinedType(refinedInfo = addInto(rinfo))) case tp: MethodOrPoly => tp.derivedLambdaType(resType = addInto(tp.resType)) case ExprType(resType) => @@ -5612,8 +5614,8 @@ object Types { else hi case (arg, _) => arg tp.derivedAppliedType(tycon, args1) - case tp @ RefinedType(parent, name, info) => - tp.derivedRefinedType(approxWildcardArgs(parent), name, info) + case tp: RefinedType => + tp.derivedRefinedType(approxWildcardArgs(tp.parent)) case _ => tp approxWildcardArgs(tp) diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 4db5158c0e7f..481768fb4dbf 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -734,8 +734,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val info1 = info.symbol.info assert(info1.derivesFrom(defn.SingletonClass)) RefinedType(parent1, name, info1.mapReduceAnd(removeSingleton)(_ & _)) - case info => - tp.derivedRefinedType(parent1, name, info) + case _ => + tp.derivedRefinedType(parent = parent1) } case tp @ AppliedType(tycon, args) => val tycon1 = tycon.safeDealias diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index c17c5f25ab5f..df463676a9b9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -1097,7 +1097,7 @@ trait Checking { case tp @ AppliedType(tycon, args) => tp.derivedAppliedType(tycon, args.mapConserve(checkGoodBounds)) case tp: RefinedType => - tp.derivedRefinedType(tp.parent, tp.refinedName, checkGoodBounds(tp.refinedInfo)) + tp.derivedRefinedType(refinedInfo = checkGoodBounds(tp.refinedInfo)) case _ => tp } diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 184c8675e678..618a6cec1a3e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -537,7 +537,7 @@ object Inferencing { } if tparams.isEmpty then tp else tp.derivedAppliedType(tycon, args1) case tp: AndOrType => tp.derivedAndOrType(captureWildcards(tp.tp1), captureWildcards(tp.tp2)) - case tp: RefinedType => tp.derivedRefinedType(captureWildcards(tp.parent), tp.refinedName, tp.refinedInfo) + case tp: RefinedType => tp.derivedRefinedType(parent = captureWildcards(tp.parent)) case tp: RecType => tp.derivedRecType(captureWildcards(tp.parent)) case tp: LazyRef => captureWildcards(tp.ref) case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot) diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index cbb13a841946..10d87778b3d8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -743,8 +743,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context): def recur(handlers: SpecialHandlers): TreeWithErrors = handlers match case (cls, handler) :: rest => def baseWithRefinements(tp: Type): Type = tp.dealias match - case tp @ RefinedType(parent, rname, rinfo) => - tp.derivedRefinedType(baseWithRefinements(parent), rname, rinfo) + case tp: RefinedType => + tp.derivedRefinedType(parent = baseWithRefinements(tp.parent)) case _ => tp.baseType(cls) val base = baseWithRefinements(formal)