Skip to content

Commit 731bb17

Browse files
committed
Post-rebase fixes
1 parent f29ab46 commit 731bb17

11 files changed

+58
-99
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,15 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
225225
if (ctx.settings.YtestPickler.value) List("pickler")
226226
else ctx.settings.YstopAfter.value
227227

228-
var forceReachPhaseMaybe =
229-
if (ctx.isBestEffort) Some("typer")
230-
else None
231-
232-
var reachedSemanticDB = false
233-
var reachedPickler = false
234-
235228
val pluginPlan = ctx.base.addPluginPhases(ctx.base.phasePlan)
236229
val phases = ctx.base.fusePhases(pluginPlan,
237230
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
238231
ctx.base.usePhases(phases)
239232

233+
var forceReachPhaseMaybe =
234+
if (ctx.isBestEffort && phases.exists(_.phaseName == "typer")) Some("typer")
235+
else None
236+
240237
if ctx.settings.YnoDoubleBindings.value then
241238
ctx.base.checkNoDoubleBindings = true
242239

@@ -263,17 +260,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
263260
case _ =>
264261
}
265262

266-
if phase.phaseName == "extractSemanticDB" then reachedSemanticDB = true
267-
if phase.phaseName == "pickler" then reachedPickler = true
268-
269-
if !reachedSemanticDB && forceReachPhaseMaybe.isEmpty && ctx.reporter.hasErrors && ctx.isBestEffort then
270-
ctx.base.allPhases.find(_.phaseName == "extractSemanticDB").foreach(_.runOn(units))
271-
reachedSemanticDB = true
272-
273-
if !reachedPickler && forceReachPhaseMaybe.isEmpty && ctx.reporter.hasErrors && ctx.isBestEffort then
274-
ctx.base.allPhases.find(_.phaseName == "pickler").foreach(_.runOn(units))
275-
reachedPickler = true
276-
277263
report.informTime(s"$phase ", start)
278264
Stats.record(s"total trees at end of $phase", ast.Trees.ntrees)
279265
for (unit <- units)

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ object FileUtils {
2424

2525
def hasTastyExtension: Boolean = file.hasExtension("tasty")
2626

27+
def hasBetastyExtension: Boolean = file.hasExtension("betasty")
28+
2729
def isTasty: Boolean = !file.isDirectory && hasTastyExtension
2830

31+
def isBestEffortTasty: Boolean = !file.isDirectory && hasBetastyExtension
32+
2933
def isScalaBinary: Boolean = file.isClass || file.isTasty
3034

3135
def isScalaOrJavaSource: Boolean = !file.isDirectory && (file.hasExtension("scala") || file.hasExtension("java"))

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import java.nio.channels.ClosedByInterruptException
77

88
import scala.util.control.NonFatal
99

10-
import dotty.tools.dotc.classpath.FileUtils.isTasty
10+
import dotty.tools.dotc.classpath.FileUtils.{isTasty, isBestEffortTasty}
1111
import dotty.tools.io.{ ClassPath, ClassRepresentation, AbstractFile }
1212
import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions
1313

1414
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, Names._
1515
import NameOps._
1616
import StdNames._
17-
import classfile.{ClassfileParser, ClassfileTastyUUIDParser, BestEffortTastyParser}
17+
import classfile.{ClassfileParser, ClassfileTastyUUIDParser}
1818
import Decorators._
1919

2020
import util.Stats
@@ -198,7 +198,7 @@ object SymbolLoaders {
198198
enterToplevelsFromSource(owner, nameOf(classRep), src)
199199
case (Some(bin), _) =>
200200
val completer =
201-
if bin.isTasty then ctx.platform.newTastyLoader(bin)
201+
if bin.isTasty || bin.isBestEffortTasty then ctx.platform.newTastyLoader(bin)
202202
else ctx.platform.newClassLoader(bin)
203203
enterClassAndModule(owner, nameOf(classRep), completer)
204204
}
@@ -411,40 +411,38 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
411411

412412
override def doComplete(root: SymDenotation)(using Context): Unit =
413413
val (classRoot, moduleRoot) = rootDenots(root.asClass)
414-
val isBestEffortTasty = classfile.name.endsWith(".betasty")
415-
val result =
416-
if isBestEffortTasty then // TODO move to TastyLoader
417-
new BestEffortTastyParser(classfile, classRoot, moduleRoot)(ctx).run()
418-
else
419-
new ClassfileParser(classfile, classRoot, moduleRoot)(ctx).run()
420-
421-
if (mayLoadTreesFromTasty || (isBestEffortTasty && ctx.withBestEffortTasty))
422-
result match {
423-
case Some(unpickler: tasty.DottyUnpickler) =>
424-
classRoot.classSymbol.rootTreeOrProvider = unpickler
425-
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
426-
case _ =>
427-
}
414+
val result = new ClassfileParser(classfile, classRoot, moduleRoot)(ctx).run()
415+
result match {
416+
case Some(unpickler: tasty.DottyUnpickler) =>
417+
classRoot.classSymbol.rootTreeOrProvider = unpickler
418+
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
419+
case _ =>
420+
}
428421

429-
private def mayLoadTreesFromTasty(using Context): Boolean =
430-
ctx.settings.YretainTrees.value || ctx.settings.fromTasty.value
431422
}
432423

