Push `expand` from `traceGC.bwd` into `desugGC.bwd`
rolyp opened this issue · comments
Currently a slice is required to have the same “structure” as the original syntax. In particular, map-like forms (records, eliminators, dictionaries) must produce slices that have the same domain as the unsliced form. However the only point at which this really matters is during bwd desugaring, where we use this invariant to restore the full original syntax. In the core language, for performance, we allow slices to be “partial”, and then use the Expandable
type class to restore them to their total form before being passed to bwd desugaring.
Since expanding environments is potentially expensive, and Expandable
introduces a certain amount of boilerplate, a better approach may be just to make the notion of slice inherently partial. (Mathematically I think it’s fine, we just use a slightly more relaxed partial order to say when something is a slice of something else.) I think the only required change is to have bwd desugaring tolerate as input (and produce as output) partial slices for the map-like syntactic forms.
Summary after initial attempt
It’s not clear yet how to map partial eliminators back to piecewise function definitions, so this will require another pass over the bwd desugaring formalism, something we can come back to for the graph-based desugaring.
For now, the core language now produces partial slices, and the surface languages tolerates them, but rather than generating partial slices in the surface language, we simply apply expand
to the incoming argument to bwd desugaring.