Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import core.Decorators.*
import util.chaining.*
import fromtasty.{TASTYCompiler, TastyFileUtil}

import scala.annotation.nowarn

/** Run the Dotty compiler.
*
* Extending this class lets you customize many aspect of the compilation
Expand All @@ -26,6 +28,7 @@ class Driver {

protected def emptyReporter: Reporter = new StoreReporter(null)

@nowarn("msg=Catching StackOverflowError can lead to unexpected behavior") // yes, but we immediately exit
protected def doCompile(compiler: Compiler, files: List[AbstractFile])(using Context): Reporter =
if files.nonEmpty then
var runOrNull = ctx.run
Expand Down
7 changes: 1 addition & 6 deletions compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
* - Parent spans contain child spans
* - If item is a non-empty tree, it has a position
*/
def checkPos(nonOverlapping: Boolean)(using Context): Unit = try {
def checkPos(nonOverlapping: Boolean)(using Context): Unit = printOnAssertionError(i"error while checking $this") {
import untpd.*
val last = LastPosRef()
def check(p: Any): Unit = p match {
Expand Down Expand Up @@ -231,11 +231,6 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
}
}
}
catch {
case ex: AssertionError =>
println(i"error while checking $this")
throw ex
}
}

object Positioned {
Expand Down
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/dotc/cc/Capability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ object Capabilities:
case info: OrType => viaInfo(info.tp1)(test) && viaInfo(info.tp2)(test)
case _ => false

try (this eq y)
printOnAssertionError(i"error while subsumes $this >> $y"):
(this eq y)
|| maxSubsumes(y, canAddHidden = !vs.isOpen)
// if vs is open, we should add new elements to the set containing `this`
// instead of adding them to the hidden set of of `this`.
Expand Down Expand Up @@ -882,9 +883,6 @@ object Capabilities:
case x: ThisType if x.cls.is(Module) =>
x.cls.sourceModule.termRef.subsumes(y)
case _ => false
catch case ex: AssertionError =>
println(i"error while subsumes $this >> $y")
throw ex
end subsumes

/** This is a maximal capability that subsumes `y` in given context and VarState.
Expand Down
16 changes: 4 additions & 12 deletions compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,8 @@ sealed abstract class CaptureSet extends Showable:
capt.println(i"WIDEN ro $this with ${this.mutability} <:< $that with ${that.mutability} to $this1")
this1.subCaptures(that, vs)
else
try
printOnAssertionError(i"error while subcap $this <:< $that"):
that.tryInclude(elems, this) && addDependent(that)
catch case ex: AssertionError =>
println(i"error while subcap $this <:< $that")
throw ex

/** Two capture sets are considered =:= equal if they mutually subcapture each other
* in a frozen state.
Expand Down Expand Up @@ -895,10 +892,8 @@ object CaptureSet:
// id == 108 then assert(false, i"trying to add $elem to $this")
assert(elem.isWellformed, elem)
assert(!this.isInstanceOf[HiddenSet] || summon[VarState].isSeparating, summon[VarState])
try includeElem(elem)
catch case ex: AssertionError =>
println(i"error for incl $elem in $this, ${summon[VarState].toString}")
throw ex
printOnAssertionError(i"error for incl $elem in $this, ${summon[VarState].toString}"):
includeElem(elem)
newElemAddedHandlers.foreach(_(elem))
val normElem = if isMaybeSet then elem else elem.stripMaybe
// assert(id != 5 || elems.size != 3, this)
Expand Down Expand Up @@ -1187,12 +1182,9 @@ object CaptureSet:
else
// Propagate backwards to source. The element will be added then by another
// forward propagation from source that hits the first branch `if origin eq source then`.
try
printOnAssertionError(i"fail while prop backwards tryInclude $elem of ${elem.getClass} from $this # $id / ${this.summarize} to $source # ${source.id}"):
reporting.trace(i"prop backwards $elem from $this # $id to $source # ${source.id} via $summarize"):
source.tryInclude(bimap.inverse.mapCapability(elem), this)
catch case ex: AssertionError =>
println(i"fail while prop backwards tryInclude $elem of ${elem.getClass} from $this # $id / ${this.summarize} to $source # ${source.id}")
throw ex

/** For a BiTypeMap, supertypes of the mapped type also constrain
* the source via the inverse type mapping and vice versa. That is, if
Expand Down
34 changes: 15 additions & 19 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1660,16 +1660,14 @@ class CheckCaptures extends Recheck, SymTransformer:
CaptureSet.Var(curEnv.owner), curEnv)
case _ =>
val res =
try
if capt eq noPrinter then
super.recheck(tree, pt)
else
trace.force(i"rechecking $tree with pt = $pt", recheckr, show = true):
printOnAssertionError(i"error while rechecking $tree against $pt"):
try
if capt eq noPrinter then
super.recheck(tree, pt)
catch case ex: AssertionError =>
println(i"error while rechecking $tree against $pt")
throw ex
finally curEnv = saved
else
trace.force(i"rechecking $tree with pt = $pt", recheckr, show = true):
super.recheck(tree, pt)
finally curEnv = saved
if tree.isTerm && !pt.isBoxed && pt != LhsProto then
markFree(res.boxedCaptureSet, tree)
res
Expand Down Expand Up @@ -1720,16 +1718,14 @@ class CheckCaptures extends Recheck, SymTransformer:
*/
override def checkConformsExpr(actual: Type, expected: Type, tree: Tree, notes: List[Note])(using Context): Type =
val saved = ccState.ignoreClassifiers
try

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review without whitespace

tree match
case tree: TypeApply if tree.symbol == defn.Any_typeCast => ccState.ignoreClassifiers = true
case _ =>
testAdapted(actual, expected, tree, notes)(err.typeMismatch)
catch case ex: AssertionError =>
println(i"error while checking $tree: $actual against $expected")
throw ex
finally
ccState.ignoreClassifiers = saved
printOnAssertionError(i"error while checking $tree: $actual against $expected"):
try
tree match
case tree: TypeApply if tree.symbol == defn.Any_typeCast => ccState.ignoreClassifiers = true
case _ =>
testAdapted(actual, expected, tree, notes)(err.typeMismatch)
finally
ccState.ignoreClassifiers = saved

@annotation.tailrec
private def findImpureUpperBound(tp: Type)(using Context): Type = tp match
Expand Down
10 changes: 2 additions & 8 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
addVar(mapFollowingAliases(tp), tp)
}

try
printOnAssertionError(i"error while mapping inferred $tp"):
ccState.withNoVarsMapped:
mapInferred(inCaptureRefinement = false)(tp)
.tap: tp1 =>
if tp1 ne tp then capt.println(i"expanded inferred in ${ctx.owner}: $tp --> $tp1")
catch case ex: AssertionError =>
println(i"error while mapping inferred $tp")
throw ex
}

/** Transform an explicitly given type by performing the following transformation
Expand Down Expand Up @@ -756,14 +753,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:

def paramsToCap(psymss: List[List[Symbol]], mt: Type)(using Context): Type = mt match
case mt: MethodType =>
try
printOnAssertionError(i"error while mapping params ${mt.paramInfos} of $sym"):
mt.derivedLambdaType(
paramInfos =
psymss.head.lazyZip(mt.paramInfos).map(localCapToGlobal),
resType = paramsToCap(psymss.tail, mt.resType))
catch case ex: AssertionError =>
println(i"error while mapping params ${mt.paramInfos} of $sym")
throw ex
case mt: PolyType =>
mt.derivedLambdaType(resType = paramsToCap(psymss.tail, mt.resType))
case _ => mt
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ private sealed trait WarningSettings:
private val WrecurseWithDefault = BooleanSetting(WarningSetting, "Wrecurse-with-default", "Warn when a method calls itself with a default argument.")
private val WwrongArrow = BooleanSetting(WarningSetting, "Wwrong-arrow", "Warn if function arrow was used instead of context literal ?=>.")
private val WinferUnion = BooleanSetting(WarningSetting, "Winfer-union", "Warn if type argument was inferred as union type.")
private val WsafeInit: Setting[Boolean] = BooleanSetting(WarningSetting, "Wsafe-init", "Ensure safe initialization of objects.")
private val WunreasonableCatch: Setting[Boolean] = BooleanSetting(WarningSetting, "Wunreasonable-catch", "Warn when catching errors that should normally not be caught.")
private val Wunused: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
WarningSetting,
name = "Wunused",
Expand Down Expand Up @@ -297,8 +299,6 @@ private sealed trait WarningSettings:
allOr("type-parameter-shadow")
end WshadowHas

val WsafeInit: Setting[Boolean] = BooleanSetting(WarningSetting, "Wsafe-init", "Ensure safe initialization of objects.")

object Whas:
def allOr(s: Setting[Boolean])(using Context): Boolean =
Wall.value || s.value
Expand All @@ -312,6 +312,7 @@ private sealed trait WarningSettings:
def wrongArrow(using Context): Boolean = allOr(WwrongArrow)
def inferUnion(using Context): Boolean = allOr(WinferUnion)
def safeInit(using Context): Boolean = allOr(WsafeInit)
def unreasonableCatch(using Context): Boolean = allOr(WunreasonableCatch)

/** "Optimizer" settings */
private sealed trait OptimizerSettings:
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ class Definitions {
def ThrowableClass(using Context): ClassSymbol = ThrowableType.symbol.asClass
@tu lazy val ExceptionClass: ClassSymbol = requiredClass("java.lang.Exception")
@tu lazy val RuntimeExceptionClass: ClassSymbol = requiredClass("java.lang.RuntimeException")
@tu lazy val ErrorType: TypeRef = requiredClassRef("java.lang.Error")

@tu lazy val SerializableType: TypeRef = JavaSerializableClass.typeRef
def SerializableClass(using Context): ClassSymbol = SerializableType.symbol.asClass
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/RecursiveOperation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object RecursiveOperation:
*
* @param ops the recursive operations, most recent first
*/
final class RecursionOverflow(ops: List[RecursiveOperation])(using val ctx: Context) extends Error:
final class RecursionOverflow(ops: List[RecursiveOperation])(using val ctx: Context) extends Throwable:
// We aren't going to show the stack trace anyway so might as well save the perf cost of throwing
override def fillInStackTrace(): Throwable =
this
Expand Down Expand Up @@ -82,6 +82,6 @@ object RecursionOverflow:
rawOverflowTitle: String,
rawOverflowDetails: RecursiveOperationDetails,
rawOverflowPosition: SrcPos | Null,
rawOverflowWeight: Int)(using Context): Error =
rawOverflowWeight: Int)(using Context): Throwable =
val ops = RecursiveOperation(rawOverflowTitle, rawOverflowDetails, rawOverflowPosition, rawOverflowWeight) :: rawOps.map(_.copy()).reverse.toList
new RecursionOverflow(ops)
66 changes: 26 additions & 40 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import NameKinds.WildcardParamName
import MatchTypes.isConcrete
import reporting.Message.Note
import scala.util.boundary, boundary.break
import scala.util.control.NonFatal

