Skip to content

Commit 46cfd39

Browse files
committed
Pass separate context parameter CState
1 parent 2217b64 commit 46cfd39

File tree

325 files changed

+4656
-4533
lines changed

Some content is hidden

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

325 files changed

+4656
-4533
lines changed

bench/src/main/scala/Benchmarks.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools.benchmarks
22

33
import dotty.tools.dotc._
4-
import core.Contexts.Context
4+
import core.Contexts._
55
import dotty.tools.FatalError
66
import reporting._
77

@@ -94,6 +94,7 @@ class CompilerOptions {
9494
class Worker extends Driver {
9595
// override to avoid printing summary information
9696
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
97+
given CState = ctx.cstate
9798
if (fileNames.nonEmpty)
9899
try {
99100
val run = compiler.newRun

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
3939
import coreBTypes._
4040
import BCodeBodyBuilder._
4141

42-
private val primitives = new DottyPrimitives(ctx)
42+
private val primitives = new DottyPrimitives(ctx, cs)
4343

4444
/*
4545
* Functionality to build the body of ASM MethodNode, except for `synchronized` and `try` expressions.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
846846
}
847847
}
848848

849-
private def getGenericSignatureHelper(sym: Symbol, owner: Symbol, memberTpe: Type)(using Context): Option[String] = {
849+
private def getGenericSignatureHelper(sym: Symbol, owner: Symbol, memberTpe: Type)(using Context, CState): Option[String] = {
850850
if (needsGenericSignature(sym)) {
851851
val erasedTypeSym = TypeErasure.fullErasure(sym.denot.info).typeSymbol
852852
if (erasedTypeSym.isPrimitiveValueClass) {
@@ -866,7 +866,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
866866
}
867867
}
868868

869-
private def verifySignature(sym: Symbol, sig: String)(using Context): Unit = {
869+
private def verifySignature(sym: Symbol, sig: String)(using Context, CState): Unit = {
870870
import scala.tools.asm.util.CheckClassAdapter
871871
def wrap(body: => Unit): Unit = {
872872
try body
@@ -927,7 +927,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
927927
throw new RuntimeException(msg)
928928
}
929929

930-
private def compilingArray(using Context) =
930+
private def compilingArray(using Context, CState) =
931931
ctx.compilationUnit.source.file.name == "Array.scala"
932932
}
933933

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CollectSuperCalls extends MiniPhase {
2222

2323
def phaseName: String = "collectSuperCalls"
2424

25-
override def transformSelect(tree: Select)(using Context): Tree = {
25+
override def transformSelect(tree: Select)(using Context, CState): Tree = {
2626
tree.qualifier match {
2727
case sup: Super =>
2828
if (tree.symbol.owner.is(Trait))
@@ -32,7 +32,7 @@ class CollectSuperCalls extends MiniPhase {
3232
tree
3333
}
3434

35-
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(using Context) = {
35+
private def registerSuperCall(sym: ClassSymbol, calls: ClassSymbol)(using Context, CState) = {
3636
genBCodePhase match {
3737
case genBCodePhase: GenBCode =>
3838
genBCodePhase.registerSuperCall(sym, calls)

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

+16-15
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import Names.TermName
3636
import Annotations.Annotation
3737
import Names.Name
3838

39-
class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(using val ctx: Context) {
39+
class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])
40+
(using val ctx: Context, val cs: CState) {
4041

4142
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
4243

@@ -109,36 +110,36 @@ object DottyBackendInterface {
109110
else clazz.getName
110111
}
111112

112-
def requiredClass(str: String)(using Context): ClassSymbol =
113+
def requiredClass(str: String)(using Context, CState): ClassSymbol =
113114
Symbols.requiredClass(str)
114115

115-
def requiredClass[T](using evidence: ClassTag[T], ctx: Context): Symbol =
116+
def requiredClass[T](using evidence: ClassTag[T], ctx: Context, cs: CState): Symbol =
116117
requiredClass(erasureString(evidence.runtimeClass))
117118

118-
def requiredModule(str: String)(using Context): Symbol =
119+
def requiredModule(str: String)(using Context, CState): Symbol =
119120
Symbols.requiredModule(str)
120121

121-
def requiredModule[T](using evidence: ClassTag[T], ctx: Context): Symbol = {
122+
def requiredModule[T](using evidence: ClassTag[T], ctx: Context, cs: CState): Symbol = {
122123
val moduleName = erasureString(evidence.runtimeClass)
123124
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
124125
requiredModule(className)
125126
}
126127

127128
extension symExtensions on (sym: Symbol) {
128129

129-
def isInterface(using Context): Boolean = (sym.is(PureInterface)) || sym.is(Trait)
130+
def isInterface(using Context, CState): Boolean = (sym.is(PureInterface)) || sym.is(Trait)
130131

131-
def isStaticConstructor(using Context): Boolean = (sym.isStaticMember && sym.isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
132+
def isStaticConstructor(using Context, CState): Boolean = (sym.isStaticMember && sym.isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
132133

133-
def isStaticMember(using Context): Boolean = (sym ne NoSymbol) &&
134+
def isStaticMember(using Context, CState): Boolean = (sym ne NoSymbol) &&
134135
(sym.is(JavaStatic) || sym.isScalaStatic)
135136
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
136137

137138
/**
138139
* True for module classes of modules that are top-level or owned only by objects. Module classes
139140
* for such objects will get a MODULE$ flag and a corresponding static initializer.
140141
*/
141-
def isStaticModuleClass(using Context): Boolean =
142+
def isStaticModuleClass(using Context, CState): Boolean =
142143
(sym.is(Module)) && {
143144
// scalac uses atPickling here
144145
// this would not work if modules are created after pickling
@@ -152,7 +153,7 @@ object DottyBackendInterface {
152153

153154

154155

155-
def originalLexicallyEnclosingClass(using Context): Symbol =
156+
def originalLexicallyEnclosingClass(using Context, CState): Symbol =
156157
// used to populate the EnclosingMethod attribute.
157158
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
158159
if (sym.exists) {
@@ -166,15 +167,15 @@ object DottyBackendInterface {
166167
* True for module classes of package level objects. The backend will generate a mirror class for
167168
* such objects.
168169
*/
169-
def isTopLevelModuleClass(using Context): Boolean =
170+
def isTopLevelModuleClass(using Context, CState): Boolean =
170171
sym.is(ModuleClass) &&
171172
atPhase(flattenPhase) {
172173
toDenot(sym).owner.is(PackageClass)
173174
}
174175

175-
def javaSimpleName(using Context): String = toDenot(sym).name.mangledString
176-
def javaClassName(using Context): String = toDenot(sym).fullName.mangledString
177-
def javaBinaryName(using Context): String = javaClassName.replace('.', '/')
176+
def javaSimpleName(using Context, CState): String = toDenot(sym).name.mangledString
177+
def javaClassName(using Context, CState): String = toDenot(sym).fullName.mangledString
178+
def javaBinaryName(using Context, CState): String = javaClassName.replace('.', '/')
178179
}
179180

180181
private val primitiveCompilationUnits = Set(
@@ -193,7 +194,7 @@ object DottyBackendInterface {
193194
* True if the current compilation unit is of a primitive class (scala.Boolean et al).
194195
* Used only in assertions.
195196
*/
196-
def isCompilingPrimitive(using Context) = {
197+
def isCompilingPrimitive(using Context, CState) = {
197198
primitiveCompilationUnits(ctx.compilationUnit.source.file.name)
198199
}
199200

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class GenBCode extends Phase {
4343

4444
private var myOutput: AbstractFile = _
4545

46-
private def outputDir(using Context): AbstractFile = {
46+
private def outputDir(using Context, CState): AbstractFile = {
4747
if (myOutput eq null)
4848
myOutput = ctx.settings.outputDir.value
4949
myOutput
5050
}
5151

52-
def run(using Context): Unit =
52+
def run(using Context, CState): Unit =
5353
new GenBCodePipeline(
5454
new DottyBackendInterface(
5555
outputDir, superCallsMap.toMap
@@ -58,6 +58,7 @@ class GenBCode extends Phase {
5858

5959

6060
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
61+
given CState = ctx.cstate
6162
try super.runOn(units)
6263
finally myOutput match {
6364
case jar: JarArchive =>
@@ -75,7 +76,7 @@ object GenBCode {
7576
val name: String = "genBCode"
7677
}
7778

78-
class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BCodeSyncAndTry {
79+
class GenBCodePipeline(val int: DottyBackendInterface)(using Context, CState) extends BCodeSyncAndTry {
7980
import DottyBackendInterface.symExtensions
8081

8182
private var tree: Tree = _

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import scala.collection.immutable
3131
*
3232
* Inspired from the `scalac` compiler.
3333
*/
34-
class DottyPrimitives(ictx: Context) {
34+
class DottyPrimitives(ictx: Context, cs: CState) {
3535
import dotty.tools.backend.ScalaPrimitivesOps._
3636

3737
@threadUnsafe private lazy val primitives: immutable.Map[Symbol, Int] = init
@@ -50,7 +50,7 @@ class DottyPrimitives(ictx: Context) {
5050
* @param tpe The type of the receiver object. It is used only for array
5151
* operations
5252
*/
53-
def getPrimitive(app: Apply, tpe: Type)(using Context): Int = {
53+
def getPrimitive(app: Apply, tpe: Type)(using Context, CState): Int = {
5454
val fun = app.fun.symbol
5555
val defn = ctx.definitions
5656
val code = app.fun match {
@@ -121,6 +121,7 @@ class DottyPrimitives(ictx: Context) {
121121
private def init: immutable.Map[Symbol, Int] = {
122122

123123
given Context = ictx
124+
given CState = cs
124125

125126
import Symbols.defn
126127
val primitives = Symbols.newMutableSymbolMap[Int]
@@ -131,7 +132,7 @@ class DottyPrimitives(ictx: Context) {
131132
primitives(s) = code
132133
}
133134

134-
def addPrimitives(cls: Symbol, method: TermName, code: Int)(using Context): Unit = {
135+
def addPrimitives(cls: Symbol, method: TermName, code: Int)(using Context, CState): Unit = {
135136
val alts = cls.info.member(method).alternatives.map(_.symbol)
136137
if (alts.isEmpty)
137138
report.error(s"Unknown primitive method $cls.$method")
@@ -399,6 +400,7 @@ class DottyPrimitives(ictx: Context) {
399400

400401
def isPrimitive(fun: Tree): Boolean =
401402
given Context = ictx
403+
given CState = cs
402404
primitives.contains(fun.symbol)
403405
|| (fun.symbol == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length,clone}}
404406
&& {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ class GenSJSIR extends Phase {
1111
override def isRunnable(using Context): Boolean =
1212
super.isRunnable && ctx.settings.scalajs.value
1313

14-
def run(using Context): Unit =
14+
def run(using Context, CState): Unit =
1515
new JSCodeGen().run()
1616
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ import ScopedVar.withScopedVars
5656
* - `genMethod()` and similar methods generate the declarations of methods.
5757
* - `genStatOrExpr()` and everything else generate the bodies of methods.
5858
*/
59-
class JSCodeGen()(using genCtx: Context) {
59+
class JSCodeGen()(using genCtx: Context, cs: CState) {
6060
import JSCodeGen._
6161
import tpd._
6262

6363
private val jsdefn = JSDefinitions.jsdefn
64-
private val primitives = new JSPrimitives(genCtx)
64+
private val primitives = new JSPrimitives(genCtx, cs)
6565

6666
private val positionConversions = new JSPositions()(using genCtx)
6767
import positionConversions._
@@ -2733,7 +2733,7 @@ class JSCodeGen()(using genCtx: Context) {
27332733
private def genActualJSArgs(sym: Symbol, args: List[Tree])(
27342734
implicit pos: Position): List[js.TreeOrJSSpread] = {
27352735

2736-
def paramNamesAndTypes(using Context): List[(Names.TermName, Type)] =
2736+
def paramNamesAndTypes(using Context, CState): List[(Names.TermName, Type)] =
27372737
sym.info.paramNamess.flatten.zip(sym.info.paramInfoss.flatten)
27382738

27392739
val wereRepeated = atPhase(elimRepeatedPhase) {

0 commit comments

Comments
 (0)