Skip to content

Commit 8ca0a94

Browse files
committed
withCompilerModIdx ~> findExtEntry?
1 parent 55262af commit 8ca0a94

File tree

6 files changed

+11
-25
lines changed

6 files changed

+11
-25
lines changed

src/Lean/Compiler/IR/CompilerM.lean

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,7 @@ private def exportIREntries (env : Environment) : Array (Name × Array EnvExtens
145145
(Lean.regularInitAttr.ext.name, initDecls)]
146146

147147
def 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]
158151
private def findInterpDecl (env : Environment) (declName : Name) : Option Decl :=

src/Lean/Compiler/IR/ElimDeadBranches.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ def addFunctionSummary (env : Environment) (fid : FunId) (v : Value) : Environme
134134
functionSummariesExt.addEntry env (fid, v)
135135

136136
def 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

141139
abbrev Assignment := Std.HashMap VarId Value
142140

src/Lean/Compiler/LCNF/Basic.lean

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff 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

766767
end Lean.Compiler.LCNF

src/Lean/Compiler/LCNF/ElimDeadBranches.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ def addFunctionSummary (env : Environment) (fid : Name) (v : Value) : Environmen
265265
Obtain the `Value` for a function name if possible.
266266
-/
267267
def 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
/--
273271
A map from variable identifiers to the `Value` produced by the abstract

src/Lean/Compiler/LCNF/PhaseExt.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ builtin_initialize baseExt : DeclExt ← mkDeclExt .base
132132
builtin_initialize monoExt : DeclExt ← mkDeclExt .mono
133133

134134
def 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

139137
def getBaseDecl? (declName : Name) : CoreM (Option Decl) := do
140138
return getDeclCore? (← getEnv) baseExt declName

src/Lean/Compiler/LCNF/SpecInfo.lean

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff 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

208208
def 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

213211
def getSpecParamInfo? [Monad m] [MonadEnv m] (declName : Name) : m (Option (Array SpecParamInfo)) :=
214212
return getSpecParamInfoCore? (← getEnv) declName

0 commit comments

Comments
 (0)