433424
class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
434425

435426
override def sourceFileOrNull: AbstractFile | Null = tastyFile
436427

437-
def description(using Context): String = "TASTy file " + tastyFile.toString
428+
def description(using Context): String =
429+
if tastyFile.extension == ".betasty" then "Best Effort TASTy file " + tastyFile.toString
430+
else "TASTy file " + tastyFile.toString
438431

439432
override def doComplete(root: SymDenotation)(using Context): Unit =
440433
val (classRoot, moduleRoot) = rootDenots(root.asClass)
434+
val isBestEffortTasty = tastyFile.name.endsWith(".betasty")
441435
val tastyBytes = tastyFile.toByteArray
442-
val unpickler = new tasty.DottyUnpickler(tastyBytes)
436+
val unpickler = new tasty.DottyUnpickler(tastyBytes, withBestEffortTasty = ctx.withBestEffortTasty)
443437
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
444-
if mayLoadTreesFromTasty then
438+
if mayLoadTreesFromTasty || (isBestEffortTasty && ctx.withBestEffortTasty) then
445439
classRoot.classSymbol.rootTreeOrProvider = unpickler
446440
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
447-
checkTastyUUID(tastyFile, tastyBytes)
441+
if isBestEffortTasty then
442+
checkBeTastyUUID(tastyFile, tastyBytes)
443+
ctx.setUsesBestEffortTasty()
444+
else
445+
checkTastyUUID(tastyFile, tastyBytes)
448446

449447

450448
private def checkTastyUUID(tastyFile: AbstractFile, tastyBytes: Array[Byte])(using Context): Unit =
@@ -458,6 +456,9 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
458456
// This will be the case in any of our tests that compile with `-Youtput-only-tasty`
459457
report.inform(s"No classfiles found for $tastyFile when checking TASTy UUID")
460458

