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

Eager variables in Pure -> Thunk #47

Open
hrutvik opened this issue Jun 23, 2023 · 0 comments
Open

Eager variables in Pure -> Thunk #47

hrutvik opened this issue Jun 23, 2023 · 0 comments
Labels
back end enhancement New feature or request

Comments

@hrutvik
Copy link
Collaborator

hrutvik commented Jun 23, 2023

Alluded to in #40, ThunkLang passes are unusual: pure_to_thunk first Forces all variables (which are thunks), then thunk_let_force attempts to detect eager variables (those that are seqed) and un-Force them. In other words:

    seq (var x) $ ... var x ...
--> let fresh = force (var x) in ... force (var x) ...        -- pure_to_thunk
--> let fresh = force (var x) in ... var fresh ...            -- thunk_let_force

It makes more sense to do this in one step (during pure_to_thunk) by tracking the eager variables currently in scope. This also avoids repeatedly seqed variables: we will know that x is eager when processing the second seq in seq (var x) $ ... seq (var x) ..., and will not issue a second Force (though we would still issue the let-binding).

We can verify this new pure_to_thunk by recombining existing relations. But we should consider combining the initial pure_to_thunk relation and thunk_let_forceProof$e_rel instead. This would reduce proof bloat, and conceptually these belong together because pure_to_thunk handles non-strictness. We can also compile the repeated seqs above without the second let-binding. Also, if we introduce Haskell's optionally-strict bindings (i.e. "bang patterns") we can more easily produce good code, as the combined relation already tracks lazy/eager bindings.

@hrutvik hrutvik added enhancement New feature or request back end labels Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back end enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant