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

Update codegen for 2018-06-22 nightly. #666

Closed
wants to merge 1 commit into from

Conversation

jebrosen
Copy link
Collaborator

@jebrosen jebrosen commented Jun 19, 2018

Fixes #660 in the master branch. Depends on rust-lang/rust#51664.

parse_seq is identical to the method removed from libsyntax.

Also includes fix for next breakage, introduced around 2018-06-22.

  • parse_optional_str and mk_mac_expr (which are private) are now re-implemented by Rocket in parser_ext.rs by a copy/paste and fixing up the paths.

  • parse_seq was deleted. This reimplementation is not quite identical: it uses parse_seq_to_end, which we already asked be made public, instead of parse_seq_to_before_end, which is still private. I think the span associated with the result is one character longer than it was in the original implementation. I would like to fix that but I am not sure how to correct it (or even inspect or verify it).

If a "quick fix" that makes no changes to libsyntax is useful or helpful, this appears to work. It does have a likelihood of bitrot, but Rocket will eventually move away from libsyntax anyway.

If requesting changes to libsyntax is preferred, I think we can get by with parse_optional_str and mk_mac_expr public, and either reintroduce parse_seq or re-implement it (correctly, not necessarily this implementation) in Rocket. Having parse_seq_to_before_end would help if we were to re-implement parse_seq in Rocket.

EDIT: I have not (yet) verified that the nightly bound (2018-06-12) is actually sufficient, but I believe it should be.

@SergioBenitez
Copy link
Member

@jebrosen The implementations for these functions: are they copied straight from the rustc source code, or did you reimplement them yourself?

@jebrosen
Copy link
Collaborator Author

These are all from rustc with only path/use directive changes, and the difference mentioned for parse_seq. From the standpoint of correctness, they should be fine now but would need to be kept up to date with any future changes in libsyntax. From the standpoint of attribution and maintenance, I would definitely ask the rust project for their opinion before considering merging this or any similar code. I probably jumped the gun by posting this as a PR.

Rereading at my original comment, it was not very clear that my intent here is to demonstrate that it is possible for this code to be duplicated and in the case of of parse_seq resurrected in rocket, not to argue that it is a desirable approach.

From my point of view, these are the options I see in order of desirability:

  1. Move away from using libsyntax, which I understand Rocket is not quite ready to do yet.
  2. Request the methods to be made public and/or defined again, which will take at least one or two days, and they may not want to bring back parse_seq.
  3. This solution, which I consider a stopgap in case parse_seq will not be brought back in libsyntax.

@SergioBenitez
Copy link
Member

We absolutely want to move away from libsyntax and compiler-plugins in general in favor of proc-macros, but proc-macros appear to be more unstable that compiler-plugins themselves. What's more, they're ill-defined at the moment, quite buggy, and not powerful enough. I plan to aid in ameliorating this situation soon.

I think we should proceed with a combination of 2) and 3) as follows: if the method still exists in libsyntax, lets submit a PR to make them public again. If not, let's reimplement them in rocket for now. We want to reduce our exposure to breakage as much as possible.

@jebrosen
Copy link
Collaborator Author

Sounds good.

I am preparing a PR for rust-lang/rust that makes the these methods public, and will remove them from this PR. parse_seq can then be identical to the implementation that was removed from rustc.

@jebrosen jebrosen changed the title Update codegen for 2018-06-12 nightly. Update codegen for 2018-06-??? nightly. Jun 20, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Jun 22, 2018
…-Simulacrum

make more libsyntax methods public

Followup for rust-lang#51502, which was sufficient only for the latest stable release of Rocket. The `master` branch uses a few more. I plan to reimplement the deleted method `parse_seq` in Rocket (see rwf2/Rocket#666), rather than resurrecting it in libsyntax.

r? @Mark-Simulacrum
@jebrosen jebrosen changed the title Update codegen for 2018-06-??? nightly. Update codegen for 2018-06-22 nightly. Jun 22, 2018
@jebrosen
Copy link
Collaborator Author

Rebased, rewrote, and also updated for compatibility with changes introduced by rust-lang/rust#48149.

@@ -27,11 +27,11 @@ fn struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, sp: Span) -> Option<St
ItemKind::Struct(_, ref generics) => {
let mut lifetimes = generics.params.iter()
.filter_map(|p| match *p {
GenericParam::Lifetime(ref def) => Some(def),
GenericParam { ref ident, ref kind, .. } if *kind == GenericParamKind::Lifetime => Some(ident),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only part I'm not quite certain of. Seems to work, but there might be a better way of doing this.

Copy link
Member

Choose a reason for hiding this comment

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

Does ident include the initial tick '? You should take a look at the generated code and ensure that it looks correct, even if it's accepted by the compiler otherwise. Aside from this, this looks good, though it would seem that kind doesn't need to be a ref kind.

Copy link
Member

Choose a reason for hiding this comment

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

I'm pushing a slightly different fix for this in 0.3. Let's use the same one for master.

@@ -14,6 +15,10 @@ pub trait ParserExt<'a> {

// Like `parse_ident` but also looks for an `ident` in a `Pat`.
fn parse_ident_inc_pat(&mut self) -> PResult<'a, Ident>;

// Duplicates previously removed method in libsyntax
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should this link back to the rust repository more concretely? I wasn't sure if I should refer to a PR, commit, URL, or just leave a generic note like this.

Copy link
Member

Choose a reason for hiding this comment

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

Let's link to the PR that removed the method. Something like, "See https://github.com/rust-lang/rust/foo/bar/baz for more details.".

@SergioBenitez
Copy link
Member

Merged in 5b8f8ee. Thanks for the excellent work, @jebrosen!

@SergioBenitez SergioBenitez added the pr: merged This pull request was merged manually. label Jun 23, 2018
@jebrosen jebrosen deleted the nightly0612-master branch June 29, 2018 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: merged This pull request was merged manually.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile fails with latest nightly (as of 2018-06-11)
2 participants