/** Provides methods to compare types.
*/
Expand Down Expand Up @@ -703,27 +704,25 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
// the isSubinfo of hasMatchingMember has problems dealing with PolyTypes
// (---> orphan params during pickling)
def isSubInfo(info1: Type, info2: Type): Boolean =
try (info1, info2) match
case (info1: PolyType, info2: PolyType) =>
info1.paramNames.hasSameLengthAs(info2.paramNames)
&& isSubInfo(info1.resultType, info2.resultType.subst(info2, info1))
case (info1: MethodType, info2: MethodType) =>
matchingMethodParams(info1, info2, precise = false)
&& isSubInfo(info1.resultType, info2.resultType.subst(info2, info1))
case (info1 @ CapturingType(parent1, refs1), info2: Type)
if info2.stripCapturing.isInstanceOf[MethodOrPoly] =>
compareCaptures(info1, refs1, info2)
&& isSubInfo(parent1, info2)
case (info1: Type, CapturingType(parent2, _))
if info1.stripCapturing.isInstanceOf[MethodOrPoly] =>
val refs1 = info1.captureSet
(refs1.isAlwaysEmpty || compareCaptures(info1, refs1, info2))
&& isSubInfo(info1, parent2)
case _ =>
isSubType(info1, info2)
catch case ex: AssertionError =>
println(i"error while subinfo $info1 <:< $info2")
throw ex
printOnAssertionError(i"error while subinfo $info1 <:< $info2"):
(info1, info2) match
case (info1: PolyType, info2: PolyType) =>
info1.paramNames.hasSameLengthAs(info2.paramNames)
&& isSubInfo(info1.resultType, info2.resultType.subst(info2, info1))
case (info1: MethodType, info2: MethodType) =>
matchingMethodParams(info1, info2, precise = false)
&& isSubInfo(info1.resultType, info2.resultType.subst(info2, info1))
case (info1 @ CapturingType(parent1, refs1), info2: Type)
if info2.stripCapturing.isInstanceOf[MethodOrPoly] =>
compareCaptures(info1, refs1, info2)
&& isSubInfo(parent1, info2)
case (info1: Type, CapturingType(parent2, _))
if info1.stripCapturing.isInstanceOf[MethodOrPoly] =>
val refs1 = info1.captureSet
(refs1.isAlwaysEmpty || compareCaptures(info1, refs1, info2))
&& isSubInfo(info1, parent2)
case _ =>
isSubType(info1, info2)

