HR IR Conversion
HR ⟷ IR Conversion
The Pass which can be found here deals with the conversion between Core HR and Core IR.
HR ⟶ IR
This phase simply removes the names from the HR form and constructs a De-Brujin index from the names given in HR.
The algorithm for this for Terms and Elims is rather simple
When we see a binder (
Pi,Lam,Sig, orLet), push the name to the stack for the form in which it is scoped over. Recurse and form and reconstruct said binder.For forms without names, recurse and reconstruct.
When a name appears, look up it's index from the stack, this is the De-Brujin index we care about. If the Index is not there then we mark it as a
Global
HR-Pattern's work in a different way, since patterns are
disconnected from terms themselves and do not interact, they work on a
system of registering pattern variables, when we come across the binder form =
Outstanding Questions
Since for
TermsandElimswe don't account for pattern variables, and just mark everything unknown as Global, how doesPattern's affect this? It seems we would mark anyPatternVarabove this form as a Global and lose that information
IR ⟶ HR
This conversion adds back names to the IR form. This is mainly used for Pretty Printing.
The algorithm for Terms and Elims is once again rather simple
When we see a binder (
Pi,Lam,Sig, orLet), generate a new name, and push it to the stack. Recurse and form the reconsturct said binderForms without names just recurse and reconsturct.
When a name appears, lookup the index from the stack, that position is the name which we care about.