File tree Expand file tree Collapse file tree 6 files changed +11
-25
lines changed
Expand file tree Collapse file tree 6 files changed +11
-25
lines changed Original file line number Diff line number Diff line change @@ -145,14 +145,7 @@ private def exportIREntries (env : Environment) : Array (Name × Array EnvExtens
145145 (Lean.regularInitAttr.ext.name, initDecls)]
146146
147147def findEnvDecl (env : Environment) (declName : Name) : Option Decl :=
148- Lean.Compiler.LCNF.withCompilerModIdx env declName
149- (fun modIdx =>
150- -- `meta import/import all`
151- guard (env.header.modules[modIdx]?.any (·.irPhases != .runtime)) *>
152- findAtSorted? (declMapExt.getModuleIREntries env modIdx) declName <|>
153- -- (closure of) `meta def`; will report `.extern`s for other `def`s so needs to come second
154- findAtSorted? (declMapExt.getModuleEntries env modIdx) declName)
155- (fun _ => declMapExt.getState env |>.find? declName)
148+ Lean.Compiler.LCNF.findExtEntry? env declMapExt declName findAtSorted? (·.2 .find?)
156149
157150@[export lean_ir_find_env_decl]
158151private def findInterpDecl (env : Environment) (declName : Name) : Option Decl :=
Original file line number Diff line number Diff line change @@ -134,9 +134,7 @@ def addFunctionSummary (env : Environment) (fid : FunId) (v : Value) : Environme
134134 functionSummariesExt.addEntry env (fid, v)
135135
136136def getFunctionSummary? (env : Environment) (fid : FunId) : Option Value :=
137- Lean.Compiler.LCNF.withCompilerModIdx env fid
138- (fun modIdx => findAtSorted? (functionSummariesExt.getModuleEntries env modIdx) fid)
139- (fun _ => functionSummariesExt.getState env |>.find? fid)
137+ Lean.Compiler.LCNF.findExtEntry? env functionSummariesExt fid findAtSorted? (·.2 .find?)
140138
141139abbrev Assignment := Std.HashMap VarId Value
142140
Original file line number Diff line number Diff line change @@ -757,10 +757,11 @@ def instantiateRevRangeArgs (e : Expr) (beginIdx endIdx : Nat) (args : Array Arg
757757 else
758758 e.instantiateRevRange beginIdx endIdx (args.map (·.toExpr))
759759
760- def withCompilerModIdx (env : Environment) (declName : Name)
761- (importedOrLocal : ModuleIdx → Option α) («local » : Unit → Option α) : Option α :=
762- match env.getModuleIdxFor? declName with
763- | some modIdx => importedOrLocal modIdx <|> «local » ()
764- | none => «local » ()
760+ def findExtEntry? [Inhabited σ] (env : Environment) (ext : PersistentEnvExtension α β σ) (declName : Name)
761+ (findAtSorted? : Array α → Name → Option α')
762+ (findInState? : σ → Name → Option α') : Option α' :=
763+ (env.getModuleIdxFor? declName).bind (fun modIdx =>
764+ findAtSorted? (ext.getModuleIREntries env modIdx) declName <|> findAtSorted? (ext.getModuleEntries env modIdx) declName)
765+ <|> findInState? (ext.getState env) declName
765766
766767end Lean.Compiler.LCNF
Original file line number Diff line number Diff line change @@ -265,9 +265,7 @@ def addFunctionSummary (env : Environment) (fid : Name) (v : Value) : Environmen
265265Obtain the `Value` for a function name if possible.
266266-/
267267def getFunctionSummary? (env : Environment) (fid : Name) : Option Value :=
268- withCompilerModIdx env fid
269- (fun modIdx => findAtSorted? (functionSummariesExt.getModuleEntries env modIdx) fid)
270- (fun _ => functionSummariesExt.getState env |>.find? fid)
268+ findExtEntry? env functionSummariesExt fid findAtSorted? (·.2 .find?)
271269
272270/--
273271A map from variable identifiers to the `Value` produced by the abstract
Original file line number Diff line number Diff line change @@ -132,9 +132,7 @@ builtin_initialize baseExt : DeclExt ← mkDeclExt .base
132132builtin_initialize monoExt : DeclExt ← mkDeclExt .mono
133133
134134def getDeclCore? (env : Environment) (ext : DeclExt) (declName : Name) : Option Decl :=
135- withCompilerModIdx env declName
136- (fun modIdx => findAtSorted? (ext.getModuleEntries env modIdx) declName)
137- (fun _ => ext.getState env |>.find? declName)
135+ findExtEntry? env ext declName findAtSorted? (·.find?)
138136
139137def getBaseDecl? (declName : Name) : CoreM (Option Decl) := do
140138 return getDeclCore? (← getEnv) baseExt declName
Original file line number Diff line number Diff line change @@ -206,9 +206,7 @@ def saveSpecParamInfo (decls : Array Decl) : CompilerM Unit := do
206206 modifyEnv fun env => specExtension.addEntry env { declName := decl.name, paramsInfo }
207207
208208def getSpecParamInfoCore? (env : Environment) (declName : Name) : Option (Array SpecParamInfo) :=
209- withCompilerModIdx env declName
210- (fun modIdx => findAtSorted? (specExtension.getModuleEntries env modIdx) declName |>.map (·.paramsInfo))
211- (fun _ => (specExtension.getState env).specInfo.find? declName)
209+ findExtEntry? env specExtension declName (findAtSorted? · · |>.map (·.paramsInfo)) (·.2 .specInfo.find?)
212210
213211def getSpecParamInfo? [Monad m] [MonadEnv m] (declName : Name) : m (Option (Array SpecParamInfo)) :=
214212 return getSpecParamInfoCore? (← getEnv) declName
You can’t perform that action at this time.
0 commit comments