Equations
Equations
@[inline]
Equations
@[extern lean_compacted_region_is_memory_mapped]
@[extern lean_compacted_region_free]
- imports : Array Lean.Import
- constants : Array Lean.ConstantInfo
- entries : Array (Lean.Name × Array Lean.EnvExtensionEntry)
Equations
- Lean.instInhabitedModuleData = { default := { imports := default, constants := default, entries := default } }
- trustLevel : UInt32
- quotInit : Bool
- mainModule : Lean.Name
- imports : Array Lean.Import
- regions : Array Lean.CompactedRegion
- moduleNames : Array Lean.Name
- moduleData : Array Lean.ModuleData
Equations
- Lean.instInhabitedEnvironmentHeader = { default := { trustLevel := default, quotInit := default, mainModule := default, imports := default, regions := default, moduleNames := default, moduleData := default } }
- const2ModIdx : Std.HashMap Lean.Name Lean.ModuleIdx
- constants : Lean.ConstMap
- extensions : Array Lean.EnvExtensionState
- header : Lean.EnvironmentHeader
Equations
- Lean.instInhabitedEnvironment = { default := { const2ModIdx := default, constants := default, extensions := default, header := default } }
Equations
- Lean.Environment.addAux env cinfo = { const2ModIdx := env.const2ModIdx, constants := Lean.SMap.insert env.constants (Lean.ConstantInfo.name cinfo) cinfo, extensions := env.extensions, header := env.header }
Equations
- Lean.Environment.find? env n = Lean.SMap.find?' env.constants n
Equations
- Lean.Environment.contains env n = Lean.SMap.contains env.constants n
Equations
- Lean.Environment.imports env = env.header.imports
Equations
- Lean.Environment.allImportedModuleNames env = env.header.moduleNames
Equations
- Lean.Environment.setMainModule env m = { const2ModIdx := env.const2ModIdx, constants := env.constants, extensions := env.extensions, header := let src := env.header; { trustLevel := src.trustLevel, quotInit := src.quotInit, mainModule := m, imports := src.imports, regions := src.regions, moduleNames := src.moduleNames, moduleData := src.moduleData } }
Equations
- Lean.Environment.mainModule env = env.header.mainModule
Equations
- Lean.Environment.getModuleIdxFor? env declName = Std.HashMap.find? env.const2ModIdx declName
Equations
- Lean.Environment.isConstructor env declName = match Lean.Environment.find? env declName with | some (Lean.ConstantInfo.ctorInfo x) => true | x => false
Equations
- Lean.Environment.getModuleIdx? env moduleName = Array.findIdx? env.header.moduleNames fun a => a == moduleName
- unknownConstant: Lean.Environment → Lean.Name → Lean.KernelException
- alreadyDeclared: Lean.Environment → Lean.Name → Lean.KernelException
- declTypeMismatch: Lean.Environment → Lean.Declaration → Lean.Expr → Lean.KernelException
- declHasMVars: Lean.Environment → Lean.Name → Lean.Expr → Lean.KernelException
- declHasFVars: Lean.Environment → Lean.Name → Lean.Expr → Lean.KernelException
- funExpected: Lean.Environment → Lean.LocalContext → Lean.Expr → Lean.KernelException
- typeExpected: Lean.Environment → Lean.LocalContext → Lean.Expr → Lean.KernelException
- letTypeMismatch: Lean.Environment → Lean.LocalContext → Lean.Name → Lean.Expr → Lean.Expr → Lean.KernelException
- exprTypeMismatch: Lean.Environment → Lean.LocalContext → Lean.Expr → Lean.Expr → Lean.KernelException
- appTypeMismatch: Lean.Environment → Lean.LocalContext → Lean.Expr → Lean.Expr → Lean.Expr → Lean.KernelException
- invalidProj: Lean.Environment → Lean.LocalContext → Lean.Expr → Lean.KernelException
- other: String → Lean.KernelException
@[extern lean_add_decl]
@[extern lean_compile_decl]
constant
Lean.Environment.compileDecl
(env : Lean.Environment)
(opt : Lean.Options)
(decl : Lean.Declaration)
:
def
Lean.Environment.addAndCompile
(env : Lean.Environment)
(opt : Lean.Options)
(decl : Lean.Declaration)
:
Equations
- Lean.Environment.addAndCompile env opt decl = do let env ← Lean.Environment.addDecl env decl Lean.Environment.compileDecl env opt decl
- ext : Type → Type
- inhabitedExt : {σ : Type} → Inhabited σ → Inhabited (ext σ)
- registerExt : {σ : Type} → IO σ → IO (ext σ)
- setState : {σ : Type} → ext σ → Lean.Environment → σ → Lean.Environment
- modifyState : {σ : Type} → ext σ → Lean.Environment → (σ → σ) → Lean.Environment
- getState : {σ : Type} → [inst : Inhabited σ] → ext σ → Lean.Environment → σ
- mkInitialExtStates : IO (Array Lean.EnvExtensionState)
- ensureExtensionsSize : Lean.Environment → IO Lean.Environment
Equations
- Lean.instInhabitedEnvExtensionInterface = { default := { ext := id, inhabitedExt := fun {σ} => id, registerExt := fun {σ} mk => mk, setState := fun {σ} x env x => env, modifyState := fun {σ} x env x => env, getState := fun {σ} [Inhabited σ] ext x => ext, mkInitialExtStates := pure #[], ensureExtensionsSize := fun env => pure env } }
instance
Lean.EnvExtensionInterfaceUnsafe.instInhabitedExt
:
{a : Type} → Inhabited (Lean.EnvExtensionInterfaceUnsafe.Ext a)
Equations
- Lean.EnvExtensionInterfaceUnsafe.instInhabitedExt = { default := { idx := default, mkInitial := default } }
Equations
- Lean.EnvExtensionInterfaceUnsafe.ensureExtensionsArraySize env = (fun loop => loop (Array.size env.extensions) env) Lean.EnvExtensionInterfaceUnsafe.ensureExtensionsArraySize.loop
partial def
Lean.EnvExtensionInterfaceUnsafe.ensureExtensionsArraySize.loop
(i : Nat)
(env : Lean.Environment)
:
unsafe def
Lean.EnvExtensionInterfaceUnsafe.setState
{σ : Type}
(ext : Lean.EnvExtensionInterfaceUnsafe.Ext σ)
(env : Lean.Environment)
(s : σ)
:
Equations
- Lean.EnvExtensionInterfaceUnsafe.setState ext env s = if h : ext.idx < Array.size env.extensions then { const2ModIdx := env.const2ModIdx, constants := env.constants, extensions := Array.set env.extensions { val := ext.idx, isLt := h } (unsafeCast s), header := env.header } else panicWithPosWithDecl "Lean.Environment" "Lean.EnvExtensionInterfaceUnsafe.setState" 219 4 Lean.EnvExtensionInterfaceUnsafe.invalidExtMsg
@[inline]
unsafe def
Lean.EnvExtensionInterfaceUnsafe.modifyState
{σ : Type}
(ext : Lean.EnvExtensionInterfaceUnsafe.Ext σ)
(env : Lean.Environment)
(f : σ → σ)
:
Equations
- Lean.EnvExtensionInterfaceUnsafe.modifyState ext env f = if ext.idx < Array.size env.extensions then { const2ModIdx := env.const2ModIdx, constants := env.constants, extensions := Array.modify env.extensions ext.idx fun s => let s := unsafeCast s; let s := f s; unsafeCast s, header := env.header } else panicWithPosWithDecl "Lean.Environment" "Lean.EnvExtensionInterfaceUnsafe.modifyState" 229 4 Lean.EnvExtensionInterfaceUnsafe.invalidExtMsg
unsafe def
Lean.EnvExtensionInterfaceUnsafe.getState
{σ : Type}
[inst : Inhabited σ]
(ext : Lean.EnvExtensionInterfaceUnsafe.Ext σ)
(env : Lean.Environment)
:
σ
Equations
- Lean.EnvExtensionInterfaceUnsafe.getState ext env = if h : ext.idx < Array.size env.extensions then let s := Array.get env.extensions { val := ext.idx, isLt := h }; unsafeCast s else panicWithPosWithDecl "Lean.Environment" "Lean.EnvExtensionInterfaceUnsafe.getState" 236 4 Lean.EnvExtensionInterfaceUnsafe.invalidExtMsg
Equations
- Lean.EnvExtensionInterfaceUnsafe.registerExt mkInitial = do let a ← Lean.initializing let _do_jp : PUnit → IO (Lean.EnvExtensionInterfaceUnsafe.Ext σ) := fun y => do let exts ← ST.Ref.get Lean.EnvExtensionInterfaceUnsafe.envExtensionsRef let idx : Nat := Array.size exts let ext : Lean.EnvExtensionInterfaceUnsafe.Ext σ := { idx := idx, mkInitial := mkInitial } ST.Ref.modify Lean.EnvExtensionInterfaceUnsafe.envExtensionsRef fun exts => Array.push exts (unsafeCast ext) pure ext if a = true then do let y ← pure PUnit.unit _do_jp y else do let y ← throw (IO.userError "failed to register environment, extensions can only be registered during initialization") _do_jp y
Equations
- Lean.EnvExtensionInterfaceUnsafe.mkInitialExtStates = do let exts ← ST.Ref.get Lean.EnvExtensionInterfaceUnsafe.envExtensionsRef Array.mapM (fun ext => ext.mkInitial) exts
Equations
- Lean.EnvExtensionInterfaceUnsafe.imp = { ext := Lean.EnvExtensionInterfaceUnsafe.Ext, inhabitedExt := fun {σ} x => { default := default }, registerExt := fun {σ} => Lean.EnvExtensionInterfaceUnsafe.registerExt, setState := fun {σ} => Lean.EnvExtensionInterfaceUnsafe.setState, modifyState := fun {σ} => Lean.EnvExtensionInterfaceUnsafe.modifyState, getState := fun {σ} [Inhabited σ] => Lean.EnvExtensionInterfaceUnsafe.getState, mkInitialExtStates := Lean.EnvExtensionInterfaceUnsafe.mkInitialExtStates, ensureExtensionsSize := Lean.EnvExtensionInterfaceUnsafe.ensureExtensionsArraySize }
@[implementedBy Lean.EnvExtensionInterfaceUnsafe.imp]
Equations
- Lean.EnvExtension.instInhabitedEnvExtension = Lean.EnvExtensionInterface.inhabitedExt Lean.EnvExtensionInterfaceImp s
def
Lean.EnvExtension.setState
{σ : Type}
(ext : Lean.EnvExtension σ)
(env : Lean.Environment)
(s : σ)
:
Equations
- Lean.EnvExtension.setState ext env s = Lean.EnvExtensionInterface.setState Lean.EnvExtensionInterfaceImp ext env s
def
Lean.EnvExtension.modifyState
{σ : Type}
(ext : Lean.EnvExtension σ)
(env : Lean.Environment)
(f : σ → σ)
:
Equations
def
Lean.EnvExtension.getState
{σ : Type}
[inst : Inhabited σ]
(ext : Lean.EnvExtension σ)
(env : Lean.Environment)
:
σ
Equations
Equations
Equations
- Lean.mkEmptyEnvironment trustLevel = do let initializing ← liftM IO.initializing let _do_jp : PUnit → IO Lean.Environment := fun y => do let exts ← Lean.mkInitialExtensionStates pure { const2ModIdx := ∅, constants := { stage₁ := true, map₁ := ∅, map₂ := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, extensions := exts, header := { trustLevel := trustLevel, quotInit := false, mainModule := default, imports := #[], regions := #[], moduleNames := #[], moduleData := #[] } } if initializing = true then do let y ← throw (IO.userError "environment objects cannot be created during initialization") _do_jp y else do let y ← pure PUnit.unit _do_jp y
@[inline]
Equations
- toEnvExtension : Lean.EnvExtension (Lean.PersistentEnvExtensionState α σ)
- name : Lean.Name
- addImportedFn : Array (Array α) → Lean.ImportM σ
- addEntryFn : σ → β → σ
- exportEntriesFn : σ → Array α
- statsFn : σ → Lean.Format
Equations
- Lean.instInhabitedPersistentEnvExtensionState = { default := { importedEntries := #[], state := default } }
instance
Lean.instInhabitedPersistentEnvExtension
{α : Type}
{β : Type}
{σ : Type}
[inst : Inhabited σ]
:
Inhabited (Lean.PersistentEnvExtension α β σ)
Equations
- Lean.instInhabitedPersistentEnvExtension = { default := { toEnvExtension := default, name := default, addImportedFn := fun x => default, addEntryFn := fun s x => s, exportEntriesFn := fun x => #[], statsFn := fun x => Lean.Format.nil } }
def
Lean.PersistentEnvExtension.getModuleEntries
{α : Type}
{β : Type}
{σ : Type}
[inst : Inhabited σ]
(ext : Lean.PersistentEnvExtension α β σ)
(env : Lean.Environment)
(m : Lean.ModuleIdx)
:
Array α
Equations
- Lean.PersistentEnvExtension.getModuleEntries ext env m = Array.get! (Lean.EnvExtension.getState ext.toEnvExtension env).importedEntries m
def
Lean.PersistentEnvExtension.addEntry
{α : Type}
{β : Type}
{σ : Type}
(ext : Lean.PersistentEnvExtension α β σ)
(env : Lean.Environment)
(b : β)
:
Equations
- Lean.PersistentEnvExtension.addEntry ext env b = Lean.EnvExtension.modifyState ext.toEnvExtension env fun s => let state := Lean.PersistentEnvExtension.addEntryFn ext s.state b; { importedEntries := s.importedEntries, state := state }
def
Lean.PersistentEnvExtension.getState
{α : Type}
{β : Type}
{σ : Type}
[inst : Inhabited σ]
(ext : Lean.PersistentEnvExtension α β σ)
(env : Lean.Environment)
:
σ
Equations
- Lean.PersistentEnvExtension.getState ext env = (Lean.EnvExtension.getState ext.toEnvExtension env).state
def
Lean.PersistentEnvExtension.setState
{α : Type}
{β : Type}
{σ : Type}
(ext : Lean.PersistentEnvExtension α β σ)
(env : Lean.Environment)
(s : σ)
:
Equations
- Lean.PersistentEnvExtension.setState ext env s = Lean.EnvExtension.modifyState ext.toEnvExtension env fun ps => { importedEntries := ps.importedEntries, state := s }
def
Lean.PersistentEnvExtension.modifyState
{α : Type}
{β : Type}
{σ : Type}
(ext : Lean.PersistentEnvExtension α β σ)
(env : Lean.Environment)
(f : σ → σ)
:
Equations
- Lean.PersistentEnvExtension.modifyState ext env f = Lean.EnvExtension.modifyState ext.toEnvExtension env fun ps => { importedEntries := ps.importedEntries, state := f ps.state }
- name : Lean.Name
- mkInitial : IO σ
- addImportedFn : Array (Array α) → Lean.ImportM σ
- addEntryFn : σ → β → σ
- exportEntriesFn : σ → Array α
- statsFn : σ → Lean.Format
unsafe def
Lean.registerPersistentEnvExtensionUnsafe
{α : Type}
{β : Type}
{σ : Type}
[inst : Inhabited σ]
(descr : Lean.PersistentEnvExtensionDescr α β σ)
:
IO (Lean.PersistentEnvExtension α β σ)
Equations
- Lean.registerPersistentEnvExtensionUnsafe descr = do let pExts ← ST.Ref.get Lean.persistentEnvExtensionsRef let _do_jp : PUnit → IO (Lean.PersistentEnvExtension α β σ) := fun y => do let ext ← Lean.registerEnvExtension do let initial ← descr.mkInitial let s : Lean.PersistentEnvExtensionState α σ := { importedEntries := #[], state := initial } pure s let pExt : Lean.PersistentEnvExtension α β σ := { toEnvExtension := ext, name := descr.name, addImportedFn := descr.addImportedFn, addEntryFn := descr.addEntryFn, exportEntriesFn := descr.exportEntriesFn, statsFn := descr.statsFn } ST.Ref.modify Lean.persistentEnvExtensionsRef fun pExts => Array.push pExts (unsafeCast pExt) pure pExt if Array.any pExts (fun ext => ext.name == descr.name) 0 (Array.size pExts) = true then do let y ← throw (IO.userError (toString "invalid environment extension, '" ++ toString descr.name ++ toString "' has already been used")) _do_jp y else do let y ← pure PUnit.unit _do_jp y
@[implementedBy Lean.registerPersistentEnvExtensionUnsafe]
constant
Lean.registerPersistentEnvExtension
{α : Type}
{β : Type}
{σ : Type}
[inst : Inhabited σ]
(descr : Lean.PersistentEnvExtensionDescr α β σ)
:
IO (Lean.PersistentEnvExtension α β σ)
Equations
- Lean.SimplePersistentEnvExtension α σ = Lean.PersistentEnvExtension α α (List α × σ)
@[specialize]
def
Lean.mkStateFromImportedEntries
{α : Type}
{σ : Type}
(addEntryFn : σ → α → σ)
(initState : σ)
(as : Array (Array α))
:
σ
Equations
- Lean.mkStateFromImportedEntries addEntryFn initState as = Array.foldl (fun r es => Array.foldl (fun r e => addEntryFn r e) r es 0 (Array.size es)) initState as 0 (Array.size as)
def
Lean.registerSimplePersistentEnvExtension
{α : Type}
{σ : Type}
[inst : Inhabited σ]
(descr : Lean.SimplePersistentEnvExtensionDescr α σ)
:
Equations
- Lean.registerSimplePersistentEnvExtension descr = Lean.registerPersistentEnvExtension { name := descr.name, mkInitial := pure ([], Lean.SimplePersistentEnvExtensionDescr.addImportedFn descr #[]), addImportedFn := fun as => pure ([], Lean.SimplePersistentEnvExtensionDescr.addImportedFn descr as), addEntryFn := fun s e => match s with | (entries, s) => (e :: entries, Lean.SimplePersistentEnvExtensionDescr.addEntryFn descr s e), exportEntriesFn := fun s => Lean.SimplePersistentEnvExtensionDescr.toArrayFn descr (List.reverse s.fst), statsFn := fun s => Lean.format "number of local entries: " ++ Lean.format (List.length s.fst) }
instance
Lean.SimplePersistentEnvExtension.instInhabitedSimplePersistentEnvExtension
{α : Type}
{σ : Type}
[inst : Inhabited σ]
:
Equations
- Lean.SimplePersistentEnvExtension.instInhabitedSimplePersistentEnvExtension = inferInstanceAs (Inhabited (Lean.PersistentEnvExtension α α (List α × σ)))
def
Lean.SimplePersistentEnvExtension.getEntries
{α : Type}
{σ : Type}
[inst : Inhabited σ]
(ext : Lean.SimplePersistentEnvExtension α σ)
(env : Lean.Environment)
:
List α
Equations
- Lean.SimplePersistentEnvExtension.getEntries ext env = (Lean.PersistentEnvExtension.getState ext env).fst
def
Lean.SimplePersistentEnvExtension.getState
{α : Type}
{σ : Type}
[inst : Inhabited σ]
(ext : Lean.SimplePersistentEnvExtension α σ)
(env : Lean.Environment)
:
σ
Equations
- Lean.SimplePersistentEnvExtension.getState ext env = (Lean.PersistentEnvExtension.getState ext env).snd
def
Lean.SimplePersistentEnvExtension.setState
{α : Type}
{σ : Type}
(ext : Lean.SimplePersistentEnvExtension α σ)
(env : Lean.Environment)
(s : σ)
:
Equations
- Lean.SimplePersistentEnvExtension.setState ext env s = Lean.PersistentEnvExtension.modifyState ext env fun x => match x with | (entries, x) => (entries, s)
def
Lean.SimplePersistentEnvExtension.modifyState
{α : Type}
{σ : Type}
(ext : Lean.SimplePersistentEnvExtension α σ)
(env : Lean.Environment)
(f : σ → σ)
:
Equations
- Lean.SimplePersistentEnvExtension.modifyState ext env f = Lean.PersistentEnvExtension.modifyState ext env fun x => match x with | (entries, s) => (entries, f s)
Equations
- Lean.mkTagDeclarationExtension name = Lean.registerSimplePersistentEnvExtension { name := name, addEntryFn := fun s n => Lean.NameSet.insert s n, addImportedFn := fun as => ∅, toArrayFn := fun es => Array.qsort (List.toArray es) Lean.Name.quickLt 0 (Array.size (List.toArray es) - 1) }
def
Lean.TagDeclarationExtension.tag
(ext : Lean.TagDeclarationExtension)
(env : Lean.Environment)
(n : Lean.Name)
:
Equations
- Lean.TagDeclarationExtension.tag ext env n = Lean.PersistentEnvExtension.addEntry ext env n
def
Lean.TagDeclarationExtension.isTagged
(ext : Lean.TagDeclarationExtension)
(env : Lean.Environment)
(n : Lean.Name)
:
Equations
- Lean.TagDeclarationExtension.isTagged ext env n = match Lean.Environment.getModuleIdxFor? env n with | some modIdx => Array.binSearchContains (Lean.PersistentEnvExtension.getModuleEntries ext env modIdx) n Lean.Name.quickLt 0 (Array.size (Lean.PersistentEnvExtension.getModuleEntries ext env modIdx) - 1) | none => Lean.NameSet.contains (Lean.SimplePersistentEnvExtension.getState ext env) n
Equations
Equations
- Lean.mkMapDeclarationExtension name = Lean.registerSimplePersistentEnvExtension { name := name, addEntryFn := fun s n => Lean.NameMap.insert s n.fst n.snd, addImportedFn := fun as => ∅, toArrayFn := fun es => Array.qsort (List.toArray es) (fun a b => Lean.Name.quickLt a.fst b.fst) 0 (Array.size (List.toArray es) - 1) }
Equations
- Lean.MapDeclarationExtension.instInhabitedMapDeclarationExtension = inferInstanceAs (Inhabited (Lean.SimplePersistentEnvExtension (Lean.Name × α) (Lean.NameMap α)))
def
Lean.MapDeclarationExtension.insert
{α : Type}
(ext : Lean.MapDeclarationExtension α)
(env : Lean.Environment)
(declName : Lean.Name)
(val : α)
:
Equations
- Lean.MapDeclarationExtension.insert ext env declName val = Lean.PersistentEnvExtension.addEntry ext env (declName, val)
def
Lean.MapDeclarationExtension.find?
{α : Type}
[inst : Inhabited α]
(ext : Lean.MapDeclarationExtension α)
(env : Lean.Environment)
(declName : Lean.Name)
:
Option α
Equations
- Lean.MapDeclarationExtension.find? ext env declName = match Lean.Environment.getModuleIdxFor? env declName with | some modIdx => match Array.binSearch (Lean.PersistentEnvExtension.getModuleEntries ext env modIdx) (declName, default) (fun a b => Lean.Name.quickLt a.fst b.fst) 0 (Array.size (Lean.PersistentEnvExtension.getModuleEntries ext env modIdx) - 1) with | some e => some e.snd | none => none | none => Lean.NameMap.find? (Lean.SimplePersistentEnvExtension.getState ext env) declName
def
Lean.MapDeclarationExtension.contains
{α : Type}
[inst : Inhabited α]
(ext : Lean.MapDeclarationExtension α)
(env : Lean.Environment)
(declName : Lean.Name)
:
Equations
- Lean.MapDeclarationExtension.contains ext env declName = match Lean.Environment.getModuleIdxFor? env declName with | some modIdx => Array.binSearchContains (Lean.PersistentEnvExtension.getModuleEntries ext env modIdx) (declName, default) (fun a b => Lean.Name.quickLt a.fst b.fst) 0 (Array.size (Lean.PersistentEnvExtension.getModuleEntries ext env modIdx) - 1) | none => Lean.NameMap.contains (Lean.SimplePersistentEnvExtension.getState ext env) declName
@[extern lean_save_module_data]
@[extern lean_read_module_data]
@[noinline]
Equations
- Lean.Environment.freeRegions env = Array.forM Lean.CompactedRegion.free env.header.regions 0 (Array.size env.header.regions)
Equations
- Lean.mkModuleData env = do let pExts ← ST.Ref.get Lean.persistentEnvExtensionsRef let entries : Array (Lean.Name × Array Lean.EnvExtensionEntry) := Nat.fold (fun i result => let state := Lean.PersistentEnvExtension.getState (Array.get! pExts i) env; let exportEntriesFn := (Array.get! pExts i).exportEntriesFn; let extName := (Array.get! pExts i).name; Array.push result (extName, exportEntriesFn state)) (Array.size pExts) #[] pure { imports := env.header.imports, constants := Lean.SMap.foldStage2 (fun cs x c => Array.push cs c) #[] env.constants, entries := entries }
Equations
- Lean.writeModule env fname = do let a ← Lean.mkModuleData env Lean.saveModuleData fname (Lean.Environment.mainModule env) a
@[extern 2lean_update_env_attributes]
- moduleNameSet : Lean.NameSet
- moduleNames : Array Lean.Name
- moduleData : Array Lean.ModuleData
- regions : Array Lean.CompactedRegion
def
Lean.importModules
(imports : List Lean.Import)
(opts : Lean.Options)
(trustLevel : optParam UInt32 0)
:
Equations
- Lean.importModules imports opts trustLevel = (fun importMods => Lean.profileitIO "import" opts (Lean.withImporting do let discr ← StateRefT'.run (importMods imports) { moduleNameSet := ∅, moduleNames := #[], moduleData := #[], regions := #[] } let x : Unit × Lean.ImportState := discr match x with | (x, s) => let numConsts := 0; do let r ← let col := s.moduleData; forIn col numConsts fun mod r => let numConsts := r; let numConsts := numConsts + Array.size mod.constants; do pure PUnit.unit pure (ForInStep.yield numConsts) let x : Nat := r let numConsts : Nat := x let modIdx : Nat := 0 let const2ModIdx : Std.HashMap Lean.Name Lean.ModuleIdx := Std.mkHashMap numConsts let constantMap : Std.HashMap Lean.Name Lean.ConstantInfo := Std.mkHashMap numConsts let r ← let col := s.moduleData; forIn col { fst := constantMap, snd := { fst := modIdx, snd := const2ModIdx } } fun mod r => let constantMap := r.fst; let x := r.snd; let modIdx := x.fst; let const2ModIdx := x.snd; do let r ← let col := mod.constants; forIn col { fst := constantMap, snd := const2ModIdx } fun cinfo r => let constantMap := r.fst; let const2ModIdx := r.snd; let const2ModIdx := Std.HashMap.insert const2ModIdx (Lean.ConstantInfo.name cinfo) modIdx; match Std.HashMap.insert' constantMap (Lean.ConstantInfo.name cinfo) cinfo with | (constantMap', replaced) => let constantMap := constantMap'; if replaced = true then do throw (IO.userError (toString "import failed, environment already contains '" ++ toString (Lean.ConstantInfo.name cinfo) ++ toString "'")) pure (ForInStep.yield { fst := constantMap, snd := const2ModIdx }) else do pure PUnit.unit pure (ForInStep.yield { fst := constantMap, snd := const2ModIdx }) let x : MProd (Std.HashMap Lean.Name Lean.ConstantInfo) (Std.HashMap Lean.Name Lean.ModuleIdx) := r match x with | { fst := constantMap, snd := const2ModIdx } => let modIdx := modIdx + 1; do pure PUnit.unit pure (ForInStep.yield { fst := constantMap, snd := { fst := modIdx, snd := const2ModIdx } }) let x : MProd (Std.HashMap Lean.Name Lean.ConstantInfo) (MProd Nat (Std.HashMap Lean.Name Lean.ModuleIdx)) := r match x with | { fst := constantMap, snd := { fst := modIdx, snd := const2ModIdx } } => let constants := Lean.SMap.fromHashMap constantMap false; do let exts ← Lean.mkInitialExtensionStates let env : Lean.Environment := { const2ModIdx := const2ModIdx, constants := constants, extensions := exts, header := { trustLevel := trustLevel, quotInit := !List.isEmpty imports, mainModule := default, imports := List.toArray imports, regions := s.regions, moduleNames := s.moduleNames, moduleData := s.moduleData } } let env ← Lean.setImportedEntries env s.moduleData 0 let env ← Lean.finalizePersistentExtensions env s.moduleData opts pure env)) Lean.importModules.importMods
unsafe def
Lean.withImportModules
{α : Type}
(imports : List Lean.Import)
(opts : Lean.Options)
(trustLevel : optParam UInt32 0)
(x : Lean.Environment → IO α)
:
IO α
Equations
- Lean.withImportModules imports opts trustLevel x = do let env ← Lean.importModules imports opts trustLevel tryFinally (x env) (Lean.Environment.freeRegions env)
Equations
- Lean.Environment.registerNamespace env n = if Lean.NameSSet.contains (Lean.SimplePersistentEnvExtension.getState Lean.namespacesExt env) n = true then env else Lean.PersistentEnvExtension.addEntry Lean.namespacesExt env n
Equations
Equations
- Lean.Environment.add env cinfo = let env := Lean.Environment.registerNamePrefixes env (Lean.ConstantInfo.name cinfo); Lean.Environment.addAux env cinfo
Equations
- Lean.Environment.displayStats env = do let pExtDescrs ← ST.Ref.get Lean.persistentEnvExtensionsRef IO.println ("direct imports: " ++ toString env.header.imports) IO.println ("number of imported modules: " ++ toString (Array.size env.header.regions)) IO.println ("number of memory-mapped modules: " ++ toString (Array.size (Array.filter (fun a => Lean.CompactedRegion.isMemoryMapped a) env.header.regions 0 (Array.size env.header.regions)))) IO.println ("number of consts: " ++ toString (Lean.SMap.size env.constants)) IO.println ("number of imported consts: " ++ toString (Lean.SMap.stageSizes env.constants).fst) IO.println ("number of local consts: " ++ toString (Lean.SMap.stageSizes env.constants).snd) IO.println ("number of buckets for imported consts: " ++ toString (Lean.SMap.numBuckets env.constants)) IO.println ("trust level: " ++ toString env.header.trustLevel) IO.println ("number of extensions: " ++ toString (Array.size env.extensions)) Array.forM (fun extDescr => do IO.println ("extension '" ++ toString extDescr.name ++ "'") let s : Lean.PersistentEnvExtensionState Lean.EnvExtensionEntry Lean.EnvExtensionState := Lean.EnvExtension.getState extDescr.toEnvExtension env let fmt : Lean.Format := Lean.PersistentEnvExtension.statsFn extDescr s.state let _do_jp : PUnit → IO Unit := fun y => IO.println (" number of imported entries: " ++ toString (Array.foldl (fun sum es => sum + Array.size es) 0 s.importedEntries 0 (Array.size s.importedEntries))) if Std.Format.isNil fmt = true then do let y ← pure PUnit.unit _do_jp y else do let y ← IO.println (" " ++ toString (Lean.Format.nest 2 (Lean.PersistentEnvExtension.statsFn extDescr s.state))) _do_jp y) pExtDescrs 0 (Array.size pExtDescrs)
@[extern lean_eval_const]
unsafe constant
Lean.Environment.evalConst
(α : Type u_1)
(env : Lean.Environment)
(opts : Lean.Options)
(constName : Lean.Name)
:
unsafe def
Lean.Environment.evalConstCheck
(α : Type)
(env : Lean.Environment)
(opts : Lean.Options)
(typeName : Lean.Name)
(constName : Lean.Name)
:
Equations
- Lean.Environment.evalConstCheck α env opts typeName constName = match Lean.Environment.find? env constName with | none => throw ("unknown constant '" ++ toString constName ++ "'") | some info => match Lean.ConstantInfo.type info with | Lean.Expr.const c x x_1 => if (c != typeName) = true then Lean.Environment.throwUnexpectedType typeName constName else Lean.Environment.evalConst α env opts constName | x => Lean.Environment.throwUnexpectedType typeName constName
Equations
- Lean.Environment.hasUnsafe env e = let c? := Lean.Expr.find? (fun e => match e with | Lean.Expr.const c x x_1 => match Lean.Environment.find? env c with | some cinfo => Lean.ConstantInfo.isUnsafe cinfo | none => false | x => false) e; Option.isSome c?
@[extern lean_kernel_is_def_eq]
constant
Lean.Kernel.isDefEq
(env : Lean.Environment)
(lctx : Lean.LocalContext)
(a : Lean.Expr)
(b : Lean.Expr)
:
@[extern lean_kernel_whnf]
- getEnv : m Lean.Environment
- modifyEnv : (Lean.Environment → Lean.Environment) → m Unit
instance
Lean.instMonadEnv
(m : Type → Type)
(n : Type → Type)
[inst : MonadLift m n]
[inst : Lean.MonadEnv m]
:
Equations
- Lean.instMonadEnv m n = { getEnv := liftM Lean.getEnv, modifyEnv := fun f => liftM (Lean.modifyEnv f) }
def
Lean.mkBaseNameFor
(env : Lean.Environment)
(declName : Lean.Name)
(elemSuffix : Lean.Name)
(suffix : Lean.Name)
:
Equations
- Lean.mkBaseNameFor env declName elemSuffix suffix = (fun go => if (!Lean.Environment.contains env (declName ++ elemSuffix)) = true then declName else go 1) (Lean.mkBaseNameFor.go env declName elemSuffix suffix)
partial def
Lean.mkBaseNameFor.go
(env : Lean.Environment)
(declName : Lean.Name)
(elemSuffix : Lean.Name)
(suffix : Lean.Name)
(idx : Nat)
: