Skip to content

Commit

Permalink
Merge branch 'main' into cc-drop-outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Oct 30, 2023
2 parents 468955b + 10a2b83 commit 7204fd7
Show file tree
Hide file tree
Showing 68 changed files with 1,175 additions and 276 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lts-backport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Add to backporting project

on:
pull_request:
types:
- closed

jobs:
add-to-backporting-project:
if: "github.event.pull_request.merged == true
&& github.event.pull_request.base.ref == 'main'
&& !contains(github.event.pull_request.body, '[Next only]')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@v1.0.5
- run: scala-cli ./project/scripts/addToBackportingProject.scala -- ${{ github.event.pull_request.number }}
env:
GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }}

Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val equalsMethod: Symbol = {
if (l.tpe <:< defn.BoxedNumberClass.info) {
if (r.tpe <:< defn.BoxedNumberClass.info) defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
else if (r.tpe <:< defn.BoxedCharClass.info) NoSymbol // ctx.requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
else if (r.tpe <:< defn.BoxedCharClass.info) defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumChar)
else defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
} else defn.BoxesRunTimeModule_externalEquals
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ class JSCodeGen()(using genCtx: Context) {
private lazy val externalEqualsNumNum: Symbol =
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumNum)
private lazy val externalEqualsNumChar: Symbol =
NoSymbol // requiredMethod(BoxesRunTimeTypeRef, nme.equalsNumChar) // this method is private
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumChar)
private lazy val externalEqualsNumObject: Symbol =
defn.BoxesRunTimeModule.requiredMethod(nme.equalsNumObject)
private lazy val externalEquals: Symbol =
Expand Down Expand Up @@ -2885,7 +2885,7 @@ class JSCodeGen()(using genCtx: Context) {
val ptfm = ctx.platform
if (lsym.derivesFrom(defn.BoxedNumberClass)) {
if (rsym.derivesFrom(defn.BoxedNumberClass)) externalEqualsNumNum
else if (rsym.derivesFrom(defn.BoxedCharClass)) externalEqualsNumObject // will be externalEqualsNumChar in 2.12, SI-9030
else if (rsym.derivesFrom(defn.BoxedCharClass)) externalEqualsNumChar
else externalEqualsNumObject
} else externalEquals
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
case defn.PolyFunctionOf(_) =>
false
case tp: MatchType =>
hasRefinement(tp.tryNormalize)
case RefinedType(parent, rname, rinfo) =>
rname == tree.name || hasRefinement(parent)
case tp: TypeProxy =>
Expand Down
14 changes: 6 additions & 8 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def Apply(fn: Tree, args: List[Tree])(using Context): Apply = fn match
case Block(Nil, expr) =>
Apply(expr, args)
case _: RefTree | _: GenericApply | _: Inlined | _: Hole =>
ta.assignType(untpd.Apply(fn, args), fn, args)
case _ =>
assert(
fn.isInstanceOf[RefTree | GenericApply | Inlined | Hole] || ctx.reporter.errorsReported,
s"Illegal Apply function prefix: $fn"
)
assert(ctx.reporter.errorsReported)
ta.assignType(untpd.Apply(fn, args), fn, args)

def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match
case Block(Nil, expr) =>
TypeApply(expr, args)
case _: RefTree | _: GenericApply =>
ta.assignType(untpd.TypeApply(fn, args), fn, args)
case _ =>
assert(
fn.isInstanceOf[RefTree | GenericApply] || ctx.reporter.errorsReported,
s"Illegal TypeApply function prefix: $fn"
)
assert(ctx.reporter.errorsReported, s"unexpected tree for type application: $fn")
ta.assignType(untpd.TypeApply(fn, args), fn, args)

def Literal(const: Constant)(using Context): Literal =
Expand Down
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -826,12 +826,16 @@ class CheckCaptures extends Recheck, SymTransformer:
*/
def adaptUniversal(actual: Type, expected: Type, tree: Tree)(using Context): Type =
if expected.captureSet.disallowsUniversal && actual.captureSet.isUniversal then
val localRoot = impliedRoot(tree)
CapturingType(
actual.stripCapturing,
localRoot.termRef.singletonCaptureSet,
actual.isBoxedCapturing)
.showing(i"adapt universal $actual vs $expected = $result", capt)
if actual.isInstanceOf[SingletonType] then
// capture set is only exposed when widening
adaptUniversal(actual.widen, expected, tree)
else
val localRoot = impliedRoot(tree)
CapturingType(
actual.stripCapturing,
localRoot.termRef.singletonCaptureSet,
actual.isBoxedCapturing)
.showing(i"adapt universal $actual vs $expected = $result", capt)
else actual

private inline val debugSuccesses = false
Expand Down
56 changes: 37 additions & 19 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
//}
assert(!ctx.settings.YnoDeepSubtypes.value)
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
report.log(explained(_.isSubType(tp1, tp2, approx)))
report.log(explained(_.isSubType(tp1, tp2, approx), short = false))
}
// Eliminate LazyRefs before checking whether we have seen a type before
val normalize = new TypeMap with CaptureSet.IdempotentCaptRefMap {
Expand Down Expand Up @@ -2959,7 +2959,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
}
}

protected def explainingTypeComparer = ExplainingTypeComparer(comparerContext)
protected def explainingTypeComparer(short: Boolean) = ExplainingTypeComparer(comparerContext, short)
protected def trackingTypeComparer = TrackingTypeComparer(comparerContext)

private def inSubComparer[T, Cmp <: TypeComparer](comparer: Cmp)(op: Cmp => T): T =
Expand All @@ -2969,8 +2969,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
finally myInstance = saved

/** The trace of comparison operations when performing `op` */
def explained[T](op: ExplainingTypeComparer => T, header: String = "Subtype trace:")(using Context): String =
val cmp = explainingTypeComparer
def explained[T](op: ExplainingTypeComparer => T, header: String = "Subtype trace:", short: Boolean)(using Context): String =
val cmp = explainingTypeComparer(short)
inSubComparer(cmp)(op)
cmp.lastTrace(header)

Expand Down Expand Up @@ -3139,8 +3139,8 @@ object TypeComparer {
def constrainPatternType(pat: Type, scrut: Type, forceInvariantRefinement: Boolean = false)(using Context): Boolean =
comparing(_.constrainPatternType(pat, scrut, forceInvariantRefinement))

def explained[T](op: ExplainingTypeComparer => T, header: String = "Subtype trace:")(using Context): String =
comparing(_.explained(op, header))
def explained[T](op: ExplainingTypeComparer => T, header: String = "Subtype trace:", short: Boolean = false)(using Context): String =
comparing(_.explained(op, header, short))

def tracked[T](op: TrackingTypeComparer => T)(using Context): T =
comparing(_.tracked(op))
Expand Down Expand Up @@ -3337,30 +3337,47 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
}
}

/** A type comparer that can record traces of subtype operations */
class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
/** A type comparer that can record traces of subtype operations
* @param short if true print only failing forward traces; never print succesful
* subtraces; never print backtraces starting with `<==`.
*/
class ExplainingTypeComparer(initctx: Context, short: Boolean) extends TypeComparer(initctx) {
import TypeComparer._

init(initctx)

override def explainingTypeComparer = this
override def explainingTypeComparer(short: Boolean) =
if short == this.short then this
else ExplainingTypeComparer(comparerContext, short)

private var indent = 0
private val b = new StringBuilder

private var skipped = false
private var lastForwardGoal: String | Null = null

override def traceIndented[T](str: String)(op: => T): T =
if (skipped) op
else {
val str1 = str.replace('\n', ' ')
if short && str1 == lastForwardGoal then
op // repeated goal, skip for clarity
else
lastForwardGoal = str1
val curLength = b.length
indent += 2
val str1 = str.replace('\n', ' ')
b.append("\n").append(" " * indent).append("==> ").append(str1)
val res = op
b.append("\n").append(" " * indent).append("<== ").append(str1).append(" = ").append(show(res))
if short then
if res == false then
if lastForwardGoal != null then // last was deepest goal that failed
b.append(" = false")
lastForwardGoal = null
else
b.length = curLength // don't show successful subtraces
else
b.append("\n").append(" " * indent).append("<== ").append(str1).append(" = ").append(show(res))
indent -= 2
res
}

private def traceIndentedIfNotShort[T](str: String)(op: => T): T =
if short then op else traceIndented(str)(op)

private def frozenNotice: String =
if frozenConstraint then " in frozen constraint" else ""
Expand All @@ -3371,7 +3388,8 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
then s" ${tp1.getClass} ${tp2.getClass}"
else ""
val approx = approxState
traceIndented(s"${show(tp1)} <: ${show(tp2)}$moreInfo${approx.show}$frozenNotice") {
def approxStr = if short then "" else approx.show
traceIndented(s"${show(tp1)} <: ${show(tp2)}$moreInfo${approxStr}$frozenNotice") {
super.recur(tp1, tp2)
}

Expand All @@ -3381,12 +3399,12 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
}

override def lub(tp1: Type, tp2: Type, canConstrain: Boolean, isSoft: Boolean): Type =
traceIndented(s"lub(${show(tp1)}, ${show(tp2)}, canConstrain=$canConstrain, isSoft=$isSoft)") {
traceIndentedIfNotShort(s"lub(${show(tp1)}, ${show(tp2)}, canConstrain=$canConstrain, isSoft=$isSoft)") {
super.lub(tp1, tp2, canConstrain, isSoft)
}

override def glb(tp1: Type, tp2: Type): Type =
traceIndented(s"glb(${show(tp1)}, ${show(tp2)})") {
traceIndentedIfNotShort(s"glb(${show(tp1)}, ${show(tp2)})") {
super.glb(tp1, tp2)
}

Expand Down
Loading

0 comments on commit 7204fd7

Please sign in to comment.