FormalConjecturesUtil/Linters/ImportLinter.lean
Explanation legend Lean4 Domain Explanation Language (L4DEL)
L4DEL explanations are a separate layer. They do not change the Lean source. Intuition is explanatory prose; numbered items are a reading path; sources link the wording back to evidence.
- L4DEL
- Lean4 Domain Explanation Language
Credit: The upstream authors and contributors retain credit for the project and mathematics. lean4-explainer only renders their pinned source and adds the separately disclosed explanation layer.
Project sources: Pinned project documentation, Formal Conjectures paper, arXiv v1
5 declarations, 0 contain sorry, 0 declared as axioms
The Import Linter
This file implements a linter that enforces import conventions in FormalConjectures:
Disallow direct
MathlibandFormalConjecturesForMathlibimports: Problem files inFormalConjecturesmust not importMathlib,Mathlib.*,FormalConjecturesForMathlib, or anyFormalConjecturesForMathlib.*module directly. They should useimport FormalConjecturesUtilinstead.Require
FormalConjecturesUtil: Problem files inFormalConjecturesmust importFormalConjecturesUtil.Keep
meta imports narrow: Ameta importdoes not bring any declarations into scope; it only loads the compiled code of the imported module (and of its transitive imports), which is whatnative_decideand#evalneed under the module system.meta imports are therefore exempt from the first rule, but they must name the module defining the evaluated declaration:meta import FormalConjecturesUtil,meta import FormalConjecturesForMathlibandmeta import Mathlibload the compiled code of the whole library and are disallowed.Require modules: Problem files in
FormalConjecturesmust be modules, and they must importFormalConjecturesUtilwithpublic import. In a module, a plainimportis private, so the statements of public declarations cannot use it.
Imports (2)
- structure
ImportLinter.ImportRefAnimportof a parsed header, retaining its syntax node line 62 sourceSource documentation
An
importof a parsed header, retaining its syntax node.TODO(v4.34.0): Replace
ImportRef,ImportRef.getIdent, andheaderToImportRefswithImportGraph.Lean.headerToImportRefsfromImportGraph.Imports.Pretty(added inleanprover-community/import-graph#133).no axioms what this means
structure ImportRef extends Import where …
- def
ImportLinter.ImportRef.getIdentExtracts the module identifier from anImportRefline 68 sourceSource documentation
Extracts the module identifier from an
ImportRef.standard axioms: propext what this means
Statement uses: ImportLinter.ImportRef,
Lean.Syntax.IdentProof uses:
Lean.TSyntax,List.cons,Lean.SyntaxNodeKind,Lean.Name.mkStr4,List.nil,ImportLinter.ImportRef.stx,ite,Eq,Bool,Lean.Syntax.isOfKind,Lean.TSyntax.raw,Bool.true,Lean.Syntax,Lean.Syntax.getArg,OfNat.ofNat,Nat,Unit,cond,Bool.or,Bool.falseand 7 more2 instances, coercions and auxiliary constants left out.
def ImportRef.getIdent (i : ImportRef) : Ident := …
Mentions: ImportLinter.ImportRef
- def
ImportLinter.headerToImportRefsCollects everyimportof a parsed header, with its modifiers and syntax line 74 sourceSource documentation
Collects every
importof a parsed header, with its modifiers and syntax.standard axioms: propext what this means
Statement uses:
Lean.TSyntax,List.cons,Lean.SyntaxNodeKind,Lean.Name.mkStr4,List.nil,Array, ImportLinter.ImportRefProof uses:
ite,Eq,Bool,Lean.Syntax.isOfKind,Lean.TSyntax.raw,Bool.true,Lean.Syntax,Lean.Syntax.getArg,OfNat.ofNat,Nat,Unit,Option,Lean.TSyntaxArray,Lean.TSyntaxArray.mk,Lean.Syntax.getArgs,Array.map,cond,Bool.or,Bool.false,Lean.Name.mkStr1and 14 more2 instances, coercions and auxiliary constants left out.
def headerToImportRefs (header : TSyntax ``Parser.Module.header) : Array ImportRef := …
Mentions: ImportLinter.ImportRef
- def
ImportLinter.checkImportsChecks a parsed header against the Formal Conjectures import rules line 92 sourceSource documentation
Checks a parsed header against the Formal Conjectures import rules.
metaimports are exempt from the rules on directMathlibandFormalConjecturesForMathlibimports.standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Lean.Elab.HeaderSyntax,optParam,Bool,Bool.true,Lean.Syntax,Lean.Syntax.missing,Lean.Elab.Command.CommandElabM,UnitProof uses:
Array, ImportLinter.ImportRef, ImportLinter.headerToImportRefs,Bind.bind,PUnit,ForIn.forIn,inferInstance,Membership,PUnit.unit,Lean.Name,Lean.Import.module,ImportLinter.ImportRef.toImport,ite,ForInStep,Eq,Lean.Import.isMeta,Pure.pure,Lean.Elab.Command.Context,StateRefT',IO.RealWorldand 40 more27 instances, coercions and auxiliary constants left out.
def checkImports (header : HeaderSyntax) (isFormalConjecturesModule : Bool := true) …
- def
ImportLinter.importLinterThe import linter ensures that: - Files inFormalConjecturesdo not importMathlib,Mathlib.*,FormalConjecturesForMathlib, orFormalConjecturesForMathlib.*directly line 140 sourceSource documentation
The import linter ensures that:
- Files in
FormalConjecturesdo not importMathlib,Mathlib.*,FormalConjecturesForMathlib, orFormalConjecturesForMathlib.*directly. - Files in
FormalConjecturesimportFormalConjecturesUtil. - Files in
FormalConjecturesdo notmeta importa whole library (FormalConjecturesUtil,FormalConjecturesForMathliborMathlib). - Files in
FormalConjecturesare modules thatpublic import FormalConjecturesUtil.
standard axioms: Classical.choice, Quot.sound, propext what this means
Statement uses:
Lean.Elab.Command.LinterProof uses:
Lean.Elab.Command.Linter.mk,Lean.withSetOptionIn,Lean.Syntax,ite,Lean.Elab.Command.CommandElabM,Unit,Eq,Bool,BEq.beq,Lean.SyntaxNodeKind,Lean.Syntax.getKind,Lean.Name.mkStr4,Bool.true,Pure.pure,Lean.Elab.Command.Context,StateRefT',IO.RealWorld,Lean.Elab.Command.State,EIO,Lean.Exceptionand 41 more29 instances, coercions and auxiliary constants left out.
def importLinter : Linter where run := withSetOptionIn fun stx ↦ do …
- Files in