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

[WIP] Check future proofing of macros with multiple arms using FIRST sets. #34140

Closed
wants to merge 10 commits into from

Conversation

LeoTestard
Copy link
Contributor

Far from being finished. The first_sets_disjoints is still the biggest missing piece.
cc @pnkfelix @nikomatsakis

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@LeoTestard LeoTestard force-pushed the macro-first-sets branch 4 times, most recently from 65973b3 to 088f7fa Compare June 8, 2016 13:09
@durka
Copy link
Contributor

durka commented Jun 8, 2016

I like the warnings, but I think we should use this info to be careful about syntax changes, rather than punishing macro authors for not predicting the future (so I would be against hard errors).

@nikomatsakis
Copy link
Contributor

I imagine we would try to take the effect of such changes into account
when making decisions, but I wouldn't consider it a decisive factor.
Consider that just about any change to the grammar can affect some
program somewhere, and we can't actually know what the full set of
programs do. Hopefully we'll find a way to employ rules that actually
prevent "future-hostile" macros but in the meantime warnings would
surely be an improvement.

On Wed, Jun 08, 2016 at 11:41:37AM -0700, Alex Burka wrote:

I like the warnings, but I think we should use this info to be careful about syntax changes, rather than punishing macro authors for not predicting the future.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#34140 (comment)

@LeoTestard
Copy link
Contributor Author

Ok so here are the first results (including the Rust codebase and the unit tests, not crater yet):

Broken macros in the Rust codebase:

  • libcollections::vec (macros.rs)
  • libsyntax::declare_features (feature_gate.rs)
  • libsyntax::maybe_whole (parser.rs)
  • librustc::enum_from_i32 (macros.rs)
  • librustc::hir_vec (hir)
  • librustc_metadata::enum_from_i32 (macros.rs) (dup of librustc::enum_from_i32?)
  • librustc_mir::unpack (build)
  • librustc_trans::ifn (context.rs)

Failed tests:

  • compile-fail/issue-16098.rs
  • compile-fail/macro-follow.rs
  • compile-fail/macro-followed-by-seq-bad.rs
  • compile-fail/macro-input-future-proofing.rs

For now I identified three patterns:

  • Legit failures
  • Failures due to the fact that the analysis currently does not descend into sequence repetitions, like vec!, but on macros that otherwise look legal
  • T versus NT failures, where T has the priority (being in the first arm), but rejected because NT could match several token trees and we don't know where we should continue the analysis. However, if the rest of the first matcher after T doesn't contain any NT matcher, then I think it's not necessary to continue the analysis and we can just accept the macro (or reject it, based on the previous context, but it should accept the cases we have here).

cc @pnkfelix

@LeoTestard LeoTestard force-pushed the macro-first-sets branch 6 times, most recently from aa43a89 to ec02edf Compare June 10, 2016 13:43
@bors
Copy link
Contributor

bors commented Jun 16, 2016

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

@LeoTestard LeoTestard force-pushed the macro-first-sets branch 10 times, most recently from eaa8234 to b519253 Compare July 6, 2016 14:31
…tcher only contain simple tokens.

Those were rejected before when the NT or seq can match several token trees because we did not know where to continue the analysis. But if the rest of the first matcher does not contain any NT matcher, we do not need to continue the analysis.
@LeoTestard LeoTestard force-pushed the macro-first-sets branch 6 times, most recently from 4a0b8b4 to 19b8ebd Compare July 12, 2016 14:24
A `tt` matcher in the second arm versus a `block` matcher in the first arm is not future-proof.
Also clean-up a bit the code for the single-TT special cases.
@LeoTestard LeoTestard force-pushed the macro-first-sets branch 2 times, most recently from 807705a to ad2eacb Compare July 25, 2016 12:36
This means a matcher will be accepted if it only contains tokens, `ident` or `tt` NT matchers, or delimited/sequences of them.
This is valid beacuse `tt` will never start matching more input that matches the second matcher.
@bors
Copy link
Contributor

bors commented Aug 12, 2016

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

@alexcrichton
Copy link
Member

r? @pnkfelix

Would be good to also get a resolution for #33840 as well.

@rust-highfive rust-highfive assigned pnkfelix and unassigned sfackler Oct 31, 2016
@brson
Copy link
Contributor

brson commented Nov 9, 2016

Ditto. Let's close if this isn't going to progress.

@steveklabnik
Copy link
Member

Ditto. Let's close if this isn't going to progress.

Agreed. @LeoTestard if you end up updating this, please let us know, but with months with no activity, I'm going to give this a close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants