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

macro_rules! macros do not backtrack #42838

Open
Mark-Simulacrum opened this issue Jun 22, 2017 · 2 comments
Open

macro_rules! macros do not backtrack #42838

Mark-Simulacrum opened this issue Jun 22, 2017 · 2 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@Mark-Simulacrum
Copy link
Member

I'm mainly filing this to be able to close other issues whose problems come down to this. I don't know if we want to fix this or will fix this, but at least there will be a single issue for it.

@Mark-Simulacrum Mark-Simulacrum added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 22, 2017
bors added a commit that referenced this issue Jul 11, 2017
…seyfried

Only match a fragment specifier the if it starts with certain tokens.

When trying to match a fragment specifier, we first predict whether the current token can be matched at all. If it cannot be matched, don't bother to push the Earley item to `bb_eis`. This can fix a lot of issues which otherwise requires full backtracking (#42838).

In this PR the prediction treatment is not done for `:item`, `:stmt` and `:tt`, but it could be expanded in the future.

Fixes #24189.
Fixes #26444.
Fixes #27832.
Fixes #34030.
Fixes #35650.
Fixes #39964.
Fixes the 4th comment in #40569.
Fixes the issue blocking #40984.
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 27, 2017
@iago-lito
Copy link
Contributor

Is it also a good place to gather resources explaining why it is the case that macros don't backtrack?
I'm not particularly in need of bactracking, but I'm curious why this (no-)feature. I guess it's a limitation due to compiler optimization? Or maybe there are deeper theoretical problems with backtracking?

@kmaork
Copy link

kmaork commented Nov 16, 2020

Is there any progress here?
Until this is solved, is there a recommended workaround for extracting the last element of a repetition?
The best I've got is reversing the whole repetition using a recursive macro and then extracting the first element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

3 participants