lean4-htt/src/Lean/Compiler/ClosedTermCache.lean
Leonardo de Moura d8210cd682 feat: mark auxiliary C constants used to store closed terms as static
This is a workaround to minimize the number of exported symbols in the
Lean executable.
See issues #466 and PR #515
2021-06-06 18:56:31 -07:00

28 lines
963 B
Text

/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Environment
namespace Lean
structure ClosedTermCache where
map : Std.PHashMap Expr Name := {}
constNames : NameSet := {}
deriving Inhabited
builtin_initialize closedTermCacheExt : EnvExtension ClosedTermCache ← registerEnvExtension (pure {})
@[export lean_cache_closed_term_name]
def cacheClosedTermName (env : Environment) (e : Expr) (n : Name) : Environment :=
closedTermCacheExt.modifyState env fun s => { s with map := s.map.insert e n, constNames := s.constNames.insert n }
@[export lean_get_closed_term_name]
def getClosedTermName? (env : Environment) (e : Expr) : Option Name :=
(closedTermCacheExt.getState env).map.find? e
def isClosedTermName (env : Environment) (n : Name) : Bool :=
(closedTermCacheExt.getState env).constNames.contains n
end Lean