Skip to content

Commit d04df74

Browse files
committed
Switch to (using Context) in more files in typer
1 parent 5ca8746 commit d04df74

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
6060
.setTyperState(new TyperState(ctx.typerState))
6161
ctx.initialize()(start) // re-initialize the base context with start
6262
def addImport(ctx: Context, rootRef: ImportInfo.RootRef) =
63-
ctx.fresh.setImportInfo(ImportInfo.rootImport(rootRef)(ctx))
63+
ctx.fresh.setImportInfo(ImportInfo.rootImport(rootRef))
6464
defn.RootImportFns.foldLeft(start.setRun(this))(addImport)
6565
}
6666

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
493493
def hasImport = {
494494
val owner1 = if (!owner.exists) defn.LanguageModule.moduleClass else owner
495495
ctx.importInfo != null &&
496-
ctx.importInfo.featureImported(feature, owner1)(ctx.withPhase(ctx.typerPhase))
496+
ctx.importInfo.featureImported(feature, owner1)(using ctx.withPhase(ctx.typerPhase))
497497
}
498498
val hasOption = {
499499
def toPrefix(sym: Symbol): String =

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object ImportInfo {
2121
)
2222

2323
/** The import info for a root import from given symbol `sym` */
24-
def rootImport(rootRef: RootRef)(implicit ctx: Context): ImportInfo =
24+
def rootImport(rootRef: RootRef)(using Context): ImportInfo =
2525
val (refFn, isPredef) = rootRef
2626
var selectors =
2727
untpd.ImportSelector(untpd.Ident(nme.WILDCARD)) // import all normal members...
@@ -30,8 +30,8 @@ object ImportInfo {
3030
if isPredef then // do not import any2stringadd
3131
selectors = untpd.ImportSelector(untpd.Ident(nme.any2stringadd), untpd.Ident(nme.WILDCARD))
3232
:: selectors
33-
def expr(implicit ctx: Context) = tpd.Ident(refFn())
34-
def imp(implicit ctx: Context) = tpd.Import(expr, selectors)
33+
def expr(using Context) = tpd.Ident(refFn())
34+
def imp(using Context) = tpd.Import(expr, selectors)
3535
ImportInfo(imp.symbol, selectors, None, isRootImport = true)
3636
}
3737

@@ -50,7 +50,7 @@ class ImportInfo(symf: Context ?=> Symbol,
5050

5151
// Dotty deviation: we cannot use a lazy val here for the same reason
5252
// that we cannot use one for `DottyPredefModuleRef`.
53-
def sym(implicit ctx: Context): Symbol = {
53+
def sym(using Context): Symbol = {
5454
if (mySym == null) {
5555
mySym = symf(using ctx)
5656
assert(mySym != null)
@@ -60,7 +60,7 @@ class ImportInfo(symf: Context ?=> Symbol,
6060
private var mySym: Symbol = _
6161

6262
/** The (TermRef) type of the qualifier of the import clause */
63-
def site(implicit ctx: Context): Type = sym.info match {
63+
def site(using Context): Type = sym.info match {
6464
case ImportType(expr) => expr.tpe
6565
case _ => NoType
6666
}
@@ -105,19 +105,19 @@ class ImportInfo(symf: Context ?=> Symbol,
105105
myReverseMapping = myReverseMapping.updated(sel.rename, sel.name)
106106

107107
/** The upper bound for `given` wildcards, or `Nothing` if there are none */
108-
def givenBound(implicit ctx: Context) =
108+
def givenBound(using Context) =
109109
if !myGivenBound.exists then
110110
myGivenBound = ctx.typer.importBound(selectors, isGiven = true)
111111
myGivenBound
112112

113113
/** The upper bound for `_` wildcards, or `Nothing` if there are none */
114-
def wildcardBound(implicit ctx: Context) =
114+
def wildcardBound(using Context) =
115115
if !myWildcardBound.exists then
116116
myWildcardBound = ctx.typer.importBound(selectors, isGiven = false)
117117
myWildcardBound
118118

119119
/** The implicit references imported by this import clause */
120-
def importedImplicits(implicit ctx: Context): List[ImplicitRef] =
120+
def importedImplicits(using Context): List[ImplicitRef] =
121121
val pre = site
122122
if isWildcardImport then
123123
pre.implicitMembers.flatMap { ref =>
@@ -157,7 +157,7 @@ class ImportInfo(symf: Context ?=> Symbol,
157157
* override import Predef.{any2stringAdd => _, StringAdd => _, _} // disables String +
158158
* override import java.lang.{} // disables all imports
159159
*/
160-
def unimported(implicit ctx: Context): Symbol =
160+
def unimported(using Context): Symbol =
161161
if myUnimported == null then
162162
lazy val sym = site.termSymbol
163163
def maybeShadowsRoot = symNameOpt match
@@ -172,7 +172,7 @@ class ImportInfo(symf: Context ?=> Symbol,
172172
private var myUnimported: Symbol = _
173173

174174
/** Does this import clause or a preceding import clause import `owner.feature`? */
175-
def featureImported(feature: TermName, owner: Symbol)(implicit ctx: Context): Boolean =
175+
def featureImported(feature: TermName, owner: Symbol)(using Context): Boolean =
176176

177177
def compute =
178178
val isImportOwner = site.widen.typeSymbol.eq(owner)
@@ -181,7 +181,7 @@ class ImportInfo(symf: Context ?=> Symbol,
181181
else
182182
var c = ctx.outer
183183
while c.importInfo eq ctx.importInfo do c = c.outer
184-
(c.importInfo != null) && c.importInfo.featureImported(feature, owner)(c)
184+
(c.importInfo != null) && c.importInfo.featureImported(feature, owner)(using c)
185185

186186
if (lastOwner.ne(owner) || !lastResults.contains(feature)) {
187187
lastOwner = owner

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ object Inferencing {
2929
* but only if the overall result of `isFullyDefined` is `true`.
3030
* Variables that are successfully minimized do not count as uninstantiated.
3131
*/
32-
def isFullyDefined(tp: Type, force: ForceDegree.Value)(implicit ctx: Context): Boolean = {
32+
def isFullyDefined(tp: Type, force: ForceDegree.Value)(using Context): Boolean = {
3333
val nestedCtx = ctx.fresh.setNewTyperState()
34-
val result = new IsFullyDefinedAccumulator(force)(nestedCtx).process(tp)
34+
val result = new IsFullyDefinedAccumulator(force)(using nestedCtx).process(tp)
3535
if (result) nestedCtx.typerState.commit()
3636
result
3737
}
3838

3939
/** The fully defined type, where all type variables are forced.
4040
* Throws an error if type contains wildcards.
4141
*/
42-
def fullyDefinedType(tp: Type, what: String, span: Span)(implicit ctx: Context): Type =
42+
def fullyDefinedType(tp: Type, what: String, span: Span)(using Context): Type =
4343
if (isFullyDefined(tp, ForceDegree.all)) tp
4444
else throw new Error(i"internal error: type of $what $tp is not fully defined, pos = $span") // !!! DEBUG
4545

@@ -52,7 +52,7 @@ object Inferencing {
5252
* If none of (1) - (4) applies, the type variable is left uninstantiated.
5353
* The method is called to instantiate type variables before an implicit search.
5454
*/
55-
def instantiateSelected(tp: Type, tvars: List[Type])(implicit ctx: Context): Unit =
55+
def instantiateSelected(tp: Type, tvars: List[Type])(using Context): Unit =
5656
if (tvars.nonEmpty)
5757
IsFullyDefinedAccumulator(
5858
ForceDegree.Value(tvars.contains, IfBottom.flip), minimizeSelected = true
@@ -61,7 +61,7 @@ object Inferencing {
6161
/** Instantiate any type variables in `tp` whose bounds contain a reference to
6262
* one of the parameters in `tparams` or `vparamss`.
6363
*/
64-
def instantiateDependent(tp: Type, tparams: List[Symbol], vparamss: List[List[Symbol]])(implicit ctx: Context): Unit = {
64+
def instantiateDependent(tp: Type, tparams: List[Symbol], vparamss: List[List[Symbol]])(using Context): Unit = {
6565
val dependentVars = new TypeAccumulator[Set[TypeVar]] {
6666
@threadUnsafe lazy val params = (tparams :: vparamss).flatten
6767
def apply(tvars: Set[TypeVar], tp: Type) = tp match {
@@ -108,7 +108,7 @@ object Inferencing {
108108
* to their upper bound.
109109
*/
110110
private class IsFullyDefinedAccumulator(force: ForceDegree.Value, minimizeSelected: Boolean = false)
111-
(implicit ctx: Context) extends TypeAccumulator[Boolean] {
111+
(using Context) extends TypeAccumulator[Boolean] {
112112

113113
private def instantiate(tvar: TypeVar, fromBelow: Boolean): Type = {
114114
val inst = tvar.instantiate(fromBelow)
@@ -167,7 +167,7 @@ object Inferencing {
167167
* instantiate the type parameter to the lower bound's approximation
168168
* (approximation because of possible F-bounds).
169169
*/
170-
def replaceSingletons(tp: Type)(implicit ctx: Context): Unit = {
170+
def replaceSingletons(tp: Type)(using Context): Unit = {
171171
val tr = new TypeTraverser {
172172
def traverse(tp: Type): Unit = {
173173
tp match {
@@ -190,7 +190,7 @@ object Inferencing {
190190
}
191191

192192
/** If `tree` has a type lambda type, infer its type parameters by comparing with expected type `pt` */
193-
def inferTypeParams(tree: Tree, pt: Type)(implicit ctx: Context): Tree = tree.tpe match {
193+
def inferTypeParams(tree: Tree, pt: Type)(using Context): Tree = tree.tpe match {
194194
case tl: TypeLambda =>
195195
val (tl1, tvars) = constrained(tl, tree)
196196
var tree1 = AppliedTypeTree(tree.withType(tl1), tvars)
@@ -201,7 +201,7 @@ object Inferencing {
201201
tree
202202
}
203203

204-
def isSkolemFree(tp: Type)(implicit ctx: Context): Boolean =
204+
def isSkolemFree(tp: Type)(using Context): Boolean =
205205
!tp.existsPart(_.isInstanceOf[SkolemType])
206206

207207
/** The list of uninstantiated type variables bound by some prefix of type `T` which
@@ -212,7 +212,7 @@ object Inferencing {
212212
* - The prefix `p` of a selection `p.f`.
213213
* - The result expression `e` of a block `{s1; .. sn; e}`.
214214
*/
215-
def tvarsInParams(tree: Tree, locked: TypeVars)(implicit ctx: Context): List[TypeVar] = {
215+
def tvarsInParams(tree: Tree, locked: TypeVars)(using Context): List[TypeVar] = {
216216
@tailrec def boundVars(tree: Tree, acc: List[TypeVar]): List[TypeVar] = tree match {
217217
case Apply(fn, _) => boundVars(fn, acc)
218218
case TypeApply(fn, targs) =>
@@ -252,7 +252,7 @@ object Inferencing {
252252
* -1 (minimize) if constraint is uniformly from below,
253253
* 0 if unconstrained, or constraint is from below and above.
254254
*/
255-
private def instDirection(param: TypeParamRef)(implicit ctx: Context): Int = {
255+
private def instDirection(param: TypeParamRef)(using Context): Int = {
256256
val constrained = ctx.typeComparer.fullBounds(param)
257257
val original = param.binder.paramInfos(param.paramNum)
258258
val cmp = ctx.typeComparer
@@ -267,7 +267,7 @@ object Inferencing {
267267
* class type reference where the class has a companion module, a reference to
268268
* that companion module. Otherwise NoType
269269
*/
270-
def companionRef(tp: Type)(implicit ctx: Context): Type =
270+
def companionRef(tp: Type)(using Context): Type =
271271
tp.underlyingClassRef(refinementOK = true) match {
272272
case tp: TypeRef =>
273273
val companion = tp.classSymbol.companionModule
@@ -281,7 +281,7 @@ object Inferencing {
281281
* @return The list of type symbols that were created
282282
* to instantiate undetermined type variables that occur non-variantly
283283
*/
284-
def maximizeType(tp: Type, span: Span, fromScala2x: Boolean)(implicit ctx: Context): List[Symbol] = {
284+
def maximizeType(tp: Type, span: Span, fromScala2x: Boolean)(using Context): List[Symbol] = {
285285
Stats.record("maximizeType")
286286
val vs = variances(tp)
287287
val patternBound = new mutable.ListBuffer[Symbol]
@@ -325,7 +325,7 @@ object Inferencing {
325325
*
326326
* we want to instantiate U to x.type right away. No need to wait further.
327327
*/
328-
private def variances(tp: Type)(implicit ctx: Context): VarianceMap = {
328+
private def variances(tp: Type)(using Context): VarianceMap = {
329329
Stats.record("variances")
330330
val constraint = ctx.typerState.constraint
331331

@@ -400,7 +400,7 @@ trait Inferencing { this: Typer =>
400400
* Then `Y` also occurs co-variantly in `T` because it needs to be minimized in order to constrain
401401
* `T` the least. See `variances` for more detail.
402402
*/
403-
def interpolateTypeVars(tree: Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): tree.type = {
403+
def interpolateTypeVars(tree: Tree, pt: Type, locked: TypeVars)(using Context): tree.type = {
404404
val state = ctx.typerState
405405

406406
// Note that some variables in `locked` might not be in `state.ownedVars`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
935935
def searchImplicit(sym: TermSymbol, tpt: Tree) = {
936936
val evTyper = new Typer
937937
val evCtx = ctx.fresh.setTyper(evTyper)
938-
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)(evCtx)
938+
val evidence = evTyper.inferImplicitArg(tpt.tpe, tpt.span)(using evCtx)
939939
evidence.tpe match {
940940
case fail: Implicits.AmbiguousImplicits =>
941941
ctx.error(evTyper.missingArgMsg(evidence, tpt.tpe, ""), tpt.sourcePos)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ class Typer extends Namer
738738
case tref: TypeRef if !tref.symbol.isClass && !ctx.isAfterTyper && !(tref =:= pt) =>
739739
require(ctx.mode.is(Mode.Pattern))
740740
inferImplicit(defn.ClassTagClass.typeRef.appliedTo(tref),
741-
EmptyTree, tree.tpt.span)(ctx.retractMode(Mode.Pattern)) match {
741+
EmptyTree, tree.tpt.span)(using ctx.retractMode(Mode.Pattern)) match {
742742
case SearchSuccess(clsTag, _, _) =>
743743
typed(untpd.Apply(untpd.TypedSplice(clsTag), untpd.TypedSplice(tree.expr)), pt)
744744
case _ =>

0 commit comments

Comments
 (0)