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

Conversation

Projects
None yet
4 participants
@petrochenkov
Contributor

petrochenkov commented Dec 1, 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_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

This comment has been minimized.

Contributor

bors commented Dec 4, 2015

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

@petrochenkov petrochenkov force-pushed the petrochenkov:hyg branch from 0aea51c to eb789de Dec 4, 2015

@petrochenkov

This comment has been minimized.

Contributor

petrochenkov commented Dec 4, 2015

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 {

This comment has been minimized.

@nrc

nrc Dec 6, 2015

Member

Why does save-analysis need the mtwt tables?

This comment has been minimized.

@petrochenkov

petrochenkov Dec 6, 2015

Contributor

It calls lower_crate, lowering uses mtwt tables.

}
impl Ident {
pub fn from_name(name: Name) -> Ident {

This comment has been minimized.

@nrc

nrc Dec 6, 2015

Member

should this be from_name_unhygienic or something? It seems like using this where you shouldn't would introduce hygiene bugs.

This comment has been minimized.

@petrochenkov

petrochenkov Dec 6, 2015

Contributor

I'm not sure how to call it better. For example, for loop desugaring calls from_name with gensym iter exactly for unhygienic_name to be hygienic.

This comment has been minimized.

@nrc

nrc Dec 7, 2015

Member

from_hygienic_name? Since the caller is guaranteeing that the input is already hygienic? Otherwise just a comment explaining the danger would be good.

pub fn lower_path(lctx: &LoweringContext, p: &Path) -> hir::Path {
// Path segments are usually unhygienic, hygienic path segments can occur only in
// identifier-like paths originating from `ExprPath`.
// Make life simpler for rustc_resolve by renaming only such segments.

This comment has been minimized.

@nrc

nrc Dec 6, 2015

Member

How much simpler does this make resolve? This seems quite a fragile treatment

This comment has been minimized.

@petrochenkov

petrochenkov Dec 6, 2015

Contributor

Renaming all path segments requires many uses of unhygienic_name in all kind of paths all over the resolve instead of one place in resolve_identifier. Most of path segments are unhygienic, only identifiers arecan be hygienic.
I even thought about splitting ExprPath into ExprPath and ExprIdent (by analogy with PatEnum and PatIdent in patterns) to make this problem go away, but this is likely not beneficial for later stages after resolve.

This comment has been minimized.

@arielb1

arielb1 Dec 7, 2015

Contributor

We probably want to do something about the ExprPath/PatEnum/PatIdent mess in the HIR when we have post-resolve HIR.

This comment has been minimized.

@petrochenkov

petrochenkov Dec 7, 2015

Contributor

Yeah, the more I learn about these things the more I like the idea of doing name resolution on AST and removing all this confusion from HIR.

@nrc

This comment has been minimized.

Member

nrc commented Dec 6, 2015

Nice!

@petrochenkov

This comment has been minimized.

Contributor

petrochenkov commented Dec 7, 2015

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

@nrc

This comment has been minimized.

Member

nrc commented Dec 7, 2015

@bors: r+

@bors

This comment has been minimized.

Contributor

bors commented Dec 7, 2015

📌 Commit c1d3164 has been approved by nrc

@bors

This comment has been minimized.

Contributor

bors commented Dec 9, 2015

⌛️ Testing commit c1d3164 with merge 462ec05...

bors added a commit that referenced this pull request Dec 9, 2015

Auto merge of #30145 - petrochenkov:hyg, r=nrc
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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@petrochenkov petrochenkov referenced this pull request May 15, 2016

Merged

Remove hir::Ident #33654

bors added a commit that referenced this pull request May 18, 2016

Auto merge of #33654 - petrochenkov:hirident, r=nrc
Remove hir::Ident

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

r? @nrc

@petrochenkov petrochenkov deleted the petrochenkov:hyg branch Sep 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment