Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upDo MTWT resolution during lowering to HIR #30145
Conversation
rust-highfive
assigned
nrc
Dec 1, 2015
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov
force-pushed the
petrochenkov:hyg
branch
from
0aea51c
to
eb789de
Dec 4, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
nrc
reviewed
Dec 6, 2015
|
|
||
| // 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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nrc
reviewed
Dec 6, 2015
| } | ||
|
|
||
| impl Ident { | ||
| pub fn from_name(name: Name) -> Ident { |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
petrochenkov
Dec 6, 2015
Author
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.
This comment has been minimized.
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.
nrc
reviewed
Dec 6, 2015
| 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.
This comment has been minimized.
nrc
Dec 6, 2015
Member
How much simpler does this make resolve? This seems quite a fragile treatment
This comment has been minimized.
This comment has been minimized.
petrochenkov
Dec 6, 2015
Author
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.
This comment has been minimized.
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.
This comment has been minimized.
petrochenkov
Dec 7, 2015
Author
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.
This comment has been minimized.
This comment has been minimized.
|
Nice! |
This comment has been minimized.
This comment has been minimized.
|
Updated with comments for |
This comment has been minimized.
This comment has been minimized.
|
@bors: r+ |
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov commentedDec 1, 2015
Instead of
ast::Ident, bindings, paths and labels in HIR now keep a new structure calledhir::Identcontaining mtwt-renamednameand the original not-renamedunhygienic_name.nameis supposed to be used by default,unhygienic_nameis rarely used.This is not ideal, but better than the status quo for two reasons:
mtwt::resolveto a name. It is still possible to usenameinstead ofunhygienic_nameby mistake, butunhygienic_names are used only in few very special circumstances, so it shouldn't be a problem.Besides name resolution
unhygienic_nameis used in some lints and debuginfo.unhygienic_namecan be very well approximated by "reverse renaming"token::intern(name.as_str())or even plain stringname.as_str(), except that it would break gensyms likeiterin desugaredforloops. This approximation is likely good enough for lints and debuginfo, but not for name resolution, unfortunately (see #27639), sounhygienic_namehas to be kept.cc #29782
r? @nrc