Skip to content

Commit 50144f4

Browse files
committed
Convert core classes (5)
1 parent 23b19e8 commit 50144f4

File tree

8 files changed

+93
-93
lines changed

8 files changed

+93
-93
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ object Contexts {
326326
/** Run `op` as if it was run in a fresh explore typer state, but possibly
327327
* optimized to re-use the current typer state.
328328
*/
329-
final def test[T](op: Context ?=> T): T = typerState.test(op)(this)
329+
final def test[T](op: Context ?=> T): T = typerState.test(op)(using this)
330330

331331
/** Is this a context for the members of a class definition? */
332332
def isClassDefContext: Boolean =

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ object TypeApplications {
3434
* @param tycon C
3535
*/
3636
object EtaExpansion {
37-
def apply(tycon: Type)(implicit ctx: Context): Type = {
37+
def apply(tycon: Type)(using Context): Type = {
3838
assert(tycon.typeParams.nonEmpty, tycon)
3939
tycon.EtaExpand(tycon.typeParamSymbols)
4040
}
4141

42-
def unapply(tp: Type)(implicit ctx: Context): Option[TypeRef] = tp match {
42+
def unapply(tp: Type)(using Context): Option[TypeRef] = tp match {
4343
case tp @ HKTypeLambda(tparams, AppliedType(fn: TypeRef, args)) if (args == tparams.map(_.paramRef)) => Some(fn)
4444
case _ => None
4545
}
4646
}
4747

4848
/** Adapt all arguments to possible higher-kinded type parameters using etaExpandIfHK
4949
*/
50-
def EtaExpandIfHK(tparams: List[TypeParamInfo], args: List[Type])(implicit ctx: Context): List[Type] =
50+
def EtaExpandIfHK(tparams: List[TypeParamInfo], args: List[Type])(using Context): List[Type] =
5151
if (tparams.isEmpty) args
5252
else args.zipWithConserve(tparams)((arg, tparam) => arg.EtaExpandIfHK(tparam.paramInfoOrCompleter))
5353

@@ -86,7 +86,7 @@ object TypeApplications {
8686
* result type. Using this mode, we can guarantee that `appliedTo` will never
8787
* produce a higher-kinded application with a type lambda as type constructor.
8888
*/
89-
class Reducer(tycon: TypeLambda, args: List[Type])(implicit ctx: Context) extends TypeMap {
89+
class Reducer(tycon: TypeLambda, args: List[Type])(using Context) extends TypeMap {
9090
private var available = (0 until args.length).toSet
9191
var allReplaced: Boolean = true
9292
def hasWildcardArg(p: TypeParamRef): Boolean =
@@ -143,7 +143,7 @@ class TypeApplications(val self: Type) extends AnyVal {
143143
* For a refinement type, the type parameters of its parent, dropping
144144
* any type parameter that is-rebound by the refinement.
145145
*/
146-
final def typeParams(implicit ctx: Context): List[TypeParamInfo] = {
146+
final def typeParams(using Context): List[TypeParamInfo] = {
147147
record("typeParams")
148148
def isTrivial(prefix: Type, tycon: Symbol) = prefix match {
149149
case prefix: ThisType =>
@@ -184,22 +184,22 @@ class TypeApplications(val self: Type) extends AnyVal {
184184
}
185185

186186
/** If `self` is a higher-kinded type, its type parameters, otherwise Nil */
187-
final def hkTypeParams(implicit ctx: Context): List[TypeParamInfo] =
187+
final def hkTypeParams(using Context): List[TypeParamInfo] =
188188
if (isLambdaSub) typeParams else Nil
189189

190190
/** If `self` is a generic class, its type parameter symbols, otherwise Nil */
191-
final def typeParamSymbols(implicit ctx: Context): List[TypeSymbol] = typeParams match {
191+
final def typeParamSymbols(using Context): List[TypeSymbol] = typeParams match {
192192
case (_: Symbol) :: _ =>
193193
assert(typeParams.forall(_.isInstanceOf[Symbol]))
194194
typeParams.asInstanceOf[List[TypeSymbol]]
195195
case _ => Nil
196196
}
197197

198198
/** Is self type bounded by a type lambda or AnyKind? */
199-
def isLambdaSub(implicit ctx: Context): Boolean = hkResult.exists
199+
def isLambdaSub(using Context): Boolean = hkResult.exists
200200

201201
/** Is self type of kind "*"? */
202-
def hasSimpleKind(implicit ctx: Context): Boolean =
202+
def hasSimpleKind(using Context): Boolean =
203203
typeParams.isEmpty && !self.hasAnyKind || {
204204
val alias = self.dealias
205205
(alias ne self) && alias.hasSimpleKind
@@ -208,7 +208,7 @@ class TypeApplications(val self: Type) extends AnyVal {
208208
/** If self type is higher-kinded, its result type, otherwise NoType.
209209
* Note: The hkResult of an any-kinded type is again AnyKind.
210210
*/
211-
def hkResult(implicit ctx: Context): Type = self.dealias match {
211+
def hkResult(using Context): Type = self.dealias match {
212212
case self: TypeRef =>
213213
if (self.symbol == defn.AnyKindClass) self else self.info.hkResult
214214
case self: AppliedType =>
@@ -227,7 +227,7 @@ class TypeApplications(val self: Type) extends AnyVal {
227227
/** Do self and other have the same kinds (not counting bounds and variances)?
228228
* Note: An any-kinded type "has the same kind" as any other type.
229229
*/
230-
def hasSameKindAs(other: Type)(implicit ctx: Context): Boolean = {
230+
def hasSameKindAs(other: Type)(using Context): Boolean = {
231231
def isAnyKind(tp: Type) = tp match {
232232
case tp: TypeRef => tp.symbol == defn.AnyKindClass
233233
case _ => false
@@ -245,7 +245,7 @@ class TypeApplications(val self: Type) extends AnyVal {
245245
}
246246

247247
/** Dealias type if it can be done without forcing the TypeRef's info */
248-
def safeDealias(implicit ctx: Context): Type = self match {
248+
def safeDealias(using Context): Type = self match {
249249
case self: TypeRef if self.denot.exists && self.symbol.isAliasType =>
250250
self.superType.stripTypeVar.safeDealias
251251
case _ =>
@@ -255,16 +255,16 @@ class TypeApplications(val self: Type) extends AnyVal {
255255
/** Convert a type constructor `TC` which has type parameters `X1, ..., Xn`
256256
* to `[X1, ..., Xn] -> TC[X1, ..., Xn]`.
257257
*/
258-
def EtaExpand(tparams: List[TypeParamInfo])(implicit ctx: Context): Type =
258+
def EtaExpand(tparams: List[TypeParamInfo])(using Context): Type =
259259
HKTypeLambda.fromParams(tparams, self.appliedTo(tparams.map(_.paramRef)))
260260
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
261261

262262
/** If self is not lambda-bound, eta expand it. */
263-
def ensureLambdaSub(implicit ctx: Context): Type =
263+
def ensureLambdaSub(using Context): Type =
264264
if (isLambdaSub) self else EtaExpansion(self)
265265

266266
/** Eta expand if `self` is a (non-lambda) class reference and `bound` is a higher-kinded type */
267-
def EtaExpandIfHK(bound: Type)(implicit ctx: Context): Type = {
267+
def EtaExpandIfHK(bound: Type)(using Context): Type = {
268268
val hkParams = bound.hkTypeParams
269269
if (hkParams.isEmpty) self
270270
else self match {
@@ -282,7 +282,7 @@ class TypeApplications(val self: Type) extends AnyVal {
282282
* @param self = `T`
283283
* @param args = `U1,...,Un`
284284
*/
285-
final def appliedTo(args: List[Type])(implicit ctx: Context): Type = {
285+
final def appliedTo(args: List[Type])(using Context): Type = {
286286
record("appliedTo")
287287
val typParams = self.typeParams
288288
val stripped = self.stripTypeVar
@@ -347,18 +347,18 @@ class TypeApplications(val self: Type) extends AnyVal {
347347
}
348348
}
349349

350-
final def appliedTo(arg: Type)(implicit ctx: Context): Type = appliedTo(arg :: Nil)
351-
final def appliedTo(arg1: Type, arg2: Type)(implicit ctx: Context): Type = appliedTo(arg1 :: arg2 :: Nil)
350+
final def appliedTo(arg: Type)(using Context): Type = appliedTo(arg :: Nil)
351+
final def appliedTo(arg1: Type, arg2: Type)(using Context): Type = appliedTo(arg1 :: arg2 :: Nil)
352352

353-
final def applyIfParameterized(args: List[Type])(implicit ctx: Context): Type =
353+
final def applyIfParameterized(args: List[Type])(using Context): Type =
354354
if (typeParams.nonEmpty) appliedTo(args) else self
355355

356356
/** A cycle-safe version of `appliedTo` where computing type parameters do not force
357357
* the typeconstructor. Instead, if the type constructor is completing, we make
358358
* up hk type parameters matching the arguments. This is needed when unpickling
359359
* Scala2 files such as `scala.collection.generic.Mapfactory`.
360360
*/
361-
final def safeAppliedTo(args: List[Type])(implicit ctx: Context): Type = self match {
361+
final def safeAppliedTo(args: List[Type])(using Context): Type = self match {
362362
case self: TypeRef if !self.symbol.isClass && self.symbol.isCompleting =>
363363
AppliedType(self, args)
364364
case _ =>
@@ -369,7 +369,7 @@ class TypeApplications(val self: Type) extends AnyVal {
369369
* A (possible lambda abstracted) match type is turned into a match alias.
370370
* Every other type is turned into a type alias
371371
*/
372-
final def toBounds(implicit ctx: Context): TypeBounds = self match {
372+
final def toBounds(using Context): TypeBounds = self match {
373373
case self: TypeBounds => self // this can happen for wildcard args
374374
case _ => if (self.isMatch) MatchAlias(self) else TypeAlias(self)
375375
}
@@ -378,7 +378,7 @@ class TypeApplications(val self: Type) extends AnyVal {
378378
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
379379
* Do the same for by name types => From[T] and => To[T]
380380
*/
381-
def translateParameterized(from: ClassSymbol, to: ClassSymbol, wildcardArg: Boolean = false)(implicit ctx: Context): Type = self match {
381+
def translateParameterized(from: ClassSymbol, to: ClassSymbol, wildcardArg: Boolean = false)(using Context): Type = self match {
382382
case self @ ExprType(tp) =>
383383
self.derivedExprType(tp.translateParameterized(from, to))
384384
case _ =>
@@ -439,37 +439,37 @@ class TypeApplications(val self: Type) extends AnyVal {
439439
* otherwise return Nil.
440440
* Existential types in arguments are returned as TypeBounds instances.
441441
*/
442-
final def argInfos(implicit ctx: Context): List[Type] = self.stripTypeVar.stripAnnots match {
442+
final def argInfos(using Context): List[Type] = self.stripTypeVar.stripAnnots match {
443443
case AppliedType(tycon, args) => args
444444
case _ => Nil
445445
}
446446

447447
/** Argument types where existential types in arguments are disallowed */
448-
def argTypes(implicit ctx: Context): List[Type] = argInfos mapConserve noBounds
448+
def argTypes(using Context): List[Type] = argInfos mapConserve noBounds
449449

450450
/** Argument types where existential types in arguments are approximated by their lower bound */
451-
def argTypesLo(implicit ctx: Context): List[Type] = argInfos.mapConserve(_.loBound)
451+
def argTypesLo(using Context): List[Type] = argInfos.mapConserve(_.loBound)
452452

453453
/** Argument types where existential types in arguments are approximated by their upper bound */
454-
def argTypesHi(implicit ctx: Context): List[Type] = argInfos.mapConserve(_.hiBound)
454+
def argTypesHi(using Context): List[Type] = argInfos.mapConserve(_.hiBound)
455455

456456
/** If this is the image of a type argument; recover the type argument,
457457
* otherwise NoType.
458458
*/
459-
final def argInfo(implicit ctx: Context): Type = self match {
459+
final def argInfo(using Context): Type = self match {
460460
case self: TypeAlias => self.alias
461461
case self: TypeBounds => self
462462
case _ => NoType
463463
}
464464

465465
/** If this is a type alias, its underlying type, otherwise the type itself */
466-
def dropAlias(implicit ctx: Context): Type = self match {
466+
def dropAlias(using Context): Type = self match {
467467
case TypeAlias(alias) => alias
468468
case _ => self
469469
}
470470

471471
/** The element type of a sequence or array */
472-
def elemType(implicit ctx: Context): Type = self.widenDealias match {
472+
def elemType(using Context): Type = self.widenDealias match {
473473
case defn.ArrayOf(elemtp) => elemtp
474474
case JavaArrayType(elemtp) => elemtp
475475
case _ => self.baseType(defn.SeqClass).argInfos.headOption.getOrElse(NoType)

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
119119
true
120120
}
121121

122-
protected def gadtBounds(sym: Symbol)(implicit ctx: Context) = ctx.gadt.bounds(sym)
122+
protected def gadtBounds(sym: Symbol)(using Context) = ctx.gadt.bounds(sym)
123123
protected def gadtAddLowerBound(sym: Symbol, b: Type): Boolean = ctx.gadt.addBound(sym, b, isUpper = false)
124124
protected def gadtAddUpperBound(sym: Symbol, b: Type): Boolean = ctx.gadt.addBound(sym, b, isUpper = true)
125125

126-
protected def typeVarInstance(tvar: TypeVar)(implicit ctx: Context): Type = tvar.underlying
126+
protected def typeVarInstance(tvar: TypeVar)(using Context): Type = tvar.underlying
127127

128128
// Subtype testing `<:<`
129129

@@ -1860,7 +1860,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
18601860
/** The greatest lower bound of a list types */
18611861
final def glb(tps: List[Type]): Type = tps.foldLeft(AnyType: Type)(glb)
18621862

1863-
def widenInUnions(implicit ctx: Context): Boolean =
1863+
def widenInUnions(using Context): Boolean =
18641864
migrateTo3 || ctx.erasedTypes
18651865

18661866
/** The least upper bound of two types
@@ -2175,7 +2175,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
21752175
}
21762176

21772177
/** Show type, handling type types better than the default */
2178-
private def showType(tp: Type)(implicit ctx: Context) = tp match {
2178+
private def showType(tp: Type)(using Context) = tp match {
21792179
case ClassInfo(_, cls, _, _, _) => cls.showLocated
21802180
case bounds: TypeBounds => "type bounds" + bounds.show
21812181
case _ => tp.show
@@ -2231,7 +2231,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
22312231
}
22322232

22332233
/** Show subtype goal that led to an assertion failure */
2234-
def showGoal(tp1: Type, tp2: Type)(implicit ctx: Context): Unit = {
2234+
def showGoal(tp1: Type, tp2: Type)(using Context): Unit = {
22352235
ctx.echo(i"assertion failure for ${show(tp1)} <:< ${show(tp2)}, frozen = $frozenConstraint")
22362236
def explainPoly(tp: Type) = tp match {
22372237
case tp: TypeParamRef => ctx.echo(s"TypeParamRef ${tp.show} found in ${tp.binder.show}")
@@ -2310,7 +2310,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
23102310
* property that in all possible contexts, the same match type expression
23112311
* is either stuck or reduces to the same case.
23122312
*/
2313-
def provablyDisjoint(tp1: Type, tp2: Type)(implicit ctx: Context): Boolean = {
2313+
def provablyDisjoint(tp1: Type, tp2: Type)(using Context): Boolean = {
23142314
// println(s"provablyDisjoint(${tp1.show}, ${tp2.show})")
23152315
/** Can we enumerate all instantiations of this type? */
23162316
def isClosedSum(tp: Symbol): Boolean =
@@ -2432,7 +2432,7 @@ object TypeComparer {
24322432
var tpe: Type = NoType
24332433
}
24342434

2435-
private[core] def show(res: Any)(implicit ctx: Context): String = res match {
2435+
private[core] def show(res: Any)(using Context): String = res match {
24362436
case res: printing.Showable if !ctx.settings.YexplainLowlevel.value => res.show
24372437
case _ => String.valueOf(res)
24382438
}
@@ -2467,14 +2467,14 @@ object TypeComparer {
24672467
val FreshApprox: ApproxState = new ApproxState(4)
24682468

24692469
/** Show trace of comparison operations when performing `op` */
2470-
def explaining[T](say: String => Unit)(op: Context ?=> T)(implicit ctx: Context): T = {
2470+
def explaining[T](say: String => Unit)(op: Context ?=> T)(using Context): T = {
24712471
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
24722472
val res = try { op(using nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
24732473
res
24742474
}
24752475

24762476
/** Like [[explaining]], but returns the trace instead */
2477-
def explained[T](op: Context ?=> T)(implicit ctx: Context): String = {
2477+
def explained[T](op: Context ?=> T)(using Context): String = {
24782478
var trace: String = null
24792479
try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace }
24802480
trace
@@ -2496,7 +2496,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
24962496
super.addOneBound(param, bound, isUpper)
24972497
}
24982498

2499-
override def gadtBounds(sym: Symbol)(implicit ctx: Context): TypeBounds = {
2499+
override def gadtBounds(sym: Symbol)(using Context): TypeBounds = {
25002500
if (sym.exists) footprint += sym.typeRef
25012501
super.gadtBounds(sym)
25022502
}
@@ -2511,12 +2511,12 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
25112511
super.gadtAddUpperBound(sym, b)
25122512
}
25132513

2514-
override def typeVarInstance(tvar: TypeVar)(implicit ctx: Context): Type = {
2514+
override def typeVarInstance(tvar: TypeVar)(using Context): Type = {
25152515
footprint += tvar
25162516
super.typeVarInstance(tvar)
25172517
}
25182518

2519-
def matchCases(scrut: Type, cases: List[Type])(implicit ctx: Context): Type = {
2519+
def matchCases(scrut: Type, cases: List[Type])(using Context): Type = {
25202520
def paramInstances = new TypeAccumulator[Array[Type]] {
25212521
def apply(inst: Array[Type], t: Type) = t match {
25222522
case t @ TypeParamRef(b, n) if b `eq` caseLambda =>

0 commit comments

Comments
 (0)