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

Use elpi.derive instead of "Scheme Equality" #1052

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Use elpi.derive instead of "Scheme Equality" #1052

wants to merge 1 commit into from

Conversation

eponier
Copy link
Contributor

@eponier eponier commented Feb 14, 2025

elpi.derive is much faster on inductives with many constructors. This is particularly interesting for type x86_op which has more than 100 constructors.

elpi.derive is much faster on inductives with many constructors. This is
particularly interesting for type x86_op which has more than 100
constructors.
@eponier
Copy link
Contributor Author

eponier commented Feb 14, 2025

There are currently a few caveats:

  • it does not work with coq.8.19 and coq-elpi 2.2.3 (it works for previous and next versions, so looks like a bug upstream); EDIT: the culprit seems to be coq-elpi.2.2.x
  • Scheme Equality has a specific impact on injection (there is a note about it in the Coq doc (I cannot put a link directly to the note, it is a bit below where the link points to)). We may want to keep Scheme Equality for wsize. to reduce the number of changes in this PR.
  • there is an option module to put all what is generated by derive inside a module. I used it for stype because there was a name clash with is_sbool. But it has impact on the extracted code, so maybe this was not the right choice (I think is_sbool is not even used, so maybe the right thing to do is just to remove it).
  • we have new warnings in the extracted OCaml code because derive generates recursive functions that are not actually recursive. There are two problems here:
    • derive should not generate fake recursive functions, but this should be fixed upstream
    • do we really want to extract these functions? (after a bit of thought, maybe they are used by eqb functions that we need, so we have no choice)
  • importing derive.std hides Datatypes.is_true; nothing problematic here, it is just painful

@@ -15,6 +15,7 @@
-arg "-w -deprecated-since-mathcomp-2.3.0"
-arg "-w -deprecated-from-Coq"
-arg "-w -deprecated-dirpath-Coq"
-arg "-async-proofs off"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, should not be there.

; call_xreg_ret := [::]
; call_reg_ret_uniq := erefl true;
|}.
Definition riscv_linux_call_conv : calling_convention :=
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated fix. The comment was not true anymore.

@@ -105,19 +107,15 @@ End CmpR.
Module Mr := Mmake CmpR.

(* ------------------------------------------------------------------ *)
#[only(eqbOK)] derive Z.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to move that elsewhere. In utils?

@@ -176,6 +176,11 @@ Section PROOF.
end.
Qed.

Lemma cons_inj {A} {x1 x2 : A} (s1 s2 : seq A) :
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to move this to utils.

@@ -147,7 +143,7 @@ Module CEDecStype.
| sword w1 =>
match t2 as t0 return {sword w1 = t0} + {True} with
| sword w2 =>
match wsize_eq_dec w1 w2 with
match Bool.reflect_dec _ _ (wsize_eqb_OK w1 w2) with
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, I reintroduced wsize_eq_dec so this change is not needed.

@@ -169,7 +167,7 @@ Module CEDecStype.
+ case: pos_dec (@pos_dec_r n n' I) => [Heq _ | [] neq ] //=.
move => _; apply/eqP => -[].
by move/eqP: (neq erefl).
case: wsize_eq_dec => // eqw.
case: Bool.reflect_dec => // eqw.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

move=> [?]; subst v.
case: ves => [// | ? []]; last by t_xrbindP.
apply: rbindP => v /=.
apply: rbindP => _ -> [->] /ok_inj /(f_equal (head (Vbool true))) /= /Vword_inj [?]; subst ws''.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use cons_inv instead

move=> [?]; subst v.
case: ves => [// | ? []]; last by t_xrbindP.
apply: rbindP => v /=.
apply: rbindP => _ -> [->] /ok_inj /(f_equal (head (Vbool true))) /= /Vword_inj [?]; subst ws''.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@eponier
Copy link
Contributor Author

eponier commented Feb 18, 2025

Note to self: it seems we can remove eq_axiom_of_scheme.

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.

1 participant