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

coqnative anomaly on complicated fixpoint generated by Equations #19986

Open
jpoiret opened this issue Jan 6, 2025 · 1 comment
Open

coqnative anomaly on complicated fixpoint generated by Equations #19986

jpoiret opened this issue Jan 6, 2025 · 1 comment
Labels
kind: bug An error, flaw, fault or unintended behaviour. needs: triage The validity of this issue needs to be checked, or the issue itself updated.

Comments

@jpoiret
Copy link

jpoiret commented Jan 6, 2025

Description of the problem

The issues/issue74.v file of Equations fails to compile with coqnative, raising the following anomaly:

Error: Anomaly "Uncaught exception Invalid_argument("index out of bounds")."
Please report at http://coq.inria.fr/bugs/.

A quick ocamldebug suggests this comes from

let reci = MLlocal (paramsi.(rec_pos.(i))) in
, with paramsi being empty.

Small Rocq / Coq file to reproduce the bug

From Stdlib.Lists Require Import List.
From Equations Require Import Equations.
Import ListNotations.

Inductive foo: Set :=
| Foo1 : list foo -> foo
| Foo2 : list foo -> foo.

Equations f (x: foo) : nat := {
  f (Foo1 l) := aux1 l;
  f (Foo2 l) := aux2 l
}

where aux1 (l : list foo) : nat := {
  aux1 [] := 1;
  aux1 (cons hd tl) := f hd + aux1 tl + aux2 tl }

where aux2 (l : list foo) : nat := {
  aux2 [] := 1;
  aux2 (cons hd tl) := f hd + aux1 tl + aux2 tl }.

Definition check := f_elim.

Eval native_compute in f_elim.

Version of Rocq / Coq where this bug occurs

8.20.0,master

Last version of Rocq / Coq where the bug did not occur

No response

@jpoiret jpoiret added kind: bug An error, flaw, fault or unintended behaviour. needs: triage The validity of this issue needs to be checked, or the issue itself updated. labels Jan 6, 2025
@ppedrot
Copy link
Member

ppedrot commented Jan 15, 2025

It seems that equations generates a fix point whose body is not η-expanded, wreaking havoc with the expected invariants of the native compiler. The latter allows a fix body to start with a telescope which may contain let binders, but at the very least it needs to be have at least as many function binders as the struct position. This looks like a reasonable assumption to me but the kernel typing is more lenient it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug An error, flaw, fault or unintended behaviour. needs: triage The validity of this issue needs to be checked, or the issue itself updated.
Projects
None yet
Development

No branches or pull requests

2 participants