From aeb3db1cbfe6a15895e3dd2d3206e7b017d1a56f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 16 Aug 2021 16:55:16 +0200 Subject: [PATCH] Remove unnecessary type from UnApply This type is never used, it is just a placeholder to make the tree typed. It is the `Typed` tree around the `UnApply` that holds the type information. Co-authored-by: Dale Wijnand --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 4 ++-- .../tools/dotc/core/tasty/TreePickler.scala | 3 ++- .../tools/dotc/core/tasty/TreeUnpickler.scala | 4 ++-- .../core/unpickleScala2/Scala2Unpickler.scala | 2 +- .../tools/dotc/typer/QuotesAndSplices.scala | 17 +++++++++++------ .../scala/quoted/runtime/impl/QuotesImpl.scala | 2 +- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 0c12eff2a0ae..0a7beba3a8b9 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -197,9 +197,9 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def Alternative(trees: List[Tree])(using Context): Alternative = ta.assignType(untpd.Alternative(trees), trees) - def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree], proto: Type)(using Context): UnApply = { + def UnApply(fun: Tree, implicits: List[Tree], patterns: List[Tree])(using Context): UnApply = { assert(fun.isInstanceOf[RefTree] || fun.isInstanceOf[GenericApply]) - ta.assignType(untpd.UnApply(fun, implicits, patterns), proto) + ta.assignType(untpd.UnApply(fun, implicits, patterns), defn.NothingType) } def ValDef(sym: TermSymbol, rhs: LazyTree = EmptyTree)(using Context): ValDef = diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 78a2c73de3ea..59047c22403d 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -538,7 +538,8 @@ class TreePickler(pickler: TastyPickler) { writeByte(IMPLICITarg) pickleTree(implicitArg) } - pickleType(tree.tpe) + // TODO write a dummy type that takes less space? + pickleType(tree.tpe) // IGNORED // TODO remove when we can break TASTy compat. patterns.foreach(pickleTree) } case tree: ValDef => diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 79088214519b..f4bb363da82a 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -1248,9 +1248,9 @@ class TreeUnpickler(reader: TastyReader, readByte() readTerm() } - val patType = readType() + val patType = readType() // IGNORED // TODO remove when we can break TASTy compat. val argPats = until(end)(readTerm()) - UnApply(fn, implicitArgs, argPats, patType) + UnApply(fn, implicitArgs, argPats) case REFINEDtpt => val refineCls = symAtAddr.getOrElse(start, newRefinedClassSymbol(coordAt(start))).asClass diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 1a70fb1e9d2d..738c8a158960 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -1175,7 +1175,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas case UNAPPLYtree => val fun = readTreeRef() val args = until(end, () => readTreeRef()) - UnApply(fun, Nil, args, defn.AnyType) // !!! this is wrong in general + UnApply(fun, Nil, args) case ARRAYVALUEtree => val elemtpt = readTreeRef() diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index fbae1afcbfbd..ac11d819b24d 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -400,8 +400,11 @@ trait QuotesAndSplices { * }, * true, // If there is at least one type splice. Used to instantiate the context with or without GADT constraints * x$2 // tasty.Reflection instance - * ) => ... + * ): Expr[S & List[t] @unchecked] => ... * ``` + * + * For a scrutinee of type `S`, the `: Expr[S & List[t] @unchecked]` tells the pattern that if the pattern matched the bound + * scrutinee `x @ '{..}` is of type `Expr[S & List[t] @unchecked]`. */ private def typedQuotePattern(tree: untpd.Quote, pt: Type, qctx: Tree)(using Context): Tree = { if tree.quoted.isTerm && !pt.derivesFrom(defn.QuotedExprClass) then @@ -469,10 +472,12 @@ trait QuotesAndSplices { val matchModule = if tree.quoted.isTerm then defn.QuoteMatching_ExprMatch else defn.QuoteMatching_TypeMatch val unapplyFun = qctx.asInstance(defn.QuoteMatchingClass.typeRef).select(matchModule).select(nme.unapply) - UnApply( - fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil), - implicits = quotedPattern :: Nil, - patterns = splicePat :: Nil, - proto = quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt)) + Typed( + UnApply( + fun = unapplyFun.appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil), + implicits = quotedPattern :: Nil, + patterns = splicePat :: Nil), + TypeTree(quoteClass.typeRef.appliedTo(replaceBindings(quoted1.tpe) & quotedPt)) + ).annotated(New(defn.UncheckedAnnot.typeRef, Nil)) } } diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 788db552a6f1..02699b857efc 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1454,7 +1454,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object Unapply extends UnapplyModule: def apply(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply = - withDefaultPos(tpd.UnApply(fun, implicits, patterns, dotc.core.Symbols.defn.NothingType)) + withDefaultPos(tpd.UnApply(fun, implicits, patterns)) def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply = withDefaultPos(tpd.cpy.UnApply(original)(fun, implicits, patterns)) def unapply(x: Unapply): (Term, List[Term], List[Tree]) =