459+
private def checkBeTastyUUID(tastyFile: AbstractFile, tastyBytes: Array[Byte])(using Context): Unit =
460+
new TastyHeaderUnpickler(tastyBytes).readHeader(true)
461+
461462
private def mayLoadTreesFromTasty(using Context): Boolean =
462463
ctx.settings.YretainTrees.value || ctx.settings.fromTasty.value
463464
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,8 @@ object Types {
30523052
if (ctx.erasedTypes) tref
30533053
else cls.info match {
30543054
case cinfo: ClassInfo => cinfo.selfType
3055-
case _: ErrorType | NoType if ctx.mode.is(Mode.Interactive) => cls.info
3055+
case _: ErrorType | NoType
3056+
if ctx.mode.is(Mode.Interactive) || ctx.isBestEffort || ctx.usesBestEffortTasty => cls.info // TODO aggregate
30563057
// can happen in IDE if `cls` is stale
30573058
}
30583059

compiler/src/dotty/tools/dotc/core/classfile/BestEffortTastyParser.scala

Lines changed: 0 additions & 46 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ExtractSemanticDB extends Phase:
4141
override def isRunnable(using Context) =
4242
import ExtractSemanticDB.{semanticdbTarget, outputDirectory}
4343
def writesToOutputJar = semanticdbTarget.isEmpty && outputDirectory.isInstanceOf[JarArchive]
44-
super.isRunnable && ctx.settings.Xsemanticdb.value && !writesToOutputJar
44+
(super.isRunnable || ctx.isBestEffort) && ctx.settings.Xsemanticdb.value && !writesToOutputJar
4545

4646
// Check not needed since it does not transform trees
4747
override def isCheckable: Boolean = false

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Pickler extends Phase {
4141

4242
// No need to repickle trees coming from TASTY
4343
override def isRunnable(using Context): Boolean =
44-
super.isRunnable && !ctx.settings.fromTasty.value && (ctx.isBestEffort || !ctx.usesBestEffortTasty)
44+
(super.isRunnable || ctx.isBestEffort) && !ctx.settings.fromTasty.value
4545

4646
private def output(name: String, msg: String) = {
4747
val s = new PrintStream(name)

compiler/test/dotc/neg-best-effort-pickling.blacklist

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ curried-dependent-ift.scala
1515
safeThrowsStrawman2.scala
1616
varargs-annot-2.scala
1717
i1642.scala
18-
i2202.scala
18+
i2202.scala
19+
20+
# new errors TODO check
21+
type-test-paths.scala
22+
type-test-paths-2.scala
23+
erased-in-tuples.scala
24+
i15158.scala

compiler/test/dotc/neg-best-effort-unpickling.blacklist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ i0091-infpaths.scala
99
exports.scala
1010
i14834.scala
1111

12-
# unpickling crashes
12+
# other type related crashes
1313
i4653.scala
14-
#i16407.scala
14+
overrideClass.scala

compiler/test/dotty/tools/dotc/BestEffortCompilationTests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import org.junit.{ Test, AfterClass }
88
import reporting.TestReporter
99
import java.io.{File => JFile}
1010

11+
import scala.language.unsafeNulls
12+
1113
class BestEffortCompilationTests {
1214
import ParallelTesting._
1315
import vulpix.TestConfiguration._

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
654654
}
655655

656656
protected def compileWithBestEffortTasty(files0: Array[JFile], bestEffortDir: JFile, flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = {
657-
val flags = flags0 and "-Ywith-best-effort-tasty"
657+
val flags = flags0
658+
.and("-Ywith-best-effort-tasty")
659+
.and("-d", targetDir.getPath)
658660
val reporter = mkReporter
659661
val driver = new Driver
660662

@@ -1520,6 +1522,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
15201522
def compileBestEffortTastyInDir(f: String, flags: TestFlags, picklingFilter: FileFilter, unpicklingFilter: FileFilter)(
15211523
implicit testGroup: TestGroup): BestEffortCompilationTest = {
15221524
val bestEffortFlag = "-Ybest-effort"
1525+
val semanticDbFlag = "-Xsemanticdb"
15231526
assert(!flags.options.contains(bestEffortFlag), "Best effort compilation flag should not be added manually")
15241527

15251528
val outDir = defaultOutputDir + testGroup + JFile.separator
@@ -1534,7 +1537,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
15341537
file: JFile,
15351538
flags: TestFlags,
15361539
outputDir: JFile
1537-
) extends JointCompilationSource(name, Array(file), flags.and(bestEffortFlag), outputDir) {
1540+
) extends JointCompilationSource(name, Array(file), flags.and(bestEffortFlag).and(semanticDbFlag), outputDir) {
15381541
override def buildInstructions(errors: Int, warnings: Int): String = {
15391542
s"""|
15401543
|Test '$title' compiled with a compiler crash,
@@ -1552,7 +1555,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
15521555
file: JFile,
15531556
flags: TestFlags,
15541557
bestEffortDir: JFile,
1555-
) extends JointCompilationSource(name, Array(file), flags, bestEffortDir, fromTasty = FromBestEffortTasty) {
1558+
) extends JointCompilationSource(name, Array(file), flags.and(bestEffortFlag), bestEffortDir, fromTasty = FromBestEffortTasty) { // TODO remove andbesteffortflag
15561559

15571560
override def buildInstructions(errors: Int, warnings: Int): String = {
15581561
def beTastyFiles(file: JFile): Array[JFile] =
@@ -1609,9 +1612,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
16091612
* directory are compiled with the `Ybest-effort` option.
16101613
* Then, are the contents of 'main' are compiled with the previous best effort directory
16111614
* on the classpath using the option `-Ywith-best-effort-tasty`.
1612-
*
16131615
*/
16141616
def compileBestEffortIntegration(f: String, flags: TestFlags)(implicit testGroup: TestGroup) = {
1617+
val bestEffortFlag = "-Ybest-effort"
1618+
val semanticDbFlag = "-Xsemanticdb"
1619+
val withBetastyFlag = "-Ywith-best-effort-tasty"
16151620
val sourceDir = new JFile(f)
16161621
val dirs = sourceDir.listFiles.toList
16171622
assert(dirs.forall(_.isDirectory), s"All files in $f have to be directories.")
@@ -1629,13 +1634,13 @@ trait ParallelTesting extends RunnerOrchestration { self =>
16291634
val step2OutDir = createOutputDirsForDir(step2SourceDir, step2SourceDir, outDir)
16301635

16311636
val step1Compilation = JointCompilationSource(
1632-
testGroup.name, step1SourceFiles, flags.and("-Ybest-effort"), step1OutDir, fromTasty = NotFromTasty
1637+
testGroup.name, step1SourceFiles, flags.and(bestEffortFlag).and(semanticDbFlag), step1OutDir, fromTasty = NotFromTasty
16331638
)
16341639

16351640
val bestEffortDir = new JFile(step1OutDir, s"META-INF${JFile.separator}best-effort")
16361641

16371642
val step2Compilation = JointCompilationSource(
1638-
testGroup.name, step2SourceFiles, flags.and("-Ywith-best-effort-tasty").and("-YisBestEffort"), step2OutDir, fromTasty = WithBestEffortTasty(bestEffortDir)
1643+
testGroup.name, step2SourceFiles, flags.and(withBetastyFlag).and(bestEffortFlag).and(semanticDbFlag), step2OutDir, fromTasty = WithBestEffortTasty(bestEffortDir)
16391644
)
16401645
(step1Compilation, step2Compilation, bestEffortDir)
16411646
}.unzip3

0 commit comments

Comments
 (0)