-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Interpolate AST nodes in quasiquote. #23085
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
I have done this a long time ago in a branch I want to revive soon (the whole stage0 syntax extensions thing) - so I am pretty confident this is the way forward (I was too afraid of bootstrapping churn to split this specific change out). |
|
@goffrie ahhh you managed to see my comment before I realized I've missed that part in tbe description. |
☔ The latest upstream changes (presumably #22561) made this pull request unmergeable. Please resolve the merge conflicts. |
e1a2420
to
39c9470
Compare
☔ The latest upstream changes (presumably #23265) made this pull request unmergeable. Please resolve the merge conflicts. |
c4933fc
to
5173007
Compare
☔ The latest upstream changes (presumably #23548) made this pull request unmergeable. Please resolve the merge conflicts. |
Is anyone looking at this? I'm pretty excited about this PR. |
Me too! It needs a rebase though. |
Sorry, I've been so busy 😭 I'll try to get this PR updated this week. |
r? @kmcallister (transferring reviewership, don't have the bandwidth right now.) |
5173007
to
6025cd2
Compare
Rebased. Can someone review this? |
Finally got time to review! This is very cool. Just resolving the staging point one way or another, and I think this is good to go. |
6025cd2
to
d61012d
Compare
@huonw I suspect that we would in fact encounter the problem you mentioned, so I removed the associated commit :( Also rebased. Should be good now? |
That's a little sad: the quasiquoted version is definitely nicer. @bors r+ |
📌 Commit d61012d has been approved by |
⌛ Testing commit d61012d with merge bfe5a6a... |
💔 Test failed - auto-linux-64-x-android-t |
☔ The latest upstream changes (presumably #24537) made this pull request unmergeable. Please resolve the merge conflicts. |
dce933b
to
fb43942
Compare
Rebased. All tests pass locally. |
⌛ Testing commit fb43942 with merge 606c9d5... |
💔 Test failed - auto-mac-32-opt |
The failure seems unrelated:
This PR only touches libsyntax; it shouldn't have anything to do with debuginfo, right? |
Yeah, I don't think it's related.
|
☔ The latest upstream changes (presumably #24759) made this pull request unmergeable. Please resolve the merge conflicts. |
fb43942
to
0dbee13
Compare
☔ The latest upstream changes (presumably #24718) made this pull request unmergeable. Please resolve the merge conflicts. |
This changes the `ToTokens` implementations for expressions, statements, etc. with almost-trivial ones that produce `Interpolated(*Nt(...))` pseudo-tokens. In this way, quasiquote now works the same way as macros do: already-parsed AST fragments are used as-is, not reparsed. The `ToSource` trait is removed. Quasiquote no longer involves pretty-printing at all, which removes the need for the `encode_with_hygiene` hack. All associated machinery is removed. A new `Nonterminal` is added, NtArm, which the parser now interpolates. This is just for quasiquote, not macros (although it could be in the future). `ToTokens` is no longer implemented for `Arg` (although this could be added again) and `Generics` (which I don't think makes sense). This breaks any compiler extensions that relied on the ability of `ToTokens` to turn AST fragments back into inspectable token trees. For this reason, this closes rust-lang#16987. As such, this is a [breaking-change]. Fixes rust-lang#16472. Fixes rust-lang#15962. Fixes rust-lang#17397. Fixes rust-lang#16617.
Such things no longer exist.
0dbee13
to
ea892dc
Compare
|
||
trait FakeExtCtxt { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change all this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote this test independently from your branch (from when it was ignore-test-ed and nonfunctional) and when rebasing I figured that my test already covered everything yours does, so I just took mine. (Also, it seems kind of fragile to me IMO to fake the ExtCtxt
methods that quasiquote happens to need, instead of creating an actual ExtCtxt
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so I agree with that part, but if you're going to change that, there are 2 other places where a FakeExtCtxt
is defined and used, and it would be good to fix them as well. As for this file's main
function, there's really no need to change it; it's just noise :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, I changed the main function for a reason - I'm testing unquotes now (which is what this branch is all about). I'll change the other files that use a FakeExtCtxt, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean, but it looks to me like the main function is effectively unchanged, just rearranged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm testing that not only (e.g.) quote_expr!(cx, 23)
works and produces 23, but also that quote_expr!(cx, $expr)
(where expr
is the result of the earlier quote) still produces 23.
Instead create an ExtCtxt structure.
This changes the `ToTokens` implementations for expressions, statements, etc. with almost-trivial ones that produce `Interpolated(*Nt(...))` pseudo-tokens. In this way, quasiquote now works the same way as macros do: already-parsed AST fragments are used as-is, not reparsed. The `ToSource` trait is removed. Quasiquote no longer involves pretty-printing at all, which removes the need for the `encode_with_hygiene` hack. All associated machinery is removed. New `Nonterminal`s are added: NtArm, NtImplItem, and NtTraitItem. These are just for quasiquote, not macros. `ToTokens` is no longer implemented for `Arg` (although this could be added again) and `Generics` (which I don't think makes sense). This breaks any compiler extensions that relied on the ability of `ToTokens` to turn AST fragments back into inspectable token trees. For this reason, this closes #16987. As such, this is a [breaking-change]. Fixes #16472. Fixes #15962. Fixes #17397. Fixes #16617.
🎉 |
rust syntax extension changes: rust-lang/rust#23085 reference fix: tomjakubowski/json_macros@d4d3133
This changes the
ToTokens
implementations for expressions, statements, etc. with almost-trivial ones that produceInterpolated(*Nt(...))
pseudo-tokens. In this way, quasiquote now works the same way as macros do: already-parsed AST fragments are used as-is, not reparsed.The
ToSource
trait is removed. Quasiquote no longer involves pretty-printing at all, which removes the need for theencode_with_hygiene
hack. All associated machinery is removed.New
Nonterminal
s are added: NtArm, NtImplItem, and NtTraitItem. These are just for quasiquote, not macros.ToTokens
is no longer implemented forArg
(although this could be added again) andGenerics
(which I don't think makes sense).This breaks any compiler extensions that relied on the ability of
ToTokens
to turn AST fragments back into inspectable token trees. For this reason, this closes #16987.As such, this is a [breaking-change].
Fixes #16472.
Fixes #15962.
Fixes #17397.
Fixes #16617.