Skip to content

Commit 5d36082

Browse files
committed
Remove all mixin traits from Contexts
Also: - Change functions from Context to context functions - Rename ctx.erasedTypes -> currentlyAfterErasure ctx.isAfterTyper -> currentlyAfterTyper - Add currentPhase, currentPeriod, ... utility methods - Replace `c.runId` by `currentRunId(using c)`. This can be changed back again if we end up not splitting period info from contexts - Add inMode, withMode, withoutMode utility wrappers - Move error messages directly into reporting: this avoids an annoying import
1 parent 4477847 commit 5d36082

File tree

208 files changed

+2796
-2803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+2796
-2803
lines changed

bench/src/main/scala/Benchmarks.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Worker extends Driver {
102102
}
103103
catch {
104104
case ex: FatalError =>
105-
ctx.error(ex.getMessage) // signals that we should fail compilation.
105+
report.error(ex.getMessage) // signals that we should fail compilation.
106106
ctx.reporter
107107
}
108108
else ctx.reporter

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package jvm
44

55
import dotty.tools.dotc.core.Flags._
66
import dotty.tools.dotc.core.Symbols._
7+
import dotty.tools.dotc.report
78

89
/**
910
* This trait contains code shared between GenBCode and GenASM that depends on types defined in
@@ -89,7 +90,7 @@ final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
8990
def enclosingMethodAttribute(classSym: Symbol, classDesc: Symbol => String, methodDesc: Symbol => String): Option[EnclosingMethodEntry] = {
9091
if (isAnonymousOrLocalClass(classSym)) {
9192
val methodOpt = enclosingMethodForEnclosingMethodAttribute(classSym)
92-
ctx.debuglog(s"enclosing method for $classSym is $methodOpt (in ${methodOpt.map(_.enclosingClass)})")
93+
report.debuglog(s"enclosing method for $classSym is $methodOpt (in ${methodOpt.map(_.enclosingClass)})")
9394
Some(EnclosingMethodEntry(
9495
classDesc(enclosingClassForEnclosingMethodAttribute(classSym)),
9596
methodOpt.map(_.javaSimpleName).orNull,

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import dotty.tools.dotc.transform.SymUtils._
2121
import dotty.tools.dotc.util.Spans._
2222
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
2323
import dotty.tools.dotc.core.Phases._
24+
import dotty.tools.dotc.report
2425

2526
/*
2627
*
@@ -277,7 +278,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
277278

278279
tree match {
279280
case ValDef(nme.THIS, _, _) =>
280-
ctx.debuglog("skipping trivial assign to _$this: " + tree)
281+
report.debuglog("skipping trivial assign to _$this: " + tree)
281282

282283
case tree@ValDef(_, _, _) =>
283284
val sym = tree.symbol
@@ -326,9 +327,9 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
326327
else {
327328
val arity = app.meth.tpe.widenDealias.firstParamTypes.size - env.size
328329
val returnsUnit = app.meth.tpe.widenDealias.resultType.classSymbol == defn.UnitClass
329-
if (returnsUnit) ctx.requiredClass(("dotty.runtime.function.JProcedure" + arity))
330-
else if (arity <= 2) ctx.requiredClass(("dotty.runtime.function.JFunction" + arity))
331-
else ctx.requiredClass(("scala.Function" + arity))
330+
if (returnsUnit) requiredClass(("dotty.runtime.function.JProcedure" + arity))
331+
else if (arity <= 2) requiredClass(("dotty.runtime.function.JFunction" + arity))
332+
else requiredClass(("scala.Function" + arity))
332333
}
333334
}
334335
val (fun, args) = call match {
@@ -669,7 +670,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
669670
var elemKind = arr.elementType
670671
val argsSize = args.length
671672
if (argsSize > dims) {
672-
ctx.error(s"too many arguments for array constructor: found ${args.length} but array has only $dims dimension(s)", ctx.source.atSpan(app.span))
673+
report.error(s"too many arguments for array constructor: found ${args.length} but array has only $dims dimension(s)", ctx.source.atSpan(app.span))
673674
}
674675
if (argsSize < dims) {
675676
/* In one step:
@@ -1431,7 +1432,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
14311432
def genInvokeDynamicLambda(ctor: Symbol, lambdaTarget: Symbol, environmentSize: Int, functionalInterface: Symbol): BType = {
14321433
import java.lang.invoke.LambdaMetafactory.FLAG_SERIALIZABLE
14331434

1434-
ctx.debuglog(s"Using invokedynamic rather than `new ${ctor.owner}`")
1435+
report.debuglog(s"Using invokedynamic rather than `new ${ctor.owner}`")
14351436
val generatedType = classBTypeFromSymbol(functionalInterface)
14361437
// Lambdas should be serializable if they implement a SAM that extends Serializable or if they
14371438
// implement a scala.Function* class.

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

+19-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import dotty.tools.dotc.core.Types._
2727
import dotty.tools.dotc.core.TypeErasure
2828
import dotty.tools.dotc.transform.GenericSignatures
2929
import dotty.tools.io.AbstractFile
30+
import dotty.tools.dotc.report
3031

3132
import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions
3233

@@ -52,11 +53,11 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
5253
def ScalaATTRName: String = "Scala"
5354
def ScalaSignatureATTRName: String = "ScalaSig"
5455

55-
@threadUnsafe lazy val AnnotationRetentionAttr: ClassSymbol = ctx.requiredClass("java.lang.annotation.Retention")
56-
@threadUnsafe lazy val AnnotationRetentionSourceAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
57-
@threadUnsafe lazy val AnnotationRetentionClassAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
58-
@threadUnsafe lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
59-
@threadUnsafe lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")
56+
@threadUnsafe lazy val AnnotationRetentionAttr: ClassSymbol = requiredClass("java.lang.annotation.Retention")
57+
@threadUnsafe lazy val AnnotationRetentionSourceAttr: TermSymbol = requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
58+
@threadUnsafe lazy val AnnotationRetentionClassAttr: TermSymbol = requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
59+
@threadUnsafe lazy val AnnotationRetentionRuntimeAttr: TermSymbol = requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
60+
@threadUnsafe lazy val JavaAnnotationClass: ClassSymbol = requiredClass("java.lang.annotation.Annotation")
6061

6162
val bCodeAsmCommon: BCodeAsmCommon[int.type] = new BCodeAsmCommon(int)
6263
import bCodeAsmCommon._
@@ -76,7 +77,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
7677
outputDirectory
7778
} catch {
7879
case ex: Throwable =>
79-
ctx.error(s"Couldn't create file for class $cName\n${ex.getMessage}", ctx.source.atSpan(csym.span))
80+
report.error(s"Couldn't create file for class $cName\n${ex.getMessage}", ctx.source.atSpan(csym.span))
8081
null
8182
}
8283
}
@@ -425,7 +426,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
425426
emitAssocs(nestedVisitor, assocs, bcodeStore)(innerClasesStore)
426427

427428
case t =>
428-
ctx.error(ex"Annotation argument is not a constant", t.sourcePos)
429+
report.error(ex"Annotation argument is not a constant", t.sourcePos)
429430
}
430431
}
431432

@@ -563,26 +564,26 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
563564
*/
564565
def addForwarders(jclass: asm.ClassVisitor, jclassName: String, moduleClass: Symbol): Unit = {
565566
assert(moduleClass.is(ModuleClass), moduleClass)
566-
ctx.debuglog(s"Dumping mirror class for object: $moduleClass")
567+
report.debuglog(s"Dumping mirror class for object: $moduleClass")
567568

568569
val linkedClass = moduleClass.companionClass
569570
lazy val conflictingNames: Set[Name] = {
570571
(linkedClass.info.allMembers.collect { case d if d.name.isTermName => d.name }).toSet
571572
}
572-
ctx.debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")
573+
report.debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")
573574

574575
for (m0 <- sortedMembersBasedOnFlags(moduleClass.info, required = Method, excluded = ExcludedForwarder)) {
575576
val m = if (m0.is(Bridge)) m0.nextOverriddenSymbol else m0
576577
if (m == NoSymbol)
577-
ctx.log(s"$m0 is a bridge method that overrides nothing, something went wrong in a previous phase.")
578+
report.log(s"$m0 is a bridge method that overrides nothing, something went wrong in a previous phase.")
578579
else if (m.isType || m.is(Deferred) || (m.owner eq defn.ObjectClass) || m.isConstructor || m.name.is(ExpandedName))
579-
ctx.debuglog(s"No forwarder for '$m' from $jclassName to '$moduleClass'")
580+
report.debuglog(s"No forwarder for '$m' from $jclassName to '$moduleClass'")
580581
else if (conflictingNames(m.name))
581-
ctx.log(s"No forwarder for $m due to conflict with ${linkedClass.info.member(m.name)}")
582+
report.log(s"No forwarder for $m due to conflict with ${linkedClass.info.member(m.name)}")
582583
else if (m.accessBoundary(defn.RootClass) ne defn.RootClass)
583-
ctx.log(s"No forwarder for non-public member $m")
584+
report.log(s"No forwarder for non-public member $m")
584585
else {
585-
ctx.log(s"Adding static forwarder for '$m' from $jclassName to '$moduleClass'")
586+
report.log(s"Adding static forwarder for '$m' from $jclassName to '$moduleClass'")
586587
addForwarder(jclass, moduleClass, m)
587588
}
588589
}
@@ -822,7 +823,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
822823
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
823824
*/
824825
case a @ AnnotatedType(t, _) =>
825-
ctx.debuglog(s"typeKind of annotated type $a")
826+
report.debuglog(s"typeKind of annotated type $a")
826827
typeToTypeKind(t)(ct)(storage)
827828

828829
/* The cases below should probably never occur. They are kept for now to avoid introducing
@@ -831,7 +832,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
831832
*/
832833

833834
case tp =>
834-
ctx.warning(
835+
report.warning(
835836
s"an unexpected type representation reached the compiler backend while compiling ${ctx.compilationUnit}: $tp. " +
836837
"If possible, please file a bug on https://github.com/lampepfl/dotty/issues")
837838

@@ -871,7 +872,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
871872
try body
872873
catch {
873874
case ex: Throwable =>
874-
ctx.error(i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
875+
report.error(i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
875876
|signature: $sig
876877
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
877878
""".trim, sym.sourcePos)
@@ -922,7 +923,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
922923
}
923924

924925
def abort(msg: String): Nothing = {
925-
ctx.error(msg)
926+
report.error(msg)
926927
throw new RuntimeException(msg)
927928
}
928929

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import scala.annotation.switch
77
import scala.collection.mutable
88
import Primitives.{NE, EQ, TestOp, ArithmeticOp}
99
import scala.tools.asm.tree.MethodInsnNode
10+
import dotty.tools.dotc.report
1011

1112
/*
1213
* A high-level facade to the ASM API for bytecode generation.
@@ -585,7 +586,7 @@ trait BCodeIdiomatic {
585586
}
586587

587588
def abort(msg: String): Nothing = {
588-
ctx.error(msg)
589+
report.error(msg)
589590
throw new RuntimeException(msg)
590591
}
591592

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import dotty.tools.dotc.core.StdNames.str
1818
import dotty.tools.dotc.core.Symbols._
1919
import dotty.tools.dotc.core.Types.Type
2020
import dotty.tools.dotc.util.Spans._
21+
import dotty.tools.dotc.report
2122

2223
/*
2324
*
@@ -118,12 +119,12 @@ trait BCodeSkelBuilder extends BCodeHelpers {
118119
val optSerial: Option[Long] =
119120
claszSymbol.getAnnotation(defn.SerialVersionUIDAnnot).flatMap { annot =>
120121
if (claszSymbol.is(Trait)) {
121-
ctx.error("@SerialVersionUID does nothing on a trait", annot.tree.sourcePos)
122+
report.error("@SerialVersionUID does nothing on a trait", annot.tree.sourcePos)
122123
None
123124
} else {
124125
val vuid = annot.argumentConstant(0).map(_.longValue)
125126
if (vuid.isEmpty)
126-
ctx.error("The argument passed to @SerialVersionUID must be a constant",
127+
report.error("The argument passed to @SerialVersionUID must be a constant",
127128
annot.argument(0).getOrElse(annot.tree).sourcePos)
128129
vuid
129130
}
@@ -192,7 +193,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
192193
// it must be a top level class (name contains no $s)
193194
val isCandidateForForwarders = (lmoc.is(Module)) && lmoc.isStatic
194195
if (isCandidateForForwarders) {
195-
ctx.log(s"Adding static forwarders from '$claszSymbol' to implementations in '$lmoc'")
196+
report.log(s"Adding static forwarders from '$claszSymbol' to implementations in '$lmoc'")
196197
addForwarders(cnode, thisName, lmoc.moduleClass)
197198
}
198199
}
@@ -388,7 +389,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
388389
*/
389390
def makeLocal(tk: BType, name: String, tpe: Type, pos: Span): Symbol = {
390391

391-
val locSym = ctx.newSymbol(methSymbol, name.toTermName, Synthetic, tpe, NoSymbol, pos)
392+
val locSym = newSymbol(methSymbol, name.toTermName, Synthetic, tpe, NoSymbol, pos)
392393
makeLocal(locSym, tk)
393394
locSym
394395
}
@@ -407,7 +408,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
407408
val loc = Local(tk, sym.javaSimpleName, nxtIdx, sym.is(Synthetic))
408409
val existing = slots.put(sym, loc)
409410
if (existing.isDefined)
410-
ctx.error("attempt to create duplicate local var.", ctx.source.atSpan(sym.span))
411+
report.error("attempt to create duplicate local var.", ctx.source.atSpan(sym.span))
411412
assert(tk.size > 0, "makeLocal called for a symbol whose type is Unit.")
412413
nxtIdx += tk.size
413414
loc
@@ -560,7 +561,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
560561

561562
if (params.size > MaximumJvmParameters) {
562563
// SI-7324
563-
ctx.error(s"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
564+
report.error(s"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
564565
return
565566
}
566567

@@ -587,7 +588,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
587588
case (_: Return) | Block(_, (_: Return)) => ()
588589
case (_: Apply) | Block(_, (_: Apply)) if rhs.symbol eq defn.throwMethod => ()
589590
case tpd.EmptyTree =>
590-
ctx.error("Concrete method has no definition: " + dd + (
591+
report.error("Concrete method has no definition: " + dd + (
591592
if (ctx.settings.Ydebug.value) "(found: " + methSymbol.owner.info.decls.toList.mkString(", ") + ")"
592593
else ""),
593594
ctx.source.atSpan(NoSpan)

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package jvm
44

55
import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream, File => JFile }
66
import dotty.tools.io._
7+
import dotty.tools.dotc.report
8+
79
import java.util.jar.Attributes.Name
810
import scala.language.postfixOps
911

@@ -61,7 +63,7 @@ trait BytecodeWriters {
6163
try out.write(jclassBytes, 0, jclassBytes.length)
6264
finally out.flush()
6365

64-
ctx.informProgress("added " + label + path + " to jar")
66+
report.informProgress("added " + label + path + " to jar")
6567
}
6668
override def close() = writer.close()
6769
}
@@ -111,7 +113,7 @@ trait BytecodeWriters {
111113

112114
try outstream.write(jclassBytes, 0, jclassBytes.length)
113115
finally outstream.close()
114-
ctx.informProgress("wrote '" + label + "' to " + outfile)
116+
report.informProgress("wrote '" + label + "' to " + outfile)
115117
}
116118
}
117119

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: DottyBackendInterface]](val bTyp
114114
* names of NothingClass and NullClass can't be emitted as-is.
115115
* TODO @lry Once there's a 2.11.3 starr, use the commented argument list. The current starr crashes on the type literal `scala.runtime.Nothing$`
116116
*/
117-
lazy val RT_NOTHING : ClassBType = classBTypeFromSymbol(ctx.requiredClass("scala.runtime.Nothing$")) // (requiredClass[scala.runtime.Nothing$])
118-
lazy val RT_NULL : ClassBType = classBTypeFromSymbol(ctx.requiredClass("scala.runtime.Null$")) // (requiredClass[scala.runtime.Null$])
117+
lazy val RT_NOTHING : ClassBType = classBTypeFromSymbol(requiredClass("scala.runtime.Nothing$")) // (requiredClass[scala.runtime.Nothing$])
118+
lazy val RT_NULL : ClassBType = classBTypeFromSymbol(requiredClass("scala.runtime.Null$")) // (requiredClass[scala.runtime.Null$])
119119

120120
lazy val ObjectReference : ClassBType = classBTypeFromSymbol(defn.ObjectClass)
121121
lazy val objArrayReference : ArrayBType = ArrayBType(ObjectReference)

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import Phases._
2323

2424
import dotty.tools.dotc.util
2525
import dotty.tools.dotc.util.Spans
26+
import dotty.tools.dotc.report
27+
2628
import Decorators._
2729
import Constants._
2830
import tpd._
@@ -81,7 +83,7 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
8183
def _1: Type = field.tpe match {
8284
case JavaArrayType(elem) => elem
8385
case _ =>
84-
ctx.error(s"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
86+
report.error(s"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
8587
UnspecifiedErrorType
8688
}
8789
def _2: List[Tree] = field.elems
@@ -107,13 +109,19 @@ object DottyBackendInterface {
107109
else clazz.getName
108110
}
109111

112+
def requiredClass(str: String)(using Context): ClassSymbol =
113+
Symbols.requiredClass(str)
114+
110115
def requiredClass[T](using evidence: ClassTag[T], ctx: Context): Symbol =
111-
ctx.requiredClass(erasureString(evidence.runtimeClass))
116+
requiredClass(erasureString(evidence.runtimeClass))
117+
118+
def requiredModule(str: String)(using Context): Symbol =
119+
Symbols.requiredModule(str)
112120

113121
def requiredModule[T](using evidence: ClassTag[T], ctx: Context): Symbol = {
114122
val moduleName = erasureString(evidence.runtimeClass)
115123
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
116-
ctx.requiredModule(className)
124+
requiredModule(className)
117125
}
118126

119127
extension symExtensions on (sym: Symbol) {

0 commit comments

Comments
 (0)