@@ -553,14 +553,13 @@ let declare_proj_coercion_instance ~flags ref from =
553553
554554(* Collects elimination constraints from other projections that might be referenced
555555 * in the type of the current projection being built.
556- * elim_cstrs_map keeps the mapping of (field name -> elim constraints) *)
556+ * elim_cstrs_map keeps the mapping of (projection constant -> elim constraints) *)
557557let collect_elim_cstrs elim_cstrs_map proj_type =
558558 let open Sorts in
559559 let rec aux_fold elim_cstrs c =
560560 match Constr. kind c with
561561 | Const (c , _ ) -> (
562- let label = Constant. label c in
563- match Id.Map. find_opt label elim_cstrs_map with
562+ match Cmap_env. find_opt c elim_cstrs_map with
564563 | None -> elim_cstrs
565564 | Some c_elim_cstrs -> ElimConstraints. union elim_cstrs c_elim_cstrs)
566565 | _ -> Constr. fold aux_fold elim_cstrs c
@@ -569,10 +568,10 @@ let collect_elim_cstrs elim_cstrs_map proj_type =
569568
570569(* Checks whether the record's quality can be eliminated into the projection's
571570 quality. If not, then it adds the elimination constraint. *)
572- let check_add_elimination_constraints ~primitive (entry , binders as univs ) fld_id elim_cstrs_map record_quality proj_typ =
571+ let check_add_elimination_constraints ~primitive (entry , binders as univs ) elim_cstrs_map record_quality proj_typ =
573572 (* When the record has primitive projections, then the constraints are added to the record itself,
574573 * not to the projections *)
575- if primitive then univs, elim_cstrs_map
574+ if primitive then univs, None
576575 else
577576 let env = Global. env () in
578577 let evd = Evd. from_env env in
@@ -581,9 +580,9 @@ let check_add_elimination_constraints ~primitive (entry, binders as univs) fld_i
581580 let qgraph = Environ. qualities env in
582581 let qgraph = try add_quality record_quality qgraph with AlreadyDeclared -> qgraph in
583582 let qgraph = try add_quality proj_quality qgraph with AlreadyDeclared -> qgraph in
584- if eliminates_to qgraph record_quality proj_quality then univs, elim_cstrs_map
583+ if eliminates_to qgraph record_quality proj_quality then univs, None
585584 else
586- let entry, elim_cstrs_map' = match entry with
585+ let entry, new_field_elim_cstrs = match entry with
587586 | UState. Polymorphic_entry uctx ->
588587 let open Sorts in
589588 let new_elim_cstr = record_quality, ElimConstraint. ElimTo , proj_quality in
@@ -592,10 +591,10 @@ let check_add_elimination_constraints ~primitive (entry, binders as univs) fld_i
592591 let elim_cstrs' = ElimConstraints. add new_elim_cstr elim_cstrs in
593592 let elim_cstrs' = ElimConstraints. union related_elim_cstrs elim_cstrs' in
594593 let uctx' = UVars.UContext. make (UVars.UContext. names uctx) (UVars.UContext. instance uctx, (elim_cstrs', univ_cstrs)) in
595- UState. Polymorphic_entry uctx', Id.Map. add fld_id elim_cstrs' elim_cstrs_map
596- | _ -> entry, elim_cstrs_map
594+ UState. Polymorphic_entry uctx', Some elim_cstrs'
595+ | _ -> entry, None
597596 in
598- (entry, binders), elim_cstrs_map'
597+ (entry, binders), new_field_elim_cstrs
599598
600599(* TODO: refactor the declaration part here; this requires some
601600 surgery as Evarutil.finalize is called too early in the path *)
@@ -627,12 +626,12 @@ let build_named_proj ~primitive ~flags ~univs ~uinstance ~kind env paramdecls
627626 in
628627 let proj = it_mkLambda_or_LetIn (mkLambda (x, rp, body)) paramdecls in
629628 let proj_typ = it_mkProd_or_LetIn (mkProd (x, rp, ccl)) paramdecls in
630- let univs, elim_cstrs_map =
629+ let univs, new_field_elim_cstrs =
631630 match decl with
632631 (* A local def might need previous elim constraints but it doesn't introduce new ones *)
633- | LocalDef _ -> univs, elim_cstrs_map
632+ | LocalDef _ -> univs, None
634633 | LocalAssum _ ->
635- check_add_elimination_constraints ~primitive univs fid elim_cstrs_map
634+ check_add_elimination_constraints ~primitive univs elim_cstrs_map
636635 record_quality proj_typ
637636 in
638637 let entry = Declare. definition_entry ~univs ~types: proj_typ proj in
@@ -644,6 +643,10 @@ let build_named_proj ~primitive ~flags ~univs ~uinstance ~kind env paramdecls
644643 let _, info = Exninfo. capture exn in
645644 Exninfo. iraise (NotDefinable (BadTypedProj (fid,ctx,te)),info)
646645 in
646+ let elim_cstrs_map = match new_field_elim_cstrs with
647+ | None -> elim_cstrs_map
648+ | Some elim_cstrs -> Cmap_env. add kn elim_cstrs elim_cstrs_map
649+ in
647650 Declare. definition_message fid;
648651 let term = match p_opt with
649652 | Some (p ,r ) ->
@@ -703,7 +706,7 @@ let declare_projections indsp ~kind ~inhabitant_id flags ?fieldlocs fieldimpls =
703706 | Polymorphic auctx -> UState. Polymorphic_entry (UVars.AbstractContext. repr auctx)
704707 in
705708 let univs = univs, UnivNames. empty_binders in
706- let elim_cstrs_map : Sorts.ElimConstraints.t Id.Map.t = Id.Map . empty in
709+ let elim_cstrs_map = Cmap_env . empty in
707710 let record_quality = Sorts. quality mip.mind_sort in
708711 let fields, _ = mip.mind_nf_lc.(0 ) in
709712 let fields = List. firstn mip.mind_consnrealdecls.(0 ) fields in
0 commit comments