Add a HIR to the compiler by nrc · Pull Request #1191 · rust-lang/rfcs (original) (raw)

@arielb1 I'm not worried about accidental breakage as much as having to modify several thousand lines. But seeing how HIR can be flattened and reduced to essentials, it's less of an issue.

Speaking of which, the current ast_map arena-allocates "roots", like the crate and inlined items.
We could just arena-allocate everything and have the HIR more like middle::Ty, in that all links to other nodes are &'tcx T.

I feel pretty good about flattening: resolve takes care of scoping, and we do preserve parent IDs already.
The only nested items that are not trivial to hoist out are closures - but we can have "closure items", more like a struct+impl pair, if not exactly that.

ast::Path desugaring is messy and implicit right now, but with HIR, it could be done by resolve:

Another table-based resolve contortion is the "trait map" - each method call and non-qualified associated path is associated with a vector of traits in scope that contains an associated item with that name.
With HIR, every block could have a reference to an interned "scope chain" which holds all the traits (and perhaps all types, for picking shorter type paths in error reporting).