Skip to content
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

Merged
merged 3 commits into from
Apr 26, 2015
Merged

Conversation

goffrie
Copy link
Contributor

@goffrie goffrie commented Mar 5, 2015

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 Nonterminals 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-highfive
Copy link
Collaborator

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.

@kmcallister
Copy link
Contributor

cc me, @eddyb, @sfackler, @pnkfelix

@eddyb
Copy link
Member

eddyb commented Mar 7, 2015

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
Copy link
Contributor Author

goffrie commented Mar 7, 2015

You're talking about the encode-idents-with-null-characters thing? AFAIK, I've ripped all that out - unless you happen to know of something I've missed?

@eddyb
Copy link
Member

eddyb commented Mar 7, 2015

@goffrie ahhh you managed to see my comment before I realized I've missed that part in tbe description.

@bors
Copy link
Contributor

bors commented Mar 9, 2015

☔ The latest upstream changes (presumably #22561) made this pull request unmergeable. Please resolve the merge conflicts.

@goffrie goffrie force-pushed the interpolating-quote branch from e1a2420 to 39c9470 Compare March 10, 2015 04:17
@bors
Copy link
Contributor

bors commented Mar 12, 2015

☔ The latest upstream changes (presumably #23265) made this pull request unmergeable. Please resolve the merge conflicts.

@goffrie goffrie force-pushed the interpolating-quote branch 2 times, most recently from c4933fc to 5173007 Compare March 16, 2015 04:49
@bors
Copy link
Contributor

bors commented Mar 20, 2015

☔ The latest upstream changes (presumably #23548) made this pull request unmergeable. Please resolve the merge conflicts.

@lambda-fairy
Copy link
Contributor

Is anyone looking at this? I'm pretty excited about this PR.

@kmcallister
Copy link
Contributor

Me too! It needs a rebase though.

@goffrie
Copy link
Contributor Author

goffrie commented Apr 5, 2015

Sorry, I've been so busy 😭 I'll try to get this PR updated this week.

@huonw
Copy link
Member

huonw commented Apr 6, 2015

r? @kmcallister (transferring reviewership, don't have the bandwidth right now.)

@rust-highfive rust-highfive assigned kmcallister and unassigned huonw Apr 6, 2015
@kmcallister kmcallister removed their assignment Apr 9, 2015
@goffrie goffrie force-pushed the interpolating-quote branch from 5173007 to 6025cd2 Compare April 9, 2015 21:31
@goffrie
Copy link
Contributor Author

goffrie commented Apr 13, 2015

Rebased. Can someone review this?

@huonw huonw self-assigned this Apr 15, 2015
@huonw
Copy link
Member

huonw commented Apr 15, 2015

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.

@goffrie goffrie force-pushed the interpolating-quote branch from 6025cd2 to d61012d Compare April 19, 2015 02:03
@goffrie
Copy link
Contributor Author

goffrie commented Apr 19, 2015

@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?

@huonw
Copy link
Member

huonw commented Apr 21, 2015

That's a little sad: the quasiquoted version is definitely nicer.

@bors r+

@bors
Copy link
Contributor

bors commented Apr 21, 2015

📌 Commit d61012d has been approved by huonw

@bors
Copy link
Contributor

bors commented Apr 21, 2015

⌛ Testing commit d61012d with merge bfe5a6a...

@bors
Copy link
Contributor

bors commented Apr 21, 2015

💔 Test failed - auto-linux-64-x-android-t

@bors
Copy link
Contributor

bors commented Apr 23, 2015

☔ The latest upstream changes (presumably #24537) made this pull request unmergeable. Please resolve the merge conflicts.

@goffrie goffrie force-pushed the interpolating-quote branch from dce933b to fb43942 Compare April 23, 2015 20:55
@goffrie
Copy link
Contributor Author

goffrie commented Apr 24, 2015

Rebased. All tests pass locally.

@alexcrichton
Copy link
Member

@bors: r=huonw fb43942

@bors
Copy link
Contributor

bors commented Apr 24, 2015

⌛ Testing commit fb43942 with merge 606c9d5...

@bors
Copy link
Contributor

bors commented Apr 24, 2015

💔 Test failed - auto-mac-32-opt

@lambda-fairy
Copy link
Contributor

The failure seems unrelated:

test [debuginfo-lldb] debuginfo/associated-types.rs ... 
command timed out: 1200 seconds without output, attempting to kill
process killed by signal 15
program finished with exit code -1
elapsedTime=2966.482249

This PR only touches libsyntax; it shouldn't have anything to do with debuginfo, right?

@goffrie
Copy link
Contributor Author

goffrie commented Apr 24, 2015

Yeah, I don't think it's related.
On Apr 23, 2015 11:52 PM, "Chris Wong" notifications@github.com wrote:

The failure seems unrelated:

test [debuginfo-lldb] debuginfo/associated-types.rs ...
command timed out: 1200 seconds without output, attempting to kill
process killed by signal 15
program finished with exit code -1
elapsedTime=2966.482249

This PR only touches libsyntax; it shouldn't have anything to do with
debuginfo, right?


Reply to this email directly or view it on GitHub
#23085 (comment).

@bors
Copy link
Contributor

bors commented Apr 24, 2015

☔ The latest upstream changes (presumably #24759) made this pull request unmergeable. Please resolve the merge conflicts.

@goffrie goffrie force-pushed the interpolating-quote branch from fb43942 to 0dbee13 Compare April 24, 2015 15:31
@bors
Copy link
Contributor

bors commented Apr 26, 2015

☔ The latest upstream changes (presumably #24718) made this pull request unmergeable. Please resolve the merge conflicts.

goffrie added 2 commits April 25, 2015 21:42
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.
@goffrie goffrie force-pushed the interpolating-quote branch from 0dbee13 to ea892dc Compare April 26, 2015 01:42

trait FakeExtCtxt {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change all this?

Copy link
Contributor Author

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.)

Copy link
Contributor

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 :(

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.
@pnkfelix
Copy link
Member

@bors: r=huonw 24ef905

@bors
Copy link
Contributor

bors commented Apr 26, 2015

⌛ Testing commit 24ef905 with merge 6365080...

bors added a commit that referenced this pull request Apr 26, 2015
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.
@bors bors merged commit 24ef905 into rust-lang:master Apr 26, 2015
@kmcallister
Copy link
Contributor

🎉

tomjakubowski added a commit to tomjakubowski/json_macros that referenced this pull request May 4, 2015
sunng87 added a commit to sunng87/tojson_macros that referenced this pull request May 9, 2015
@goffrie goffrie deleted the interpolating-quote branch October 12, 2017 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment