| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Names |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
let global_env_summary_name = "Global environment" |
| 17 |
|
| 18 |
module GlobalSafeEnv : sig |
| 19 |
|
| 20 |
val safe_env : unit -> Safe_typing.safe_environment |
| 21 |
val set_safe_env : Safe_typing.safe_environment -> unit |
| 22 |
val is_joined_environment : unit -> bool |
| 23 |
val is_curmod_library : unit -> bool |
| 24 |
val global_env_summary_tag : Safe_typing.safe_environment Summary.Dyn.tag |
| 25 |
|
| 26 |
end = struct |
| 27 |
|
| 28 |
let global_env, global_env_summary_tag = |
| 29 |
Summary.ref_tag ~name:global_env_summary_name Safe_typing.empty_environment |
| 30 |
|
| 31 |
let is_joined_environment () = |
| 32 |
Safe_typing.is_joined_environment !global_env |
| 33 |
|
| 34 |
let is_curmod_library () = |
| 35 |
Safe_typing.is_curmod_library !global_env |
| 36 |
|
| 37 |
let assert_not_synterp () = |
| 38 |
if !Flags.in_synterp_phase = Some true then |
| 39 |
CErrors.anomaly ( |
| 40 |
Pp.strbrk"The global environment cannot be accessed during the syntactic interpretation phase.") |
| 41 |
|
| 42 |
let safe_env () = assert_not_synterp(); !global_env |
| 43 |
|
| 44 |
let set_safe_env e = global_env := e |
| 45 |
|
| 46 |
end |
| 47 |
|
| 48 |
let global_env_summary_tag = GlobalSafeEnv.global_env_summary_tag |
| 49 |
|
| 50 |
let safe_env = GlobalSafeEnv.safe_env |
| 51 |
let is_joined_environment = GlobalSafeEnv.is_joined_environment |
| 52 |
let is_curmod_library = GlobalSafeEnv.is_curmod_library |
| 53 |
|
| 54 |
let env () = Safe_typing.env_of_safe_env (safe_env ()) |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
let prof f () = |
| 59 |
NewProfile.profile "kernel" f () |
| 60 |
|
| 61 |
let globalize0 f = prof (fun () -> GlobalSafeEnv.set_safe_env (f (safe_env ()))) () |
| 62 |
|
| 63 |
let globalize f = |
| 64 |
prof (fun () -> |
| 65 |
let res,env = f (safe_env ()) in GlobalSafeEnv.set_safe_env env; res) |
| 66 |
() |
| 67 |
|
| 68 |
let globalize0_with_summary fs f = |
| 69 |
let env = prof (fun () -> f (safe_env ())) () in |
| 70 |
Summary.Interp.unfreeze_summaries fs; |
| 71 |
GlobalSafeEnv.set_safe_env env |
| 72 |
|
| 73 |
let globalize_with_summary fs f = |
| 74 |
let res,env = prof (fun () -> f (safe_env ())) () in |
| 75 |
Summary.Interp.unfreeze_summaries fs; |
| 76 |
GlobalSafeEnv.set_safe_env env; |
| 77 |
res |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
let push_named_assum a = globalize0 (Safe_typing.push_named_assum a) |
| 82 |
let push_named_def d = globalize0 (Safe_typing.push_named_def d) |
| 83 |
let push_section_context c = globalize0 (Safe_typing.push_section_context c) |
| 84 |
let add_univ_constraints c = globalize0 (Safe_typing.push_context_set ~strict:true (Univ.Level.Set.empty, c)) |
| 85 |
let push_context_set c = globalize0 (Safe_typing.push_context_set ~strict:true c) |
| 86 |
let push_qualities ~rigid c = globalize0 (Safe_typing.push_qualities ~rigid c) |
| 87 |
|
| 88 |
let set_impredicative_set c = globalize0 (Safe_typing.set_impredicative_set c) |
| 89 |
let set_indices_matter b = globalize0 (Safe_typing.set_indices_matter b) |
| 90 |
let set_typing_flags c = globalize0 (Safe_typing.set_typing_flags c) |
| 91 |
let set_check_guarded c = globalize0 (Safe_typing.set_check_guarded c) |
| 92 |
let set_check_positive c = globalize0 (Safe_typing.set_check_positive c) |
| 93 |
let set_check_universes c = globalize0 (Safe_typing.set_check_universes c) |
| 94 |
let typing_flags () = Environ.typing_flags (env ()) |
| 95 |
let set_allow_sprop b = globalize0 (Safe_typing.set_allow_sprop b) |
| 96 |
let sprop_allowed () = Environ.sprop_allowed (env()) |
| 97 |
let set_rewrite_rules_allowed b = globalize0 (Safe_typing.set_rewrite_rules_allowed b) |
| 98 |
let rewrite_rules_allowed () = Environ.rewrite_rules_allowed (env()) |
| 99 |
let export_private_constants cd = globalize (Safe_typing.export_private_constants cd) |
| 100 |
let add_constant ?typing_flags id d = globalize (Safe_typing.add_constant ?typing_flags id d) |
| 101 |
let fill_opaque c = globalize0 (Safe_typing.fill_opaque c) |
| 102 |
let add_rewrite_rules id c = globalize0 (Safe_typing.add_rewrite_rules id c) |
| 103 |
let add_mind ?typing_flags id mie = globalize (Safe_typing.add_mind ?typing_flags id mie) |
| 104 |
let add_modtype id me inl = globalize (Safe_typing.add_modtype id me inl) |
| 105 |
let add_module id me inl = globalize (Safe_typing.add_module id me inl) |
| 106 |
let add_include me ismod inl = globalize (Safe_typing.add_include me ismod inl) |
| 107 |
|
| 108 |
let open_section () = globalize0 Safe_typing.open_section |
| 109 |
let close_section fs = globalize0_with_summary fs Safe_typing.close_section |
| 110 |
let sections_are_opened () = Safe_typing.sections_are_opened (safe_env()) |
| 111 |
|
| 112 |
let sections () = Safe_typing.sections_of_safe_env @@ safe_env () |
| 113 |
|
| 114 |
let force_sections () = match sections() with |
| 115 |
| Some s -> s |
| 116 |
| None -> |
| 117 |
|
| 118 |
CErrors.user_err Pp.(str "No open section.") |
| 119 |
|
| 120 |
let section_segment_of_constant con = |
| 121 |
Section.segment_of_constant con (force_sections ()) |
| 122 |
|
| 123 |
let section_segment_of_inductive kn = |
| 124 |
Section.segment_of_inductive kn (force_sections ()) |
| 125 |
|
| 126 |
let section_segment_of_reference = let open GlobRef in function |
| 127 |
| ConstRef c -> section_segment_of_constant c |
| 128 |
| IndRef (kn,_) | ConstructRef ((kn,_),_) -> |
| 129 |
section_segment_of_inductive kn |
| 130 |
| VarRef _ -> Cooking.empty_cooking_info |
| 131 |
|
| 132 |
let is_in_section ref = match sections () with |
| 133 |
| None -> false |
| 134 |
| Some sec -> |
| 135 |
Section.is_in_section (env ()) ref sec |
| 136 |
|
| 137 |
let section_instance ref = |
| 138 |
Cooking.instance_of_cooking_info (section_segment_of_reference ref) |
| 139 |
|
| 140 |
let discharge_section_proj_repr p = |
| 141 |
let ind = Projection.Repr.inductive p in |
| 142 |
let sec = section_segment_of_reference (GlobRef.IndRef ind) in |
| 143 |
Cooking.discharge_proj_repr sec p |
| 144 |
|
| 145 |
let discharge_proj_repr p = |
| 146 |
if is_in_section (Names.GlobRef.IndRef (Names.Projection.Repr.inductive p)) then |
| 147 |
discharge_section_proj_repr p |
| 148 |
else |
| 149 |
p |
| 150 |
|
| 151 |
let start_module id = globalize (Safe_typing.start_module id) |
| 152 |
let start_modtype id = globalize (Safe_typing.start_modtype id) |
| 153 |
|
| 154 |
let end_module fs id mtyo = |
| 155 |
globalize_with_summary fs (Safe_typing.end_module id mtyo) |
| 156 |
|
| 157 |
let end_modtype fs id = |
| 158 |
globalize_with_summary fs (Safe_typing.end_modtype id) |
| 159 |
|
| 160 |
let add_module_parameter mbid mte inl = |
| 161 |
globalize (Safe_typing.add_module_parameter mbid mte inl) |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
let universes () = Environ.universes (env()) |
| 166 |
let qualities () = Environ.qvars (env()) |
| 167 |
let elim_graph () = Environ.qualities (env()) |
| 168 |
let named_context () = Environ.named_context (env()) |
| 169 |
let named_context_val () = Environ.named_context_val (env()) |
| 170 |
|
| 171 |
let lookup_named id = Environ.lookup_named id (env()) |
| 172 |
let lookup_constant kn = Environ.lookup_constant kn (env()) |
| 173 |
let lookup_inductive ind = Inductive.lookup_mind_specif (env()) ind |
| 174 |
let lookup_pinductive (ind,_) = Inductive.lookup_mind_specif (env()) ind |
| 175 |
let lookup_mind kn = Environ.lookup_mind kn (env()) |
| 176 |
|
| 177 |
let lookup_module mp = Environ.lookup_module mp (env()) |
| 178 |
let lookup_modtype kn = Environ.lookup_modtype kn (env()) |
| 179 |
|
| 180 |
let exists_objlabel id = Safe_typing.exists_objlabel id (safe_env ()) |
| 181 |
|
| 182 |
type indirect_accessor = { |
| 183 |
access_proof : Opaqueproof.opaque -> Opaqueproof.opaque_proofterm option; |
| 184 |
} |
| 185 |
|
| 186 |
let force_proof access o = match access.access_proof o with |
| 187 |
| None -> CErrors.user_err Pp.(str "Cannot access opaque delayed proof") |
| 188 |
| Some (c, u) -> (c, u) |
| 189 |
|
| 190 |
let body_of_constant_body access cb = |
| 191 |
let open Declarations in |
| 192 |
match cb.const_body with |
| 193 |
| Undef _ | Primitive _ | Symbol _ -> |
| 194 |
None |
| 195 |
| Def c -> |
| 196 |
let u = match cb.const_universes with |
| 197 |
| Monomorphic -> Opaqueproof.PrivateMonomorphic () |
| 198 |
| Polymorphic auctx -> Opaqueproof.PrivatePolymorphic Univ.ContextSet.empty |
| 199 |
in |
| 200 |
Some (c, u, Declareops.constant_polymorphic_context cb) |
| 201 |
| OpaqueDef o -> |
| 202 |
let c, u = force_proof access o in |
| 203 |
Some (c, u, Declareops.constant_polymorphic_context cb) |
| 204 |
|
| 205 |
let body_of_constant access cst = body_of_constant_body access (lookup_constant cst) |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
let constant_of_delta_kn kn = |
| 210 |
Safe_typing.constant_of_delta_kn_senv (safe_env ()) kn |
| 211 |
|
| 212 |
let mind_of_delta_kn kn = |
| 213 |
Safe_typing.mind_of_delta_kn_senv (safe_env ()) kn |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
let start_library dir = globalize (Safe_typing.start_library dir) |
| 218 |
let export ~output_native_objects s = |
| 219 |
Safe_typing.export ~output_native_objects (safe_env ()) s |
| 220 |
let import c t d = globalize (Safe_typing.import c t d) |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
let env_of_context hyps = |
| 226 |
Environ.reset_with_named_context hyps (env()) |
| 227 |
|
| 228 |
let is_polymorphic r = |
| 229 |
Environ.is_polymorphic (env()) r |
| 230 |
|
| 231 |
let is_template_polymorphic r = |
| 232 |
Environ.is_template_polymorphic (env ()) r |
| 233 |
|
| 234 |
let is_type_in_type r = |
| 235 |
Environ.is_type_in_type (env ()) r |
| 236 |
|
| 237 |
let current_modpath () = |
| 238 |
Safe_typing.current_modpath (safe_env ()) |
| 239 |
|
| 240 |
let current_dirpath () = |
| 241 |
Safe_typing.current_dirpath (safe_env ()) |
| 242 |
|
| 243 |
let register_inline c = globalize0 (Safe_typing.register_inline c) |
| 244 |
let register_inductive c r = globalize0 (Safe_typing.register_inductive c r) |
| 245 |
|
| 246 |
let set_strategy k l = |
| 247 |
globalize0 (Safe_typing.set_strategy k l) |
| 248 |
|
| 249 |
let set_share_reduction b = |
| 250 |
globalize0 (Safe_typing.set_share_reduction b) |
| 251 |
|
| 252 |
let set_VM b = globalize0 (Safe_typing.set_VM b) |
| 253 |
let set_native_compiler b = globalize0 (Safe_typing.set_native_compiler b) |
| 254 |
|
| 255 |
module Internal = |
| 256 |
struct |
| 257 |
|
| 258 |
let reset_safe_env = GlobalSafeEnv.set_safe_env |
| 259 |
|
| 260 |
end |