if defn.isFunctionType(tp2) then
if tp2.derivesFrom(defn.PolyFunctionClass) then
Expand All @@ -732,10 +731,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
tp1w.widenDealias match
case tp1: RefinedType =>
return
try isSubInfo(tp1.refinedInfo, tp2.refinedInfo)
catch case ex: AssertionError =>
println(i"error while subInfo ${tp1.refinedInfo} <:< ${tp2.refinedInfo}")
throw ex
printOnAssertionError(i"error while subInfo ${tp1.refinedInfo} <:< ${tp2.refinedInfo}"):
isSubInfo(tp1.refinedInfo, tp2.refinedInfo)
case _ =>
end if

Expand Down Expand Up @@ -906,7 +903,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case CapturingType(parent2, refs2) =>
def compareCapturing: Boolean =
val refs1 = tp1.captureSet
try
printOnAssertionError(i"assertion failed while compare captured $tp1 <:< $tp2"):
if refs1.isAlwaysEmpty && refs1.mutability == CaptureSet.Mutability.Ignored then
recur(tp1, parent2)
else parent2 match
Expand All @@ -932,9 +929,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
// this alternative is needed in case the right hand side is a
// capturing type that contains the lhs as an alternative of a union type.
)
catch case ex: AssertionError =>
println(i"assertion failed while compare captured $tp1 <:< $tp2")
throw ex
compareCapturing || fourthTry
case tp2: AnnotatedType if tp2.isRefining =>
(tp1.derivesAnnotWith(tp2.annot.sameAnnotation) || tp1.isBottomType) &&
Expand Down Expand Up @@ -1678,13 +1672,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
if (Stats.monitored) recordStatistics(result, savedSuccessCount)
result
catch
case ex: AssertionError =>
showGoal(tp1, tp2)
recCount -= 1
restore()
successCount = savedSuccessCount
throw ex
case ex: Exception =>
case NonFatal(ex) =>
if ex.isInstanceOf[AssertionError] then showGoal(tp1, tp2)
recCount -= 1
restore()
successCount = savedSuccessCount
Expand Down Expand Up @@ -2975,11 +2964,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling

protected def subCaptures(refs1: CaptureSet, refs2: CaptureSet,
vs: CaptureSet.VarState = makeVarState())(using Context): Boolean =
try
printOnAssertionError(i"fail while subCaptures $refs1 <:< $refs2"):
refs1.subCaptures(refs2, vs)
catch case ex: AssertionError =>
println(i"fail while subCaptures $refs1 <:< $refs2")
throw ex

/**
* - Compare capture sets using subCaptures. If the lower type derives from Stateful and the
Expand Down
7 changes: 1 addition & 6 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
*
* Note: Need to ensure correspondence with erasure!
*/
private def sigName(tp: Type)(using Context): TypeName = try
private def sigName(tp: Type)(using Context): TypeName = printOnAssertionError(s"no sig for $tp"):
tp match {
case tp: TypeRef =>
if (!tp.denot.exists)
Expand Down Expand Up @@ -1112,9 +1112,4 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
assert(erasedTp ne tp, tp)
sigName(erasedTp)
}
catch {
case ex: AssertionError =>
println(s"no sig for $tp because of ${ex.printStackTrace()}")
throw ex
}
}
Loading
Loading