Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desugaring of Case #58

Open
hrutvik opened this issue Sep 21, 2023 · 1 comment
Open

Desugaring of Case #58

hrutvik opened this issue Sep 21, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@hrutvik
Copy link
Collaborator

hrutvik commented Sep 21, 2023

Currently Case desugars to a series of nested let expressions, e.g.:

exp_of (case x = e of C a b c -> k)
  =>  let x = exp_of e in
        if ... then
          let a = proj 0 x; b = proj 1 x; c = proj 2 x in exp_of c
        else fail

This causes issues when the pattern variables (a,b,c) shadow the Case variable (x), decoupling the binding structure of compiler expressions from semantic expressions. This requires keeping around invariants on a lack of shadowing in various places where we might otherwise hope to avoid them.

@myreen suggests an alternative desugaring which could help:

exp_of (case x = e of C [a,b,c] -> k)
  =>  let x = exp_of e in if ... then (\ a b c. exp_of c) (proj 0 x) (proj 1 x) (proj 2 x) else fail

In this desugaring, x can never be shadowed by any of the pattern variables - we would no longer need to carry around the invariants.

An initial approach could be to define an alternative exp_of and prove equivalence to the old one. Proofs can then choose which one to use. Better yet is to replace the existing exp_of and update all proofs.

@hrutvik hrutvik added the enhancement New feature or request label Sep 21, 2023
@myreen
Copy link
Contributor

myreen commented Jan 24, 2024

An initial approach could be to define an alternative exp_of and prove equivalence to the old one. Proofs can then choose which one to use. Better yet is to replace the existing exp_of and update all proofs.

I suggest going straight for the "replace the existing exp_of and update all proofs", i.e. actually modifying the Case expansion in exp_of, rather than defining an alternative version.

The relevant definition is here. The definition lets_for_def should be deleted, and the use of lets_for in rows_of should be replaced a nesting of lambdas (Lam).

.

hrutvik added a commit that referenced this issue Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants