-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Make mtwt resolution part of the HIR lowering #29782
Comments
I tried it as an alternative to #29748, I agree, it would be much nicer and would kill such hygiene bugs in their root. Maybe things can be restructured somehow, so that HIR could be modified once more after resolution? |
Could you give an example of a not-new binding that should not be renamed? My understanding was that applying the mtwt algorithm should handle all of that, and |
when we start name resolution, so |
Urgh. I'll have to think about that... |
Having thought about this, I agree this is a show-stopper, also the world is a cold and awful place. I think the 'right' thing to do here is to merge the HIR lowering with name resolution so there are no un-resolved names in the HIR (modulo associated types), that needs thought to see if it will work, I guess. |
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
Currently we do the resolution step of mtwt lazily and on demand in name resolution and (unfortunately) elsewhere. That means we have to keep the (big) tables around longer than is nice and means we are open to hygiene bugs where people forget to do mtwt resolution.
A better solution is to eagerly do mtwt resolution as part of the HIR lowering step. This also means no more
Ident
s in the HIR, onlyName
s, which is a plus.Happy to mentor this, it's probably better as a second or third bug than a first though since its not super easy.
The text was updated successfully, but these errors were encountered: