Skip to content

Commit 9ce8a06

Browse files
authored
perf: macro_inline ctorIdx for single constructor inductives (#11379)
This PR sets `@[macro_inline]` on the (trivial) `.ctorIdx` for inductive types with one constructor, to reduce the number of symbols generated by the compiler.
1 parent 3772bb8 commit 9ce8a06

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Lean/Meta/Constructions/CtorIdx.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,20 @@ public def mkCtorIdx (indName : Name) : MetaM Unit :=
7171
value := mkApp value alt
7272
pure value
7373
mkLambdaFVars (xs.push x) value
74-
addAndCompile (.defnDecl (← mkDefinitionValInferringUnsafe
74+
let decl := .defnDecl (← mkDefinitionValInferringUnsafe
7575
(name := declName)
7676
(levelParams := info.levelParams)
7777
(type := declType)
7878
(value := declValue)
7979
(hints := ReducibilityHints.abbrev)
80-
))
80+
)
81+
addDecl decl
8182
modifyEnv fun env => addToCompletionBlackList env declName
8283
modifyEnv fun env => addProtected env declName
8384
setReducibleAttribute declName
85+
if info.numCtors = 1 then
86+
setInlineAttribute declName .macroInline
87+
compileDecl decl
8488

8589
-- Deprecated alias for enumeration types (which used to have `toCtorIdx`)
8690
if (← isEnumType indName) then

0 commit comments

Comments
 (0)