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 should not be serialized through strings in crate metadata. #49511

Closed
eddyb opened this issue Mar 30, 2018 · 8 comments · Fixed by #66364
Closed

macro_rules macros should not be serialized through strings in crate metadata. #49511

eddyb opened this issue Mar 30, 2018 · 8 comments · Fixed by #66364
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eddyb
Copy link
Member

eddyb commented Mar 30, 2018

macro_rules should use TokenStreams instead of being pretty-printed into a string and later re-parsed. This is required to get correct/precise hygiene information and original source spans.

For example, right now macros from libstd get <std macros> in their spans instead of the original source, and we hide printing any of that source because it looks much worse than the original, and those spans also don't capture any fine-grained information from macro-defining macros.

IIRC @ibabushkin started working on this (see #43847) but I couldn't find a tracking issue.
cc @alexcrichton @jseyfried @Manishearth

@eddyb eddyb added I-nominated A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 30, 2018
@durka
Copy link
Contributor

durka commented Mar 30, 2018

This should help with re-exported macro docs #26560 as well.

@nikomatsakis
Copy link
Contributor

triage: P-medium

@nikomatsakis
Copy link
Contributor

In case there is a decision to be made here, seems like clearly "yes", right? Otherwise, I'm not sure why this is nominated, so removing the tag.

@nikomatsakis nikomatsakis added P-medium Medium priority and removed I-nominated labels Apr 26, 2018
@eddyb
Copy link
Member Author

eddyb commented Apr 26, 2018

@nikomatsakis I think it was nominated to assign someone to it.

@ibabushkin
Copy link
Contributor

ibabushkin commented Apr 27, 2018

Here is my last (rather old) attempt at this: branch, previous PR. I was unable to get this to a working state (due to lack of time, and strange issues).

@steveklabnik
Copy link
Member

Triage: it's not clear to me where this lives in the compiler to see if it's something that has been fixed or not; does anyone know where to look? That would help future folks reading this ticket.

@petrochenkov
Copy link
Contributor

#66364 fixes this for macro_rules (they are no longer encoded as strings).

Even after #66364 hygienic properties are still not encoded in metadata and are set heuristically on macro loading, that's one of the primary reasons why Span::def_site is not stabilized.

@eddyb
Copy link
Member Author

eddyb commented Feb 10, 2020

I think merging #66364 should close this issue, because even though I said:

This is required to get correct/precise hygiene information and original source spans.

I mean that this is a prerequisite to precise hygiene information, but that is a separate concern that affect all serialized Spans and should be tracked separately.

bors added a commit that referenced this issue Mar 9, 2020
Cleanup `rmeta::MacroDef`

Avoid using rountrip parsing in the encoder and in `fn load_macro_untracked`.

The main reason I was interested in this was to remove `rustc_parse` as a dependency of `rustc_metadata` but it seems like this had other benefits as well.

Fixes #49511.

r? @eddyb
cc @matthewjasper @estebank @petrochenkov
bors added a commit that referenced this issue Mar 10, 2020
Cleanup `rmeta::MacroDef`

Avoid using rountrip parsing in the encoder and in `fn load_macro_untracked`.

The main reason I was interested in this was to remove `rustc_parse` as a dependency of `rustc_metadata` but it seems like this had other benefits as well.

Fixes #49511.

r? @eddyb
cc @matthewjasper @estebank @petrochenkov
@bors bors closed this as completed in 1581278 Mar 10, 2020
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-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants