Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed Feb 12, 2024
1 parent 5475c2b commit 818ef78
Show file tree
Hide file tree
Showing 34 changed files with 107 additions and 92 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GenBCode extends Phase { self =>

override def description: String = GenBCode.description

override def isRunnable(using Context) = super.isRunnable && !ctx.usesBestEffortTasty
override def isRunnable(using Context) = super.isRunnable && !ctx.usedBestEffortTasty

private val superCallsMap = new MutableSymbolMap[Set[ClassSymbol]]
def registerSuperCall(sym: Symbol, calls: ClassSymbol): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GenSJSIR extends Phase {
override def description: String = GenSJSIR.description

override def isRunnable(using Context): Boolean =
super.isRunnable && ctx.settings.scalajs.value && !ctx.usesBestEffortTasty
super.isRunnable && ctx.settings.scalajs.value && !ctx.usedBestEffortTasty

def run(using Context): Unit =
new JSCodeGen().run()
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Driver {
catch
case ex: FatalError =>
report.error(ex.getMessage.nn) // signals that we should fail compilation.
case ex: Throwable if ctx.usesBestEffortTasty =>
case ex: Throwable if ctx.usedBestEffortTasty =>
report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.")
case ex: TypeError if !runOrNull.enrichedErrorMessage =>
println(runOrNull.enrichErrorMessage(s"${ex.toMessage} while compiling ${files.map(_.path).mkString(", ")}"))
Expand Down
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, stopAfter, ctx.settings.Ycheck.value)
ctx.base.usePhases(phases)

var forceReachPhaseMaybe =
if (ctx.isBestEffort && phases.exists(_.phaseName == "typer")) Some("typer")
else None

if ctx.settings.YnoDoubleBindings.value then
ctx.base.checkNoDoubleBindings = true

Expand All @@ -309,6 +305,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
val profiler = ctx.profiler
var phasesWereAdjusted = false

var forceReachPhaseMaybe =
if (ctx.isBestEffort && phases.exists(_.phaseName == "typer")) Some("typer")
else None

for phase <- allPhases do
doEnterPhase(phase)
val phaseWillRun = phase.isRunnable || forceReachPhaseMaybe.nonEmpty
Expand All @@ -325,11 +325,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
lastPrintedTree = printTree(lastPrintedTree)(using printCtx(unit))

forceReachPhaseMaybe match {
case Some(forceReachPhase) if phase.phaseName == forceReachPhase =>
forceReachPhaseMaybe = None
case _ =>
}
if forceReachPhaseMaybe.contains(phase.phaseName) then
forceReachPhaseMaybe = None

report.informTime(s"$phase ", start)
Stats.record(s"total trees at end of $phase", ast.Trees.ntrees)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
case _: RefTree | _: GenericApply | _: Inlined | _: Hole =>
ta.assignType(untpd.Apply(fn, args), fn, args)
case _ =>
assert(ctx.isBestEffort || ctx.usesBestEffortTasty || ctx.reporter.errorsReported)
assert(ctx.reporter.errorsReported || ctx.tolerateErrorsForBestEffort)
ta.assignType(untpd.Apply(fn, args), fn, args)

def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match
Expand All @@ -58,7 +58,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
case _: RefTree | _: GenericApply =>
ta.assignType(untpd.TypeApply(fn, args), fn, args)
case _ =>
assert(ctx.isBestEffort || ctx.usesBestEffortTasty || ctx.reporter.errorsReported, s"unexpected tree for type application: $fn")
assert(ctx.reporter.errorsReported || ctx.tolerateErrorsForBestEffort, s"unexpected tree for type application: $fn")
ta.assignType(untpd.TypeApply(fn, args), fn, args)

def Literal(const: Constant)(using Context): Literal =
Expand Down
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,20 @@ object Contexts {
/** Is the explicit nulls option set? */
def explicitNulls: Boolean = base.settings.YexplicitNulls.value

/** Is best-effort-dir option set? */
/** Is the best-effort option set? */
def isBestEffort: Boolean = base.settings.YbestEffort.value

/** Is the from-best-effort-tasty option set to true? */
/** Is the with-best-effort-tasty option set? */
def withBestEffortTasty: Boolean = base.settings.YwithBestEffortTasty.value

/** Were any best effort tasty dependencies used during compilation? */
def usesBestEffortTasty: Boolean = base.usedBestEffortTasty
def usedBestEffortTasty: Boolean = base.usedBestEffortTasty

/** Confirm that a best effort tasty dependency was used during compilation. */
def setUsesBestEffortTasty(): Unit = base.usedBestEffortTasty = true
def setUsedBestEffortTasty(): Unit = base.usedBestEffortTasty = true

/** Is either the best-effort option set or .betasty files were used during compilation? */
def tolerateErrorsForBestEffort = isBestEffort || usedBestEffortTasty

/** A fresh clone of this context embedded in this context. */
def fresh: FreshContext = freshOver(this)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/DenotTransformers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object DenotTransformers {
/** The transformation method */
def transform(ref: SingleDenotation)(using Context): SingleDenotation

override def isRunnable(using Context) = super.isRunnable && !ctx.usesBestEffortTasty
override def isRunnable(using Context) = super.isRunnable && !ctx.usedBestEffortTasty
}

/** A transformer that only transforms the info field of denotations */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ object Denotations {
|| ctx.settings.YtestPickler.value // mixing test pickler with debug printing can travel back in time
|| ctx.mode.is(Mode.Printing) // no use to be picky when printing error messages
|| symbol.isOneOf(ValidForeverFlags)
|| ctx.isBestEffort || ctx.usesBestEffortTasty,
|| ctx.tolerateErrorsForBestEffort,
s"denotation $this invalid in run ${ctx.runId}. ValidFor: $validFor")
var d: SingleDenotation = this
while ({
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ object SymDenotations {
* TODO: Find a more robust way to characterize self symbols, maybe by
* spending a Flag on them?
*/
final def isSelfSym(using Context): Boolean =
final def isSelfSym(using Context): Boolean =
if !ctx.isBestEffort || exists then
owner.infoOrCompleter match {
case ClassInfo(_, _, _, _, selfInfo) =>
Expand Down Expand Up @@ -1985,7 +1985,7 @@ object SymDenotations {
case p :: parents1 =>
p.classSymbol match {
case pcls: ClassSymbol => builder.addAll(pcls.baseClasses)
case _ => assert(isRefinementClass || p.isError || ctx.mode.is(Mode.Interactive) || ctx.isBestEffort || ctx.usesBestEffortTasty, s"$this has non-class parent: $p")
case _ => assert(isRefinementClass || p.isError || ctx.mode.is(Mode.Interactive) || ctx.tolerateErrorsForBestEffort, s"$this has non-class parent: $p")
}
traverse(parents1)
case nil =>
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,19 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
else "TASTy file " + tastyFile.toString

override def doComplete(root: SymDenotation)(using Context): Unit =
val isBestEffortTasty = tastyFile.name.endsWith(".betasty")
val isBestEffortTasty = tastyFile.extension == "betasty"
try
val (classRoot, moduleRoot) = rootDenots(root.asClass)
if (!isBestEffortTasty || ctx.withBestEffortTasty) then
val tastyBytes = tastyFile.toByteArray
val unpickler = new tasty.DottyUnpickler(tastyBytes, isBestEffortTasty = isBestEffortTasty)
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(using ctx.withSource(util.NoSource))
if mayLoadTreesFromTasty || (isBestEffortTasty && ctx.withBestEffortTasty) then
if mayLoadTreesFromTasty || isBestEffortTasty then
classRoot.classSymbol.rootTreeOrProvider = unpickler
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
if isBestEffortTasty then
checkBeTastyUUID(tastyFile, tastyBytes)
ctx.setUsesBestEffortTasty()
ctx.setUsedBestEffortTasty()
else
checkTastyUUID(tastyFile, tastyBytes)
else
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,9 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
assert(!etp.isInstanceOf[WildcardType] || inSigName, i"Unexpected WildcardType erasure for $tp")
etp

/** Like translucentSuperType, but issue a fatal error if it does not exist. */
/** Like translucentSuperType, but issue a fatal error if it does not exist.
* If using the best-effort option, the fatal error will not be issued.
*/
private def checkedSuperType(tp: TypeProxy)(using Context): Type =
val tp1 = tp.translucentSuperType
if !tp1.exists then
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3080,7 +3080,7 @@ object Types {
else cls.info match {
case cinfo: ClassInfo => cinfo.selfType
case _: ErrorType | NoType
if ctx.mode.is(Mode.Interactive) || ctx.isBestEffort || ctx.usesBestEffortTasty => cls.info
if ctx.mode.is(Mode.Interactive) || ctx.tolerateErrorsForBestEffort => cls.info
// can happen in IDE if `cls` is stale
}

Expand Down Expand Up @@ -3605,8 +3605,9 @@ object Types {

def apply(tp1: Type, tp2: Type, soft: Boolean)(using Context): OrType = {
def where = i"in union $tp1 | $tp2"
if (!ctx.usesBestEffortTasty) expectValueTypeOrWildcard(tp1, where)
if (!ctx.usesBestEffortTasty) expectValueTypeOrWildcard(tp2, where)
if !ctx.usedBestEffortTasty then
expectValueTypeOrWildcard(tp1, where)
expectValueTypeOrWildcard(tp2, where)
assertUnerased()
unique(new CachedOrType(tp1, tp2, soft))
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object DottyUnpickler {
posUnpickler: Option[PositionUnpickler],
commentUnpickler: Option[CommentUnpickler],
attributeUnpickler: Option[AttributeUnpickler],
isBestEffortTasty: Boolean = false
isBestEffortTasty: Boolean
) extends SectionUnpickler[TreeUnpickler](ASTsSection) {
def unpickle(reader: TastyReader, nameAtRef: NameTable): TreeUnpickler =
new TreeUnpickler(reader, nameAtRef, posUnpickler, commentUnpickler, attributeUnpickler, isBestEffortTasty)
Expand All @@ -47,10 +47,10 @@ object DottyUnpickler {

/** A class for unpickling Tasty trees and symbols.
* @param bytes the bytearray containing the Tasty file from which we unpickle
* @param isBestEffortTasty specifies whether file should be unpickled as a Best Effort TASTy
* @param mode the tasty file contains package (TopLevel), an expression (Term) or a type (TypeTree)
* @param isBestEffortTasty specifies wheather file should be unpickled as a Best Effort TASTy
*/
class DottyUnpickler(bytes: Array[Byte], mode: UnpickleMode = UnpickleMode.TopLevel, isBestEffortTasty: Boolean = false) extends ClassfileParser.Embedded with tpd.TreeProvider {
class DottyUnpickler(bytes: Array[Byte], isBestEffortTasty: Boolean, mode: UnpickleMode = UnpickleMode.TopLevel) extends ClassfileParser.Embedded with tpd.TreeProvider {
import tpd.*
import DottyUnpickler.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools.dotc
package core
package tasty

class TastyHTMLPrinter(bytes: Array[Byte]) extends TastyPrinter(bytes) {
class TastyHTMLPrinter(bytes: Array[Byte]) extends TastyPrinter(bytes, isBestEffortTasty = false) {
override protected def nameStr(str: String): String = s"<span class='name'>$str</span>"
override protected def treeStr(str: String): String = s"<span class='tree'>$str</span>"
override protected def lengthStr(str: String): String = s"<span class='length'>$str</span>"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object TastyPickler {

}

class TastyPickler(val rootCls: ClassSymbol) {
class TastyPickler(val rootCls: ClassSymbol, isBestEffortTasty: Boolean) {

private val sections = new mutable.ArrayBuffer[(NameRef, TastyBuffer)]

Expand All @@ -32,7 +32,7 @@ class TastyPickler(val rootCls: ClassSymbol) {
def newSection(name: String, buf: TastyBuffer): Unit =
sections += ((nameBuffer.nameIndex(name.toTermName), buf))

def assembleParts(isBestEffortTasty: Boolean = false): Array[Byte] = {
def assembleParts(): Array[Byte] = {
def lengthWithLength(buf: TastyBuffer) =
buf.length + natSize(buf.length)

Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import dotty.tools.io.{JarArchive, Path}

object TastyPrinter:

def showContents(bytes: Array[Byte], noColor: Boolean, isBestEffortTasty: Boolean = false): String =
def showContents(bytes: Array[Byte], noColor: Boolean, isBestEffortTasty: Boolean): String =
val printer =
if noColor then new TastyPrinter(bytes, isBestEffortTasty)
else new TastyAnsiiPrinter(bytes, isBestEffortTasty)
Expand All @@ -29,7 +29,7 @@ object TastyPrinter:
val noColor = args.contains("-color:never")
val allowBetasty = args.contains(betastyOpt)
var printLastLine = false
def printTasty(fileName: String, bytes: Array[Byte], isBestEffortTasty: Boolean = false): Unit =
def printTasty(fileName: String, bytes: Array[Byte], isBestEffortTasty: Boolean): Unit =
println(line)
println(fileName)
println(line)
Expand All @@ -51,7 +51,7 @@ object TastyPrinter:
val jar = JarArchive.open(Path(arg), create = false)
try
for file <- jar.iterator() if file.name.endsWith(".tasty") do
printTasty(s"$arg ${file.path}", file.toByteArray)
printTasty(s"$arg ${file.path}", file.toByteArray, false)
finally jar.close()
else
println(s"Not a '.tasty' or '.jar' file: $arg")
Expand All @@ -61,7 +61,7 @@ object TastyPrinter:
println(line)
}

class TastyPrinter(bytes: Array[Byte], isBestEffortTasty: Boolean = false) {
class TastyPrinter(bytes: Array[Byte], isBestEffortTasty: Boolean) {

private val sb: StringBuilder = new StringBuilder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object TastyUnpickler {

import TastyUnpickler.*

class TastyUnpickler(reader: TastyReader, isBestEffortTasty: Boolean = false) {
class TastyUnpickler(reader: TastyReader, isBestEffortTasty: Boolean) {
import reader.*

def this(bytes: Array[Byte]) = this(new TastyReader(bytes), false)
Expand Down
Loading

0 comments on commit 818ef78

Please sign in to comment.