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

Do MTWT resolution during lowering to HIR #30145

Merged
merged 2 commits into from
Dec 9, 2015
Merged

Conversation

petrochenkov
Copy link
Contributor

Instead of ast::Ident, bindings, paths and labels in HIR now keep a new structure called hir::Ident containing mtwt-renamed name and the original not-renamed unhygienic_name. name is supposed to be used by default, unhygienic_name is rarely used.

This is not ideal, but better than the status quo for two reasons:

  • MTWT tables can be cleared immediately after lowering to HIR
  • This is less bug-prone, because it is impossible now to forget applying mtwt::resolve to a name. It is still possible to use name instead of unhygienic_name by mistake, but unhygienic_names are used only in few very special circumstances, so it shouldn't be a problem.

Besides name resolution unhygienic_name is used in some lints and debuginfo. unhygienic_name can be very well approximated by "reverse renaming" token::intern(name.as_str()) or even plain string name.as_str(), except that it would break gensyms like iter in desugared for loops. This approximation is likely good enough for lints and debuginfo, but not for name resolution, unfortunately (see #27639), so unhygienic_name has to be kept.

cc #29782

r? @nrc

@bors
Copy link
Contributor

bors commented Dec 4, 2015

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

@petrochenkov
Copy link
Contributor Author

Rebased.


// Discard MTWT tables that aren't required past lowering to HIR.
if !sess.opts.debugging_opts.keep_mtwt_tables &&
!sess.opts.debugging_opts.save_analysis {
Copy link
Member

Choose a reason for hiding this comment

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

Why does save-analysis need the mtwt tables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It calls lower_crate, lowering uses mtwt tables.

@nrc
Copy link
Member

nrc commented Dec 6, 2015

Nice!

@petrochenkov
Copy link
Contributor Author

Updated with comments for Ident::from_name and for identifiers in path segments

@nrc
Copy link
Member

nrc commented Dec 7, 2015

@bors: r+

@bors
Copy link
Contributor

bors commented Dec 7, 2015

📌 Commit c1d3164 has been approved by nrc

@bors
Copy link
Contributor

bors commented Dec 9, 2015

⌛ Testing commit c1d3164 with merge 462ec05...

bors added a commit that referenced this pull request Dec 9, 2015
Instead of `ast::Ident`, bindings, paths and labels in HIR now keep a new structure called `hir::Ident` containing mtwt-renamed `name` and the original not-renamed `unhygienic_name`. `name` is supposed to be used by default, `unhygienic_name` is rarely used.

This is not ideal, but better than the status quo for two reasons:
- MTWT tables can be cleared immediately after lowering to HIR
- This is less bug-prone, because it is impossible now to forget applying `mtwt::resolve` to a name. It is still possible to use `name` instead of `unhygienic_name` by mistake, but `unhygienic_name`s are used only in few very special circumstances, so it shouldn't be a problem.

Besides name resolution `unhygienic_name` is used in some lints and debuginfo. `unhygienic_name` can be very well approximated by "reverse renaming" `token::intern(name.as_str())` or even plain string `name.as_str()`, except that it would break gensyms like `iter` in desugared `for` loops. This approximation is likely good enough for lints and debuginfo, but not for name resolution, unfortunately (see #27639), so `unhygienic_name` has to be kept.

cc #29782

r? @nrc
@bors bors merged commit c1d3164 into rust-lang:master Dec 9, 2015
@petrochenkov petrochenkov mentioned this pull request May 15, 2016
bors added a commit that referenced this pull request May 18, 2016
Remove hir::Ident

Now when name resolution is done on AST, `hir::Ident` is no longer necessary.
See #30145 for more details.

r? @nrc
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.

4 participants