Skip to content

Keep hole types in pickled TASTy #8566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object TreePickler {
override def isTerm: Boolean = isTermHole
override def isType: Boolean = !isTermHole
override def fallbackToText(printer: Printer): Text =
s"[[$idx|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
s"[[$idx|" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
}
}

Expand Down Expand Up @@ -603,6 +603,7 @@ class TreePickler(pickler: TastyPickler) {
writeByte(HOLE)
withLength {
writeNat(idx)
pickleType(tree.tpe, richTypes = true)
args.foreach(pickleTree)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ class TreeUnpickler(reader: TastyReader,

def readHole(end: Addr, isType: Boolean)(implicit ctx: Context): Tree = {
val idx = readNat()
val tpe = readType()
val args = until(end)(readTerm())
val splice = splices(idx)
def wrap(arg: Tree) =
Expand Down
18 changes: 17 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,23 @@ class ReifyQuotes extends MacroTransform {
*/
private def makeHole(isTermHole: Boolean, body: Tree, splices: List[Tree], tpe: Type)(implicit ctx: Context): Hole = {
val idx = embedded.addTree(body, NoSymbol)
Hole(isTermHole, idx, splices).withType(tpe).asInstanceOf[Hole]
val holeType = getHoleType(tpe)
Hole(isTermHole, idx, splices).withType(holeType).asInstanceOf[Hole]
}

private def getHoleType(using ctx: Context) = new TypeMap() {
override def apply(tp: Type): Type = tp match
case tp: TypeRef if tp.typeSymbol.isSplice =>
apply(tp.dealias)
case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal =>
val hiBound = tp.typeSymbol.info match
case info @ ClassInfo(_, _, classParents, _, _) => classParents.reduce(_ & _)
case info => info.hiBound
apply(hiBound)
case tp @ TermRef(NoPrefix, _) =>
apply(tp.widenTermRefExpr)
case tp =>
mapOver(tp)
}

override def transform(tree: Tree)(implicit ctx: Context): Tree =
Expand Down