Skip to content

Commit

Permalink
hconstr don't use push_unknown_rel for matches
Browse files Browse the repository at this point in the history
  • Loading branch information
SkySkimmer committed Jul 26, 2024
1 parent a09b311 commit 6519bec
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions kernel/hConstr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ module Tbl = struct
end

type local_env = {
(* only used for globals, rel context is not correct *)
globals : Environ.env;
(* unique identifiers for each binder crossed *)
rels : int Range.t;
(* global counter *)
Expand All @@ -120,14 +122,16 @@ type local_env = {
letin_uids : int Tbl.t Tbl.t;
}

let empty_env () = {
let empty_env env = {
globals = env;
rels = Range.empty;
cnt = ref 0;
unknown_cnt = ref 0;
assum_uids = Tbl.create 47;
letin_uids = Tbl.create 47;
}

(* still used in fixpoint *)
let push_unknown_rel env =
incr env.cnt;
incr env.unknown_cnt;
Expand Down Expand Up @@ -172,6 +176,12 @@ let push_letin ~body ~typ env =
in
{ env with rels = Range.cons uid env.rels }

module RelDecl = Context.Rel.Declaration

let push_decl d env = match d with
| RelDecl.LocalAssum (_,t) -> push_assum t env
| RelDecl.LocalDef (_,body,typ) -> push_letin ~body ~typ env

let hash_annot = hash_annot Name.hash

let hash_array hashf a = Array.fold_left (fun hash x -> Hashset.Combine.combine hash (hashf x)) 0 a
Expand Down Expand Up @@ -337,22 +347,29 @@ and of_constr_aux tbl local_env c =
let u = UVars.Instance.hcons u in
Construct (c,u)
| Case (ci,u,pms,(p,r),iv,c,bl) ->
let of_ctx (bnd, c) =
let p', bl' =
let mib, mip = Inductive.lookup_mind_specif local_env.globals ci.ci_ind in
let (_, (p,_), _, _, bl) = Inductive.expand_case_specif mib (ci,u,pms,(p,r),iv,c,bl) in
let p = Term.decompose_lambda_n_decls (mip.Declarations.mind_nrealdecls + 1) p in
let bl = Array.map2 Term.decompose_lambda_n_decls ci.ci_cstr_ndecls bl in
p, bl
in
let of_ctx (bnd, c) (bnd', _) =
let () = hcons_inplace hcons_annot bnd in
let local_env = Array.fold_left (fun local_env _ -> push_unknown_rel local_env) local_env bnd in
let local_env = push_rel_context tbl local_env bnd' in
let c = of_constr tbl local_env c in
bnd, c
in
let ci = hcons_caseinfo ci in
let u = UVars.Instance.hcons u in
let pms = Array.map (of_constr tbl local_env) pms in
let p = of_ctx p in
let p = of_ctx p p' in
let iv = match iv with
| NoInvert -> NoInvert
| CaseInvert {indices} -> CaseInvert {indices=Array.map (of_constr tbl local_env) indices}
in
let c = of_constr tbl local_env c in
let bl = Array.map of_ctx bl in
let bl = Array.map2 of_ctx bl bl' in
Case (ci,u,pms,(p,r),iv,c,bl)
| Fix (ln,(lna,tl,bl)) ->
let () = hcons_inplace hcons_annot lna in
Expand Down Expand Up @@ -380,6 +397,13 @@ and of_constr_aux tbl local_env c =
let ty = of_constr tbl local_env ty in
Array (u,t,def,ty)

and push_rel_context tbl local_env ctx =
List.fold_right (fun d local_env ->
let d = RelDecl.map_constr_het (fun r -> r) (of_constr tbl local_env) d in
push_decl d local_env)
ctx
local_env

let dbg = CDebug.create ~name:"hconstr" ()

let tree_size c =
Expand All @@ -389,7 +413,7 @@ let tree_size c =
aux 0 c

let of_constr env c =
let local_env = empty_env () in
let local_env = empty_env env in
let local_env = iterate push_unknown_rel (Environ.nb_rel env) local_env in
let tbl = Tbl.create 57 in
let c = of_constr tbl local_env c in
Expand Down

0 comments on commit 6519bec

Please sign in to comment.