Writing the Database #
This file defines WriteDB, the interface for populating the database. Lake runs one single
command per module (and genCore for Init/Std/Lake/Lean), each of which writes to the shared SQLite
database through WriteDB. Later, the fromDb command reads everything back via ReadDB (defined
in DocGen4.DB.Read) and generates HTML.
WriteDB and ReadDB are separate types because writers and readers have different needs. The
database schema lives in DocGen4.DB.Schema.
Module Item Positions #
Within a module, each item (declaration, module doc, constructor) is assigned a sequential Int64
position starting from 0. This position serves as the item's identity within the module: the
composite key (module_name, position) is the primary key for most tables. Positions are assigned
in the order items appear in the module's members array, with constructors and structure fields
interleaved between their parent declarations. For example, a module containing a module doc, a
definition, and an inductive with two constructors might have positions:
0: module doc 1: definition 2: inductive 3: constructor 1 (of the inductive at position 2) 4: constructor 2 (of the inductive at position 2)
The position counter is a mutable Int64 in updateModuleDb. Structures consume extra positions
for their constructor and fields. The read side reconstructs module members by querying name_info
and module_docs_markdown ordered by position.
Changing the Schema #
When adding a new column or table:
- Add the DDL in
DocGen4.DB.Schema(theddlstring ingetDb). - Add a prepared statement to
WriteStmtsand itspreparemethod below. - Add a
WriteStmts.saveXyzmethod with positionalbindcalls that match the SQL. - Expose it through
WriteDB(the structure at the top of this file) and the mutex wrapper inensureWriteDb. - Add a prepared statement and loader to
ReadStmtsinDocGen4.DB.Read. - If the change affects serialized blob types, check that there is an update
serializedCodeTypeDefsinDocGen4.DB.Schemaso the type hash invalidates stale databases. Otherwise, assess the risk of users getting old databases and consider adding another invalidation.
A write-only database handle. Used during the analysis phase to populate the database.
- sqlite : SQLite
- saveDeclarationRange (modName : String) (position : Int64) (declRange : Lean.DeclarationRange) : IO Unit
- saveStructureConstructor (modName : String) (position ctorPos : Int64) (info : Process.NameInfo) : IO Unit
- saveNameOnly (modName : String) (position : Int64) (kind : String) (name : Lean.Name) (type : RenderedCode) (declRange : Lean.DeclarationRange) : IO Unit
Save minimal info to name_info for name lookups (not for rendering)
Save an internal name (like a recursor) that should link to its target declaration
Save a tactic defined in this module
Instances For
Equations
- db.saveDocstring modName position (Sum.inl md) = db.saveMarkdownDocstring modName position md
- db.saveDocstring modName position (Sum.inr v) = db.saveVersoDocstring modName position v
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- DocGen4.DB.DBM.run values dbFile act = do let db ← DocGen4.DB.ensureWriteDb values dbFile ReaderT.run act { values := values, db := db }
Instances For
Equations
- DocGen4.DB.withDB f = do let __do_lift ← read f __do_lift.db
Instances For
Open a database for reading only.
Read operations are protected by a Std.Mutex internally (see mkReadDB), so a single ReadDB
can be shared across tasks without corrupting state. However, sharing serializes all reads through
one SQLite connection. For parallel workloads, each task should call openForReading to get its own
connection.
Equations
- DocGen4.DB.openForReading dbFile values = do let sqlite ← SQLite.openWith dbFile SQLite.OpenFlags.readonly none 1800000 DocGen4.DB.mkReadDB sqlite values
Instances For
DB Reading #
Context needed for cross-module linking, without loading full module contents.
- sourceUrls : Std.HashMap Lean.Name String
- name2ModIdx : Std.HashMap Lean.Name Lean.ModuleIdx
Instances For
Load the linking context from the database.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.axiomInfo info) = "axiom"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.theoremInfo info) = "theorem"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.opaqueInfo info) = "opaque"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.definitionInfo info) = "definition"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.instanceInfo info) = "instance"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.inductiveInfo info) = "inductive"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.structureInfo info) = "structure"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.classInfo info) = "class"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.classInductiveInfo info) = "class inductive"
- DocGen4.updateModuleDb.infoKind (DocGen4.Process.DocInfo.ctorInfo info) = "constructor"