Region renumbering?

Hi everyone,

I hope this is an ok place to ask questions about the reasons behind compiler design decisions. If it's not, I'd be glad to be directed to the right place!

Why are individual MIR control-flow graphs cloned, and their regions renumbered, before region constraint generation and inference? I'm guessing it's because the region indices/tags in the original MIR are global, but we'd prefer a small number of consecutive integers for our inference variables, or something like that... But in that case, why not use function-local labels in the original MIR in the first place?

If the renumbering is absolutely necessary, why is it done by cloning and renumbering the CFG? Why not use an auxiliary data structure, like a simple map between the "MIR" regions and the "borrowck" regions?

Anyway, the dev guide does a good job describing the high-level architecture, but a lot of these "motivation" questions aren't really addressed. Hopefully this is the place to find the answers to them. Thanks very much!

Edit: more "whys" for you. As a matter of fact, why should lifetime tags actually live inside TyKind? They are conceptually part of the type. But this makes type comparison harder, might (?) be the ultimate reason the renumbering is needed, and fills up the type interner with loads of quasi-duplicates. The ascribed regions aren't used during the HIR typechecking phase, are they? Couldn't they be ascribed in the first place at the beginning of borrow checking, in a (pseudotype) Map<Place, Region>?

7 Likes

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