Skip to content

Commit 1870b14

Browse files
authored
Merge pull request #6861 from dotty-staging/refactor-dotc2
More dotc refactorings
2 parents 7c94e5c + 740e11b commit 1870b14

38 files changed

+104
-315
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
518518
* @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4
519519
*/
520520
def getGenericSignature(sym: Symbol, owner: Symbol): String = {
521-
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
521+
ctx.atPhase(ctx.erasurePhase) {
522522
val memberTpe =
523523
if (sym.is(Flags.Method)) sym.denot.info
524524
else owner.denot.thisType.memberInfo(sym)
@@ -533,7 +533,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
533533
// But for now, just like we did in mixin, we just avoid writing a wrong generic signature
534534
// (one that doesn't erase to the actual signature). See run/t3452b for a test case.
535535

536-
val memberTpe = ctx.atPhase(ctx.erasurePhase) { implicit ctx => moduleClass.denot.thisType.memberInfo(sym) }
536+
val memberTpe = ctx.atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) }
537537
val erasedMemberType = TypeErasure.erasure(memberTpe)
538538
if (erasedMemberType =:= sym.denot.info)
539539
getGenericSignature(sym, moduleClass, memberTpe).orNull
@@ -782,7 +782,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
782782

783783
private def definedClasses(phase: Phase) =
784784
if (sym.isDefinedInCurrentRun)
785-
ctx.atPhase(phase) { implicit ctx =>
785+
ctx.atPhase(phase) {
786786
toDenot(sym).info.decls.filter(_.isClass)
787787
}
788788
else Nil
@@ -835,13 +835,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
835835
* such objects.
836836
*/
837837
def isTopLevelModuleClass: Boolean = sym.isModuleClass &&
838-
ctx.atPhase(ctx.flattenPhase) { implicit ctx =>
838+
ctx.atPhase(ctx.flattenPhase) {
839839
toDenot(sym).owner.is(Flags.PackageClass)
840840
}
841841

842842
def addRemoteRemoteExceptionAnnotation: Unit = ()
843843

844-
def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
844+
def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) {
845845
toDenot(sym).info.abstractTermMembers.toList match {
846846
case x :: Nil => x.symbol
847847
case Nil => abort(s"${sym.show} is not a functional interface. It doesn't have abstract methods")

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
162162
val (cl1, cl2) =
163163
if (classSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (classSymbol, dupClassSym)
164164
else (dupClassSym, classSymbol)
165-
ctx.atPhase(ctx.typerPhase) { implicit ctx =>
166-
ctx.warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
165+
ctx.atPhase(ctx.typerPhase) {
166+
the[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
167167
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.sourcePos)
168168
}
169169
}
@@ -263,7 +263,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
263263

264264
// ----------- compiler and sbt's callbacks
265265

266-
val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) { implicit ctx =>
266+
val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) {
267267
(ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal)
268268
}
269269

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ class JSCodeGen()(implicit ctx: Context) {
19621962
if (isStat) {
19631963
boxedResult
19641964
} else {
1965-
val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) { implicit ctx =>
1965+
val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) {
19661966
sym.info.finalResultType
19671967
}
19681968
unbox(boxedResult, tpe)
@@ -2578,13 +2578,13 @@ class JSCodeGen()(implicit ctx: Context) {
25782578
def paramNamesAndTypes(implicit ctx: Context): List[(Names.TermName, Type)] =
25792579
sym.info.paramNamess.flatten.zip(sym.info.paramInfoss.flatten)
25802580

2581-
val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) { implicit ctx =>
2581+
val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) {
25822582
val list = for ((name, tpe) <- paramNamesAndTypes)
25832583
yield (name -> tpe.isRepeatedParam)
25842584
list.toMap
25852585
}
25862586

2587-
val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) { implicit ctx =>
2587+
val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) {
25882588
paramNamesAndTypes.toMap
25892589
}
25902590

compiler/src/dotty/tools/backend/sjs/JSInterop.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object JSInterop {
1616
/** Is this symbol a JavaScript type? */
1717
def isJSType(sym: Symbol)(implicit ctx: Context): Boolean = {
1818
//sym.hasAnnotation(jsdefn.RawJSTypeAnnot)
19-
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
19+
ctx.atPhase(ctx.erasurePhase) {
2020
sym.derivesFrom(jsdefn.JSAnyClass)
2121
}
2222
}
@@ -32,7 +32,7 @@ object JSInterop {
3232
* much as *accessor* methods created for `val`s and `var`s.
3333
*/
3434
def isJSGetter(sym: Symbol)(implicit ctx: Context): Boolean = {
35-
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
35+
sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) {
3636
sym.info.isParameterless
3737
}
3838
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,32 @@ object Annotations {
124124
}
125125

126126
/** Create an annotation where the tree is computed lazily. */
127-
def deferred(sym: Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
127+
def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
128128
new LazyAnnotation {
129129
override def symbol(implicit ctx: Context): Symbol = sym
130-
def complete(implicit ctx: Context) = treeFn(ctx)
130+
def complete(implicit ctx: Context) = treeFn given ctx
131131
}
132132

133133
/** Create an annotation where the symbol and the tree are computed lazily. */
134-
def deferredSymAndTree(symf: Context => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation =
134+
def deferredSymAndTree(symf: given Context => Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
135135
new LazyAnnotation {
136136
private[this] var mySym: Symbol = _
137137

138138
override def symbol(implicit ctx: Context): Symbol = {
139139
if (mySym == null || mySym.defRunId != ctx.runId) {
140-
mySym = symf(ctx)
140+
mySym = symf given ctx
141141
assert(mySym != null)
142142
}
143143
mySym
144144
}
145-
def complete(implicit ctx: Context) = treeFn(ctx)
145+
def complete(implicit ctx: Context) = treeFn given ctx
146146
}
147147

148148
def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
149-
deferred(atp.classSymbol, implicit ctx => New(atp, args))
149+
deferred(atp.classSymbol)(New(atp, args))
150150

151151
def deferredResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
152-
deferred(atp.classSymbol, implicit ctx => resolveConstructor(atp, args))
152+
deferred(atp.classSymbol)(resolveConstructor(atp, args))
153153

154154
def makeAlias(sym: TermSymbol)(implicit ctx: Context): Annotation =
155155
apply(defn.AliasAnnot, List(
@@ -165,7 +165,7 @@ object Annotations {
165165
New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
166166
.withSpan(span)
167167
}
168-
deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx))
168+
deferred(defn.ChildAnnot)(makeChildLater(ctx))
169169
}
170170

171171
/** A regular, non-deferred Child annotation */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ object Contexts {
315315
/** Run `op` as if it was run in a fresh explore typer state, but possibly
316316
* optimized to re-use the current typer state.
317317
*/
318-
final def test[T](op: Context => T): T = typerState.test(op)(this)
318+
final def test[T](op: given Context => T): T = typerState.test(op)(this)
319319

320320
/** Is this a context for the members of a class definition? */
321321
def isClassDefContext: Boolean =
@@ -404,7 +404,7 @@ object Contexts {
404404
case _ => None
405405
}
406406
ctx.fresh.setImportInfo(
407-
new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt, imp.importDelegate))
407+
ImportInfo(sym, imp.selectors, impNameOpt, imp.importDelegate))
408408
}
409409

410410
/** Does current phase use an erased types interpretation? */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ object Decorators {
204204
* give more info about type variables and to disambiguate where needed.
205205
*/
206206
def ex(args: Any*)(implicit ctx: Context): String =
207-
explained(implicit ctx => em(args: _*))
207+
explained(em(args: _*))
208208
}
209209

210210
implicit class ArrayInterpolator[T <: AnyRef](val arr: Array[T]) extends AnyVal {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ abstract class Periods { self: Context =>
2121
op(ctx.fresh.setPeriod(pd))
2222

2323
/** Execute `op` at given phase id */
24-
def atPhase[T](pid: PhaseId)(op: Context => T): T =
25-
op(ctx.withPhase(pid))
24+
def atPhase[T](pid: PhaseId)(op: given Context => T): T =
25+
op given ctx.withPhase(pid)
2626

2727
/** The period containing the current period where denotations do not change.
2828
* We compute this by taking as first phase the first phase less or equal to

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ trait Phases {
3131
}
3232

3333
/** Execute `op` at given phase */
34-
def atPhase[T](phase: Phase)(op: Context => T): T =
34+
def atPhase[T](phase: Phase)(op: given Context => T): T =
3535
atPhase(phase.id)(op)
3636

37-
def atNextPhase[T](op: Context => T): T = atPhase(phase.next)(op)
37+
def atNextPhase[T](op: given Context => T): T = atPhase(phase.next)(op)
3838

39-
def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T =
40-
if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op)
39+
def atPhaseNotLaterThan[T](limit: Phase)(op: given Context => T): T =
40+
if (!limit.exists || phase <= limit) op given this else atPhase(limit)(op)
4141

4242
def isAfterTyper: Boolean = base.isAfterTyper(phase)
4343
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
195195
//}
196196
assert(!ctx.settings.YnoDeepSubtypes.value)
197197
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
198-
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2, approx)))
198+
ctx.log(TypeComparer.explained(the[Context].typeComparer.isSubType(tp1, tp2, approx)))
199199
}
200200
// Eliminate LazyRefs before checking whether we have seen a type before
201201
val normalize = new TypeMap {
@@ -2307,15 +2307,15 @@ object TypeComparer {
23072307
*/
23082308
val FreshApprox: ApproxState = new ApproxState(4)
23092309

2310-
/** Show trace of comparison operations when performing `op` as result string */
2311-
def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = {
2310+
/** Show trace of comparison operations when performing `op` */
2311+
def explaining[T](say: String => Unit)(op: given Context => T)(implicit ctx: Context): T = {
23122312
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
2313-
val res = try { op(nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
2313+
val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) }
23142314
res
23152315
}
23162316

23172317
/** Like [[explaining]], but returns the trace instead */
2318-
def explained[T](op: Context => T)(implicit ctx: Context): String = {
2318+
def explained[T](op: given Context => T)(implicit ctx: Context): String = {
23192319
var trace: String = null
23202320
try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace }
23212321
trace

0 commit comments

Comments
 (0)