Skip to content

Commit

Permalink
Statically ensure that all TC evars are a subset of undefined evars.
Browse files Browse the repository at this point in the history
The Evd.set_typeclass_evars primitive was making the assumption that all
callers were respecting this invariant. Rather than exporting an unsafe API
that can mess with the expected invariants of the evarmap data structure,
we simply check at runtime that all evar arguments are indeed undefined.

Fixes coq#19587: Error: Anomaly "Uncaught exception Not_found."
  • Loading branch information
ppedrot committed Sep 24, 2024
1 parent fe26a71 commit 0a3cda8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions engine/evd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ let get_typeclass_evars evd = evd.evar_flags.typeclass_evars

let set_typeclass_evars evd tcs =
let flags = evd.evar_flags in
let tcs = Evar.Set.filter (fun evk -> Evar.Map.mem evk evd.undf_evars) tcs in
{ evd with evar_flags = { flags with typeclass_evars = tcs } }

let is_typeclass_evar evd evk =
Expand Down
31 changes: 31 additions & 0 deletions test-suite/bugs/bug_19587.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Require Import Coq.Setoids.Setoid Coq.Classes.Morphisms.

Class ring α := { rng_zero : α; }.
Class field := { }.

Parameter lap_eq : forall {α} {r : ring α}, list α -> list α -> Prop.

Declare Instance lap_eq_equiv : forall {α} {r : ring α}, Equivalence lap_eq.

Axiom lap_eq_0 : forall (α : Type) (r : ring α), lap_eq (cons rng_zero nil) nil.

Definition puiseux_series (α : Type) := nat -> α.

Definition ps_zero {α} {r : ring α} : puiseux_series α := fun i => rng_zero.

Definition ps_ring α (R : ring α) (K : field) : ring (puiseux_series α) :=
{| rng_zero := ps_zero; |}.

Canonical Structure ps_ring.

Theorem glop : forall
(α : Type) (R : ring α) (K : field),
@lap_eq (puiseux_series α) (@ps_ring α R K)
(@cons (puiseux_series α) (@ps_zero α R) (@nil (puiseux_series α)))
nil.
Proof.
intros.
Check 1%nat.
rewrite lap_eq_0.
Check 1%nat.
Abort.

0 comments on commit 0a3cda8

Please sign in to comment.