Skip to content

Commit 7415348

Browse files
committed
Fixes in other code calling the compiler
1 parent ee87736 commit 7415348

File tree

27 files changed

+103
-65
lines changed

27 files changed

+103
-65
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
8585

8686
/** The context created for this run */
8787
given runContext[Dummy_so_its_a_def] as Context = myCtx
88-
given runCState[Dummy_so_its_a_def] as CState = myCtx.cstate
88+
given runCState[Dummy_so_its_a_def] as CState =
89+
if myCtx == null then Nowhere else myCtx.cstate
8990

9091
assert(currentRunId(using runContext) <= Periods.MaxPossibleRunId)
9192

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ object Phases {
292292
def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
293293
units.map { unit =>
294294
val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit)
295+
assert(unitCtx.compilationUnit != null)
295296
run(using unitCtx, unitCtx.cstate)
296297
unitCtx.compilationUnit
297298
}

compiler/test/dotty/tools/DottyTest.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ trait DottyTest extends ContextEscapeDetection {
2222
dotc.parsing.Scanners // initialize keywords
2323

2424
implicit var ctx: Context = initialCtx
25+
given [DummySoItsADef] as CState = ctx.cstate
2526

2627
protected def initialCtx: FreshContext = {
2728
val base = new ContextBase {}
@@ -54,7 +55,8 @@ trait DottyTest extends ContextEscapeDetection {
5455
val lastGroup = allPhases.find(x => x.contains(targetPhase)).get.takeWhile(x => !(x eq targetPhase))
5556
val checker = new Phase {
5657
def phaseName = "assertionChecker"
57-
override def run(using ctx: Context): Unit = assertion(ctx.compilationUnit.tpdTree, ctx)
58+
override def run(using ctx: Context, cs: CState): Unit =
59+
assertion(ctx.compilationUnit.tpdTree, ctx)
5860
}
5961
val lastGroupAppended = List(lastGroup ::: targetPhase :: Nil)
6062

compiler/test/dotty/tools/compilerSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import dotc.core.Comments.{ContextDoc, ContextDocstrings}
1717
* one used to compile the sources, this makes it easier to test for potential
1818
* issues involving retrieving symbols defined in a previous run.
1919
*/
20-
def inCompilerContext[T](classpath: String, separateRun: Boolean = true, scalaSources: String*)(op: Context ?=> T): T =
20+
def inCompilerContext[T](classpath: String, separateRun: Boolean = true, scalaSources: String*)(op: (Context, CState) ?=> T): T =
2121
val compiler = Compiler()
2222
val rootCtx = initCtx(classpath)
2323
val firstRun = compiler.newRun(using rootCtx)
2424
firstRun.compileFromStrings(scalaSources.toList)
2525
val opRun = if separateRun
2626
then compiler.newRun(using rootCtx)
2727
else firstRun
28-
op(using opRun.runContext)
28+
op(using opRun.runContext, opRun.runContext.cstate)
2929

3030
private def initCtx(classpath: String): Context =
3131
val ctx0 = (new ContextBase).initialCtx.fresh

compiler/test/dotty/tools/dotc/ast/UntypedTreeMapTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UntpdTreeMapTest extends DottyTest {
2222
def testMapInterpolatedString = {
2323
val tree = parse(""" q"hello ${2017}!" """)
2424
val identity = new UntypedTreeMap {
25-
override def transform(tree: Tree)(using Context): Tree = tree match {
25+
override def transform(tree: Tree)(using Context, CState): Tree = tree match {
2626
case _ => super.transform(tree)
2727
}
2828
}

compiler/test/dotty/tools/dotc/classpath/ZipAndJarFileLookupFactoryTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.junit.Test
44
import java.nio.file._
55
import java.nio.file.attribute.FileTime
66

7-
import dotty.tools.dotc.core.Contexts.{Context, ContextBase, ctx}
7+
import dotty.tools.dotc.core.Contexts.{Context, ContextBase, CState, ctx}
88
import dotty.tools.io.AbstractFile
99

1010

@@ -16,7 +16,8 @@ class ZipAndJarFileLookupFactoryTest {
1616
val f = Files.createTempFile("test-", ".jar")
1717
Files.delete(f)
1818

19-
given Context = new ContextBase().initialCtx
19+
given c as Context = new ContextBase().initialCtx
20+
given CState = c.cstate
2021
assert(!ctx.settings.YdisableFlatCpCaching.value) // we're testing with our JAR metadata caching enabled.
2122

2223
def createCp = ZipAndJarClassPathFactory.create(AbstractFile.getFile(f))

compiler/test/dotty/tools/dotc/core/tasty/CommentPicklingTest.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.ast.tpd.TreeOps
55
import dotty.tools.dotc.{Driver, Main}
66
import dotty.tools.dotc.core.Comments.CommentsContext
7-
import dotty.tools.dotc.core.Contexts.Context
7+
import dotty.tools.dotc.core.Contexts._
88
import dotty.tools.dotc.core.Decorators.PreNamedString
99
import dotty.tools.dotc.core.Mode
1010
import dotty.tools.dotc.core.Names.Name
@@ -59,6 +59,7 @@ class CommentPicklingTest {
5959

6060
private def compileAndCheckComment(sources: List[String], treeName: Name, expectedComment: Option[String]): Unit = {
6161
compileAndUnpickle(sources) { (trees, ctx) =>
62+
given CState = ctx.cstate
6263
findTreeNamed(treeName)(trees, ctx) match {
6364
case Some(md: tpd.MemberDef) =>
6465
val symbol = md.symbol(using ctx)
@@ -73,6 +74,7 @@ class CommentPicklingTest {
7374

7475
private def findTreeNamed(name: Name)(trees: List[tpd.Tree], ctx: Context): Option[tpd.MemberDef] = {
7576
implicit val _ctx: Context = ctx
77+
given CState = ctx.cstate
7678
trees.flatMap { _.find { case md: tpd.MemberDef => md.name == name; case _ => false }
7779
.map(_.asInstanceOf[tpd.MemberDef]).toList
7880
}.headOption
@@ -108,6 +110,7 @@ class CommentPicklingTest {
108110
override def initCtx = super.initCtx.addMode(Mode.ReadComments)
109111
def unpickle[T](args: Array[String], files: List[File])(fn: (List[tpd.Tree], Context) => T): T = {
110112
implicit val (_, ctx: Context) = setup(args, initCtx)
113+
given CState = ctx.cstate
111114
ctx.initialize()
112115
val trees = files.flatMap { f =>
113116
val unpickler = new DottyUnpickler(f.toByteArray())

compiler/test/dotty/tools/dotc/parsing/DeSugarTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ast.Trees._
1010
import ast.desugar
1111
import ast.desugar._
1212
import core.Mode
13-
import Contexts.Context
13+
import Contexts.{Context, CState}
1414

1515
import scala.collection.mutable.ListBuffer
1616

@@ -34,7 +34,7 @@ class DeSugarTest extends ParserTest {
3434
def transform(tree: Tree, mode: Mode)(using Context): Tree = withMode(mode) { transform(tree) }
3535
def transform(trees: List[Tree], mode: Mode)(using Context): List[Tree] = withMode(mode) { transform(trees) }
3636

37-
override def transform(tree: Tree)(using Context): Tree = {
37+
override def transform(tree: Tree)(using Context, CState): Tree = {
3838
val tree1 = desugar(tree)(using ctx.withModeBits(curMode))
3939
tree1 match {
4040
case TypedSplice(t) =>

compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import core.Contexts._
1414
import core.Flags
1515

1616
object ModifiersParsingTest {
17-
given Context = (new ContextBase).initialCtx
17+
private given c as Context = (new ContextBase).initialCtx
18+
private given CState = ctx.cstate
1819

1920
def parse(code: String): Tree = {
2021
val (_, stats) = new Parser(SourceFile.virtual("<meta>", code)).templateStatSeq()

compiler/test/dotty/tools/dotc/parsing/parsePackage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package parsing
55
import dotty.tools.dotc._
66
import core._, ast._
77
import Trees._
8-
import Contexts.Context
8+
import Contexts.{Context, CState}
99

1010
object parsePackage extends ParserTest {
1111

@@ -14,7 +14,7 @@ object parsePackage extends ParserTest {
1414
var nodes = 0
1515

1616
val transformer = new UntypedTreeMap {
17-
override def transform(tree: Tree)(using Context): Tree = {
17+
override def transform(tree: Tree)(using Context, CState): Tree = {
1818
nodes += 1
1919
tree match {
2020
case Ident(name) =>

0 commit comments

Comments
 (0)