Skip to content

Commit 4c31f5c

Browse files
committed
Post-rebase fixes
1 parent f29ab46 commit 4c31f5c

File tree

13 files changed

+57
-104
lines changed

13 files changed

+57
-104
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/core/tasty/TreePickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class TreePickler(pickler: TastyPickler) {
344344
def pickleDef(tag: Int, mdef: MemberDef, tpt: Tree, rhs: Tree = EmptyTree, pickleParams: => Unit = ())(using Context): Unit = {
345345
val sym = mdef.symbol
346346

347-
if assertForBestEffort(symRefs(sym) == NoAddr && !(tag == TYPEDEF && tpt.isInstanceOf[Template] && !tpt.symbol.exists)) then
347+
if assertForBestEffort(symRefs.get(sym) == Some(NoAddr) && !(tag == TYPEDEF && tpt.isInstanceOf[Template] && !tpt.symbol.exists)) then
348348
assert(symRefs(sym) == NoAddr, sym)
349349
registerDef(sym)
350350
writeByte(tag)

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: 2 additions & 2 deletions
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)
@@ -147,7 +147,7 @@ class Pickler extends Phase {
147147
unit.pickled += (cls -> demandPickled)
148148
end for
149149
catch
150-
case NonFatal(ex) =>
150+
case NonFatal(ex) if ctx.isBestEffort =>
151151
report.bestEffortError(ex, "Some best-effort tasty files will not be generated.")
152152
}
153153

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ toplevel-cyclic
1212
curried-dependent-ift.scala
1313

1414
# semantic db generation fails in the first compilation
15-
safeThrowsStrawman2.scala
16-
varargs-annot-2.scala
1715
i1642.scala
18-
i2202.scala
16+
17+
# new errors TODO check
18+
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

0 commit comments

Comments
 (0)