+
+(* check_metasenv_consistency checks that the "canonical" context of a
+metavariable is consitent - up to relocation via the relocation list l -
+with the actual context *)
+
+and check_metasenv_consistency metasenv context canonical_context l =
+ let module C = Cic in
+ let module R = CicReduction in
+ let module S = CicSubstitution in
+ let lifted_canonical_context =
+ let rec aux i =
+ function
+ [] -> []
+ | (Some (n,C.Decl t))::tl ->
+ (Some (n,C.Decl (S.lift_meta l (S.lift i t))))::(aux (i+1) tl)
+ | (Some (n,C.Def t))::tl ->
+ (Some (n,C.Def (S.lift_meta l (S.lift i t))))::(aux (i+1) tl)
+ | None::tl -> None::(aux (i+1) tl)
+ in
+ aux 1 canonical_context
+ in
+ List.iter2
+ (fun t ct ->
+ let res =
+ match (t,ct) with
+ _,None -> true
+ | Some t,Some (_,C.Def ct) ->
+ R.are_convertible context t ct
+ | Some t,Some (_,C.Decl ct) ->
+ R.are_convertible context (type_of_aux' metasenv context t) ct
+ | _, _ -> false
+ in
+ if not res then raise MetasenvInconsistency
+ ) l lifted_canonical_context
+