Skip to content

Commit

Permalink
feat: [(builtin_)incremental] elab attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed May 23, 2024
1 parent 73a0c73 commit 2509941
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Lean/Elab/Term.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,33 @@ builtin_initialize
registerTraceClass `Elab.debug
registerTraceClass `Elab.reuse

builtin_initialize incrementalAttr : TagAttribute ←
registerTagAttribute `incremental "Marks an elaborator (tactic or command, currently) as \
supporting incremental elaboration. For unmarked elaborators, the corresponding snapshot bundle \
field in the elaboration context is unset so as to prevent accidental, incorrect reuse."

builtin_initialize builtinIncrementalElabs : IO.Ref NameSet ← IO.mkRef {}

def addBuiltinIncrementalElab (decl : Name) : IO Unit := do
builtinIncrementalElabs.modify fun s => s.insert decl

builtin_initialize
registerBuiltinAttribute {
name := `builtin_incremental
descr := s!"(builtin) {incrementalAttr.attr.descr}"
applicationTime := .afterCompilation
add := fun decl stx kind => do
Attribute.Builtin.ensureNoArgs stx
unless kind == AttributeKind.global do
throwError "invalid attribute 'builtin_incremental', must be global"
declareBuiltin decl <| mkApp (mkConst ``addBuiltinIncrementalElab) (toExpr decl)
}

/-- Checks whether a declaration is annotated with `[builtin_incremental]` or `[incremental]`. -/
def isIncrementalElab (decl : Name) : CoreM Bool :=
(return (← builtinIncrementalElabs.get).contains decl) <||>
(return incrementalAttr.hasTag (← getEnv) decl)

export Term (TermElabM)

end Lean.Elab

0 comments on commit 2509941

Please sign in to comment.