Skip to content

Commit b64a704

Browse files
committed
fix: cache TrivialStructureInfo in LCNF toMono
1 parent 4694aaa commit b64a704

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Lean/Compiler/LCNF/MonoTypes.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,23 @@ structure TrivialStructureInfo where
3535
fieldIdx : Nat
3636
deriving Inhabited, Repr
3737

38+
builtin_initialize trivialStructureInfoExt : CacheExtension Name (Option TrivialStructureInfo) ←
39+
CacheExtension.register
40+
3841
/--
3942
Return `some fieldIdx` if `declName` is the name of an inductive datatype s.t.
4043
- It does not have builtin support in the runtime.
4144
- It has only one constructor.
4245
- This constructor has only one computationally relevant field.
4346
-/
4447
def hasTrivialStructure? (declName : Name) : CoreM (Option TrivialStructureInfo) := do
48+
match (← trivialStructureInfoExt.find? declName) with
49+
| some info? => return info?
50+
| none =>
51+
let info? ← fillCache
52+
trivialStructureInfoExt.insert declName info?
53+
return info?
54+
where fillCache : CoreM (Option TrivialStructureInfo) := do
4555
if isRuntimeBultinType declName then return none
4656
let .inductInfo info ← getConstInfo declName | return none
4757
if info.isUnsafe || info.isRec then return none

0 commit comments

Comments
 (0)