Rewrite canonicalType to be actually correct.
Remove unused code and variables.
Change init declarations to initGlobalDecls.
Define state augmentations for handling records and annotations.