lean4-htt/library/init/lean/compiler/closedtermcache.lean
Leonardo de Moura 0a08569b46 feat(library/init/lean/environment): remove lazy, add addImported field to PersistentEnvExtension
It seems `lazy := false` is only going to be used in the attribute
manager. So, I remove it. I added a new field `addImported : Bool`
instead. An extension can specify whether `addEntryFn` is going to be
invoked or not for imported entries. `addImported := false` is useful for extensions such
as `protected`, and I will use it in the attribute manager too.
2019-06-03 16:45:27 -07:00

33 lines
1,019 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.lean.environment
namespace Lean
abbrev ClosedTermCache := SMap Expr Name Expr.quickLt
def mkClosedTermCacheExtension : IO (PersistentEnvExtension (Expr × Name) ClosedTermCache) :=
registerPersistentEnvExtension {
name := `closedTermCache,
initState := {},
addEntryFn := λ init s ⟨e, n⟩,
let s := if init then s else s.switch in
s.insert e n
}
@[init mkClosedTermCacheExtension]
constant closedTermCacheExt : PersistentEnvExtension (Expr × Name) ClosedTermCache := default _
@[export lean.cache_closed_term_name_core]
def cacheClosedTermName (env : Environment) (e : Expr) (n : Name) : Environment :=
closedTermCacheExt.addEntry env (e, n)
@[export lean.get_closed_term_name_core]
def getClosedTermName (env : Environment) (e : Expr) : Option Name :=
(closedTermCacheExt.getState env).find e
end Lean