-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Encoding of quote HOLE in TASTy #17137
Labels
Comments
nicolasstucki
added
itype:bug
area:metaprogramming:quotes
Issues related to quotes and splices
labels
Mar 22, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 23, 2023
nicolasstucki
added a commit
that referenced
this issue
Aug 8, 2023
This is a new encoding of HOLE that differentiates between type and term arguments of the hole. ``` -- pickled quote trees: These trees can only appear in pickled quotes. They will never be in a TASTy file. EXPLICITtpt tpt_Term -- Tag for a type tree that in a context where it is not explicitly known that this tree is a type. HOLE Length idx_Nat tpe_Type arg_Tree* -- Splice hole with index `idx`, the type of the hole `tpe`, type and term arguments of the hole `arg`s ``` We will pickle type trees in `arg_Tree` using the `EXPLICITtpt` tag. We will only have hole captured types if there is a type defined in a quote and used in a nested quote. Most of the time we do not have those types and therefore no overhead in the encoding compared to before this change. Alternative to #17225 Fixes #17137
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler version
3.0, 3.1, 3.2, 3.3
Problem
Compiling with
-Xprint:splicing
, we can see the variables defined in the outer quote and used in the inner one (T, x
). In that phase we replace the splice with a quote hole{{{ 0 | T | T, x | ... }
.We currently pickle this hole we have to pickle the captured variables
T, x
as trees.https://github.com/lampepfl/dotty/blob/d36cd2d142f490e5ba7fcb29906b6b0a27cf8702/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala#L668-L673
The problem is that we do not know if the tree has to be unpickled as a type or a term. We unpickle all of them as terms
https://github.com/lampepfl/dotty/blob/d36cd2d142f490e5ba7fcb29906b6b0a27cf8702/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala#L1470-L1476
If a type contains a term reference, such as a
TypeTree(tp: TermRef)
, the unpicker will unpickle it as anIdent
orSelect
. This implies that the type is unpickled as a term, which causes trouble later when we wrap them inquoted.{Expr,Type}
.Solution 1
We have to pickle the hole with a format where we can unpickle types a types and terms as terms. For this we need to split the arguments into type and term arguments. We need to make sure that the order of arguments retains the order that is defined in the splicing phase. Therefore, we need to split the type arguments from term arguments during the splicing phase.
The tricky part is to find a way to encode this tree in tasty without braking TASTy binary compatibility.
Solution 2
Define a method and a type in the standard library to encode the holes.
This would make the pickled tasty slightly larger.
The text was updated successfully, but these errors were encountered: