Skip to content

Commit 3510309

Browse files
committed
Encode qualifier arguments as E-Nodes
1 parent 7dafb35 commit 3510309

38 files changed

+1552
-627
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,7 +2559,8 @@ object desugar {
25592559
tree
25602560

25612561
if Feature.qualifiedTypesEnabled then
2562-
transform(tpt)
2562+
trace(i"desugar qualified types in pattern: $tpt", Printers.qualifiedTypes):
2563+
transform(tpt)
25632564
else
25642565
tpt
25652566

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,11 @@ class Definitions {
625625
@tu lazy val Int_/ : Symbol = IntClass.requiredMethod(nme.DIV, List(IntType))
626626
@tu lazy val Int_* : Symbol = IntClass.requiredMethod(nme.MUL, List(IntType))
627627
@tu lazy val Int_== : Symbol = IntClass.requiredMethod(nme.EQ, List(IntType))
628+
@tu lazy val Int_!= : Symbol = IntClass.requiredMethod(nme.NE, List(IntType))
628629
@tu lazy val Int_>= : Symbol = IntClass.requiredMethod(nme.GE, List(IntType))
629630
@tu lazy val Int_<= : Symbol = IntClass.requiredMethod(nme.LE, List(IntType))
630631
@tu lazy val Int_> : Symbol = IntClass.requiredMethod(nme.GT, List(IntType))
632+
@tu lazy val Int_< : Symbol = IntClass.requiredMethod(nme.LT, List(IntType))
631633
@tu lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
632634
def LongClass(using Context): ClassSymbol = LongType.symbol.asClass
633635
@tu lazy val Long_+ : Symbol = LongClass.requiredMethod(nme.PLUS, List(LongType))

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
888888
throw ex
889889
compareCapturing || fourthTry
890890
case QualifiedType(parent2, qualifier2) =>
891-
QualifiedTypes.typeImplies(tp1, qualifier2) && recur(tp1, parent2)
891+
recur(tp1, parent2) && QualifiedTypes.typeImplies(tp1, qualifier2, qualifierSolver())
892892
case tp2: AnnotatedType if tp2.isRefining =>
893893
(tp1.derivesAnnotWith(tp2.annot.sameAnnotation) || tp1.isBottomType) &&
894894
recur(tp1, tp2.parent)
@@ -3309,6 +3309,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
33093309

33103310
protected def explainingTypeComparer(short: Boolean) = ExplainingTypeComparer(comparerContext, short)
33113311
protected def matchReducer = MatchReducer(comparerContext)
3312+
protected def qualifierSolver() = qualified_types.QualifierSolver(using comparerContext)
33123313

33133314
private def inSubComparer[T, Cmp <: TypeComparer](comparer: Cmp)(op: Cmp => T): T =
33143315
val saved = myInstance
@@ -3974,7 +3975,7 @@ class ExplainingTypeComparer(initctx: Context, short: Boolean) extends TypeCompa
39743975
lastForwardGoal = null
39753976

39763977
override def traceIndented[T](str: String)(op: => T): T =
3977-
val str1 = str.replace('\n', ' ')
3978+
val str1 = str
39783979
if short && str1 == lastForwardGoal then
39793980
op // repeated goal, skip for clarity
39803981
else
@@ -4043,5 +4044,9 @@ class ExplainingTypeComparer(initctx: Context, short: Boolean) extends TypeCompa
40434044
super.subCaptures(refs1, refs2, vs)
40444045
}
40454046

4047+
override def qualifierSolver() =
4048+
val traceIndented0 = [T] => (message: String) => traceIndented[T](message)
4049+
qualified_types.ExplainingQualifierSolver(traceIndented0)(using comparerContext)
4050+
40464051
def lastTrace(header: String): String = header + { try b.toString finally b.clear() }
40474052
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import compiletime.uninitialized
4141
import cc.*
4242
import CaptureSet.IdentityCaptRefMap
4343
import Capabilities.*
44-
import qualified_types.QualifiedType
44+
import qualified_types.{QualifiedType, QualifiedAnnotation}
4545
import scala.annotation.internal.sharable
4646
import scala.annotation.threadUnsafe
4747

@@ -6271,6 +6271,8 @@ object Types extends TypeUtils {
62716271
tp.derivedAnnotatedType(underlying, annot)
62726272
protected def derivedCapturingType(tp: Type, parent: Type, refs: CaptureSet): Type =
62736273
tp.derivedCapturingType(parent, refs)
6274+
protected def derivedENodeParamRef(tp: qualified_types.ENodeParamRef, index: Int, underlying: Type): Type =
6275+
tp.derivedENodeParamRef(index, underlying)
62746276
protected def derivedWildcardType(tp: WildcardType, bounds: Type): Type =
62756277
tp.derivedWildcardType(bounds)
62766278
protected def derivedSkolemType(tp: SkolemType, info: Type): Type =
@@ -6483,6 +6485,9 @@ object Types extends TypeUtils {
64836485
case tp: JavaArrayType =>
64846486
derivedJavaArrayType(tp, this(tp.elemType))
64856487

6488+
case tp: qualified_types.ENodeParamRef =>
6489+
derivedENodeParamRef(tp, tp.index, this(tp.underlying))
6490+
64866491
case _ =>
64876492
tp
64886493
}

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ object Parsers {
16641664
* | `(' [ FunArgType {`,' FunArgType } ] `)'
16651665
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
16661666
* MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
1667-
* QualifiedType2 ::= InfixType `with` PostfixExprf
1667+
* QualifiedType2 ::= InfixType `with` PostfixExpr
16681668
* IntoType ::= [‘into’] IntoTargetType
16691669
* | ‘( IntoType ‘)’
16701670
* IntoTargetType ::= Type

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ class PlainPrinter(_ctx: Context) extends Printer {
469469
"<" ~ reprStr ~ ":" ~ toText(tp.info) ~ ">"
470470
else
471471
reprStr
472+
case qualified_types.ENodeParamRef(index, underlying) =>
473+
if ctx.settings.XprintTypes.value then
474+
"<" ~ "eparam" ~ index.toString ~ ":" ~ toText(underlying) ~ ">"
475+
else
476+
"eparam" ~ index.toString
472477
}
473478
}
474479

0 commit comments

Comments
 (0)