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

Typed extraction integration #1030

Merged
merged 7 commits into from
Dec 13, 2023
Merged

Conversation

mattam82
Copy link
Member

@mattam82 mattam82 commented Dec 13, 2023

This finally updates the typed extraction correctness proof, including the dearging optimization, allowing it to use efficent environment representations.
We additionally prove that it preserves wellformedness and fixpoint eta-expansion, so it can be integrated in all existing pipelines. We generalize a bit the correctness theorem so that we have a simulation for all terms (it used to be restricted to constants that evaluate to constructors). This mainly required adding a bit more of invariants on valid masks in the environment. The transformation is partial in the sense that if the environment analysis does not produce valid masks for dearging, we will just use the identity transformation, to fit in the total erasure pipelines we have for now.
The new commands "MetaCoq (Bypass) Typed Erase" run the extracted verified extraction in OCaml.

@mattam82 mattam82 merged commit b646cd3 into coq-8.17 Dec 13, 2023
@TheoWinterhalter TheoWinterhalter deleted the typed-extraction-integration branch December 13, 2023 16:34
@4ever2
Copy link
Contributor

4ever2 commented Jun 17, 2024

@mattam82 could you please elaborate a bit on what these changes to the valid masks are?

This PR breaks all our extraction examples in https://github.com/AU-COBRA/coq-elm-extraction and https://github.com/AU-COBRA/coq-rust-extraction when both the do_trim_ctor_masks and check_valid_masks flags are set to true in dearg_transform.

Those examples worked before and it is not clear to me if it is a bug or that is the expected behaviour after this PR.

@spitters
Copy link

spitters commented Sep 3, 2024

@mattam82 pinging this issue, so it does not become stale...

@mattam82
Copy link
Member Author

mattam82 commented Oct 8, 2024

IIRC, I changed the default value of do_trim_ctor_masks as otherwise the valid mask check was always failing for me, but I might be wrong. In any case, we should probably make this configurable for the whole pipeline to debug this issue.

@mattam82
Copy link
Member Author

mattam82 commented Oct 8, 2024

The relevant part of the new invariant is this:


Definition check_oib_masks masks i oib :=
  forallbi (fun c cb => #|get_branch_mask masks i c| == cb.2) 0 oib.(ind_ctors) &&
  match oib.(ind_projs) with
  | [] => true
  | _ :: _ =>
    let mask := get_branch_mask masks i 0 in
    #|mask| == #|oib.(ind_projs)|
  end.

I guess previously we didn't consider primitive projections, but they have to be masked if some arguments are removed (and hence some projections are not defined anymore).

@4ever2
Copy link
Contributor

4ever2 commented Nov 12, 2024

Thanks for the help. I see now why it doesn't work anymore, the new check that you added to check_valid_masks assumes that the length of the masks will be equal to the number of constructor arguments. However, do_trim_ctor_masks trims trailing false values in the masks so when enabled the assumption might be broken.

I suppose we should change the check in check_oib_masks to <= instead or document that the two flags are incompatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants