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

unification stack overflows in trivial cases #12557

Open
JasonGross opened this issue Jun 21, 2020 · 3 comments
Open

unification stack overflows in trivial cases #12557

JasonGross opened this issue Jun 21, 2020 · 3 comments
Labels
kind: bug An error, flaw, fault or unintended behaviour. part: unification The unification mechanism.

Comments

@JasonGross
Copy link
Member

Description of the problem

Notation unwrap_refl o :=
  ((fun v (pf : o = Some v) => v) _ eq_refl) (only parsing).

Check unwrap_refl (option_map S (Some 0)).
Check unwrap_refl (option_map _ (Some 0)). (* Error: Stack overflow. *)
Check unwrap_refl (option_map S (Some _)). (* Error: Stack overflow. *)

Coq Version

8.11.1

@ejgallego
Copy link
Member

See the backtrace in #12558 for more information, some kind of cycle seems to be created.

@herbelin
Copy link
Member

A shorter example is:

Check ((fun (v : nat) (pf : S (?[f] 0) = S v :> nat) => v) ?[x] eq_refl).

The occur-check in Evarsolve.occur_evar_upto_types is too weak. It accepts the circularity ?x := ?f[v:=?x] 0.

It is not bad that it accepts this circularity, because this is an erasable circularity. For instance ?f[v] := fun _ => v would be an ok solution. But it is bad that it accepts it w/o first restricting the problem to its valid solutions.

Possible strategies:

  • to postpone
  • to restrict ?f to remove the dependency in v:=?x (but possibly loosing solutions)
  • to refine the problem, making a disjunction on either depending on ?x and seeing that there is then no other choice than ?f:=fun _ => v or restricting. Indeed, IINM, the problem has two disjoint most general solutions which cannot be discriminated anyway:
    • ?f[v] := fun _ => v and ?x unresolved
    • ?f[v] := ?f' and ?x := ?f' 0 for unresolved restriction ?f' of ?f

A way to implement this would be to absorb the argument 0 (with evar_absorb_arguments) and to send the problem to solve_evar_evar. In general, this should be done with care because it loses information on when to apply the 1st order unification heuristics, but in a solve_simple_eqn case like ?x = ?y args this seems ok.

@Janno
Copy link
Contributor

Janno commented Jun 22, 2020

I noticed that the example does not crash when using Unicoq. It might be worth looking into what their solution is.

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. part: unification The unification mechanism.
Projects
None yet
Development

No branches or pull requests

4 participants