Removing the Hair trait from MIR construction

Just FYI, I’m planning to remove the Hair trait from MIR construction (PR coming soon). The reason is that the way I had it currently implemented, the Hair trait serves two roles: it hosted a bunch of associated types that are used by the Mir (e.g., Ty) and it also hosted some associated types and methods that were used solely by MIR construction (e.g., Expr and can_drop). The latter required access to an inference context, but that in turn requires that the type which implements the Hair trait contains a InferCtxt<'a, 'tcx>. THIS in turn means that you have a Mir type that looks like Mir<Cx<'a,'tcx>>. This is the type we would have to store in some table in the tcx. The problem is that the lifetime 'a is local to the MIR construction pass.

The only solution I see (besides removing the trait) is to split the Hair trait into two traits, one that hosts the associated type, and one that is the “builder”. I experimented with this but it’s kind of annoying and verbose. Frankly, while the Hair trait was a fun experiment, it’s unclear that it carries its weight anyhow. The idea was to allow us to gin up artificial inputs beyond full .rs files – this seems maybe useful but also maybe like something we will implement and then rarely if ever use. So I am decided to just remove the trait instead.

PR coming soon.

Yay! (mostly because I got lost in the MIR source everytime Hair came up.)

Heh :slight_smile: I was sad because the code becomes less abstract, in some sense, since it uses all concrete types, but I also recognize that makes it easier to understand as well. However, we ARE still using the Hair in the sense that there is an initial transformation from Hir -> Hair and then Hair -> Mir. But hopefully it’ll be easier to follow this way as well.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.