Skip to content

Commit 5069182

Browse files
committed
Simplify quoted.Type implicit search
Now it is a plain `given` definition and follows the normal implicit resulution rules. Dealiasing of local inconsitent type aliases references are handled by `PCPCheckAndHeal` before healing is atempted.
1 parent 013b1e0 commit 5069182

File tree

4 files changed

+6
-19
lines changed

4 files changed

+6
-19
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
175175
tp match
176176
case tp: TypeRef =>
177177
tp.prefix match
178-
case NoPrefix if level > levelOf(tp.symbol) =>
179-
tryHeal(tp.symbol, tp, pos)
178+
case NoPrefix if level > levelOf(tp.symbol) && !tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) =>
179+
val tp1 = tp.dealias
180+
if tp1 != tp then apply(tp1)
181+
else tryHeal(tp.symbol, tp, pos)
180182
case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) =>
181183
tryHeal(tp.symbol, tp, pos)
182184
case prefix: TermRef if tp.symbol.isTypeSplice =>

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
4848
case _ => EmptyTree
4949
end synthesizedClassTag
5050

51-
/** Synthesize the tree for `scala.quoted.Type[T]` for an implicit `scala.quoted.Type[T]`.
52-
* `T` is deeply dealiased to avoid references to local type aliases.
53-
*/
54-
val synthesizedTypeTag: SpecialHandler = (formal, span) =>
55-
val qctx = ctx.typer.inferImplicitArg(defn.QuoteContextClass.typeRef, span)
56-
qctx.tpe match
57-
case tpe: Implicits.SearchFailureType => report.error(tpe.msg, ctx.source.atSpan(span))
58-
case _ =>
59-
val deepDealias = new TypeMap:
60-
def apply(tp: Type): Type = mapOver(tp.dealias)
61-
val t = deepDealias(formal.select(tpnme.spliceType))
62-
ref(defn.QuotedTypeModule_apply).appliedToType(t).select(nme.apply).appliedTo(qctx)
63-
end synthesizedTypeTag
64-
6551
val synthesizedTupleFunction: SpecialHandler = (formal, span) =>
6652
formal match
6753
case AppliedType(_, funArgs @ fun :: tupled :: Nil) =>
@@ -391,7 +377,6 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
391377

392378
val specialHandlers = List(
393379
defn.ClassTagClass -> synthesizedClassTag,
394-
defn.QuotedTypeClass -> synthesizedTypeTag,
395380
defn.EqlClass -> synthesizedEql,
396381
defn.TupledFunctionClass -> synthesizedTupleFunction,
397382
defn.ValueOfClass -> synthesizedValueOf,

library/src-bootstrapped/scala/quoted/Type.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object Type {
2525

2626
/** Return a quoted.Type with the given type */
2727
@compileTimeOnly("Reference to `scala.quoted.Type.apply` was not handled by ReifyQuotes")
28-
def apply[T <: AnyKind]: QuoteContext ?=> Type[T] = ???
28+
given apply[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ???
2929

3030
def UnitTag: QuoteContext ?=> Type[Unit] =
3131
qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]

tests/run-macros/i7048/Lib_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ given [U] as IsExpr[Expr[U]] = new IsExpr[Expr[U]] {
1212

1313
def f(x: Any): String = x.toString
1414

15-
def g[T](x: T)(using e: IsExpr[T], tu: Type[e.Underlying]): QuoteContext ?=> Expr[String] = {
15+
def g[T](x: T)(using e: IsExpr[T])(using tu: Type[e.Underlying]): QuoteContext ?=> Expr[String] = {
1616
val underlying: Expr[e.Underlying] = e.toExpr(x)
1717
'{f($underlying)}
1818
}

0 commit comments

Comments
 (0)