path
stringlengths
12
84
imports
sequencelengths
0
4.45k
premises
listlengths
0
625
.lake/packages/lean4/src/lean/Lean/ParserCompiler/Attribute.lean
[ ".lake/packages/lean4/src/lean/Lean/Attributes.lean", ".lake/packages/lean4/src/lean/Lean/ToExpr.lean", ".lake/packages/lean4/src/lean/Lean/Compiler/InitAttr.lean" ]
[ { "full_name": "Lean.ParserCompiler.CombinatorAttribute", "code": "structure CombinatorAttribute where\n impl : AttributeImpl\n ext : SimplePersistentEnvExtension (Name Γ— Name) (NameMap Name)\n deriving Inhabited", "start": [ 14, 1 ], "end": [ 17, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.registerCombinatorAttribute", "code": "def registerCombinatorAttribute (name : Name) (descr : String) (ref : Name := by exact decl_name%)\n : IO CombinatorAttribute := do\n let ext : SimplePersistentEnvExtension (Name Γ— Name) (NameMap Name) ← registerSimplePersistentEnvExtension {\n name := ref,\n addImportedFn := mkStateFromImportedEntries (fun s p => s.insert p.1 p.2) {},\n addEntryFn := fun (s : NameMap Name) (p : Name Γ— Name) => s.insert p.1 p.2,\n }\n let attrImpl : AttributeImpl := {\n ref := ref,\n name := name,\n descr := descr,\n add := fun decl stx _ => do\n let env ← getEnv\n let parserDeclName ← Elab.realizeGlobalConstNoOverloadWithInfo (← Attribute.Builtin.getIdent stx)\n setEnv <| ext.addEntry env (parserDeclName, decl)\n }\n registerBuiltinAttribute attrImpl\n pure { impl := attrImpl, ext := ext }", "start": [ 20, 1 ], "end": [ 37, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.CombinatorAttribute.getDeclFor?", "code": "def getDeclFor? (attr : CombinatorAttribute) (env : Environment) (parserDecl : Name) : Option Name :=\n (attr.ext.getState env).find? parserDecl", "start": [ 41, 1 ], "end": [ 42, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.CombinatorAttribute.setDeclFor", "code": "def setDeclFor (attr : CombinatorAttribute) (env : Environment) (parserDecl : Name) (decl : Name) : Environment :=\n attr.ext.addEntry env (parserDecl, decl)", "start": [ 44, 1 ], "end": [ 45, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.CombinatorAttribute.runDeclFor", "code": "unsafe def runDeclFor {Ξ±} (attr : CombinatorAttribute) (parserDecl : Name) : CoreM Ξ± := do\n match attr.getDeclFor? (← getEnv) parserDecl with\n | some d => evalConst Ξ± d\n | _ => throwError \"no declaration of attribute [{attr.impl.name}] found for '{parserDecl}'\"", "start": [ 47, 1 ], "end": [ 50, 99 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/StrInterpolation.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Basic.lean" ]
[ { "full_name": "Lean.Parser.isQuotableCharForStrInterpolant", "code": "def isQuotableCharForStrInterpolant (c : Char) : Bool :=\n c == '{' || isQuotableCharDefault c", "start": [ 10, 1 ], "end": [ 11, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.interpolatedStrFn", "code": "partial def interpolatedStrFn (p : ParserFn) : ParserFn := fun c s =>\n let input := c.input\n let stackSize := s.stackSize\n let rec parse (startPos : String.Pos) (c : ParserContext) (s : ParserState) : ParserState :=\n let i := s.pos\n if input.atEnd i then\n let s := s.mkError \"unterminated string literal\"\n s.mkNode interpolatedStrKind stackSize\n else\n let curr := input.get i\n let s := s.setPos (input.next i)\n if curr == '\\\"' then\n let s := mkNodeToken interpolatedStrLitKind startPos c s\n s.mkNode interpolatedStrKind stackSize\n else if curr == '\\\\' then\n andthenFn (quotedCharCoreFn isQuotableCharForStrInterpolant true) (parse startPos) c s\n else if curr == '{' then\n let s := mkNodeToken interpolatedStrLitKind startPos c s\n let s := p c s\n if s.hasError then s\n else\n let i := s.pos\n let curr := input.get i\n if curr == '}' then\n let s := s.setPos (input.next i)\n parse i c s\n else\n let s := s.mkError \"'}'\"\n s.mkNode interpolatedStrKind stackSize\n else\n parse startPos c s\n let startPos := s.pos\n if input.atEnd startPos then\n s.mkEOIError\n else\n let curr := input.get s.pos;\n if curr != '\\\"' then\n s.mkError \"interpolated string\"\n else\n let s := s.next input startPos\n parse startPos c s", "start": [ 13, 1 ], "end": [ 53, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.interpolatedStrNoAntiquot", "code": "@[inline] def interpolatedStrNoAntiquot (p : Parser) : Parser := {\n fn := interpolatedStrFn (withoutPosition p).fn,\n info := mkAtomicInfo \"interpolatedStr\"\n}", "start": [ 55, 1 ], "end": [ 58, 2 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.interpolatedStr", "code": "def interpolatedStr (p : Parser) : Parser :=\n withAntiquot (mkAntiquot \"interpolatedStr\" interpolatedStrKind) $ interpolatedStrNoAntiquot p", "start": [ 60, 1 ], "end": [ 72, 96 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Basic.lean
[ ".lake/packages/lean4/src/lean/Lean/KeyedDeclsAttribute.lean" ]
[ { "full_name": "Lean.PrettyPrinter.runForNodeKind", "code": "unsafe def runForNodeKind {Ξ±} (attr : KeyedDeclsAttribute Ξ±) (k : SyntaxNodeKind) (interp : ParserDescr β†’ CoreM Ξ±) : CoreM Ξ± := do\n match attr.getValues (← getEnv) k with\n | p::_ => pure p\n | _ =>\n let info ← getConstInfo k\n if info.type.isConstOf ``ParserDescr || info.type.isConstOf ``TrailingParserDescr then\n let d ← evalConst ParserDescr k\n interp d\n else\n throwError \"no declaration of attribute [{attr.defn.name}] found for '{k}'\"", "start": [ 16, 1 ], "end": [ 26, 82 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Parenthesizer.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Parser/StrInterpolation.lean", ".lake/packages/lean4/src/lean/Lean/ParserCompiler/Attribute.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Extension.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Parenthesizer.Context", "code": "structure Context where\n cat : Name := Name.anonymous", "start": [ 84, 1 ], "end": [ 86, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.State", "code": "structure State where\n stxTrav : Syntax.Traverser\n contPrec : Option Nat := none\n contCat : Name := Name.anonymous\n minPrec : Option Nat := none\n trailPrec : Option Nat := none\n trailCat : Name := Name.anonymous\n visitedToken : Bool := false", "start": [ 88, 1 ], "end": [ 99, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ParenthesizerM", "code": "abbrev ParenthesizerM := ReaderT Parenthesizer.Context $ StateRefT Parenthesizer.State CoreM", "start": [ 103, 1 ], "end": [ 103, 93 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer", "code": "abbrev Parenthesizer := ParenthesizerM Unit", "start": [ 104, 1 ], "end": [ 104, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ParenthesizerM.orElse", "code": "@[inline] def ParenthesizerM.orElse (p₁ : ParenthesizerM Ξ±) (pβ‚‚ : Unit β†’ ParenthesizerM Ξ±) : ParenthesizerM Ξ± := do\n let s ← get\n catchInternalId backtrackExceptionId\n p₁\n (fun _ => do set s; pβ‚‚ ())", "start": [ 106, 1 ], "end": [ 110, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.mkParenthesizerAttribute", "code": "unsafe def mkParenthesizerAttribute : IO (KeyedDeclsAttribute Parenthesizer) :=\n KeyedDeclsAttribute.init {\n builtinName := `builtin_parenthesizer,\n name := `parenthesizer,\n descr := \"Register a parenthesizer for a parser.\n\n [parenthesizer k] registers a declaration of type `Lean.PrettyPrinter.Parenthesizer` for the `SyntaxNodeKind` `k`.\",\n valueTypeName := `Lean.PrettyPrinter.Parenthesizer,\n evalKey := fun builtin stx => do\n let env ← getEnv\n let stx ← Attribute.Builtin.getIdent stx\n let id := stx.getId\n unless (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id do\n throwError \"invalid [parenthesizer] argument, unknown syntax kind '{id}'\"\n if (← getEnv).contains id && (← Elab.getInfoState).enabled then\n Elab.addConstInfo stx id none\n pure id\n } `Lean.PrettyPrinter.parenthesizerAttribute", "start": [ 114, 1 ], "end": [ 133, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.parenthesizerAttribute", "code": "@[builtin_init mkParenthesizerAttribute] opaque parenthesizerAttribute : KeyedDeclsAttribute Parenthesizer", "start": [ 134, 1 ], "end": [ 134, 107 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.CategoryParenthesizer", "code": "abbrev CategoryParenthesizer := (prec : Nat) β†’ Parenthesizer", "start": [ 136, 1 ], "end": [ 136, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.mkCategoryParenthesizerAttribute", "code": "unsafe def mkCategoryParenthesizerAttribute : IO (KeyedDeclsAttribute CategoryParenthesizer) :=\n KeyedDeclsAttribute.init {\n builtinName := `builtin_category_parenthesizer,\n name := `category_parenthesizer,\n descr := \"Register a parenthesizer for a syntax category.\n\n [category_parenthesizer cat] registers a declaration of type `Lean.PrettyPrinter.CategoryParenthesizer` for the category `cat`,\n which is used when parenthesizing calls of `categoryParser cat prec`. Implementations should call `maybeParenthesize`\n with the precedence and `cat`. If no category parenthesizer is registered, the category will never be parenthesized,\n but still be traversed for parenthesizing nested categories.\",\n valueTypeName := `Lean.PrettyPrinter.CategoryParenthesizer,\n evalKey := fun _ stx => do\n let env ← getEnv\n let stx ← Attribute.Builtin.getIdent stx\n let id := stx.getId\n let some cat := (Parser.parserExtension.getState env).categories.find? id\n | throwError \"invalid [category_parenthesizer] argument, unknown parser category '{toString id}'\"\n if (← Elab.getInfoState).enabled && (← getEnv).contains cat.declName then\n Elab.addConstInfo stx cat.declName none\n pure id\n } `Lean.PrettyPrinter.categoryParenthesizerAttribute", "start": [ 138, 1 ], "end": [ 158, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.categoryParenthesizerAttribute", "code": "@[builtin_init mkCategoryParenthesizerAttribute] opaque categoryParenthesizerAttribute : KeyedDeclsAttribute CategoryParenthesizer", "start": [ 159, 1 ], "end": [ 159, 131 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.mkCombinatorParenthesizerAttribute", "code": "unsafe def mkCombinatorParenthesizerAttribute : IO ParserCompiler.CombinatorAttribute :=\n ParserCompiler.registerCombinatorAttribute\n `combinator_parenthesizer\n \"Register a parenthesizer for a parser combinator.\n\n [combinator_parenthesizer c] registers a declaration of type `Lean.PrettyPrinter.Parenthesizer` for the `Parser` declaration `c`.\n Note that, unlike with [parenthesizer], this is not a node kind since combinators usually do not introduce their own node kinds.\n The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced\n with `Parenthesizer` in the parameter types.\"", "start": [ 161, 1 ], "end": [ 169, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.combinatorParenthesizerAttribute", "code": "@[builtin_init mkCombinatorParenthesizerAttribute] opaque combinatorParenthesizerAttribute : ParserCompiler.CombinatorAttribute", "start": [ 170, 1 ], "end": [ 170, 128 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.throwBacktrack", "code": "def throwBacktrack {Ξ±} : ParenthesizerM Ξ± :=\nthrow $ Exception.internal backtrackExceptionId", "start": [ 177, 1 ], "end": [ 178, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.addPrecCheck", "code": "def addPrecCheck (prec : Nat) : ParenthesizerM Unit :=\n modify fun st => { st with contPrec := Nat.min (st.contPrec.getD prec) prec, minPrec := Nat.min (st.minPrec.getD prec) prec }", "start": [ 188, 1 ], "end": [ 189, 128 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.visitArgs", "code": "def visitArgs (x : ParenthesizerM Unit) : ParenthesizerM Unit := do\n let stx ← getCur\n if stx.getArgs.size > 0 then\n goDown (stx.getArgs.size - 1) *> x <* goUp\n goLeft", "start": [ 191, 1 ], "end": [ 196, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.maybeParenthesize", "code": "def maybeParenthesize (cat : Name) (canJuxtapose : Bool) (mkParen : Syntax β†’ Syntax) (prec : Nat) (x : ParenthesizerM Unit) : ParenthesizerM Unit := do\n let stx ← getCur\n let idx ← getIdx\n let st ← get\n set { stxTrav := st.stxTrav : State }\n trace[PrettyPrinter.parenthesize] \"parenthesizing (cont := {(st.contPrec, st.contCat)}){indentD (format stx)}\"\n x\n let { minPrec := some minPrec, trailPrec := trailPrec, trailCat := trailCat, .. } ← get\n | trace[PrettyPrinter.parenthesize] \"visited a syntax tree without precedences?!{line ++ format stx}\"\n trace[PrettyPrinter.parenthesize] (m!\"...precedences are {prec} >? {minPrec}\" ++ if canJuxtapose then m!\", {(trailPrec, trailCat)} <=? {(st.contPrec, st.contCat)}\" else \"\")\n if (prec > minPrec || canJuxtapose && match trailPrec, st.contPrec with | some trailPrec, some contPrec => trailCat == st.contCat && trailPrec <= contPrec | _, _ => false) then\n if idx > 0 then goRight\n let mut stx ← getCur\n if let SourceInfo.original _ pos trail endPos := stx.getHeadInfo then\n stx := stx.setHeadInfo (SourceInfo.original \"\".toSubstring pos trail endPos)\n if let SourceInfo.original lead pos _ endPos := stx.getTailInfo then\n stx := stx.setTailInfo (SourceInfo.original lead pos \"\".toSubstring endPos)\n let mut stx' := mkParen stx\n if let SourceInfo.original lead pos _ endPos := stx.getHeadInfo then\n stx' := stx'.setHeadInfo (SourceInfo.original lead pos \"\".toSubstring endPos)\n if let SourceInfo.original _ pos trail endPos := stx.getTailInfo then\n stx' := stx'.setTailInfo (SourceInfo.original \"\".toSubstring pos trail endPos)\n trace[PrettyPrinter.parenthesize] \"parenthesized: {stx'.formatStx none}\"\n setCur stx'\n goLeft\n modify (fun st => { st with contPrec := Parser.maxPrec, contCat := cat, trailPrec := none })\n let { trailPrec := trailPrec, .. } ← get\n if st.visitedToken then\n modify fun stP => { stP with trailPrec := st.trailPrec, trailCat := st.trailCat }\n else\n let trailPrec := match trailPrec with\n | some trailPrec => Nat.min trailPrec prec\n | _ => prec\n modify fun stP => { stP with trailPrec := trailPrec, trailCat := cat }\n modify fun stP => { stP with minPrec := st.minPrec }", "start": [ 206, 1 ], "end": [ 252, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.visitToken", "code": "def visitToken : Parenthesizer := do\n modify fun st => { st with contPrec := none, contCat := Name.anonymous, visitedToken := true }\n goLeft", "start": [ 254, 1 ], "end": [ 257, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.orelse.parenthesizer", "code": "@[combinator_parenthesizer orelse] partial def orelse.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer := do\n let stx ← getCur\n if stx.getKind == `choice then\n visitArgs $ stx.getArgs.size.forM fun _ => do\n orelse.parenthesizer p1 p2\n else\n p1 <|> p2", "start": [ 259, 1 ], "end": [ 268, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.recover.parenthesizer", "code": "@[combinator_parenthesizer recover]\ndef recover.parenthesizer (p : PrettyPrinter.Parenthesizer) : PrettyPrinter.Parenthesizer := p", "start": [ 270, 1 ], "end": [ 271, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.recover'.parenthesizer", "code": "@[combinator_parenthesizer recover']\ndef recover'.parenthesizer (p : PrettyPrinter.Parenthesizer) : PrettyPrinter.Parenthesizer := p", "start": [ 273, 1 ], "end": [ 274, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.mkAntiquot.parenthesizer'", "code": "@[extern \"lean_mk_antiquot_parenthesizer\"]\nopaque mkAntiquot.parenthesizer' (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPseudoKind := false) : Parenthesizer", "start": [ 280, 1 ], "end": [ 281, 133 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.liftCoreM", "code": "@[inline] def liftCoreM {Ξ±} (x : CoreM Ξ±) : ParenthesizerM Ξ± :=\n liftM x", "start": [ 283, 1 ], "end": [ 284, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.interpretParserDescr'", "code": "@[extern \"lean_pretty_printer_parenthesizer_interpret_parser_descr\"]\nopaque interpretParserDescr' : ParserDescr β†’ CoreM Parenthesizer", "start": [ 287, 1 ], "end": [ 288, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.parenthesizerForKindUnsafe", "code": "unsafe def parenthesizerForKindUnsafe (k : SyntaxNodeKind) : Parenthesizer := do\n if k == `missing then\n pure ()\n else\n let p ← runForNodeKind parenthesizerAttribute k interpretParserDescr'\n p", "start": [ 290, 1 ], "end": [ 295, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.parenthesizerForKind", "code": "@[implemented_by parenthesizerForKindUnsafe]\nopaque parenthesizerForKind (k : SyntaxNodeKind) : Parenthesizer", "start": [ 297, 1 ], "end": [ 298, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.withAntiquot.parenthesizer", "code": "@[combinator_parenthesizer withAntiquot]\ndef withAntiquot.parenthesizer (antiP p : Parenthesizer) : Parenthesizer := do\n let stx ← getCur\n if stx.isAntiquot || stx.isAntiquotSplice then\n orelse.parenthesizer antiP p\n else\n p", "start": [ 300, 1 ], "end": [ 307, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.withAntiquotSuffixSplice.parenthesizer", "code": "@[combinator_parenthesizer withAntiquotSuffixSplice]\ndef withAntiquotSuffixSplice.parenthesizer (_ : SyntaxNodeKind) (p suffix : Parenthesizer) : Parenthesizer := do\n if (← getCur).isAntiquotSuffixSplice then\n visitArgs <| suffix *> p\n else\n p", "start": [ 309, 1 ], "end": [ 314, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.tokenWithAntiquot.parenthesizer", "code": "@[combinator_parenthesizer tokenWithAntiquot]\ndef tokenWithAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n if (← getCur).isTokenAntiquot then\n visitArgs p\n else\n p", "start": [ 316, 1 ], "end": [ 321, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.parenthesizeCategoryCore", "code": "partial def parenthesizeCategoryCore (cat : Name) (_prec : Nat) : Parenthesizer :=\n withReader (fun ctx => { ctx with cat := cat }) do\n let stx ← getCur\n if stx.getKind == `choice then\n visitArgs $ stx.getArgs.size.forM fun _ => do\n parenthesizeCategoryCore cat _prec\n else\n withAntiquot.parenthesizer (mkAntiquot.parenthesizer' cat.toString cat (isPseudoKind := true)) (parenthesizerForKind stx.getKind)\n modify fun st => { st with contCat := cat }", "start": [ 323, 1 ], "end": [ 331, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.categoryParser.parenthesizer", "code": "@[combinator_parenthesizer categoryParser]\ndef categoryParser.parenthesizer (cat : Name) (prec : Nat) : Parenthesizer := do\n let env ← getEnv\n match categoryParenthesizerAttribute.getValues env cat with\n | p::_ => p prec\n | _ => parenthesizeCategoryCore cat prec", "start": [ 333, 1 ], "end": [ 340, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.parserOfStack.parenthesizer", "code": "@[combinator_parenthesizer parserOfStack]\ndef parserOfStack.parenthesizer (offset : Nat) (_prec : Nat := 0) : Parenthesizer := do\n let st ← get\n let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset)\n parenthesizerForKind stx.getKind", "start": [ 342, 1 ], "end": [ 346, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.term.parenthesizer", "code": "@[builtin_category_parenthesizer term]\ndef term.parenthesizer : CategoryParenthesizer | prec => do\n maybeParenthesize `term true wrapParens prec $\n parenthesizeCategoryCore `term prec\nwhere\n \n wrapParens (stx : Syntax) : Syntax := Unhygienic.run do\n let pstx ← `(($(⟨stx⟩)))\n return pstx.raw.setInfo (SourceInfo.fromRef stx)", "start": [ 348, 1 ], "end": [ 361, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.tactic.parenthesizer", "code": "@[builtin_category_parenthesizer tactic]\ndef tactic.parenthesizer : CategoryParenthesizer | prec => do\n maybeParenthesize `tactic false (fun stx => Unhygienic.run `(tactic|($(⟨stx⟩)))) prec $\n parenthesizeCategoryCore `tactic prec", "start": [ 363, 1 ], "end": [ 366, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.level.parenthesizer", "code": "@[builtin_category_parenthesizer level]\ndef level.parenthesizer : CategoryParenthesizer | prec => do\n maybeParenthesize `level false (fun stx => Unhygienic.run `(level|($(⟨stx⟩)))) prec $\n parenthesizeCategoryCore `level prec", "start": [ 368, 1 ], "end": [ 371, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.rawStx.parenthesizer", "code": "@[builtin_category_parenthesizer rawStx]\ndef rawStx.parenthesizer : CategoryParenthesizer | _ => do\n goLeft", "start": [ 373, 1 ], "end": [ 375, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.error.parenthesizer", "code": "@[combinator_parenthesizer error]\ndef error.parenthesizer (_msg : String) : Parenthesizer :=\n pure ()", "start": [ 377, 1 ], "end": [ 379, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.errorAtSavedPos.parenthesizer", "code": "@[combinator_parenthesizer errorAtSavedPos]\ndef errorAtSavedPos.parenthesizer (_msg : String) (_delta : Bool) : Parenthesizer :=\n pure ()", "start": [ 381, 1 ], "end": [ 383, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.atomic.parenthesizer", "code": "@[combinator_parenthesizer atomic]\ndef atomic.parenthesizer (p : Parenthesizer) : Parenthesizer :=\n p", "start": [ 385, 1 ], "end": [ 387, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.lookahead.parenthesizer", "code": "@[combinator_parenthesizer lookahead]\ndef lookahead.parenthesizer (_ : Parenthesizer) : Parenthesizer :=\n pure ()", "start": [ 389, 1 ], "end": [ 391, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.notFollowedBy.parenthesizer", "code": "@[combinator_parenthesizer notFollowedBy]\ndef notFollowedBy.parenthesizer (_ : Parenthesizer) : Parenthesizer :=\n pure ()", "start": [ 393, 1 ], "end": [ 395, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.andthen.parenthesizer", "code": "@[combinator_parenthesizer andthen]\ndef andthen.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer :=\n p2 *> p1", "start": [ 397, 1 ], "end": [ 399, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkKind", "code": "def checkKind (k : SyntaxNodeKind) : Parenthesizer := do\n let stx ← getCur\n if k != stx.getKind then\n trace[PrettyPrinter.parenthesize.backtrack] \"unexpected node kind '{stx.getKind}', expected '{k}'\"\n throwBacktrack", "start": [ 401, 1 ], "end": [ 406, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.node.parenthesizer", "code": "@[combinator_parenthesizer node]\ndef node.parenthesizer (k : SyntaxNodeKind) (p : Parenthesizer) : Parenthesizer := do\n checkKind k\n visitArgs p", "start": [ 408, 1 ], "end": [ 411, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkPrec.parenthesizer", "code": "@[combinator_parenthesizer checkPrec]\ndef checkPrec.parenthesizer (prec : Nat) : Parenthesizer :=\n addPrecCheck prec", "start": [ 413, 1 ], "end": [ 415, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.withFn.parenthesizer", "code": "@[combinator_parenthesizer withFn]\ndef withFn.parenthesizer (_ : ParserFn β†’ ParserFn) (p : Parenthesizer) : Parenthesizer := p", "start": [ 417, 1 ], "end": [ 418, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.leadingNode.parenthesizer", "code": "@[combinator_parenthesizer leadingNode]\ndef leadingNode.parenthesizer (k : SyntaxNodeKind) (prec : Nat) (p : Parenthesizer) : Parenthesizer := do\n node.parenthesizer k p\n addPrecCheck prec\n modify fun st => { st with contPrec := Nat.min (Parser.maxPrec-1) prec }", "start": [ 420, 1 ], "end": [ 427, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.trailingNode.parenthesizer", "code": "@[combinator_parenthesizer trailingNode]\ndef trailingNode.parenthesizer (k : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Parenthesizer) : Parenthesizer := do\n checkKind k\n visitArgs do\n p\n addPrecCheck prec\n let ctx ← read\n modify fun st => { st with contCat := ctx.cat }\n categoryParser.parenthesizer ctx.cat lhsPrec", "start": [ 429, 1 ], "end": [ 441, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.rawCh.parenthesizer", "code": "@[combinator_parenthesizer rawCh] def rawCh.parenthesizer (_ch : Char) := visitToken", "start": [ 443, 1 ], "end": [ 443, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.symbolNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer symbolNoAntiquot] def symbolNoAntiquot.parenthesizer (_sym : String) := visitToken", "start": [ 445, 1 ], "end": [ 445, 110 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.unicodeSymbolNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer unicodeSymbolNoAntiquot] def unicodeSymbolNoAntiquot.parenthesizer (_sym _asciiSym : String) := visitToken", "start": [ 446, 1 ], "end": [ 446, 134 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.identNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer identNoAntiquot] def identNoAntiquot.parenthesizer := do checkKind identKind; visitToken", "start": [ 448, 1 ], "end": [ 448, 116 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.rawIdentNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer rawIdentNoAntiquot] def rawIdentNoAntiquot.parenthesizer := visitToken", "start": [ 449, 1 ], "end": [ 449, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.identEq.parenthesizer", "code": "@[combinator_parenthesizer identEq] def identEq.parenthesizer (_id : Name) := visitToken", "start": [ 450, 1 ], "end": [ 450, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.nonReservedSymbolNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.parenthesizer (_sym : String) (_includeIdent : Bool) := visitToken", "start": [ 451, 1 ], "end": [ 451, 155 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.charLitNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer charLitNoAntiquot] def charLitNoAntiquot.parenthesizer := visitToken", "start": [ 453, 1 ], "end": [ 453, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.strLitNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer strLitNoAntiquot] def strLitNoAntiquot.parenthesizer := visitToken", "start": [ 454, 1 ], "end": [ 454, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.nameLitNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer nameLitNoAntiquot] def nameLitNoAntiquot.parenthesizer := visitToken", "start": [ 455, 1 ], "end": [ 455, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.numLitNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer numLitNoAntiquot] def numLitNoAntiquot.parenthesizer := visitToken", "start": [ 456, 1 ], "end": [ 456, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.scientificLitNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer scientificLitNoAntiquot] def scientificLitNoAntiquot.parenthesizer := visitToken", "start": [ 457, 1 ], "end": [ 457, 108 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.fieldIdx.parenthesizer", "code": "@[combinator_parenthesizer fieldIdx] def fieldIdx.parenthesizer := visitToken", "start": [ 458, 1 ], "end": [ 458, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.manyNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer manyNoAntiquot]\ndef manyNoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n let stx ← getCur\n visitArgs $ stx.getArgs.size.forM fun _ => p", "start": [ 460, 1 ], "end": [ 463, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.many1NoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer many1NoAntiquot]\ndef many1NoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n manyNoAntiquot.parenthesizer p", "start": [ 465, 1 ], "end": [ 467, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.many1Unbox.parenthesizer", "code": "@[combinator_parenthesizer many1Unbox]\ndef many1Unbox.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n let stx ← getCur\n if stx.getKind == nullKind then\n manyNoAntiquot.parenthesizer p\n else\n p", "start": [ 469, 1 ], "end": [ 475, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.optionalNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer optionalNoAntiquot]\ndef optionalNoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n visitArgs p", "start": [ 477, 1 ], "end": [ 479, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.sepByNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer sepByNoAntiquot]\ndef sepByNoAntiquot.parenthesizer (p pSep : Parenthesizer) : Parenthesizer := do\n let stx ← getCur\n visitArgs <| (List.range stx.getArgs.size).reverse.forM fun i => if i % 2 == 0 then p else pSep", "start": [ 481, 1 ], "end": [ 484, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.sepBy1NoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer sepBy1NoAntiquot] def sepBy1NoAntiquot.parenthesizer := sepByNoAntiquot.parenthesizer", "start": [ 486, 1 ], "end": [ 486, 113 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.withPosition.parenthesizer", "code": "@[combinator_parenthesizer withPosition] def withPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n modify fun st => { st with contPrec := none }\n p", "start": [ 488, 1 ], "end": [ 491, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.withPositionAfterLinebreak.parenthesizer", "code": "@[combinator_parenthesizer withPositionAfterLinebreak] def withPositionAfterLinebreak.parenthesizer (p : Parenthesizer) : Parenthesizer :=\n withPosition.parenthesizer p", "start": [ 492, 1 ], "end": [ 494, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.withoutInfo.parenthesizer", "code": "@[combinator_parenthesizer withoutInfo] def withoutInfo.parenthesizer (p : Parenthesizer) : Parenthesizer := p", "start": [ 496, 1 ], "end": [ 496, 111 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkStackTop.parenthesizer", "code": "@[combinator_parenthesizer checkStackTop] def checkStackTop.parenthesizer : Parenthesizer := pure ()", "start": [ 498, 1 ], "end": [ 498, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkWsBefore.parenthesizer", "code": "@[combinator_parenthesizer checkWsBefore] def checkWsBefore.parenthesizer : Parenthesizer := pure ()", "start": [ 499, 1 ], "end": [ 499, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkNoWsBefore.parenthesizer", "code": "@[combinator_parenthesizer checkNoWsBefore] def checkNoWsBefore.parenthesizer : Parenthesizer := pure ()", "start": [ 500, 1 ], "end": [ 500, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkLinebreakBefore.parenthesizer", "code": "@[combinator_parenthesizer checkLinebreakBefore] def checkLinebreakBefore.parenthesizer : Parenthesizer := pure ()", "start": [ 501, 1 ], "end": [ 501, 115 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkTailWs.parenthesizer", "code": "@[combinator_parenthesizer checkTailWs] def checkTailWs.parenthesizer : Parenthesizer := pure ()", "start": [ 502, 1 ], "end": [ 502, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkColEq.parenthesizer", "code": "@[combinator_parenthesizer checkColEq] def checkColEq.parenthesizer : Parenthesizer := pure ()", "start": [ 503, 1 ], "end": [ 503, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkColGe.parenthesizer", "code": "@[combinator_parenthesizer checkColGe] def checkColGe.parenthesizer : Parenthesizer := pure ()", "start": [ 504, 1 ], "end": [ 504, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkColGt.parenthesizer", "code": "@[combinator_parenthesizer checkColGt] def checkColGt.parenthesizer : Parenthesizer := pure ()", "start": [ 505, 1 ], "end": [ 505, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkLineEq.parenthesizer", "code": "@[combinator_parenthesizer checkLineEq] def checkLineEq.parenthesizer : Parenthesizer := pure ()", "start": [ 506, 1 ], "end": [ 506, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.eoi.parenthesizer", "code": "@[combinator_parenthesizer eoi] def eoi.parenthesizer : Parenthesizer := pure ()", "start": [ 507, 1 ], "end": [ 507, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.checkNoImmediateColon.parenthesizer", "code": "@[combinator_parenthesizer checkNoImmediateColon] def checkNoImmediateColon.parenthesizer : Parenthesizer := pure ()", "start": [ 508, 1 ], "end": [ 508, 117 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.skip.parenthesizer", "code": "@[combinator_parenthesizer skip] def skip.parenthesizer : Parenthesizer := pure ()", "start": [ 509, 1 ], "end": [ 509, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.pushNone.parenthesizer", "code": "@[combinator_parenthesizer pushNone] def pushNone.parenthesizer : Parenthesizer := goLeft", "start": [ 511, 1 ], "end": [ 511, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.hygieneInfoNoAntiquot.parenthesizer", "code": "@[combinator_parenthesizer hygieneInfoNoAntiquot] def hygieneInfoNoAntiquot.parenthesizer : Parenthesizer := goLeft", "start": [ 512, 1 ], "end": [ 512, 116 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.interpolatedStr.parenthesizer", "code": "@[combinator_parenthesizer interpolatedStr]\ndef interpolatedStr.parenthesizer (p : Parenthesizer) : Parenthesizer := do\n visitArgs $ (← getCur).getArgs.reverse.forM fun chunk =>\n if chunk.isOfKind interpolatedStrLitKind then\n goLeft\n else\n p", "start": [ 514, 1 ], "end": [ 520, 8 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.ite", "code": "@[combinator_parenthesizer _root_.ite, macro_inline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Parenthesizer) : Parenthesizer :=\n if c then t else e", "start": [ 522, 1 ], "end": [ 523, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.ParenthesizerAliasValue", "code": "abbrev ParenthesizerAliasValue := AliasValue Parenthesizer", "start": [ 527, 1 ], "end": [ 527, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.registerAlias", "code": "def registerAlias (aliasName : Name) (v : ParenthesizerAliasValue) : IO Unit := do\n Parser.registerAliasCore parenthesizerAliasesRef aliasName v", "start": [ 531, 1 ], "end": [ 532, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.parenthesize", "code": "def parenthesize (parenthesizer : Parenthesizer) (stx : Syntax) : CoreM Syntax := do\n trace[PrettyPrinter.parenthesize.input] \"{format stx}\"\n catchInternalId backtrackExceptionId\n (do\n let (_, st) ← (parenthesizer {}).run { stxTrav := Syntax.Traverser.fromSyntax stx }\n pure st.stxTrav.cur)\n (fun _ => throwError \"parenthesize: uncaught backtrack exception\")", "start": [ 541, 1 ], "end": [ 548, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.parenthesizeCategory", "code": "def parenthesizeCategory (cat : Name) := parenthesize <| categoryParser.parenthesizer cat 0", "start": [ 550, 1 ], "end": [ 550, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.parenthesizeTerm", "code": "def parenthesizeTerm := parenthesizeCategory `term", "start": [ 552, 1 ], "end": [ 552, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.parenthesizeTactic", "code": "def parenthesizeTactic := parenthesizeCategory `tactic", "start": [ 553, 1 ], "end": [ 553, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.parenthesizeCommand", "code": "def parenthesizeCommand := parenthesizeCategory `command", "start": [ 554, 1 ], "end": [ 554, 57 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Formatter.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Basic.lean", ".lake/packages/lean4/src/lean/Lean/ParserCompiler/Attribute.lean", ".lake/packages/lean4/src/lean/Lean/KeyedDeclsAttribute.lean", ".lake/packages/lean4/src/lean/Lean/CoreM.lean", ".lake/packages/lean4/src/lean/Lean/Parser/StrInterpolation.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Extension.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Formatter.Context", "code": "structure Context where\n options : Options\n table : Parser.TokenTable", "start": [ 27, 1 ], "end": [ 29, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.State", "code": "structure State where\n stxTrav : Syntax.Traverser\n leadWord : String := \"\"\n isUngrouped : Bool := false\n mustBeGrouped : Bool := true\n stack : Array Format := #[]", "start": [ 31, 1 ], "end": [ 43, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.FormatterM", "code": "abbrev FormatterM := ReaderT Formatter.Context $ StateRefT Formatter.State CoreM", "start": [ 47, 1 ], "end": [ 47, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.FormatterM.orElse", "code": "@[inline] def FormatterM.orElse {Ξ±} (p₁ : FormatterM Ξ±) (pβ‚‚ : Unit β†’ FormatterM Ξ±) : FormatterM Ξ± := do\n let s ← get\n catchInternalId backtrackExceptionId\n p₁\n (fun _ => do set s; pβ‚‚ ())", "start": [ 49, 1 ], "end": [ 53, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter", "code": "abbrev Formatter := FormatterM Unit", "start": [ 57, 1 ], "end": [ 57, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.mkFormatterAttribute", "code": "unsafe def mkFormatterAttribute : IO (KeyedDeclsAttribute Formatter) :=\n KeyedDeclsAttribute.init {\n builtinName := `builtin_formatter,\n name := `formatter,\n descr := \"Register a formatter for a parser.\n\n [formatter k] registers a declaration of type `Lean.PrettyPrinter.Formatter` for the `SyntaxNodeKind` `k`.\",\n valueTypeName := `Lean.PrettyPrinter.Formatter,\n evalKey := fun builtin stx => do\n let env ← getEnv\n let stx ← Attribute.Builtin.getIdent stx\n let id := stx.getId\n unless (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id do\n throwError \"invalid [formatter] argument, unknown syntax kind '{id}'\"\n if (← getEnv).contains id && (← Elab.getInfoState).enabled then\n Elab.addConstInfo stx id none\n pure id\n } `Lean.PrettyPrinter.formatterAttribute", "start": [ 59, 1 ], "end": [ 78, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.formatterAttribute", "code": "@[builtin_init mkFormatterAttribute] opaque formatterAttribute : KeyedDeclsAttribute Formatter", "start": [ 79, 1 ], "end": [ 79, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.mkCombinatorFormatterAttribute", "code": "unsafe def mkCombinatorFormatterAttribute : IO ParserCompiler.CombinatorAttribute :=\n ParserCompiler.registerCombinatorAttribute\n `combinator_formatter\n \"Register a formatter for a parser combinator.\n\n [combinator_formatter c] registers a declaration of type `Lean.PrettyPrinter.Formatter` for the `Parser` declaration `c`.\n Note that, unlike with [formatter], this is not a node kind since combinators usually do not introduce their own node kinds.\n The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced\n with `Formatter` in the parameter types.\"", "start": [ 81, 1 ], "end": [ 89, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.combinatorFormatterAttribute", "code": "@[builtin_init mkCombinatorFormatterAttribute] opaque combinatorFormatterAttribute : ParserCompiler.CombinatorAttribute", "start": [ 90, 1 ], "end": [ 90, 120 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.throwBacktrack", "code": "def throwBacktrack {Ξ±} : FormatterM Ξ± :=\nthrow $ Exception.internal backtrackExceptionId", "start": [ 97, 1 ], "end": [ 98, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.getStack", "code": "def getStack : FormatterM (Array Format) := do\n let st ← get\n pure st.stack", "start": [ 108, 1 ], "end": [ 110, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.getStackSize", "code": "def getStackSize : FormatterM Nat := do\n let stack ← getStack;\n pure stack.size", "start": [ 112, 1 ], "end": [ 114, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.setStack", "code": "def setStack (stack : Array Format) : FormatterM Unit :=\n modify fun st => { st with stack := stack }", "start": [ 116, 1 ], "end": [ 117, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.push", "code": "private def push (f : Format) : FormatterM Unit :=\n modify fun st => { st with stack := st.stack.push f, isUngrouped := false }", "start": [ 119, 1 ], "end": [ 120, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.pushWhitespace", "code": "def pushWhitespace (f : Format) : FormatterM Unit := do\n push f\n modify fun st => { st with leadWord := \"\", isUngrouped := false }", "start": [ 122, 1 ], "end": [ 124, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.pushLine", "code": "def pushLine : FormatterM Unit :=\n pushWhitespace Format.line", "start": [ 126, 1 ], "end": [ 127, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.pushAlign", "code": "def pushAlign (force : Bool) : FormatterM Unit :=\n pushWhitespace (.align force)", "start": [ 129, 1 ], "end": [ 130, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.visitArgs", "code": "def visitArgs (x : FormatterM Unit) : FormatterM Unit := do\n let stx ← getCur\n if stx.getArgs.size > 0 then\n goDown (stx.getArgs.size - 1) *> x <* goUp\n goLeft", "start": [ 132, 1 ], "end": [ 137, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.fold", "code": "def fold (fn : Array Format β†’ Format) (x : FormatterM Unit) : FormatterM Unit := do\n let sp ← getStackSize\n x\n let stack ← getStack\n let f := fn $ stack.extract sp stack.size\n setStack $ (stack.shrink sp).push f", "start": [ 139, 1 ], "end": [ 145, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.concat", "code": "def concat (x : FormatterM Unit) : FormatterM Unit := do\n fold (Array.foldl (fun acc f => if acc.isNil then f else f ++ acc) Format.nil) x", "start": [ 147, 1 ], "end": [ 149, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.indent", "code": "def indent (x : Formatter) (indent : Option Int := none) : Formatter := do\n concat x\n let ctx ← read\n let indent := indent.getD $ Std.Format.getIndent ctx.options\n modify fun st => { st with stack := st.stack.modify (st.stack.size - 1) (Format.nest indent) }", "start": [ 151, 1 ], "end": [ 155, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.fill", "code": "def fill (x : Formatter) : Formatter := do\n concat x\n modify fun st => { st with\n stack := st.stack.modify (st.stack.size - 1) Format.fill\n isUngrouped := false\n }", "start": [ 157, 1 ], "end": [ 162, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.group", "code": "def group (x : Formatter) : Formatter := do\n concat x\n modify fun st => { st with\n stack := st.stack.modify (st.stack.size - 1) Format.group\n isUngrouped := false\n }", "start": [ 164, 1 ], "end": [ 169, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.withMaybeTag", "code": "def withMaybeTag (pos? : Option String.Pos) (x : FormatterM Unit) : Formatter := do\n if let some p := pos? then\n concat x\n modify fun st => {\n st with stack := st.stack.modify (st.stack.size - 1) fun fmt =>\n if fmt matches Format.tag .. then fmt\n else Format.tag p.byteIdx fmt\n }\n else\n x", "start": [ 171, 1 ], "end": [ 182, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.orelse.formatter", "code": "@[combinator_formatter orelse] partial def orelse.formatter (p1 p2 : Formatter) : Formatter := do\n let stx ← getCur\n if stx.getKind == `choice then\n visitArgs do\n orelse.formatter p1 p2\n else\n p1 <|> p2", "start": [ 184, 1 ], "end": [ 195, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.recover.formatter", "code": "@[combinator_formatter recover]\ndef recover.formatter (fmt : PrettyPrinter.Formatter) := fmt", "start": [ 197, 1 ], "end": [ 198, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.recover'.formatter", "code": "@[combinator_formatter recover']\ndef recover'.formatter (fmt : PrettyPrinter.Formatter) := fmt", "start": [ 200, 1 ], "end": [ 201, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.mkAntiquot.formatter'", "code": "@[extern \"lean_mk_antiquot_formatter\"]\nopaque mkAntiquot.formatter' (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPseudoKind := false) : Formatter", "start": [ 207, 1 ], "end": [ 208, 125 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.interpretParserDescr'", "code": "@[extern \"lean_pretty_printer_formatter_interpret_parser_descr\"]\nopaque interpretParserDescr' : ParserDescr β†’ CoreM Formatter", "start": [ 211, 1 ], "end": [ 212, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.SourceInfo.getExprPos?", "code": "private def SourceInfo.getExprPos? : SourceInfo β†’ Option String.Pos\n | SourceInfo.synthetic (pos := pos) .. => pos\n | _ => none", "start": [ 214, 1 ], "end": [ 216, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.getExprPos?", "code": "private def getExprPos? : Syntax β†’ Option String.Pos\n | Syntax.node info _ _ => SourceInfo.getExprPos? info\n | Syntax.atom info _ => SourceInfo.getExprPos? info\n | Syntax.ident info _ _ _ => SourceInfo.getExprPos? info\n | Syntax.missing => none", "start": [ 218, 1 ], "end": [ 222, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.formatterForKindUnsafe", "code": "unsafe def formatterForKindUnsafe (k : SyntaxNodeKind) : Formatter := do\n if k == `missing then\n push \"<missing>\"\n goLeft\n else\n let stx ← getCur\n let f ← runForNodeKind formatterAttribute k interpretParserDescr'\n withMaybeTag (getExprPos? stx) f", "start": [ 224, 1 ], "end": [ 231, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.formatterForKind", "code": "@[implemented_by formatterForKindUnsafe]\nopaque formatterForKind (k : SyntaxNodeKind) : Formatter", "start": [ 233, 1 ], "end": [ 234, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.withAntiquot.formatter", "code": "@[combinator_formatter withAntiquot]\ndef withAntiquot.formatter (antiP p : Formatter) : Formatter :=\n orelse.formatter antiP p", "start": [ 236, 1 ], "end": [ 240, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.withAntiquotSuffixSplice.formatter", "code": "@[combinator_formatter withAntiquotSuffixSplice]\ndef withAntiquotSuffixSplice.formatter (_ : SyntaxNodeKind) (p suffix : Formatter) : Formatter := do\n if (← getCur).isAntiquotSuffixSplice then\n visitArgs <| suffix *> p\n else\n p", "start": [ 242, 1 ], "end": [ 247, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.tokenWithAntiquot.formatter", "code": "@[combinator_formatter tokenWithAntiquot]\ndef tokenWithAntiquot.formatter (p : Formatter) : Formatter := do\n if (← getCur).isTokenAntiquot then\n visitArgs p\n else\n p", "start": [ 249, 1 ], "end": [ 254, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.categoryFormatterCore", "code": "def categoryFormatterCore (cat : Name) : Formatter := do\n modify fun st => { st with mustBeGrouped := true, isUngrouped := false }\n let stx ← getCur\n trace[PrettyPrinter.format] \"formatting {indentD (format stx)}\"\n if stx.getKind == `choice then\n visitArgs do\n formatterForKind (← getCur).getKind\n else if cat == `rawStx then\n withAntiquot.formatter (mkAntiquot.formatter' cat.toString cat (isPseudoKind := true)) (push stx.formatStx *> goLeft)\n else\n withAntiquot.formatter (mkAntiquot.formatter' cat.toString cat (isPseudoKind := true)) (formatterForKind stx.getKind)\n modify fun st => { st with mustBeGrouped := true, isUngrouped := !st.mustBeGrouped }", "start": [ 256, 1 ], "end": [ 269, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.categoryParser.formatter", "code": "@[combinator_formatter categoryParser]\ndef categoryParser.formatter (cat : Name) : Formatter := do\n concat <| categoryFormatterCore cat\n unless (← get).isUngrouped do\n let indent := Std.Format.getIndent (← read).options\n modify fun st => { st with\n stack := st.stack.modify (st.stack.size - 1) fun fmt =>\n fmt.nest indent |>.fill\n }", "start": [ 271, 1 ], "end": [ 279, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.categoryFormatter", "code": "def categoryFormatter (cat : Name) : Formatter :=\n fill <| indent <| categoryFormatterCore cat", "start": [ 281, 1 ], "end": [ 282, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.parserOfStack.formatter", "code": "@[combinator_formatter parserOfStack]\ndef parserOfStack.formatter (offset : Nat) (_prec : Nat := 0) : Formatter := do\n let st ← get\n let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset)\n formatterForKind stx.getKind", "start": [ 284, 1 ], "end": [ 288, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.error.formatter", "code": "@[combinator_formatter error]\ndef error.formatter (_msg : String) : Formatter := pure ()", "start": [ 290, 1 ], "end": [ 291, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.errorAtSavedPos.formatter", "code": "@[combinator_formatter errorAtSavedPos]\ndef errorAtSavedPos.formatter (_msg : String) (_delta : Bool) : Formatter := pure ()", "start": [ 292, 1 ], "end": [ 293, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.lookahead.formatter", "code": "@[combinator_formatter lookahead]\ndef lookahead.formatter (_ : Formatter) : Formatter := pure ()", "start": [ 294, 1 ], "end": [ 295, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.notFollowedBy.formatter", "code": "@[combinator_formatter notFollowedBy]\ndef notFollowedBy.formatter (_ : Formatter) : Formatter := pure ()", "start": [ 297, 1 ], "end": [ 298, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.andthen.formatter", "code": "@[combinator_formatter andthen]\ndef andthen.formatter (p1 p2 : Formatter) : Formatter := p2 *> p1", "start": [ 300, 1 ], "end": [ 301, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkKind", "code": "def checkKind (k : SyntaxNodeKind) : FormatterM Unit := do\n let stx ← getCur\n if k != stx.getKind then\n trace[PrettyPrinter.format.backtrack] \"unexpected node kind '{stx.getKind}', expected '{k}'\"\n throwBacktrack", "start": [ 303, 1 ], "end": [ 307, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.node.formatter", "code": "@[combinator_formatter node]\ndef node.formatter (k : SyntaxNodeKind) (p : Formatter) : Formatter := do\n checkKind k;\n visitArgs p", "start": [ 309, 1 ], "end": [ 312, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.withFn.formatter", "code": "@[combinator_formatter withFn]\ndef withFn.formatter (_ : ParserFn β†’ ParserFn) (p : Formatter) : Formatter := p", "start": [ 314, 1 ], "end": [ 315, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.trailingNode.formatter", "code": "@[combinator_formatter trailingNode]\ndef trailingNode.formatter (k : SyntaxNodeKind) (_ _ : Nat) (p : Formatter) : Formatter := do\n checkKind k\n visitArgs do\n p;\n categoryParser.formatter `foo", "start": [ 317, 1 ], "end": [ 323, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.parseToken", "code": "def parseToken (s : String) : FormatterM ParserState :=\n return (Parser.andthenFn Parser.whitespace (Parser.tokenFn [])).run {\n input := s,\n fileName := \"\",\n fileMap := FileMap.ofString \"\"\n } {\n env := ← getEnv,\n options := ← getOptions\n } ((← read).table) (Parser.mkParserState s)", "start": [ 325, 1 ], "end": [ 334, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.pushToken", "code": "def pushToken (info : SourceInfo) (tk : String) : FormatterM Unit := do\n match info with\n | SourceInfo.original _ _ ss _ =>\n let ss' := ss.trim\n if !ss'.isEmpty then\n let ws := { ss with startPos := ss'.stopPos }\n if ws.contains '\\n' then\n push s!\"\\n{ss'}\"\n else\n push s!\" {ss'}\"\n modify fun st => { st with leadWord := \"\" }\n | _ => pure ()\n\n let st ← get\n if st.leadWord != \"\" && tk.trimRight == tk then\n let tk' := tk.trimLeft\n let t ← parseToken $ tk' ++ st.leadWord\n if t.pos <= tk'.endPos then\n push tk\n modify fun st => { st with leadWord := if tk.trimLeft == tk then tk ++ st.leadWord else \"\" }\n else\n push $ tk ++ \" \"\n modify fun st => { st with leadWord := if tk.trimLeft == tk then tk else \"\" }\n else\n if st.leadWord == \"\" then\n push tk.trimRight\n else if tk.endsWith \" \" then\n pushLine\n push tk.trimRight\n else\n push tk modify fun st => { st with leadWord := if tk.trimLeft == tk then tk else \"\" }\n\n match info with\n | SourceInfo.original ss _ _ _ =>\n let ss' := ss.trim\n if !ss'.isEmpty then\n let ws := { ss with startPos := ss'.stopPos }\n if ws.contains '\\n' then do\n indent (push s!\"{ss'}\\n\") (some ((0:Int) - Std.Format.getIndent (← getOptions)))\n else\n pushLine\n push ss'.toString\n modify fun st => { st with leadWord := \"\" }\n | _ => pure ()", "start": [ 336, 1 ], "end": [ 388, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.symbolNoAntiquot.formatter", "code": "@[combinator_formatter symbolNoAntiquot]\ndef symbolNoAntiquot.formatter (sym : String) : Formatter := do\n let stx ← getCur\n if stx.isToken sym then do\n let (Syntax.atom info _) ← pure stx | unreachable!\n withMaybeTag (getExprPos? stx) (pushToken info sym)\n goLeft\n else do\n trace[PrettyPrinter.format.backtrack] \"unexpected syntax '{format stx}', expected symbol '{sym}'\"\n throwBacktrack", "start": [ 390, 1 ], "end": [ 399, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.nonReservedSymbolNoAntiquot.formatter", "code": "@[combinator_formatter nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.formatter := symbolNoAntiquot.formatter", "start": [ 401, 1 ], "end": [ 401, 124 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.rawCh.formatter", "code": "@[combinator_formatter rawCh] def rawCh.formatter (ch : Char) := symbolNoAntiquot.formatter ch.toString", "start": [ 403, 1 ], "end": [ 403, 104 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.unicodeSymbolNoAntiquot.formatter", "code": "@[combinator_formatter unicodeSymbolNoAntiquot]\ndef unicodeSymbolNoAntiquot.formatter (sym asciiSym : String) : Formatter := do\n let Syntax.atom info val ← getCur\n | throwError m!\"not an atom: {← getCur}\"\n if val == sym.trim then\n pushToken info sym\n else\n pushToken info asciiSym;\n goLeft", "start": [ 405, 1 ], "end": [ 413, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.identNoAntiquot.formatter", "code": "@[combinator_formatter identNoAntiquot]\ndef identNoAntiquot.formatter : Formatter := do\n checkKind identKind\n let stx@(Syntax.ident info _ id _) ← getCur\n | throwError m!\"not an ident: {← getCur}\"\n let id := id.simpMacroScopes\n withMaybeTag (getExprPos? stx) (pushToken info id.toString)\n goLeft", "start": [ 415, 1 ], "end": [ 422, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.rawIdentNoAntiquot.formatter", "code": "@[combinator_formatter rawIdentNoAntiquot] def rawIdentNoAntiquot.formatter : Formatter := do\n checkKind identKind\n let Syntax.ident info _ id _ ← getCur\n | throwError m!\"not an ident: {← getCur}\"\n pushToken info id.toString\n goLeft", "start": [ 424, 1 ], "end": [ 429, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.identEq.formatter", "code": "@[combinator_formatter identEq] def identEq.formatter (_id : Name) := rawIdentNoAntiquot.formatter", "start": [ 431, 1 ], "end": [ 431, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.visitAtom", "code": "def visitAtom (k : SyntaxNodeKind) : Formatter := do\n let stx ← getCur\n if k != Name.anonymous then\n checkKind k\n let Syntax.atom info val ← pure $ stx.ifNode (fun n => n.getArg 0) (fun _ => stx)\n | throwError m!\"not an atom: {stx}\"\n pushToken info val\n goLeft", "start": [ 433, 1 ], "end": [ 440, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.charLitNoAntiquot.formatter", "code": "@[combinator_formatter charLitNoAntiquot] def charLitNoAntiquot.formatter := visitAtom charLitKind", "start": [ 442, 1 ], "end": [ 442, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.strLitNoAntiquot.formatter", "code": "@[combinator_formatter strLitNoAntiquot] def strLitNoAntiquot.formatter := visitAtom strLitKind", "start": [ 443, 1 ], "end": [ 443, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.nameLitNoAntiquot.formatter", "code": "@[combinator_formatter nameLitNoAntiquot] def nameLitNoAntiquot.formatter := visitAtom nameLitKind", "start": [ 444, 1 ], "end": [ 444, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.numLitNoAntiquot.formatter", "code": "@[combinator_formatter numLitNoAntiquot] def numLitNoAntiquot.formatter := visitAtom numLitKind", "start": [ 445, 1 ], "end": [ 445, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.scientificLitNoAntiquot.formatter", "code": "@[combinator_formatter scientificLitNoAntiquot] def scientificLitNoAntiquot.formatter := visitAtom scientificLitKind", "start": [ 446, 1 ], "end": [ 446, 117 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.fieldIdx.formatter", "code": "@[combinator_formatter fieldIdx] def fieldIdx.formatter := visitAtom fieldIdxKind", "start": [ 447, 1 ], "end": [ 447, 82 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.manyNoAntiquot.formatter", "code": "@[combinator_formatter manyNoAntiquot]\ndef manyNoAntiquot.formatter (p : Formatter) : Formatter := do\n let stx ← getCur\n visitArgs $ stx.getArgs.size.forM fun _ => p", "start": [ 449, 1 ], "end": [ 452, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.many1NoAntiquot.formatter", "code": "@[combinator_formatter many1NoAntiquot] def many1NoAntiquot.formatter (p : Formatter) : Formatter := manyNoAntiquot.formatter p", "start": [ 454, 1 ], "end": [ 454, 128 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.optionalNoAntiquot.formatter", "code": "@[combinator_formatter optionalNoAntiquot]\ndef optionalNoAntiquot.formatter (p : Formatter) : Formatter := visitArgs p", "start": [ 456, 1 ], "end": [ 457, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.many1Unbox.formatter", "code": "@[combinator_formatter many1Unbox]\ndef many1Unbox.formatter (p : Formatter) : Formatter := do\n let stx ← getCur\n if stx.getKind == nullKind then do\n manyNoAntiquot.formatter p\n else\n p", "start": [ 459, 1 ], "end": [ 465, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.sepByNoAntiquot.formatter", "code": "@[combinator_formatter sepByNoAntiquot]\ndef sepByNoAntiquot.formatter (p pSep : Formatter) : Formatter := do\n let stx ← getCur\n visitArgs <| (List.range stx.getArgs.size).reverse.forM fun i => if i % 2 == 0 then p else pSep", "start": [ 467, 1 ], "end": [ 470, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.sepBy1NoAntiquot.formatter", "code": "@[combinator_formatter sepBy1NoAntiquot] def sepBy1NoAntiquot.formatter := sepByNoAntiquot.formatter", "start": [ 472, 1 ], "end": [ 472, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.withoutInfo.formatter", "code": "@[combinator_formatter withoutInfo] def withoutInfo.formatter (p : Formatter) : Formatter := p", "start": [ 474, 1 ], "end": [ 474, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkWsBefore.formatter", "code": "@[combinator_formatter checkWsBefore] def checkWsBefore.formatter : Formatter := do\n let st ← get\n if st.leadWord != \"\" then\n pushLine", "start": [ 475, 1 ], "end": [ 478, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkPrec.formatter", "code": "@[combinator_formatter checkPrec] def checkPrec.formatter : Formatter := pure ()", "start": [ 480, 1 ], "end": [ 480, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkLhsPrec.formatter", "code": "@[combinator_formatter checkLhsPrec] def checkLhsPrec.formatter : Formatter := pure ()", "start": [ 481, 1 ], "end": [ 481, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.setLhsPrec.formatter", "code": "@[combinator_formatter setLhsPrec] def setLhsPrec.formatter : Formatter := pure ()", "start": [ 482, 1 ], "end": [ 482, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkStackTop.formatter", "code": "@[combinator_formatter checkStackTop] def checkStackTop.formatter : Formatter := pure ()", "start": [ 483, 1 ], "end": [ 483, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkNoWsBefore.formatter", "code": "@[combinator_formatter checkNoWsBefore] def checkNoWsBefore.formatter : Formatter :=\n modify fun st => { st with leadWord := \"\" }", "start": [ 484, 1 ], "end": [ 486, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkLinebreakBefore.formatter", "code": "@[combinator_formatter checkLinebreakBefore] def checkLinebreakBefore.formatter : Formatter := pure ()", "start": [ 487, 1 ], "end": [ 487, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkTailWs.formatter", "code": "@[combinator_formatter checkTailWs] def checkTailWs.formatter : Formatter := pure ()", "start": [ 488, 1 ], "end": [ 488, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkColEq.formatter", "code": "@[combinator_formatter checkColEq] def checkColEq.formatter : Formatter := pure ()", "start": [ 489, 1 ], "end": [ 489, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkColGe.formatter", "code": "@[combinator_formatter checkColGe] def checkColGe.formatter : Formatter := pure ()", "start": [ 490, 1 ], "end": [ 490, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkColGt.formatter", "code": "@[combinator_formatter checkColGt] def checkColGt.formatter : Formatter := pure ()", "start": [ 491, 1 ], "end": [ 491, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkLineEq.formatter", "code": "@[combinator_formatter checkLineEq] def checkLineEq.formatter : Formatter := pure ()", "start": [ 492, 1 ], "end": [ 492, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.eoi.formatter", "code": "@[combinator_formatter eoi] def eoi.formatter : Formatter := pure ()", "start": [ 494, 1 ], "end": [ 494, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.checkNoImmediateColon.formatter", "code": "@[combinator_formatter checkNoImmediateColon] def checkNoImmediateColon.formatter : Formatter := pure ()", "start": [ 495, 1 ], "end": [ 495, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.skip.formatter", "code": "@[combinator_formatter skip] def skip.formatter : Formatter := pure ()", "start": [ 496, 1 ], "end": [ 496, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.pushNone.formatter", "code": "@[combinator_formatter pushNone] def pushNone.formatter : Formatter := goLeft", "start": [ 498, 1 ], "end": [ 498, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.hygieneInfoNoAntiquot.formatter", "code": "@[combinator_formatter hygieneInfoNoAntiquot] def hygieneInfoNoAntiquot.formatter : Formatter := goLeft", "start": [ 499, 1 ], "end": [ 499, 104 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.interpolatedStr.formatter", "code": "@[combinator_formatter interpolatedStr]\ndef interpolatedStr.formatter (p : Formatter) : Formatter := do\n visitArgs $ (← getCur).getArgs.reverse.forM fun chunk =>\n match chunk.isLit? interpolatedStrLitKind with\n | some str => push str *> goLeft\n | none => p", "start": [ 501, 1 ], "end": [ 506, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.ite", "code": "@[combinator_formatter _root_.ite, macro_inline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Formatter) : Formatter :=\n if c then t else e", "start": [ 508, 1 ], "end": [ 509, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.FormatterAliasValue", "code": "abbrev FormatterAliasValue := AliasValue Formatter", "start": [ 511, 1 ], "end": [ 511, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.registerAlias", "code": "def registerAlias (aliasName : Name) (v : FormatterAliasValue) : IO Unit := do\n Parser.registerAliasCore formatterAliasesRef aliasName v", "start": [ 515, 1 ], "end": [ 516, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.format", "code": "def format (formatter : Formatter) (stx : Syntax) : CoreM Format := do\n trace[PrettyPrinter.format.input] \"{Std.format stx}\"\n let options ← getOptions\n let table ← Parser.builtinTokenTable.get\n catchInternalId backtrackExceptionId\n (do\n let (_, st) ← (concat formatter { table, options }).run { stxTrav := .fromSyntax stx }\n let mut f := st.stack[0]!\n if pp.oneline.get options then\n let mut s := f.pretty' options |>.trim\n let lineEnd := s.find (Β· == '\\n')\n if lineEnd < s.endPos then\n s := s.extract 0 lineEnd ++ \" [...]\"\n f := s\n return .fill f)\n (fun _ => throwError \"format: uncaught backtrack exception\")", "start": [ 531, 1 ], "end": [ 547, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.formatCategory", "code": "def formatCategory (cat : Name) := format <| categoryFormatter cat", "start": [ 549, 1 ], "end": [ 549, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.formatTerm", "code": "def formatTerm := formatCategory `term", "start": [ 551, 1 ], "end": [ 551, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.formatTactic", "code": "def formatTactic := formatCategory `tactic", "start": [ 552, 1 ], "end": [ 552, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.formatCommand", "code": "def formatCommand := formatCategory `command", "start": [ 553, 1 ], "end": [ 553, 45 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/NatInstTesters.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.isInstOfNatNat", "code": "def isInstOfNatNat (e : Expr) : MetaM Bool := do\n let_expr instOfNatNat _ ← e | return false\n return true", "start": [ 14, 1 ], "end": [ 16, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstAddNat", "code": "def isInstAddNat (e : Expr) : MetaM Bool := do\n let_expr instAddNat ← e | return false\n return true", "start": [ 17, 1 ], "end": [ 19, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstSubNat", "code": "def isInstSubNat (e : Expr) : MetaM Bool := do\n let_expr instSubNat ← e | return false\n return true", "start": [ 20, 1 ], "end": [ 22, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstMulNat", "code": "def isInstMulNat (e : Expr) : MetaM Bool := do\n let_expr instMulNat ← e | return false\n return true", "start": [ 23, 1 ], "end": [ 25, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstDivNat", "code": "def isInstDivNat (e : Expr) : MetaM Bool := do\n let_expr Nat.instDiv ← e | return false\n return true", "start": [ 26, 1 ], "end": [ 28, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstModNat", "code": "def isInstModNat (e : Expr) : MetaM Bool := do\n let_expr Nat.instMod ← e | return false\n return true", "start": [ 29, 1 ], "end": [ 31, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstNatPowNat", "code": "def isInstNatPowNat (e : Expr) : MetaM Bool := do\n let_expr instNatPowNat ← e | return false\n return true", "start": [ 32, 1 ], "end": [ 34, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstPowNat", "code": "def isInstPowNat (e : Expr) : MetaM Bool := do\n let_expr instPowNat _ i ← e | return false\n isInstNatPowNat i", "start": [ 35, 1 ], "end": [ 37, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstHAddNat", "code": "def isInstHAddNat (e : Expr) : MetaM Bool := do\n let_expr instHAdd _ i ← e | return false\n isInstAddNat i", "start": [ 38, 1 ], "end": [ 40, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstHSubNat", "code": "def isInstHSubNat (e : Expr) : MetaM Bool := do\n let_expr instHSub _ i ← e | return false\n isInstSubNat i", "start": [ 41, 1 ], "end": [ 43, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstHMulNat", "code": "def isInstHMulNat (e : Expr) : MetaM Bool := do\n let_expr instHMul _ i ← e | return false\n isInstMulNat i", "start": [ 44, 1 ], "end": [ 46, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstHDivNat", "code": "def isInstHDivNat (e : Expr) : MetaM Bool := do\n let_expr instHDiv _ i ← e | return false\n isInstDivNat i", "start": [ 47, 1 ], "end": [ 49, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstHModNat", "code": "def isInstHModNat (e : Expr) : MetaM Bool := do\n let_expr instHMod _ i ← e | return false\n isInstModNat i", "start": [ 50, 1 ], "end": [ 52, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstHPowNat", "code": "def isInstHPowNat (e : Expr) : MetaM Bool := do\n let_expr instHPow _ _ i ← e | return false\n isInstPowNat i", "start": [ 53, 1 ], "end": [ 55, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstLTNat", "code": "def isInstLTNat (e : Expr) : MetaM Bool := do\n let_expr instLTNat ← e | return false\n return true", "start": [ 56, 1 ], "end": [ 58, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstLENat", "code": "def isInstLENat (e : Expr) : MetaM Bool := do\n let_expr instLENat ← e | return false\n return true", "start": [ 59, 1 ], "end": [ 61, 14 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Extra.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Formatter.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Parenthesizer.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Extension.lean" ]
[ { "full_name": "Lean.Parser.optional", "code": "@[run_builtin_parser_attribute_hooks] def optional (p : Parser) : Parser :=\n optionalNoAntiquot (withAntiquotSpliceAndSuffix `optional p (symbol \"?\"))", "start": [ 25, 1 ], "end": [ 35, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.many", "code": "@[run_builtin_parser_attribute_hooks] def many (p : Parser) : Parser :=\n manyNoAntiquot (withAntiquotSpliceAndSuffix `many p (symbol \"*\"))", "start": [ 37, 1 ], "end": [ 45, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.many1", "code": "@[run_builtin_parser_attribute_hooks] def many1 (p : Parser) : Parser :=\n many1NoAntiquot (withAntiquotSpliceAndSuffix `many p (symbol \"*\"))", "start": [ 47, 1 ], "end": [ 60, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ident", "code": "@[run_builtin_parser_attribute_hooks] def ident : Parser :=\n withAntiquot (mkAntiquot \"ident\" identKind) identNoAntiquot", "start": [ 62, 1 ], "end": [ 74, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.identWithPartialTrailingDot", "code": "@[run_builtin_parser_attribute_hooks] def identWithPartialTrailingDot :=\n ident >> optional (checkNoWsBefore >> \".\" >> checkNoWsBefore >> ident)", "start": [ 80, 1 ], "end": [ 81, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.rawIdent", "code": "@[run_builtin_parser_attribute_hooks] def rawIdent : Parser :=\n withAntiquot (mkAntiquot \"ident\" identKind) rawIdentNoAntiquot", "start": [ 84, 1 ], "end": [ 85, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.hygieneInfo", "code": "@[run_builtin_parser_attribute_hooks] def hygieneInfo : Parser :=\n withAntiquot (mkAntiquot \"hygieneInfo\" hygieneInfoKind (anonymous := false)) hygieneInfoNoAntiquot", "start": [ 87, 1 ], "end": [ 100, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.numLit", "code": "@[run_builtin_parser_attribute_hooks] def numLit : Parser :=\n withAntiquot (mkAntiquot \"num\" numLitKind) numLitNoAntiquot", "start": [ 102, 1 ], "end": [ 113, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.scientificLit", "code": "@[run_builtin_parser_attribute_hooks] def scientificLit : Parser :=\n withAntiquot (mkAntiquot \"scientific\" scientificLitKind) scientificLitNoAntiquot", "start": [ 115, 1 ], "end": [ 121, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.strLit", "code": "@[run_builtin_parser_attribute_hooks] def strLit : Parser :=\n withAntiquot (mkAntiquot \"str\" strLitKind) strLitNoAntiquot", "start": [ 123, 1 ], "end": [ 131, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.charLit", "code": "@[run_builtin_parser_attribute_hooks] def charLit : Parser :=\n withAntiquot (mkAntiquot \"char\" charLitKind) charLitNoAntiquot", "start": [ 133, 1 ], "end": [ 142, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.nameLit", "code": "@[run_builtin_parser_attribute_hooks] def nameLit : Parser :=\n withAntiquot (mkAntiquot \"name\" nameLitKind) nameLitNoAntiquot", "start": [ 144, 1 ], "end": [ 151, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.group", "code": "@[run_builtin_parser_attribute_hooks, inline] def group (p : Parser) : Parser :=\n node groupKind p", "start": [ 153, 1 ], "end": [ 160, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.many1Indent", "code": "@[run_builtin_parser_attribute_hooks, inline] def many1Indent (p : Parser) : Parser :=\n withPosition $ many1 (checkColGe \"irrelevant\" >> p)", "start": [ 162, 1 ], "end": [ 169, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.manyIndent", "code": "@[run_builtin_parser_attribute_hooks, inline] def manyIndent (p : Parser) : Parser :=\n withPosition $ many (checkColGe \"irrelevant\" >> p)", "start": [ 171, 1 ], "end": [ 178, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.sepByIndent", "code": "@[inline] def sepByIndent (p : Parser) (sep : String) (psep : Parser := symbol sep) (allowTrailingSep : Bool := false) : Parser :=\n let p := withAntiquotSpliceAndSuffix `sepBy p (symbol \"*\")\n withPosition $ sepBy (checkColGe \"irrelevant\" >> p) sep (psep <|> checkColEq \"irrelevant\" >> checkLinebreakBefore >> pushNone) allowTrailingSep", "start": [ 180, 1 ], "end": [ 182, 146 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.sepBy1Indent", "code": "@[inline] def sepBy1Indent (p : Parser) (sep : String) (psep : Parser := symbol sep) (allowTrailingSep : Bool := false) : Parser :=\n let p := withAntiquotSpliceAndSuffix `sepBy p (symbol \"*\")\n withPosition $ sepBy1 (checkColGe \"irrelevant\" >> p) sep (psep <|> checkColEq \"irrelevant\" >> checkLinebreakBefore >> pushNone) allowTrailingSep", "start": [ 184, 1 ], "end": [ 186, 147 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.sepByIndent.formatter", "code": "@[combinator_formatter sepByIndent]\ndef sepByIndent.formatter (p : Formatter) (_sep : String) (pSep : Formatter) : Formatter := do\n let stx ← getCur\n let hasNewlineSep := stx.getArgs.mapIdx (fun ⟨i, _⟩ n =>\n i % 2 == 1 && n.matchesNull 0 && i != stx.getArgs.size - 1) |>.any id\n visitArgs do\n for i in (List.range stx.getArgs.size).reverse do\n if i % 2 == 0 then p else pSep <|>\n ((if i == stx.getArgs.size - 1 then pure () else pushWhitespace \"\\n\") *> goLeft)\n if hasNewlineSep then\n pushAlign (force := true)", "start": [ 189, 1 ], "end": [ 202, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.sepBy1Indent.formatter", "code": "@[combinator_formatter sepBy1Indent] def sepBy1Indent.formatter := sepByIndent.formatter", "start": [ 204, 1 ], "end": [ 204, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.notSymbol", "code": "@[run_builtin_parser_attribute_hooks] abbrev notSymbol (s : String) : Parser :=\n notFollowedBy (symbol s) s", "start": [ 208, 1 ], "end": [ 209, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.patternIgnore", "code": "@[inline, run_builtin_parser_attribute_hooks] def patternIgnore : Parser β†’ Parser := node `patternIgnore", "start": [ 211, 1 ], "end": [ 212, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppHardSpace", "code": "@[inline] def ppHardSpace : Parser := skip", "start": [ 214, 1 ], "end": [ 215, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppSpace", "code": "@[inline] def ppSpace : Parser := skip", "start": [ 216, 1 ], "end": [ 217, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppLine", "code": "@[inline] def ppLine : Parser := skip", "start": [ 218, 1 ], "end": [ 219, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppRealFill", "code": "@[inline] def ppRealFill : Parser β†’ Parser := id", "start": [ 220, 1 ], "end": [ 221, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppRealGroup", "code": "@[inline] def ppRealGroup : Parser β†’ Parser := id", "start": [ 222, 1 ], "end": [ 223, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppIndent", "code": "@[inline] def ppIndent : Parser β†’ Parser := id", "start": [ 224, 1 ], "end": [ 225, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppGroup", "code": "@[inline] def ppGroup (p : Parser) : Parser := ppRealFill (ppIndent p)", "start": [ 226, 1 ], "end": [ 229, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppDedent", "code": "@[inline] def ppDedent : Parser β†’ Parser := id", "start": [ 230, 1 ], "end": [ 233, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppAllowUngrouped", "code": "@[inline] def ppAllowUngrouped : Parser := skip", "start": [ 235, 1 ], "end": [ 245, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppDedentIfGrouped", "code": "@[inline] def ppDedentIfGrouped : Parser β†’ Parser := id", "start": [ 247, 1 ], "end": [ 251, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ppHardLineUnlessUngrouped", "code": "@[inline] def ppHardLineUnlessUngrouped : Parser := skip", "start": [ 253, 1 ], "end": [ 257, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppHardSpace.formatter", "code": "@[combinator_formatter ppHardSpace] def ppHardSpace.formatter : Formatter := Formatter.pushWhitespace \" \"", "start": [ 264, 1 ], "end": [ 264, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppSpace.formatter", "code": "@[combinator_formatter ppSpace] def ppSpace.formatter : Formatter := Formatter.pushLine", "start": [ 265, 1 ], "end": [ 265, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppLine.formatter", "code": "@[combinator_formatter ppLine] def ppLine.formatter : Formatter := Formatter.pushWhitespace \"\\n\"", "start": [ 266, 1 ], "end": [ 266, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppRealFill.formatter", "code": "@[combinator_formatter ppRealFill] def ppRealFill.formatter (p : Formatter) : Formatter := Formatter.fill p", "start": [ 267, 1 ], "end": [ 267, 108 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppRealGroup.formatter", "code": "@[combinator_formatter ppRealGroup] def ppRealGroup.formatter (p : Formatter) : Formatter := Formatter.group p", "start": [ 268, 1 ], "end": [ 268, 111 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppIndent.formatter", "code": "@[combinator_formatter ppIndent] def ppIndent.formatter (p : Formatter) : Formatter := Formatter.indent p", "start": [ 269, 1 ], "end": [ 269, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppDedent.formatter", "code": "@[combinator_formatter ppDedent] def ppDedent.formatter (p : Formatter) : Formatter := do\n let opts ← getOptions\n Formatter.indent p (some ((0:Int) - Std.Format.getIndent opts))", "start": [ 270, 1 ], "end": [ 272, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppAllowUngrouped.formatter", "code": "@[combinator_formatter ppAllowUngrouped] def ppAllowUngrouped.formatter : Formatter := do\n modify ({ Β· with mustBeGrouped := false })", "start": [ 274, 1 ], "end": [ 275, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppDedentIfGrouped.formatter", "code": "@[combinator_formatter ppDedentIfGrouped] def ppDedentIfGrouped.formatter (p : Formatter) : Formatter := do\n Formatter.concat p\n let indent := Std.Format.getIndent (← getOptions)\n unless (← get).isUngrouped do\n modify fun st => { st with stack := st.stack.modify (st.stack.size - 1) (Β·.nest (0 - indent)) }", "start": [ 276, 1 ], "end": [ 280, 100 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ppHardLineUnlessUngrouped.formatter", "code": "@[combinator_formatter ppHardLineUnlessUngrouped] def ppHardLineUnlessUngrouped.formatter : Formatter := do\n if (← get).isUngrouped then\n Formatter.pushLine\n else\n ppLine.formatter", "start": [ 281, 1 ], "end": [ 285, 21 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/GlobalInstances.lean
[ ".lake/packages/lean4/src/lean/Lean/ScopedEnvExtension.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.addGlobalInstance", "code": "def addGlobalInstance (declName : Name) (attrKind : AttributeKind) : MetaM Unit := do\n globalInstanceExtension.add declName attrKind", "start": [ 18, 1 ], "end": [ 19, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isGlobalInstance", "code": "@[export lean_is_instance]\ndef isGlobalInstance (env : Environment) (declName : Name) : Bool :=\n globalInstanceExtension.getState env |>.contains declName", "start": [ 21, 1 ], "end": [ 23, 60 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Offset.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/NatInstTesters.lean", ".lake/packages/lean4/src/lean/Lean/Meta/InferType.lean", ".lake/packages/lean4/src/lean/Lean/Data/LBool.lean" ]
[ { "full_name": "Lean.Meta.withInstantiatedMVars", "code": "private abbrev withInstantiatedMVars (e : Expr) (k : Expr β†’ OptionT MetaM Ξ±) : OptionT MetaM Ξ± := do\n let eNew ← instantiateMVars e\n if eNew.getAppFn.isMVar then\n failure\n else\n k eNew", "start": [ 13, 1 ], "end": [ 18, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.evalNat", "code": "partial def evalNat (e : Expr) : OptionT MetaM Nat := do\n match e with\n | .lit (.natVal n) => return n\n | .mdata _ e => evalNat e\n | .const ``Nat.zero .. => return 0\n | .app .. => visit e\n | .mvar .. => visit e\n | _ => failure\nwhere\n visit e := do\n match_expr e with\n | OfNat.ofNat _ n i => guard (← isInstOfNatNat i); evalNat n\n | Nat.succ a => return (← evalNat a) + 1\n | Nat.add a b => return (← evalNat a) + (← evalNat b)\n | Add.add _ i a b => guard (← isInstAddNat i); return (← evalNat a) + (← evalNat b)\n | HAdd.hAdd _ _ _ i a b => guard (← isInstHAddNat i); return (← evalNat a) + (← evalNat b)\n | Nat.sub a b => return (← evalNat a) - (← evalNat b)\n | Sub.sub _ i a b => guard (← isInstSubNat i); return (← evalNat a) - (← evalNat b)\n | HSub.hSub _ _ _ i a b => guard (← isInstHSubNat i); return (← evalNat a) - (← evalNat b)\n | Nat.mul a b => return (← evalNat a) * (← evalNat b)\n | Mul.mul _ i a b => guard (← isInstMulNat i); return (← evalNat a) * (← evalNat b)\n | HMul.hMul _ _ _ i a b => guard (← isInstHMulNat i); return (← evalNat a) * (← evalNat b)\n | Nat.div a b => return (← evalNat a) / (← evalNat b)\n | Div.div _ i a b => guard (← isInstDivNat i); return (← evalNat a) / (← evalNat b)\n | HDiv.hDiv _ _ _ i a b => guard (← isInstHDivNat i); return (← evalNat a) / (← evalNat b)\n | Nat.mod a b => return (← evalNat a) % (← evalNat b)\n | Mod.mod _ i a b => guard (← isInstModNat i); return (← evalNat a) % (← evalNat b)\n | HMod.hMod _ _ _ i a b => guard (← isInstHModNat i); return (← evalNat a) % (← evalNat b)\n | Nat.pow a b => return (← evalNat a) ^ (← evalNat b)\n | NatPow.pow _ i a b => guard (← isInstNatPowNat i); return (← evalNat a) ^ (← evalNat b)\n | Pow.pow _ _ i a b => guard (← isInstPowNat i); return (← evalNat a) ^ (← evalNat b)\n | HPow.hPow _ _ _ i a b => guard (← isInstHPowNat i); return (← evalNat a) ^ (← evalNat b)\n | _ => failure", "start": [ 20, 1 ], "end": [ 55, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchesInstance", "code": "def matchesInstance (e inst : Expr) : MetaM Bool :=\n withNewMCtxDepth (withTransparency .instances (isDefEq e inst))", "start": [ 57, 1 ], "end": [ 65, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getOffset", "code": "private partial def getOffset (e : Expr) : MetaM (Expr Γ— Nat) :=\n return (← isOffset? e).getD (e, 0)", "start": [ 69, 1 ], "end": [ 75, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isOffset?", "code": "partial def isOffset? (e : Expr) : OptionT MetaM (Expr Γ— Nat) := do\n let add (a b : Expr) := do\n let v ← evalNat b\n let (s, k) ← getOffset a\n return (s, k+v)\n match_expr e with\n | Nat.succ a =>\n let (s, k) ← getOffset a\n return (s, k+1)\n | Nat.add a b => add a b\n | Add.add _ i a b => guard (← matchesInstance i Nat.mkInstAdd); add a b\n | HAdd.hAdd _ _ _ i a b => guard (← matchesInstance i Nat.mkInstHAdd); add a b\n | _ => failure", "start": [ 77, 1 ], "end": [ 92, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isNatZero", "code": "private def isNatZero (e : Expr) : MetaM Bool := do\n match (← evalNat e) with\n | some v => return v == 0\n | _ => return false", "start": [ 96, 1 ], "end": [ 99, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkOffset", "code": "private def mkOffset (e : Expr) (offset : Nat) : MetaM Expr := do\n if offset == 0 then\n return e\n else if (← isNatZero e) then\n return mkNatLit offset\n else\n return mkNatAdd e (mkNatLit offset)", "start": [ 101, 1 ], "end": [ 107, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isDefEqOffset", "code": "def isDefEqOffset (s t : Expr) : MetaM LBool := do\n let ifNatExpr (x : MetaM LBool) : MetaM LBool := do\n let type ← inferType s\n if (← withNewMCtxDepth <| Meta.isExprDefEqAux type (mkConst ``Nat)) then\n x\n else\n return LBool.undef\n let isDefEq (s t) : MetaM LBool :=\n ifNatExpr <| toLBoolM <| Meta.isExprDefEqAux s t\n if !(← getConfig).offsetCnstrs then\n return LBool.undef\n else\n match (← isOffset? s) with\n | some (s, k₁) =>\n match (← isOffset? t) with\n | some (t, kβ‚‚) => if k₁ == kβ‚‚ then\n isDefEq s t\n else if k₁ < kβ‚‚ then\n isDefEq s (← mkOffset t (kβ‚‚ - k₁))\n else\n isDefEq (← mkOffset s (k₁ - kβ‚‚)) t\n | none =>\n match (← evalNat t) with\n | some vβ‚‚ => if vβ‚‚ β‰₯ k₁ then\n isDefEq s (mkNatLit <| vβ‚‚ - k₁)\n else\n ifNatExpr <| return LBool.false\n | none =>\n return LBool.undef\n | none =>\n match (← evalNat s) with\n | some v₁ =>\n match (← isOffset? t) with\n | some (t, kβ‚‚) => if v₁ β‰₯ kβ‚‚ then\n isDefEq (mkNatLit <| v₁ - kβ‚‚) t\n else\n ifNatExpr <| return LBool.false\n | none =>\n match (← evalNat t) with\n | some vβ‚‚ => ifNatExpr <| return (v₁ == vβ‚‚).toLBool | none => return LBool.undef\n | none => return LBool.undef", "start": [ 109, 1 ], "end": [ 154, 35 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/LitValues.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.getRawNatValue?", "code": "def getRawNatValue? (e : Expr) : Option Nat :=\n match e.consumeMData with\n | .lit (.natVal n) => some n\n | _ => none", "start": [ 22, 1 ], "end": [ 26, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getOfNatValue?", "code": "def getOfNatValue? (e : Expr) (typeDeclName : Name) : MetaM (Option (Nat Γ— Expr)) := OptionT.run do\n let_expr OfNat.ofNat type n _ ← e | failure\n let type ← whnfD type\n guard <| type.getAppFn.isConstOf typeDeclName\n let .lit (.natVal n) := n.consumeMData | failure\n return (n, type)", "start": [ 28, 1 ], "end": [ 34, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getNatValue?", "code": "def getNatValue? (e : Expr) : MetaM (Option Nat) := do\n let e := e.consumeMData\n if let some n := getRawNatValue? e then\n return some n\n let some (n, _) ← getOfNatValue? e ``Nat | return none\n return some n", "start": [ 36, 1 ], "end": [ 42, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getIntValue?", "code": "def getIntValue? (e : Expr) : MetaM (Option Int) := do\n if let some (n, _) ← getOfNatValue? e ``Int then\n return some n\n let_expr Neg.neg _ _ a ← e | return none\n let some (n, _) ← getOfNatValue? a ``Int | return none\n return some (-↑n)", "start": [ 44, 1 ], "end": [ 50, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getCharValue?", "code": "def getCharValue? (e : Expr) : MetaM (Option Char) := do\n let_expr Char.ofNat n ← e | return none\n let some n ← getNatValue? n | return none\n return some (Char.ofNat n)", "start": [ 52, 1 ], "end": [ 56, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getStringValue?", "code": "def getStringValue? (e : Expr) : (Option String) :=\n match e with\n | .lit (.strVal s) => some s\n | _ => none", "start": [ 58, 1 ], "end": [ 62, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getFinValue?", "code": "def getFinValue? (e : Expr) : MetaM (Option ((n : Nat) Γ— Fin n)) := OptionT.run do\n let (v, type) ← getOfNatValue? e ``Fin\n let n ← getNatValue? (← whnfD type.appArg!)\n match n with\n | 0 => failure\n | m+1 => return ⟨m+1, Fin.ofNat v⟩", "start": [ 64, 1 ], "end": [ 70, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getBitVecValue?", "code": "def getBitVecValue? (e : Expr) : MetaM (Option ((n : Nat) Γ— BitVec n)) := OptionT.run do\n match_expr e with\n | BitVec.ofNat nExpr vExpr =>\n let n ← getNatValue? nExpr\n let v ← getNatValue? vExpr\n return ⟨n, BitVec.ofNat n v⟩\n | BitVec.ofNatLt nExpr vExpr _ =>\n let n ← getNatValue? nExpr\n let v ← getNatValue? vExpr\n return ⟨n, BitVec.ofNat n v⟩\n | _ =>\n let (v, type) ← getOfNatValue? e ``BitVec\n let n ← getNatValue? (← whnfD type.appArg!)\n return ⟨n, BitVec.ofNat n v⟩", "start": [ 72, 1 ], "end": [ 92, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUInt8Value?", "code": "def getUInt8Value? (e : Expr) : MetaM (Option UInt8) := OptionT.run do\n let (n, _) ← getOfNatValue? e ``UInt8\n return UInt8.ofNat n", "start": [ 94, 1 ], "end": [ 97, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUInt16Value?", "code": "def getUInt16Value? (e : Expr) : MetaM (Option UInt16) := OptionT.run do\n let (n, _) ← getOfNatValue? e ``UInt16\n return UInt16.ofNat n", "start": [ 99, 1 ], "end": [ 102, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUInt32Value?", "code": "def getUInt32Value? (e : Expr) : MetaM (Option UInt32) := OptionT.run do\n let (n, _) ← getOfNatValue? e ``UInt32\n return UInt32.ofNat n", "start": [ 104, 1 ], "end": [ 107, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUInt64Value?", "code": "def getUInt64Value? (e : Expr) : MetaM (Option UInt64) := OptionT.run do\n let (n, _) ← getOfNatValue? e ``UInt64\n return UInt64.ofNat n", "start": [ 109, 1 ], "end": [ 112, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.normLitValue", "code": "def normLitValue (e : Expr) : MetaM Expr := do\n let e ← instantiateMVars e\n if let some n ← getNatValue? e then return toExpr n\n if let some n ← getIntValue? e then return toExpr n\n if let some ⟨_, n⟩ ← getFinValue? e then return toExpr n\n if let some ⟨_, n⟩ ← getBitVecValue? e then return toExpr n\n if let some s := getStringValue? e then return toExpr s\n if let some c ← getCharValue? e then return toExpr c\n if let some n ← getUInt8Value? e then return toExpr n\n if let some n ← getUInt16Value? e then return toExpr n\n if let some n ← getUInt32Value? e then return toExpr n\n if let some n ← getUInt64Value? e then return toExpr n\n return e", "start": [ 116, 1 ], "end": [ 132, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isLitValue", "code": "def isLitValue (e : Expr) : MetaM Bool := do\n let e ← instantiateMVars e\n if (← getNatValue? e).isSome then return true\n if (← getIntValue? e).isSome then return true\n if (← getFinValue? e).isSome then return true\n if (← getBitVecValue? e).isSome then return true\n if (getStringValue? e).isSome then return true\n if (← getCharValue? e).isSome then return true\n if (← getUInt8Value? e).isSome then return true\n if (← getUInt16Value? e).isSome then return true\n if (← getUInt32Value? e).isSome then return true\n if (← getUInt64Value? e).isSome then return true\n return false", "start": [ 134, 1 ], "end": [ 149, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.litToCtor", "code": "def litToCtor (e : Expr) : MetaM Expr := do\n let e ← instantiateMVars e\n if let some n ← getNatValue? e then\n if n = 0 then\n return mkConst ``Nat.zero\n else\n return .app (mkConst ``Nat.succ) (toExpr (n-1))\n if let some n ← getIntValue? e then\n if n < 0 then\n return .app (mkConst ``Int.negSucc) (toExpr (- (n+1)).toNat)\n else\n return .app (mkConst ``Int.ofNat) (toExpr n.toNat)\n if let some ⟨n, v⟩ ← getFinValue? e then\n let i := toExpr v.val\n let n := toExpr n\n let p := mkApp4 (mkConst ``LT.lt [0]) (mkConst ``Nat) (mkConst ``instLTNat) i n\n let h := mkApp3 (mkConst ``of_decide_eq_true) p\n (mkApp2 (mkConst ``Nat.decLt) i n)\n (mkApp2 (mkConst ``Eq.refl [1]) (mkConst ``Bool) (mkConst ``true))\n return mkApp3 (mkConst ``Fin.mk) n i h\n return e", "start": [ 151, 1 ], "end": [ 177, 11 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Level.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Extra.lean" ]
[ { "full_name": "Lean.Parser.levelParser", "code": "@[inline] def levelParser (rbp : Nat := 0) : Parser :=\n categoryParser `level rbp", "start": [ 15, 1 ], "end": [ 16, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.paren", "code": "@[builtin_level_parser] def paren := leading_parser\n \"(\" >> withoutPosition levelParser >> \")\"", "start": [ 20, 1 ], "end": [ 21, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.max", "code": "@[builtin_level_parser] def max := leading_parser\n nonReservedSymbol \"max\" true >> many1 (ppSpace >> levelParser maxPrec)", "start": [ 22, 1 ], "end": [ 23, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.imax", "code": "@[builtin_level_parser] def imax := leading_parser\n nonReservedSymbol \"imax\" true >> many1 (ppSpace >> levelParser maxPrec)", "start": [ 24, 1 ], "end": [ 25, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.hole", "code": "@[builtin_level_parser] def hole := leading_parser\n \"_\"", "start": [ 26, 1 ], "end": [ 27, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.num", "code": "@[builtin_level_parser] def num :=\n checkPrec maxPrec >> numLit", "start": [ 28, 1 ], "end": [ 29, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.ident", "code": "@[builtin_level_parser] def ident :=\n checkPrec maxPrec >> Parser.ident", "start": [ 30, 1 ], "end": [ 31, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Level.addLit", "code": "@[builtin_level_parser] def addLit := trailing_parser:65\n \" + \" >> numLit", "start": [ 32, 1 ], "end": [ 33, 18 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Attr.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Extra.lean" ]
[ { "full_name": "Lean.Parser.priorityParser", "code": "@[inline] def priorityParser (rbp : Nat := 0) : Parser :=\n categoryParser `prio rbp", "start": [ 20, 1 ], "end": [ 21, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.attrParser", "code": "@[inline] def attrParser (rbp : Nat := 0) : Parser :=\n categoryParser `attr rbp", "start": [ 23, 1 ], "end": [ 24, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Priority.numPrio", "code": "@[builtin_prio_parser] def numPrio := checkPrec maxPrec >> numLit", "start": [ 30, 1 ], "end": [ 30, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.simple", "code": "@[builtin_attr_parser] def simple := leading_parser ident >> optional (ppSpace >> (priorityParser <|> ident))", "start": [ 36, 1 ], "end": [ 36, 114 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.macro", "code": "@[builtin_attr_parser] def Β«macroΒ» := leading_parser \"macro \" >> ident", "start": [ 38, 1 ], "end": [ 38, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.export", "code": "@[builtin_attr_parser] def Β«exportΒ» := leading_parser \"export \" >> ident", "start": [ 39, 1 ], "end": [ 39, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.recursor", "code": "@[builtin_attr_parser] def recursor := leading_parser nonReservedSymbol \"recursor \" >> numLit", "start": [ 42, 1 ], "end": [ 42, 102 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.class", "code": "@[builtin_attr_parser] def Β«classΒ» := leading_parser \"class\"", "start": [ 43, 1 ], "end": [ 43, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.instance", "code": "@[builtin_attr_parser] def Β«instanceΒ» := leading_parser \"instance\" >> optional (ppSpace >> priorityParser)", "start": [ 44, 1 ], "end": [ 44, 113 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.default_instance", "code": "@[builtin_attr_parser] def default_instance := leading_parser nonReservedSymbol \"default_instance\" >> optional (ppSpace >> priorityParser)", "start": [ 45, 1 ], "end": [ 45, 139 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.specialize", "code": "@[builtin_attr_parser] def Β«specializeΒ» := leading_parser (nonReservedSymbol \"specialize\") >> many (ppSpace >> (ident <|> numLit))", "start": [ 46, 1 ], "end": [ 46, 135 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.externEntry", "code": "def externEntry := leading_parser\n optional (ident >> ppSpace) >> optional (nonReservedSymbol \"inline \") >> strLit", "start": [ 48, 1 ], "end": [ 49, 82 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.extern", "code": "@[builtin_attr_parser] def extern := leading_parser\n nonReservedSymbol \"extern\" >> optional (ppSpace >> numLit) >> many (ppSpace >> externEntry)", "start": [ 50, 1 ], "end": [ 51, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.tactic_alt", "code": "@[builtin_attr_parser] def Β«tactic_altΒ» := leading_parser\n \"tactic_alt\" >> ppSpace >> ident", "start": [ 53, 1 ], "end": [ 61, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Attr.tactic_tag", "code": "@[builtin_attr_parser] def Β«tactic_tagΒ» := leading_parser\n \"tactic_tag\" >> many1 (ppSpace >> ident)", "start": [ 63, 1 ], "end": [ 69, 43 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/GetUnfoldableConst.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/GlobalInstances.lean" ]
[ { "full_name": "Lean.Meta.canUnfoldDefault", "code": "private def canUnfoldDefault (cfg : Config) (info : ConstantInfo) : CoreM Bool := do\n match cfg.transparency with\n | .all => return true\n | .default => return !(← isIrreducible info.name)\n | m =>\n if (← isReducible info.name) then\n return true\n else if m == .instances && isGlobalInstance (← getEnv) info.name then\n return true\n else\n return false", "start": [ 11, 1 ], "end": [ 21, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.canUnfold", "code": "def canUnfold (info : ConstantInfo) : MetaM Bool := do\n let ctx ← read\n if let some f := ctx.canUnfold? then\n f ctx.config info\n else\n canUnfoldDefault ctx.config info", "start": [ 23, 1 ], "end": [ 28, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUnfoldableConst?", "code": "def getUnfoldableConst? (constName : Name) : MetaM (Option ConstantInfo) := do\n match (← getEnv).find? constName with\n | some (info@(.thmInfo _)) => getTheoremInfo info\n | some (info@(.defnInfo _)) => if (← canUnfold info) then return info else return none\n | some info => return some info\n | none => throwUnknownConstant constName", "start": [ 30, 1 ], "end": [ 43, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUnfoldableConstNoEx?", "code": "def getUnfoldableConstNoEx? (constName : Name) : MetaM (Option ConstantInfo) := do\n match (← getEnv).find? constName with\n | some (info@(.thmInfo _)) => getTheoremInfo info\n | some (info@(.defnInfo _)) => if (← canUnfold info) then return info else return none\n | some info => return some info\n | none => return none", "start": [ 45, 1 ], "end": [ 53, 45 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/FunInfo.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/InferType.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.checkFunInfoCache", "code": "@[inline] private def checkFunInfoCache (fn : Expr) (maxArgs? : Option Nat) (k : MetaM FunInfo) : MetaM FunInfo := do\n let t ← getTransparency\n match (← get).cache.funInfo.find? ⟨t, fn, maxArgs?⟩ with\n | some finfo => pure finfo\n | none => do\n let finfo ← k\n modify fun s => { s with cache := { s.cache with funInfo := s.cache.funInfo.insert ⟨t, fn, maxArgs?⟩ finfo } }\n pure finfo", "start": [ 12, 1 ], "end": [ 19, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whenHasVar", "code": "@[inline] private def whenHasVar {Ξ±} (e : Expr) (deps : Ξ±) (k : Ξ± β†’ Ξ±) : Ξ± :=\n if e.hasFVar then k deps else deps", "start": [ 21, 1 ], "end": [ 22, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.collectDeps", "code": "private def collectDeps (fvars : Array Expr) (e : Expr) : Array Nat :=\n let rec visit (e : Expr) (deps : Array Nat) : Array Nat :=\n match e with\n | .app f a => whenHasVar e deps (visit a ∘ visit f)\n | .forallE _ d b _ => whenHasVar e deps (visit b ∘ visit d)\n | .lam _ d b _ => whenHasVar e deps (visit b ∘ visit d)\n | .letE _ t v b _ => whenHasVar e deps (visit b ∘ visit v ∘ visit t)\n | .proj _ _ e => visit e deps\n | .mdata _ e => visit e deps\n | .fvar .. =>\n match fvars.indexOf? e with\n | none => deps\n | some i => if deps.contains i.val then deps else deps.push i.val\n | _ => deps\n let deps := visit e #[]\n deps.qsort (fun i j => i < j)", "start": [ 24, 1 ], "end": [ 39, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.updateHasFwdDeps", "code": "private def updateHasFwdDeps (pinfo : Array ParamInfo) (backDeps : Array Nat) : Array ParamInfo :=\n if backDeps.size == 0 then\n pinfo\n else\n pinfo.mapIdx fun i info =>\n if info.hasFwdDeps then\n info\n else if backDeps.contains i then\n { info with hasFwdDeps := true }\n else\n info", "start": [ 41, 1 ], "end": [ 53, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getFunInfoAux", "code": "private def getFunInfoAux (fn : Expr) (maxArgs? : Option Nat) : MetaM FunInfo :=\n checkFunInfoCache fn maxArgs? do\n let fnType ← inferType fn\n withTransparency TransparencyMode.default do\n forallBoundedTelescope fnType maxArgs? fun fvars type => do\n let mut paramInfo := #[]\n let mut higherOrderOutParams : FVarIdSet := {}\n for i in [:fvars.size] do\n let fvar := fvars[i]!\n let decl ← getFVarLocalDecl fvar\n let backDeps := collectDeps fvars decl.type\n let dependsOnHigherOrderOutParam :=\n !higherOrderOutParams.isEmpty\n && Option.isSome (decl.type.find? fun e => e.isFVar && higherOrderOutParams.contains e.fvarId!)\n paramInfo := updateHasFwdDeps paramInfo backDeps\n paramInfo := paramInfo.push {\n backDeps, dependsOnHigherOrderOutParam\n binderInfo := decl.binderInfo\n isProp := (← isProp decl.type)\n isDecInst := (← forallTelescopeReducing decl.type fun _ type => return type.isAppOf ``Decidable)\n }\n if decl.binderInfo == .instImplicit then\n \n if let some className ← isClass? decl.type then\n if let some outParamPositions := getOutParamPositions? (← getEnv) className then\n unless outParamPositions.isEmpty do\n let args := decl.type.getAppArgs\n for i in [:args.size] do\n if outParamPositions.contains i then\n let arg := args[i]!\n if let some idx := fvars.indexOf? arg then\n if (← whnf (← inferType arg)).isForall then\n paramInfo := paramInfo.modify idx fun info => { info with higherOrderOutParam := true }\n higherOrderOutParams := higherOrderOutParams.insert arg.fvarId!\n let resultDeps := collectDeps fvars type\n paramInfo := updateHasFwdDeps paramInfo resultDeps\n return { resultDeps, paramInfo }", "start": [ 55, 1 ], "end": [ 91, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getFunInfo", "code": "def getFunInfo (fn : Expr) : MetaM FunInfo :=\n getFunInfoAux fn none", "start": [ 93, 1 ], "end": [ 94, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getFunInfoNArgs", "code": "def getFunInfoNArgs (fn : Expr) (nargs : Nat) : MetaM FunInfo :=\n getFunInfoAux fn (some nargs)", "start": [ 96, 1 ], "end": [ 97, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FunInfo.getArity", "code": "def FunInfo.getArity (info : FunInfo) : Nat :=\n info.paramInfo.size", "start": [ 99, 1 ], "end": [ 100, 22 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/CtorRecognizer.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/LitValues.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Offset.lean" ]
[ { "full_name": "Lean.Meta.getConstructorVal?", "code": "private def getConstructorVal? (env : Environment) (ctorName : Name) : Option ConstructorVal :=\n match env.find? ctorName with\n | some (.ctorInfo v) => v\n | _ => none", "start": [ 12, 1 ], "end": [ 15, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isConstructorAppCore?", "code": "def isConstructorAppCore? (e : Expr) : MetaM (Option ConstructorVal) := do\n let .const n _ := e.getAppFn | return none\n let some v := getConstructorVal? (← getEnv) n | return none\n if v.numParams + v.numFields == e.getAppNumArgs then\n return some v\n else\n return none", "start": [ 17, 1 ], "end": [ 27, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isConstructorApp?", "code": "def isConstructorApp? (e : Expr) : MetaM (Option ConstructorVal) := do\n isConstructorAppCore? (← litToCtor e)", "start": [ 29, 1 ], "end": [ 34, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isConstructorApp'?", "code": "def isConstructorApp'? (e : Expr) : MetaM (Option ConstructorVal) := do\n if let some r ← isConstructorApp? e then\n return r\n isConstructorApp? (← whnf e)", "start": [ 36, 1 ], "end": [ 42, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isConstructorApp", "code": "def isConstructorApp (e : Expr) : MetaM Bool :=\n return (← isConstructorApp? e).isSome", "start": [ 44, 1 ], "end": [ 49, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isConstructorApp'", "code": "def isConstructorApp' (e : Expr) : MetaM Bool := do\n if (← isConstructorApp e) then return true\n return (← isConstructorApp (← whnf e))", "start": [ 51, 1 ], "end": [ 56, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.constructorApp?", "code": "def constructorApp? (e : Expr) : MetaM (Option (ConstructorVal Γ— Array Expr)) := do\n let e ← litToCtor e\n let .const declName _ := e.getAppFn | return none\n let some v := getConstructorVal? (← getEnv) declName | return none\n if v.numParams + v.numFields == e.getAppNumArgs then\n return some (v, e.getAppArgs)\n else\n return none", "start": [ 58, 1 ], "end": [ 69, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.constructorApp'?", "code": "def constructorApp'? (e : Expr) : MetaM (Option (ConstructorVal Γ— Array Expr)) := do\n if let some (e, k) ← isOffset? e then\n if k = 0 then\n return none\n else\n let .ctorInfo val ← getConstInfo ``Nat.succ | return none\n if k = 1 then return some (val, #[e])\n else return some (val, #[mkNatAdd e (toExpr (k-1))])\n else if let some r ← constructorApp? e then\n return some r\n else\n constructorApp? (← whnf e)", "start": [ 71, 1 ], "end": [ 86, 31 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Match/MatchPatternAttr.lean
[ ".lake/packages/lean4/src/lean/Lean/Attributes.lean" ]
[ { "full_name": "Lean.hasMatchPatternAttribute", "code": "@[export lean_has_match_pattern_attribute]\ndef hasMatchPatternAttribute (env : Environment) (n : Name) : Bool :=\n matchPatternAttr.hasTag env n", "start": [ 14, 1 ], "end": [ 16, 32 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Match/MatcherInfo.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.Match.DiscrInfo", "code": "structure DiscrInfo where\n \n hName? : Option Name := none\n deriving Inhabited", "start": [ 12, 1 ], "end": [ 15, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo", "code": "structure MatcherInfo where\n numParams : Nat\n numDiscrs : Nat\n altNumParams : Array Nat\n uElimPos? : Option Nat\n \n discrInfos : Array DiscrInfo", "start": [ 17, 1 ], "end": [ 34, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.numAlts", "code": "def MatcherInfo.numAlts (info : MatcherInfo) : Nat :=\n info.altNumParams.size", "start": [ 36, 1 ], "end": [ 37, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.arity", "code": "def MatcherInfo.arity (info : MatcherInfo) : Nat :=\n info.numParams + 1 + info.numDiscrs + info.numAlts", "start": [ 39, 1 ], "end": [ 40, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.getFirstDiscrPos", "code": "def MatcherInfo.getFirstDiscrPos (info : MatcherInfo) : Nat :=\n info.numParams + 1", "start": [ 42, 1 ], "end": [ 43, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.getDiscrRange", "code": "def MatcherInfo.getDiscrRange (info : MatcherInfo) : Std.Range :=\n { start := info.getFirstDiscrPos, stop := info.getFirstDiscrPos + info.numDiscrs }", "start": [ 45, 1 ], "end": [ 46, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.getFirstAltPos", "code": "def MatcherInfo.getFirstAltPos (info : MatcherInfo) : Nat :=\n info.numParams + 1 + info.numDiscrs", "start": [ 48, 1 ], "end": [ 49, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.getAltRange", "code": "def MatcherInfo.getAltRange (info : MatcherInfo) : Std.Range :=\n { start := info.getFirstAltPos, stop := info.getFirstAltPos + info.numAlts }", "start": [ 51, 1 ], "end": [ 52, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.getMotivePos", "code": "def MatcherInfo.getMotivePos (info : MatcherInfo) : Nat :=\n info.numParams", "start": [ 54, 1 ], "end": [ 55, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.getNumEqsFromDiscrInfos", "code": "def getNumEqsFromDiscrInfos (infos : Array DiscrInfo) : Nat := Id.run do\n let mut r := 0\n for info in infos do\n if info.hName?.isSome then\n r := r + 1\n return r", "start": [ 57, 1 ], "end": [ 62, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.MatcherInfo.getNumDiscrEqs", "code": "def MatcherInfo.getNumDiscrEqs (info : MatcherInfo) : Nat :=\n getNumEqsFromDiscrInfos info.discrInfos", "start": [ 64, 1 ], "end": [ 65, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.Extension.Entry", "code": "structure Entry where\n name : Name\n info : MatcherInfo", "start": [ 69, 1 ], "end": [ 71, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.Extension.State", "code": "structure State where\n map : SMap Name MatcherInfo := {}", "start": [ 73, 1 ], "end": [ 74, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.Extension.State.addEntry", "code": "def State.addEntry (s : State) (e : Entry) : State := { s with map := s.map.insert e.name e.info }", "start": [ 78, 1 ], "end": [ 78, 100 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.Extension.State.switch", "code": "def State.switch (s : State) : State := { s with map := s.map.switch }", "start": [ 79, 1 ], "end": [ 79, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.Extension.addMatcherInfo", "code": "def addMatcherInfo (env : Environment) (matcherName : Name) (info : MatcherInfo) : Environment :=\n extension.addEntry env { name := matcherName, info := info }", "start": [ 87, 1 ], "end": [ 88, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.Extension.getMatcherInfo?", "code": "def getMatcherInfo? (env : Environment) (declName : Name) : Option MatcherInfo :=\n (extension.getState env).map.find? declName", "start": [ 90, 1 ], "end": [ 91, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Match.addMatcherInfo", "code": "def addMatcherInfo (matcherName : Name) (info : MatcherInfo) : MetaM Unit :=\n modifyEnv fun env => Extension.addMatcherInfo env matcherName info", "start": [ 95, 1 ], "end": [ 96, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMatcherInfoCore?", "code": "def getMatcherInfoCore? (env : Environment) (declName : Name) : Option MatcherInfo :=\n Match.Extension.getMatcherInfo? env declName", "start": [ 102, 1 ], "end": [ 103, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMatcherInfo?", "code": "def getMatcherInfo? [Monad m] [MonadEnv m] (declName : Name) : m (Option MatcherInfo) :=\n return getMatcherInfoCore? (← getEnv) declName", "start": [ 105, 1 ], "end": [ 106, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMatcherCore", "code": "@[export lean_is_matcher]\ndef isMatcherCore (env : Environment) (declName : Name) : Bool :=\n getMatcherInfoCore? env declName |>.isSome", "start": [ 108, 1 ], "end": [ 110, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMatcher", "code": "def isMatcher [Monad m] [MonadEnv m] (declName : Name) : m Bool :=\n return isMatcherCore (← getEnv) declName", "start": [ 112, 1 ], "end": [ 113, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMatcherAppCore?", "code": "def isMatcherAppCore? (env : Environment) (e : Expr) : Option MatcherInfo :=\n let fn := e.getAppFn\n if fn.isConst then\n if let some matcherInfo := getMatcherInfoCore? env fn.constName! then\n if e.getAppNumArgs β‰₯ matcherInfo.arity then some matcherInfo else none\n else\n none\n else\n none", "start": [ 115, 1 ], "end": [ 123, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMatcherAppCore", "code": "def isMatcherAppCore (env : Environment) (e : Expr) : Bool :=\n isMatcherAppCore? env e |>.isSome", "start": [ 125, 1 ], "end": [ 126, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMatcherApp", "code": "def isMatcherApp [Monad m] [MonadEnv m] (e : Expr) : m Bool :=\n return isMatcherAppCore (← getEnv) e", "start": [ 128, 1 ], "end": [ 129, 39 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/Recognizers.lean
[ ".lake/packages/lean4/src/lean/Lean/Environment.lean" ]
[ { "full_name": "Lean.Expr.const?", "code": "@[inline] def const? (e : Expr) : Option (Name Γ— List Level) :=\n match e with\n | Expr.const n us => some (n, us)\n | _ => none", "start": [ 12, 1 ], "end": [ 15, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.app1?", "code": "@[inline] def app1? (e : Expr) (fName : Name) : Option Expr :=\n if e.isAppOfArity fName 1 then\n some e.appArg!\n else\n none", "start": [ 17, 1 ], "end": [ 21, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.app2?", "code": "@[inline] def app2? (e : Expr) (fName : Name) : Option (Expr Γ— Expr) :=\n if e.isAppOfArity fName 2 then\n some (e.appFn!.appArg!, e.appArg!)\n else\n none", "start": [ 23, 1 ], "end": [ 27, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.app3?", "code": "@[inline] def app3? (e : Expr) (fName : Name) : Option (Expr Γ— Expr Γ— Expr) :=\n if e.isAppOfArity fName 3 then\n some (e.appFn!.appFn!.appArg!, e.appFn!.appArg!, e.appArg!)\n else\n none", "start": [ 29, 1 ], "end": [ 33, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.app4?", "code": "@[inline] def app4? (e : Expr) (fName : Name) : Option (Expr Γ— Expr Γ— Expr Γ— Expr) :=\n if e.isAppOfArity fName 4 then\n some (e.appFn!.appFn!.appFn!.appArg!, e.appFn!.appFn!.appArg!, e.appFn!.appArg!, e.appArg!)\n else\n none", "start": [ 35, 1 ], "end": [ 39, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.eq?", "code": "@[inline] def eq? (p : Expr) : Option (Expr Γ— Expr Γ— Expr) :=\n p.app3? ``Eq", "start": [ 41, 1 ], "end": [ 42, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ne?", "code": "@[inline] def ne? (p : Expr) : Option (Expr Γ— Expr Γ— Expr) :=\n p.app3? ``Ne", "start": [ 44, 1 ], "end": [ 45, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.iff?", "code": "@[inline] def iff? (p : Expr) : Option (Expr Γ— Expr) :=\n p.app2? ``Iff", "start": [ 47, 1 ], "end": [ 48, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.eqOrIff?", "code": "@[inline] def eqOrIff? (p : Expr) : Option (Expr Γ— Expr) :=\n if let some (_, lhs, rhs) := p.app3? ``Eq then\n some (lhs, rhs)\n else\n p.iff?", "start": [ 50, 1 ], "end": [ 54, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.not?", "code": "@[inline] def not? (p : Expr) : Option Expr :=\n p.app1? ``Not", "start": [ 56, 1 ], "end": [ 57, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.notNot?", "code": "@[inline] def notNot? (p : Expr) : Option Expr :=\n match p.not? with\n | some p => p.not?\n | none => none", "start": [ 59, 1 ], "end": [ 62, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.and?", "code": "@[inline] def and? (p : Expr) : Option (Expr Γ— Expr) :=\n p.app2? ``And", "start": [ 64, 1 ], "end": [ 65, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.heq?", "code": "@[inline] def heq? (p : Expr) : Option (Expr Γ— Expr Γ— Expr Γ— Expr) :=\n p.app4? ``HEq", "start": [ 67, 1 ], "end": [ 68, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.natAdd?", "code": "def natAdd? (e : Expr) : Option (Expr Γ— Expr) :=\n e.app2? ``Nat.add", "start": [ 70, 1 ], "end": [ 71, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.arrow?", "code": "@[inline] def arrow? : Expr β†’ Option (Expr Γ— Expr)\n | Expr.forallE _ Ξ± Ξ² _ => if Ξ².hasLooseBVars then none else some (Ξ±, Ξ²)\n | _ => none", "start": [ 73, 1 ], "end": [ 75, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.isEq", "code": "def isEq (e : Expr) :=\n e.isAppOfArity ``Eq 3", "start": [ 77, 1 ], "end": [ 78, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.isHEq", "code": "def isHEq (e : Expr) :=\n e.isAppOfArity ``HEq 4", "start": [ 80, 1 ], "end": [ 81, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.isIte", "code": "def isIte (e : Expr) :=\n e.isAppOfArity ``ite 5", "start": [ 83, 1 ], "end": [ 84, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.isDIte", "code": "def isDIte (e : Expr) :=\n e.isAppOfArity ``dite 5", "start": [ 86, 1 ], "end": [ 87, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.listLit?", "code": "partial def listLit? (e : Expr) : Option (Expr Γ— List Expr) :=\n let rec loop (e : Expr) (acc : List Expr) :=\n if e.isAppOfArity' ``List.nil 1 then\n some (e.appArg!', acc.reverse)\n else if e.isAppOfArity' ``List.cons 3 then\n loop e.appArg!' (e.appFn!'.appArg!' :: acc)\n else\n none\n loop e []", "start": [ 89, 1 ], "end": [ 97, 12 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.arrayLit?", "code": "def arrayLit? (e : Expr) : Option (Expr Γ— List Expr) :=\n if e.isAppOfArity' ``List.toArray 2 then\n listLit? e.appArg!'\n else\n none", "start": [ 99, 1 ], "end": [ 103, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.prod?", "code": "def prod? (e : Expr) : Option (Expr Γ— Expr) :=\n e.app2? ``Prod", "start": [ 105, 1 ], "end": [ 107, 17 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Structure.lean
[ ".lake/packages/lean4/src/lean/Lean/ProjFns.lean", ".lake/packages/lean4/src/lean/Lean/Environment.lean" ]
[ { "full_name": "Lean.StructureFieldInfo", "code": "structure StructureFieldInfo where\n fieldName : Name\n projFn : Name\n \n subobject? : Option Name\n binderInfo : BinderInfo\n autoParam? : Option Expr := none\n deriving Inhabited, Repr", "start": [ 14, 1 ], "end": [ 21, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.StructureFieldInfo.lt", "code": "def StructureFieldInfo.lt (i₁ iβ‚‚ : StructureFieldInfo) : Bool :=\n Name.quickLt i₁.fieldName iβ‚‚.fieldName", "start": [ 23, 1 ], "end": [ 24, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.StructureInfo", "code": "structure StructureInfo where\n structName : Name\n fieldNames : Array Name := #[] fieldInfo : Array StructureFieldInfo := #[] deriving Inhabited", "start": [ 26, 1 ], "end": [ 30, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.StructureInfo.lt", "code": "def StructureInfo.lt (i₁ iβ‚‚ : StructureInfo) : Bool :=\n Name.quickLt i₁.structName iβ‚‚.structName", "start": [ 32, 1 ], "end": [ 33, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.StructureInfo.getProjFn?", "code": "def StructureInfo.getProjFn? (info : StructureInfo) (i : Nat) : Option Name :=\n if h : i < info.fieldNames.size then\n let fieldName := info.fieldNames.get ⟨i, h⟩\n info.fieldInfo.binSearch { fieldName := fieldName, projFn := default, subobject? := none, binderInfo := default } StructureFieldInfo.lt |>.map (Β·.projFn)\n else\n none", "start": [ 35, 1 ], "end": [ 40, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.StructureState", "code": "private structure StructureState where\n map : PersistentHashMap Name StructureInfo := {}\n deriving Inhabited", "start": [ 42, 1 ], "end": [ 45, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.StructureDescr", "code": "structure StructureDescr where\n structName : Name\n fields : Array StructureFieldInfo deriving Inhabited", "start": [ 53, 1 ], "end": [ 56, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.registerStructure", "code": "def registerStructure (env : Environment) (e : StructureDescr) : Environment :=\n structureExt.addEntry env {\n structName := e.structName\n fieldNames := e.fields.map fun e => e.fieldName\n fieldInfo := e.fields.qsort StructureFieldInfo.lt\n }", "start": [ 58, 1 ], "end": [ 63, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getStructureInfo?", "code": "def getStructureInfo? (env : Environment) (structName : Name) : Option StructureInfo :=\n match env.getModuleIdxFor? structName with\n | some modIdx => structureExt.getModuleEntries env modIdx |>.binSearch { structName } StructureInfo.lt\n | none => structureExt.getState env |>.map.find? structName", "start": [ 65, 1 ], "end": [ 68, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getStructureCtor", "code": "def getStructureCtor (env : Environment) (constName : Name) : ConstructorVal :=\n match env.find? constName with\n | some (.inductInfo { isRec := false, ctors := [ctorName], .. }) =>\n match env.find? ctorName with\n | some (ConstantInfo.ctorInfo val) => val\n | _ => panic! \"ill-formed environment\"\n | _ => panic! \"structure expected\"", "start": [ 70, 1 ], "end": [ 76, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getStructureFields", "code": "def getStructureFields (env : Environment) (structName : Name) : Array Name :=\n if let some info := getStructureInfo? env structName then\n info.fieldNames\n else\n panic! \"structure expected\"", "start": [ 78, 1 ], "end": [ 83, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getFieldInfo?", "code": "def getFieldInfo? (env : Environment) (structName : Name) (fieldName : Name) : Option StructureFieldInfo :=\n if let some info := getStructureInfo? env structName then\n info.fieldInfo.binSearch { fieldName := fieldName, projFn := default, subobject? := none, binderInfo := default } StructureFieldInfo.lt\n else\n none", "start": [ 85, 1 ], "end": [ 89, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.isSubobjectField?", "code": "def isSubobjectField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=\n if let some fieldInfo := getFieldInfo? env structName fieldName then\n fieldInfo.subobject?\n else\n none", "start": [ 91, 1 ], "end": [ 96, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getParentStructures", "code": "def getParentStructures (env : Environment) (structName : Name) : Array Name :=\n let fieldNames := getStructureFields env structName;\n fieldNames.foldl (init := #[]) fun acc fieldName =>\n match isSubobjectField? env structName fieldName with\n | some parentStructName => acc.push parentStructName\n | none => acc", "start": [ 98, 1 ], "end": [ 104, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getAllParentStructures", "code": "partial def getAllParentStructures (env : Environment) (structName : Name) : Array Name :=\n visit structName |>.run #[] |>.2\nwhere\n visit (structName : Name) : StateT (Array Name) Id Unit := do\n for p in getParentStructures env structName do\n modify fun s => s.push p\n visit p", "start": [ 106, 1 ], "end": [ 113, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.findField?", "code": "partial def findField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=\n if (getStructureFields env structName).contains fieldName then\n some structName\n else\n getParentStructures env structName |>.findSome? fun parentStructName => findField? env parentStructName fieldName", "start": [ 115, 1 ], "end": [ 120, 118 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getStructureFieldsFlattenedAux", "code": "private partial def getStructureFieldsFlattenedAux (env : Environment) (structName : Name) (fullNames : Array Name) (includeSubobjectFields : Bool) : Array Name :=\n (getStructureFields env structName).foldl (init := fullNames) fun fullNames fieldName =>\n match isSubobjectField? env structName fieldName with\n | some parentStructName =>\n let fullNames := if includeSubobjectFields then fullNames.push fieldName else fullNames\n getStructureFieldsFlattenedAux env parentStructName fullNames includeSubobjectFields\n | none => fullNames.push fieldName", "start": [ 122, 1 ], "end": [ 128, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getStructureFieldsFlattened", "code": "def getStructureFieldsFlattened (env : Environment) (structName : Name) (includeSubobjectFields := true) : Array Name :=\n getStructureFieldsFlattenedAux env structName #[] includeSubobjectFields", "start": [ 130, 1 ], "end": [ 140, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.isStructure", "code": "def isStructure (env : Environment) (constName : Name) : Bool :=\n getStructureInfo? env constName |>.isSome", "start": [ 142, 1 ], "end": [ 149, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getProjFnForField?", "code": "def getProjFnForField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=\n if let some fieldInfo := getFieldInfo? env structName fieldName then\n some fieldInfo.projFn\n else\n none", "start": [ 151, 1 ], "end": [ 155, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getProjFnInfoForField?", "code": "def getProjFnInfoForField? (env : Environment) (structName : Name) (fieldName : Name) : Option (Name Γ— ProjectionFunctionInfo) :=\n if let some projFn := getProjFnForField? env structName fieldName then\n (projFn, Β·) <$> env.getProjectionFnInfo? projFn\n else\n none", "start": [ 157, 1 ], "end": [ 161, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.mkDefaultFnOfProjFn", "code": "def mkDefaultFnOfProjFn (projFn : Name) : Name :=\n projFn ++ `_default", "start": [ 163, 1 ], "end": [ 164, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getDefaultFnForField?", "code": "def getDefaultFnForField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=\n if let some projName := getProjFnForField? env structName fieldName then\n let defFn := mkDefaultFnOfProjFn projName\n if env.contains defFn then defFn else none\n else\n let defFn := mkDefaultFnOfProjFn (structName ++ fieldName)\n if env.contains defFn then defFn else none", "start": [ 166, 1 ], "end": [ 173, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPathToBaseStructureAux", "code": "partial def getPathToBaseStructureAux (env : Environment) (baseStructName : Name) (structName : Name) (path : List Name) : Option (List Name) :=\n if baseStructName == structName then\n some path.reverse\n else\n let fieldNames := getStructureFields env structName;\n fieldNames.findSome? fun fieldName =>\n match isSubobjectField? env structName fieldName with\n | none => none\n | some parentStructName =>\n match getProjFnForField? env structName fieldName with\n | none => none\n | some projFn => getPathToBaseStructureAux env baseStructName parentStructName (projFn :: path)", "start": [ 175, 1 ], "end": [ 186, 104 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPathToBaseStructure?", "code": "def getPathToBaseStructure? (env : Environment) (baseStructName : Name) (structName : Name) : Option (List Name) :=\n getPathToBaseStructureAux env baseStructName structName []", "start": [ 188, 1 ], "end": [ 193, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.isStructureLike", "code": "def isStructureLike (env : Environment) (constName : Name) : Bool :=\n match env.find? constName with\n | some (.inductInfo { isRec := false, ctors := [_], numIndices := 0, .. }) => true\n | _ => false", "start": [ 195, 1 ], "end": [ 199, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getStructureLikeNumFields", "code": "def getStructureLikeNumFields (env : Environment) (constName : Name) : Nat :=\n match env.find? constName with\n | some (.inductInfo { isRec := false, ctors := [ctor], numIndices := 0, .. }) =>\n match env.find? ctor with\n | some (.ctorInfo { numFields := n, .. }) => n\n | _ => 0\n | _ => 0", "start": [ 201, 1 ], "end": [ 208, 11 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Term.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Attr.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Level.lean" ]
[ { "full_name": "Lean.Parser.Command.commentBody", "code": "def commentBody : Parser :=\n{ fn := rawFn (finishCommentBlock (pushMissingOnError := true) 1) (trailingWs := true) }", "start": [ 14, 1 ], "end": [ 15, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.commentBody.parenthesizer", "code": "@[combinator_parenthesizer commentBody]\ndef commentBody.parenthesizer := PrettyPrinter.Parenthesizer.visitToken", "start": [ 17, 1 ], "end": [ 18, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.commentBody.formatter", "code": "@[combinator_formatter commentBody]\ndef commentBody.formatter := PrettyPrinter.Formatter.visitAtom Name.anonymous", "start": [ 19, 1 ], "end": [ 20, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.docComment", "code": "def docComment := leading_parser\n ppDedent $ \"", "start": [ 22, 1 ], "end": [ 28, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.tacticParser", "code": "@[inline] def tacticParser (rbp : Nat := 0) : Parser :=\n categoryParser `tactic rbp", "start": [ 35, 1 ], "end": [ 36, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.convParser", "code": "@[inline] def convParser (rbp : Nat := 0) : Parser :=\n categoryParser `conv rbp", "start": [ 38, 1 ], "end": [ 39, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.sepByIndentSemicolon", "code": "@[run_builtin_parser_attribute_hooks]\ndef sepByIndentSemicolon (p : Parser) : Parser :=\n sepByIndent p \"; \" (allowTrailingSep := true)", "start": [ 43, 1 ], "end": [ 54, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.sepBy1IndentSemicolon", "code": "@[run_builtin_parser_attribute_hooks]\ndef sepBy1IndentSemicolon (p : Parser) : Parser :=\n sepBy1Indent p \"; \" (allowTrailingSep := true)", "start": [ 56, 1 ], "end": [ 67, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.tacticSeq1Indented", "code": "def tacticSeq1Indented : Parser := leading_parser\n sepBy1IndentSemicolon tacticParser", "start": [ 73, 1 ], "end": [ 74, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.tacticSeqBracketed", "code": "def tacticSeqBracketed : Parser := leading_parser\n \"{\" >> sepByIndentSemicolon tacticParser >> ppDedent (ppLine >> \"}\")", "start": [ 75, 1 ], "end": [ 78, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.tacticSeq", "code": "def tacticSeq := leading_parser\n tacticSeqBracketed <|> tacticSeq1Indented", "start": [ 80, 1 ], "end": [ 83, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.tacticSeqIndentGt", "code": "def tacticSeqIndentGt := withAntiquot (mkAntiquot \"tacticSeq\" ``tacticSeq) <| node ``tacticSeq <|\n tacticSeqBracketed <|> (checkColGt \"indented tactic sequence\" >> tacticSeq1Indented)", "start": [ 85, 1 ], "end": [ 89, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.seq1", "code": "def seq1 :=\n node `Lean.Parser.Tactic.seq1 $ sepBy1 tacticParser \";\\n\" (allowTrailingSep := true)", "start": [ 92, 1 ], "end": [ 93, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.darrow", "code": "def darrow : Parser := \" => \"", "start": [ 97, 1 ], "end": [ 97, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.semicolonOrLinebreak", "code": "def semicolonOrLinebreak := \";\" <|> checkLinebreakBefore >> pushNone", "start": [ 98, 1 ], "end": [ 98, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.byTactic", "code": "@[builtin_term_parser] def byTactic := leading_parser:leadPrec\n ppAllowUngrouped >> \"by \" >> Tactic.tacticSeqIndentGt", "start": [ 105, 1 ], "end": [ 107, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.byTactic'", "code": "def byTactic' := leading_parser\n \"by \" >> Tactic.tacticSeqIndentGt", "start": [ 115, 1 ], "end": [ 116, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.optSemicolon", "code": "def optSemicolon (p : Parser) : Parser :=\n ppDedent $ semicolonOrLinebreak >> ppLine >> p", "start": [ 119, 1 ], "end": [ 120, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.ident", "code": "@[builtin_term_parser] def ident :=\n checkPrec maxPrec >> Parser.ident", "start": [ 123, 1 ], "end": [ 124, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.num", "code": "@[builtin_term_parser] def num : Parser :=\n checkPrec maxPrec >> numLit", "start": [ 125, 1 ], "end": [ 126, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.scientific", "code": "@[builtin_term_parser] def scientific : Parser :=\n checkPrec maxPrec >> scientificLit", "start": [ 127, 1 ], "end": [ 128, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.str", "code": "@[builtin_term_parser] def str : Parser :=\n checkPrec maxPrec >> strLit", "start": [ 129, 1 ], "end": [ 130, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.char", "code": "@[builtin_term_parser] def char : Parser :=\n checkPrec maxPrec >> charLit", "start": [ 131, 1 ], "end": [ 132, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.type", "code": "@[builtin_term_parser] def type := leading_parser\n \"Type\" >> optional (checkWsBefore \"\" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec)", "start": [ 133, 1 ], "end": [ 135, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.sort", "code": "@[builtin_term_parser] def sort := leading_parser\n \"Sort\" >> optional (checkWsBefore \"\" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec)", "start": [ 136, 1 ], "end": [ 138, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.prop", "code": "@[builtin_term_parser] def prop := leading_parser\n \"Prop\"", "start": [ 139, 1 ], "end": [ 141, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.hole", "code": "@[builtin_term_parser] def hole := leading_parser\n \"_\"", "start": [ 142, 1 ], "end": [ 144, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.syntheticHole", "code": "@[builtin_term_parser] def syntheticHole := leading_parser\n \"?\" >> (ident <|> hole)", "start": [ 145, 1 ], "end": [ 148, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.omission", "code": "@[builtin_term_parser] def omission := leading_parser\n \"β‹―\"", "start": [ 149, 1 ], "end": [ 158, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binderIdent", "code": "def binderIdent : Parser := ident <|> hole", "start": [ 159, 1 ], "end": [ 159, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.sorry", "code": "@[builtin_term_parser] def Β«sorryΒ» := leading_parser\n \"sorry\"", "start": [ 160, 1 ], "end": [ 162, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.cdot", "code": "@[builtin_term_parser] def cdot := leading_parser\n symbol \"Β·\" <|> \".\"", "start": [ 163, 1 ], "end": [ 168, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.typeAscription", "code": "@[builtin_term_parser] def typeAscription := leading_parser\n \"(\" >> (withoutPosition (withoutForbidden (termParser >> \" :\" >> optional (ppSpace >> termParser)))) >> \")\"", "start": [ 169, 1 ], "end": [ 176, 110 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.tuple", "code": "@[builtin_term_parser] def tuple := leading_parser\n \"(\" >> optional (withoutPosition (withoutForbidden (termParser >> \", \" >> sepBy1 termParser \", \" (allowTrailingSep := true)))) >> \")\"", "start": [ 177, 1 ], "end": [ 179, 136 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.paren", "code": "@[builtin_term_parser] def paren := leading_parser\n \"(\" >> withoutPosition (withoutForbidden (ppDedentIfGrouped termParser)) >> \")\"", "start": [ 180, 1 ], "end": [ 190, 82 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.anonymousCtor", "code": "@[builtin_term_parser] def anonymousCtor := leading_parser\n \"⟨\" >> withoutPosition (withoutForbidden (sepBy termParser \", \" (allowTrailingSep := true))) >> \"⟩\"", "start": [ 191, 1 ], "end": [ 199, 102 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.optIdent", "code": "def optIdent : Parser :=\n optional (atomic (ident >> \" : \"))", "start": [ 200, 1 ], "end": [ 201, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.fromTerm", "code": "def fromTerm := leading_parser\n \"from \" >> termParser", "start": [ 202, 1 ], "end": [ 203, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.showRhs", "code": "def showRhs := fromTerm <|> byTactic'", "start": [ 204, 1 ], "end": [ 204, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.sufficesDecl", "code": "def sufficesDecl := leading_parser\n (atomic (group (binderIdent >> \" : \")) <|> hygieneInfo) >> termParser >> ppSpace >> showRhs", "start": [ 205, 1 ], "end": [ 208, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.suffices", "code": "@[builtin_term_parser] def Β«sufficesΒ» := leading_parser:leadPrec\n withPosition (\"suffices \" >> sufficesDecl) >> optSemicolon termParser", "start": [ 209, 1 ], "end": [ 210, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.show", "code": "@[builtin_term_parser] def Β«showΒ» := leading_parser:leadPrec \"show \" >> termParser >> ppSpace >> showRhs", "start": [ 211, 1 ], "end": [ 211, 109 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.structInstArrayRef", "code": "def structInstArrayRef := leading_parser\n \"[\" >> withoutPosition termParser >> \"]\"", "start": [ 212, 1 ], "end": [ 213, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.structInstLVal", "code": "def structInstLVal := leading_parser\n (ident <|> fieldIdx <|> structInstArrayRef) >>\n many (group (\".\" >> (ident <|> fieldIdx)) <|> structInstArrayRef)", "start": [ 214, 1 ], "end": [ 216, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.structInstField", "code": "def structInstField := ppGroup $ leading_parser\n structInstLVal >> \" := \" >> termParser", "start": [ 217, 1 ], "end": [ 218, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.structInstFieldAbbrev", "code": "def structInstFieldAbbrev := leading_parser\n atomic (ident >> notFollowedBy (\".\" <|> \":=\" <|> symbol \"[\") \"invalid field abbreviation\")", "start": [ 219, 1 ], "end": [ 221, 93 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.optEllipsis", "code": "def optEllipsis := leading_parser\n optional \" ..\"", "start": [ 222, 1 ], "end": [ 223, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.structInst", "code": "@[builtin_term_parser] def structInst := leading_parser\n \"{ \" >> withoutPosition (optional (atomic (sepBy1 termParser \", \" >> \" with \"))\n >> sepByIndent (structInstFieldAbbrev <|> structInstField) \", \" (allowTrailingSep := true)\n >> optEllipsis\n >> optional (\" : \" >> termParser)) >> \" }\"", "start": [ 224, 1 ], "end": [ 237, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.typeSpec", "code": "def typeSpec := leading_parser \" : \" >> termParser", "start": [ 238, 1 ], "end": [ 238, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.optType", "code": "def optType : Parser := optional typeSpec", "start": [ 239, 1 ], "end": [ 239, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.explicit", "code": "@[builtin_term_parser] def explicit := leading_parser\n \"@\" >> termParser maxPrec", "start": [ 240, 1 ], "end": [ 245, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.inaccessible", "code": "@[builtin_term_parser] def inaccessible := leading_parser\n \".(\" >> withoutPosition termParser >> \")\"", "start": [ 246, 1 ], "end": [ 251, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binderType", "code": "def binderType (requireType := false) : Parser :=\n if requireType then node nullKind (\" : \" >> termParser) else optional (\" : \" >> termParser)", "start": [ 252, 1 ], "end": [ 253, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binderTactic", "code": "def binderTactic := leading_parser\n atomic (symbol \" := \" >> \" by \") >> Tactic.tacticSeq", "start": [ 254, 1 ], "end": [ 255, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binderDefault", "code": "def binderDefault := leading_parser\n \" := \" >> termParser", "start": [ 256, 1 ], "end": [ 257, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binderDefault.parenthesizer", "code": "@[combinator_parenthesizer Lean.Parser.Term.binderDefault] def binderDefault.parenthesizer : Parenthesizer := do\n let prec := match (← getCur) with\n | `(binderDefault| := by $_) => maxPrec\n | _ => 0\n visitArgs do\n term.parenthesizer prec\n visitToken", "start": [ 260, 1 ], "end": [ 267, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.explicitBinder", "code": "def explicitBinder (requireType := false) := leading_parser ppGroup <|\n \"(\" >> withoutPosition (many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault)) >> \")\"", "start": [ 269, 1 ], "end": [ 274, 123 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.implicitBinder", "code": "def implicitBinder (requireType := false) := leading_parser ppGroup <|\n \"{\" >> withoutPosition (many1 binderIdent >> binderType requireType) >> \"}\"", "start": [ 275, 1 ], "end": [ 285, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.strictImplicitLeftBracket", "code": "def strictImplicitLeftBracket := atomic (group (symbol \"{\" >> \"{\")) <|> \"⦃\"", "start": [ 286, 1 ], "end": [ 286, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.strictImplicitRightBracket", "code": "def strictImplicitRightBracket := atomic (group (symbol \"}\" >> \"}\")) <|> \"⦄\"", "start": [ 287, 1 ], "end": [ 287, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.strictImplicitBinder", "code": "def strictImplicitBinder (requireType := false) := leading_parser ppGroup <|\n strictImplicitLeftBracket >> many1 binderIdent >>\n binderType requireType >> strictImplicitRightBracket", "start": [ 288, 1 ], "end": [ 303, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.instBinder", "code": "def instBinder := leading_parser ppGroup <|\n \"[\" >> withoutPosition (optIdent >> termParser) >> \"]\"", "start": [ 304, 1 ], "end": [ 312, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.bracketedBinder", "code": "def bracketedBinder (requireType := false) :=\n withAntiquot (mkAntiquot \"bracketedBinder\" decl_name% (isPseudoKind := true)) <|\n explicitBinder requireType <|> strictImplicitBinder requireType <|>\n implicitBinder requireType <|> instBinder", "start": [ 313, 1 ], "end": [ 322, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.depArrow", "code": "@[builtin_term_parser] def depArrow := leading_parser:25\n bracketedBinder true >> unicodeSymbol \" β†’ \" \" -> \" >> termParser", "start": [ 339, 1 ], "end": [ 340, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.forall", "code": "@[builtin_term_parser]\ndef Β«forallΒ» := leading_parser:leadPrec\n unicodeSymbol \"βˆ€\" \"forall\" >>\n many1 (ppSpace >> (binderIdent <|> bracketedBinder)) >>\n optType >> \", \" >> termParser", "start": [ 342, 1 ], "end": [ 346, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchAlt", "code": "def matchAlt (rhsParser : Parser := termParser) : Parser :=\n leading_parser (withAnonymousAntiquot := false)\n \"| \" >> ppIndent (\n sepBy1 (sepBy1 termParser \", \") \" | \" >> darrow >>\n checkColGe \"alternative right-hand-side to start in a column greater than or equal to the corresponding '|'\" >>\n rhsParser)", "start": [ 348, 1 ], "end": [ 353, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchAltExpr", "code": "def matchAltExpr := matchAlt", "start": [ 354, 1 ], "end": [ 357, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchAlts", "code": "def matchAlts (rhsParser : Parser := termParser) : Parser :=\n leading_parser withPosition $ many1Indent (ppLine >> matchAlt rhsParser)", "start": [ 362, 1 ], "end": [ 363, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchDiscr", "code": "def matchDiscr := leading_parser\n optional (atomic (ident >> \" : \")) >> termParser", "start": [ 365, 1 ], "end": [ 368, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.trueVal", "code": "def trueVal := leading_parser nonReservedSymbol \"true\"", "start": [ 370, 1 ], "end": [ 370, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.falseVal", "code": "def falseVal := leading_parser nonReservedSymbol \"false\"", "start": [ 371, 1 ], "end": [ 371, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.generalizingParam", "code": "def generalizingParam := leading_parser\n atomic (\"(\" >> nonReservedSymbol \"generalizing\") >> \" := \" >>\n (trueVal <|> falseVal) >> \")\" >> ppSpace", "start": [ 372, 1 ], "end": [ 374, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.motive", "code": "def motive := leading_parser\n atomic (\"(\" >> nonReservedSymbol \"motive\" >> \" := \") >>\n withoutPosition termParser >> \")\" >> ppSpace", "start": [ 376, 1 ], "end": [ 378, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.match", "code": "@[builtin_term_parser] def Β«matchΒ» := leading_parser:leadPrec\n \"match \" >> optional generalizingParam >> optional motive >> sepBy1 matchDiscr \", \" >>\n \" with\" >> ppDedent matchAlts", "start": [ 380, 1 ], "end": [ 415, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.nomatch", "code": "@[builtin_term_parser] def Β«nomatchΒ» := leading_parser:leadPrec \"nomatch \" >> sepBy1 termParser \", \"", "start": [ 416, 1 ], "end": [ 421, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.nofun", "code": "@[builtin_term_parser] def Β«nofunΒ» := leading_parser \"nofun\"", "start": [ 423, 1 ], "end": [ 423, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.funImplicitBinder", "code": "def funImplicitBinder := withAntiquot (mkAntiquot \"implicitBinder\" ``implicitBinder) <|\n atomic (lookahead (\"{\" >> many1 binderIdent >> (symbol \" : \" <|> \"}\"))) >> implicitBinder", "start": [ 425, 1 ], "end": [ 426, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.funStrictImplicitBinder", "code": "def funStrictImplicitBinder :=\n atomic (lookahead (\n strictImplicitLeftBracket >> many1 binderIdent >>\n (symbol \" : \" <|> strictImplicitRightBracket))) >>\n strictImplicitBinder", "start": [ 427, 1 ], "end": [ 431, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.funBinder", "code": "def funBinder : Parser :=\n withAntiquot (mkAntiquot \"funBinder\" decl_name% (isPseudoKind := true)) <|\n funStrictImplicitBinder <|> funImplicitBinder <|> instBinder <|> termParser maxPrec", "start": [ 432, 1 ], "end": [ 434, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.basicFun", "code": "def basicFun : Parser := leading_parser (withAnonymousAntiquot := false)\n ppGroup (many1 (ppSpace >> funBinder) >> optType >> unicodeSymbol \" ↦\" \" =>\") >> ppSpace >> termParser", "start": [ 437, 1 ], "end": [ 438, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.fun", "code": "@[builtin_term_parser] def Β«funΒ» := leading_parser:maxPrec\n ppAllowUngrouped >> unicodeSymbol \"Ξ»\" \"fun\" >> (basicFun <|> matchAlts)", "start": [ 439, 1 ], "end": [ 440, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.optExprPrecedence", "code": "def optExprPrecedence := optional (atomic \":\" >> termParser maxPrec)", "start": [ 442, 1 ], "end": [ 442, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.withAnonymousAntiquot", "code": "def withAnonymousAntiquot := leading_parser\n atomic (\" (\" >> nonReservedSymbol \"withAnonymousAntiquot\" >> \" := \") >>\n (trueVal <|> falseVal) >> \")\"", "start": [ 443, 1 ], "end": [ 445, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.leading_parser", "code": "@[builtin_term_parser] def Β«leading_parserΒ» := leading_parser:leadPrec\n \"leading_parser\" >> optExprPrecedence >> optional withAnonymousAntiquot >> ppSpace >> termParser", "start": [ 446, 1 ], "end": [ 447, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.trailing_parser", "code": "@[builtin_term_parser] def Β«trailing_parserΒ» := leading_parser:leadPrec\n \"trailing_parser\" >> optExprPrecedence >> optExprPrecedence >> ppSpace >> termParser", "start": [ 448, 1 ], "end": [ 449, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.borrowed", "code": "@[builtin_term_parser] def borrowed := leading_parser\n \"@& \" >> termParser leadPrec", "start": [ 451, 1 ], "end": [ 452, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.quotedName", "code": "@[builtin_term_parser] def quotedName := leading_parser nameLit", "start": [ 453, 1 ], "end": [ 454, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doubleQuotedName", "code": "@[builtin_term_parser] def doubleQuotedName := leading_parser\n \"`\" >> checkNoWsBefore >> rawCh '`' (trailingWs := false) >> ident", "start": [ 455, 1 ], "end": [ 462, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letIdBinder", "code": "def letIdBinder :=\n withAntiquot (mkAntiquot \"letIdBinder\" decl_name% (isPseudoKind := true)) <|\n binderIdent <|> bracketedBinder", "start": [ 464, 1 ], "end": [ 466, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letIdLhs", "code": "def letIdLhs : Parser :=\n binderIdent >> notFollowedBy (checkNoWsBefore \"\" >> \"[\")\n \"space is required before instance '[...]' binders to distinguish them from array updates `let x[i] := e; ...`\" >>\n many (ppSpace >> letIdBinder) >> optType", "start": [ 468, 1 ], "end": [ 471, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letIdDecl", "code": "def letIdDecl := leading_parser (withAnonymousAntiquot := false)\n atomic (letIdLhs >> \" := \") >> termParser", "start": [ 472, 1 ], "end": [ 473, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letPatDecl", "code": "def letPatDecl := leading_parser (withAnonymousAntiquot := false)\n atomic (termParser >> pushNone >> optType >> \" := \") >> termParser", "start": [ 474, 1 ], "end": [ 475, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letEqnsDecl", "code": "def letEqnsDecl := leading_parser (withAnonymousAntiquot := false)\n letIdLhs >> (\" := \" <|> matchAlts)", "start": [ 492, 1 ], "end": [ 493, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letDecl", "code": "def letDecl := leading_parser (withAnonymousAntiquot := false)\n notFollowedBy (nonReservedSymbol \"rec\") \"rec\" >>\n (letIdDecl <|> letPatDecl <|> letEqnsDecl)", "start": [ 494, 1 ], "end": [ 502, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.let", "code": "@[builtin_term_parser] def Β«letΒ» := leading_parser:leadPrec\n withPosition (\"let \" >> letDecl) >> optSemicolon termParser", "start": [ 503, 1 ], "end": [ 525, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.let_fun", "code": "@[builtin_term_parser] def Β«let_funΒ» := leading_parser:leadPrec\n withPosition ((symbol \"let_fun \" <|> \"let_Ξ» \") >> letDecl) >> optSemicolon termParser", "start": [ 526, 1 ], "end": [ 532, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.let_delayed", "code": "@[builtin_term_parser] def Β«let_delayedΒ» := leading_parser:leadPrec\n withPosition (\"let_delayed \" >> letDecl) >> optSemicolon termParser", "start": [ 533, 1 ], "end": [ 537, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.let_tmp", "code": "@[builtin_term_parser] def Β«let_tmpΒ» := leading_parser:leadPrec\n withPosition (\"let_tmp \" >> letDecl) >> optSemicolon termParser", "start": [ 538, 1 ], "end": [ 543, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.haveId", "code": "def haveId := leading_parser (withAnonymousAntiquot := false)\n (ppSpace >> binderIdent) <|> hygieneInfo", "start": [ 545, 1 ], "end": [ 546, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.haveIdLhs", "code": "def haveIdLhs :=\n haveId >> many (ppSpace >> letIdBinder) >> optType", "start": [ 548, 1 ], "end": [ 549, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.haveIdDecl", "code": "def haveIdDecl := leading_parser (withAnonymousAntiquot := false)\n atomic (haveIdLhs >> \" := \") >> termParser", "start": [ 550, 1 ], "end": [ 551, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.haveEqnsDecl", "code": "def haveEqnsDecl := leading_parser (withAnonymousAntiquot := false)\n haveIdLhs >> matchAlts", "start": [ 552, 1 ], "end": [ 553, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.haveDecl", "code": "def haveDecl := leading_parser (withAnonymousAntiquot := false)\n haveIdDecl <|> (ppSpace >> letPatDecl) <|> haveEqnsDecl", "start": [ 554, 1 ], "end": [ 558, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.have", "code": "@[builtin_term_parser] def Β«haveΒ» := leading_parser:leadPrec\n withPosition (\"have\" >> haveDecl) >> optSemicolon termParser", "start": [ 559, 1 ], "end": [ 560, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.haveI", "code": "@[builtin_term_parser] def Β«haveIΒ» := leading_parser\n withPosition (\"haveI \" >> haveDecl) >> optSemicolon termParser", "start": [ 561, 1 ], "end": [ 563, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letI", "code": "@[builtin_term_parser] def Β«letIΒ» := leading_parser\n withPosition (\"letI \" >> haveDecl) >> optSemicolon termParser", "start": [ 564, 1 ], "end": [ 566, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.scoped", "code": "def Β«scopedΒ» := leading_parser \"scoped \"", "start": [ 568, 1 ], "end": [ 568, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.local", "code": "def Β«localΒ» := leading_parser \"local \"", "start": [ 569, 1 ], "end": [ 569, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.attrKind", "code": "def attrKind := leading_parser optional (Β«scopedΒ» <|> Β«localΒ»)", "start": [ 570, 1 ], "end": [ 571, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.attrInstance", "code": "def attrInstance := ppGroup $ leading_parser attrKind >> attrParser", "start": [ 572, 1 ], "end": [ 572, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.attributes", "code": "def attributes := leading_parser\n \"@[\" >> withoutPosition (sepBy1 attrInstance \", \") >> \"] \"", "start": [ 574, 1 ], "end": [ 575, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Termination.terminationBy", "code": "def terminationBy := leading_parser\n \"termination_by \" >>\n optional (atomic (many (ppSpace >> Term.binderIdent) >> \" => \")) >>\n termParser", "start": [ 585, 1 ], "end": [ 605, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Termination.terminationBy?", "code": "@[inherit_doc terminationBy]\ndef terminationBy? := leading_parser\n \"termination_by?\"", "start": [ 607, 1 ], "end": [ 609, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Termination.decreasingBy", "code": "def decreasingBy := leading_parser\n ppDedent ppLine >> \"decreasing_by \" >> Tactic.tacticSeqIndentGt", "start": [ 611, 1 ], "end": [ 618, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Termination.suffix", "code": "def suffix := leading_parser\n optional (ppDedent ppLine >> (terminationBy? <|> terminationBy)) >> optional decreasingBy", "start": [ 620, 1 ], "end": [ 624, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letRecDecl", "code": "def letRecDecl := leading_parser\n optional Command.docComment >> optional Β«attributesΒ» >> letDecl >> Termination.suffix", "start": [ 629, 1 ], "end": [ 632, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letRecDecls", "code": "def letRecDecls := leading_parser\n sepBy1 letRecDecl \", \"", "start": [ 633, 1 ], "end": [ 635, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letrec", "code": "@[builtin_term_parser]\ndef Β«letrecΒ» := leading_parser:leadPrec\n withPosition (group (\"let \" >> nonReservedSymbol \"rec \") >> letRecDecls) >>\n optSemicolon termParser", "start": [ 636, 1 ], "end": [ 639, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.whereDecls", "code": "@[run_builtin_parser_attribute_hooks]\ndef whereDecls := leading_parser\n ppDedent ppLine >> \"where\" >> sepBy1Indent (ppGroup letRecDecl) \"; \" (allowTrailingSep := true)", "start": [ 641, 1 ], "end": [ 643, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchAltsWhereDecls", "code": "@[run_builtin_parser_attribute_hooks]\ndef matchAltsWhereDecls := leading_parser\n matchAlts >> Termination.suffix >> optional whereDecls", "start": [ 645, 1 ], "end": [ 647, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.noindex", "code": "@[builtin_term_parser] def noindex := leading_parser\n \"no_index \" >> termParser maxPrec", "start": [ 649, 1 ], "end": [ 650, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.unsafe", "code": "@[builtin_term_parser] def Β«unsafeΒ» := leading_parser:leadPrec \"unsafe \" >> termParser", "start": [ 652, 1 ], "end": [ 663, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binrel", "code": "@[builtin_term_parser] def binrel := leading_parser\n \"binrel% \" >> ident >> ppSpace >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 665, 1 ], "end": [ 667, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binrel_no_prop", "code": "@[builtin_term_parser] def binrel_no_prop := leading_parser\n \"binrel_no_prop% \" >> ident >> ppSpace >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 668, 1 ], "end": [ 670, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binop", "code": "@[builtin_term_parser] def binop := leading_parser\n \"binop% \" >> ident >> ppSpace >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 671, 1 ], "end": [ 673, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.binop_lazy", "code": "@[builtin_term_parser] def binop_lazy := leading_parser\n \"binop_lazy% \" >> ident >> ppSpace >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 674, 1 ], "end": [ 676, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.leftact", "code": "@[builtin_term_parser] def leftact := leading_parser\n \"leftact% \" >> ident >> ppSpace >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 677, 1 ], "end": [ 680, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.rightact", "code": "@[builtin_term_parser] def rightact := leading_parser\n \"rightact% \" >> ident >> ppSpace >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 681, 1 ], "end": [ 684, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.unop", "code": "@[builtin_term_parser] def unop := leading_parser\n \"unop% \" >> ident >> ppSpace >> termParser maxPrec", "start": [ 685, 1 ], "end": [ 687, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.forInMacro", "code": "@[builtin_term_parser] def forInMacro := leading_parser\n \"for_in% \" >> termParser maxPrec >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 689, 1 ], "end": [ 690, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.forInMacro'", "code": "@[builtin_term_parser] def forInMacro' := leading_parser\n \"for_in'% \" >> termParser maxPrec >> termParser maxPrec >> ppSpace >> termParser maxPrec", "start": [ 691, 1 ], "end": [ 692, 91 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.declName", "code": "@[builtin_term_parser] def declName := leading_parser \"decl_name%\"", "start": [ 694, 1 ], "end": [ 695, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.withDeclName", "code": "@[builtin_term_parser] def withDeclName := leading_parser\n \"with_decl_name% \" >> optional \"?\" >> ident >> ppSpace >> termParser", "start": [ 697, 1 ], "end": [ 704, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.typeOf", "code": "@[builtin_term_parser] def typeOf := leading_parser\n \"type_of% \" >> termParser maxPrec", "start": [ 705, 1 ], "end": [ 706, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.ensureTypeOf", "code": "@[builtin_term_parser] def ensureTypeOf := leading_parser\n \"ensure_type_of% \" >> termParser maxPrec >> strLit >> ppSpace >> termParser", "start": [ 707, 1 ], "end": [ 708, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.ensureExpectedType", "code": "@[builtin_term_parser] def ensureExpectedType := leading_parser\n \"ensure_expected_type% \" >> strLit >> ppSpace >> termParser maxPrec", "start": [ 709, 1 ], "end": [ 710, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.noImplicitLambda", "code": "@[builtin_term_parser] def noImplicitLambda := leading_parser\n \"no_implicit_lambda% \" >> termParser maxPrec", "start": [ 711, 1 ], "end": [ 712, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.clear", "code": "@[builtin_term_parser] def clear := leading_parser\n \"clear% \" >> ident >> semicolonOrLinebreak >> ppDedent ppLine >> termParser", "start": [ 714, 1 ], "end": [ 719, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letMVar", "code": "@[builtin_term_parser] def letMVar := leading_parser\n \"let_mvar% \" >> \"?\" >> ident >> \" := \" >> termParser >> \"; \" >> termParser", "start": [ 721, 1 ], "end": [ 722, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.waitIfTypeMVar", "code": "@[builtin_term_parser] def waitIfTypeMVar := leading_parser\n \"wait_if_type_mvar% \" >> \"?\" >> ident >> \"; \" >> termParser", "start": [ 723, 1 ], "end": [ 724, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.waitIfTypeContainsMVar", "code": "@[builtin_term_parser] def waitIfTypeContainsMVar := leading_parser\n \"wait_if_type_contains_mvar% \" >> \"?\" >> ident >> \"; \" >> termParser", "start": [ 725, 1 ], "end": [ 726, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.waitIfContainsMVar", "code": "@[builtin_term_parser] def waitIfContainsMVar := leading_parser\n \"wait_if_contains_mvar% \" >> \"?\" >> ident >> \"; \" >> termParser", "start": [ 727, 1 ], "end": [ 728, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.defaultOrOfNonempty", "code": "@[builtin_term_parser] def defaultOrOfNonempty := leading_parser\n \"default_or_ofNonempty% \" >> optional \"unsafe\"", "start": [ 730, 1 ], "end": [ 731, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.noErrorIfUnused", "code": "@[builtin_term_parser] def noErrorIfUnused := leading_parser\n \"no_error_if_unused% \" >> termParser", "start": [ 733, 1 ], "end": [ 738, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.namedArgument", "code": "def namedArgument := leading_parser (withAnonymousAntiquot := false)\n atomic (\"(\" >> ident >> \" := \") >> withoutPosition termParser >> \")\"", "start": [ 740, 1 ], "end": [ 741, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.ellipsis", "code": "def ellipsis := leading_parser (withAnonymousAntiquot := false)\n \"..\" >> notFollowedBy \".\" \"`.` immediately after `..`\"", "start": [ 742, 1 ], "end": [ 743, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.argument", "code": "def argument :=\n checkWsBefore \"expected space\" >>\n checkColGt \"expected to be indented\" >>\n (namedArgument <|> ellipsis <|> termParser argPrec)", "start": [ 744, 1 ], "end": [ 747, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.app", "code": "@[builtin_term_parser] def app := trailing_parser:leadPrec:maxPrec many1 argument", "start": [ 751, 1 ], "end": [ 751, 82 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.proj", "code": "@[builtin_term_parser] def proj := trailing_parser\n checkNoWsBefore >> \".\" >> checkNoWsBefore >> (fieldIdx <|> rawIdent)", "start": [ 753, 1 ], "end": [ 766, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.completion", "code": "@[builtin_term_parser] def completion := trailing_parser\n checkNoWsBefore >> \".\"", "start": [ 767, 1 ], "end": [ 768, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.arrow", "code": "@[builtin_term_parser] def arrow := trailing_parser\n checkPrec 25 >> unicodeSymbol \" β†’ \" \" -> \" >> termParser 25", "start": [ 769, 1 ], "end": [ 770, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.identProjKind", "code": "def identProjKind := `Lean.Parser.Term.identProj", "start": [ 772, 1 ], "end": [ 781, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.isIdent", "code": "def isIdent (stx : Syntax) : Bool :=\n stx.isAntiquot || stx.isIdent", "start": [ 783, 1 ], "end": [ 785, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.explicitUniv", "code": "@[builtin_term_parser] def explicitUniv : TrailingParser := trailing_parser\n checkStackTop isIdent \"expected preceding identifier\" >>\n checkNoWsBefore \"no space before '.{'\" >> \".{\" >>\n sepBy1 levelParser \", \" >> \"}\"", "start": [ 787, 1 ], "end": [ 791, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.namedPattern", "code": "@[builtin_term_parser] def namedPattern : TrailingParser := trailing_parser\n checkStackTop isIdent \"expected preceding identifier\" >>\n checkNoWsBefore \"no space before '@'\" >> \"@\" >>\n optional (atomic (ident >> \":\")) >> termParser maxPrec", "start": [ 792, 1 ], "end": [ 797, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.pipeProj", "code": "@[builtin_term_parser] def pipeProj := trailing_parser:minPrec\n \" |>.\" >> checkNoWsBefore >> (fieldIdx <|> rawIdent) >> many argument", "start": [ 799, 1 ], "end": [ 804, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.pipeCompletion", "code": "@[builtin_term_parser] def pipeCompletion := trailing_parser:minPrec\n \" |>.\"", "start": [ 805, 1 ], "end": [ 806, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.subst", "code": "@[builtin_term_parser] def subst := trailing_parser:75\n \" β–Έ \" >> sepBy1 (termParser 75) \" β–Έ \"", "start": [ 808, 1 ], "end": [ 821, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.bracketedBinderF", "code": "def bracketedBinderF := bracketedBinder", "start": [ 823, 1 ], "end": [ 823, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.panic", "code": "@[builtin_term_parser] def panic := leading_parser:leadPrec\n \"panic! \" >> termParser", "start": [ 826, 1 ], "end": [ 835, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.unreachable", "code": "@[builtin_term_parser] def unreachable := leading_parser:leadPrec\n \"unreachable!\"", "start": [ 836, 1 ], "end": [ 838, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.dbgTrace", "code": "@[builtin_term_parser] def dbgTrace := leading_parser:leadPrec\n withPosition (\"dbg_trace\" >> (interpolatedStr termParser <|> termParser)) >>\n optSemicolon termParser", "start": [ 839, 1 ], "end": [ 845, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.assert", "code": "@[builtin_term_parser] def assert := leading_parser:leadPrec\n withPosition (\"assert! \" >> termParser) >> optSemicolon termParser", "start": [ 846, 1 ], "end": [ 848, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.macroArg", "code": "def macroArg := termParser maxPrec", "start": [ 850, 1 ], "end": [ 850, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.macroDollarArg", "code": "def macroDollarArg := leading_parser \"$\" >> termParser 10", "start": [ 851, 1 ], "end": [ 851, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.macroLastArg", "code": "def macroLastArg := macroDollarArg <|> macroArg", "start": [ 852, 1 ], "end": [ 852, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.stateRefT", "code": "@[builtin_term_parser] def stateRefT := leading_parser\n \"StateRefT \" >> macroArg >> ppSpace >> macroLastArg", "start": [ 855, 1 ], "end": [ 856, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.dynamicQuot", "code": "@[builtin_term_parser] def dynamicQuot := withoutPosition <| leading_parser\n \"`(\" >> ident >> \"| \" >> incQuotDepth (parserOfStack 1) >> \")\"", "start": [ 858, 1 ], "end": [ 859, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.dotIdent", "code": "@[builtin_term_parser] def dotIdent := leading_parser\n \".\" >> checkNoWsBefore >> rawIdent", "start": [ 861, 1 ], "end": [ 862, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.showTermElabImpl", "code": "@[builtin_term_parser] def showTermElabImpl :=\n leading_parser:leadPrec \"show_term_elab \" >> termParser", "start": [ 864, 1 ], "end": [ 868, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchExprPat", "code": "def matchExprPat := leading_parser optional (atomic (ident >> \"@\")) >> ident >> many binderIdent", "start": [ 874, 1 ], "end": [ 874, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchExprAlt", "code": "def matchExprAlt (rhsParser : Parser) := leading_parser \"| \" >> ppIndent (matchExprPat >> \" => \" >> rhsParser)", "start": [ 875, 1 ], "end": [ 875, 111 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchExprElseAlt", "code": "def matchExprElseAlt (rhsParser : Parser) := leading_parser \"| \" >> ppIndent (hole >> \" => \" >> rhsParser)", "start": [ 876, 1 ], "end": [ 876, 107 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchExprAlts", "code": "def matchExprAlts (rhsParser : Parser) :=\n leading_parser withPosition $\n many (ppLine >> checkColGe \"irrelevant\" >> notFollowedBy (symbol \"| \" >> \" _ \") \"irrelevant\" >> matchExprAlt rhsParser)\n >> (ppLine >> checkColGe \"else-alternative for `match_expr`, i.e., `| _ => ...`\" >> matchExprElseAlt rhsParser)", "start": [ 877, 1 ], "end": [ 880, 116 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.matchExpr", "code": "@[builtin_term_parser] def matchExpr := leading_parser:leadPrec\n \"match_expr \" >> termParser >> \" with\" >> ppDedent (matchExprAlts termParser)", "start": [ 881, 1 ], "end": [ 882, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letExpr", "code": "@[builtin_term_parser] def letExpr := leading_parser:leadPrec\n withPosition (\"let_expr \" >> matchExprPat >> \" := \" >> termParser >> checkColGt >> \" | \" >> termParser) >> optSemicolon termParser", "start": [ 884, 1 ], "end": [ 885, 133 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.quot", "code": "@[builtin_term_parser default+1] def Tactic.quot : Parser := leading_parser\n \"`(tactic| \" >> withoutPosition (incQuotDepth tacticParser) >> \")\"", "start": [ 889, 1 ], "end": [ 890, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.quotSeq", "code": "@[builtin_term_parser] def Tactic.quotSeq : Parser := leading_parser\n \"`(tactic| \" >> withoutPosition (incQuotDepth Tactic.seq1) >> \")\"", "start": [ 891, 1 ], "end": [ 892, 68 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/CollectMVars.lean
[ ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.CollectMVars.State", "code": "structure State where\n visitedExpr : ExprSet := {}\n result : Array MVarId := #[]", "start": [ 13, 1 ], "end": [ 15, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectMVars.Visitor", "code": "abbrev Visitor := State β†’ State", "start": [ 19, 1 ], "end": [ 19, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectMVars.visit", "code": "partial def visit (e : Expr) : Visitor := fun s =>\n if !e.hasExprMVar || s.visitedExpr.contains e then s\n else main e { s with visitedExpr := s.visitedExpr.insert e }", "start": [ 22, 3 ], "end": [ 24, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectMVars.main", "code": "partial def main : Expr β†’ Visitor\n | Expr.proj _ _ e => visit e\n | Expr.forallE _ d b _ => visit b ∘ visit d\n | Expr.lam _ d b _ => visit b ∘ visit d\n | Expr.letE _ t v b _ => visit b ∘ visit v ∘ visit t\n | Expr.app f a => visit a ∘ visit f\n | Expr.mdata _ b => visit b\n | Expr.mvar mvarId => fun s => { s with result := s.result.push mvarId }\n | _ => id", "start": [ 26, 3 ], "end": [ 34, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.collectMVars", "code": "def Expr.collectMVars (s : CollectMVars.State) (e : Expr) : CollectMVars.State :=\n CollectMVars.visit e s", "start": [ 39, 1 ], "end": [ 40, 25 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Transform.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.TransformStep", "code": "inductive TransformStep where\n \n | done (e : Expr)\n \n | visit (e : Expr)\n \n | continue (e? : Option Expr := none)\n deriving Inhabited, Repr", "start": [ 11, 1 ], "end": [ 24, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Core.transform", "code": "partial def transform {m} [Monad m] [MonadLiftT CoreM m] [MonadControlT CoreM m]\n (input : Expr)\n (pre : Expr β†’ m TransformStep := fun _ => return .continue)\n (post : Expr β†’ m TransformStep := fun e => return .done e)\n : m Expr :=\n let _ : STWorld IO.RealWorld m := ⟨⟩\n let _ : MonadLiftT (ST IO.RealWorld) m := { monadLift := fun x => liftM (m := CoreM) (liftM (m := ST IO.RealWorld) x) }\n let rec visit (e : Expr) : MonadCacheT ExprStructEq Expr m Expr :=\n checkCache { val := e : ExprStructEq } fun _ => Core.withIncRecDepth do\n let rec visitPost (e : Expr) : MonadCacheT ExprStructEq Expr m Expr := do\n match (← post e) with\n | .done e => pure e\n | .visit e => visit e\n | .continue e? => pure (e?.getD e)\n match (← pre e) with\n | .done e => pure e\n | .visit e => visitPost (← visit e)\n | .continue e? =>\n let e := e?.getD e\n match e with\n | Expr.forallE _ d b _ => visitPost (e.updateForallE! (← visit d) (← visit b))\n | Expr.lam _ d b _ => visitPost (e.updateLambdaE! (← visit d) (← visit b))\n | Expr.letE _ t v b _ => visitPost (e.updateLet! (← visit t) (← visit v) (← visit b))\n | Expr.app .. => e.withApp fun f args => do visitPost (mkAppN (← visit f) (← args.mapM visit))\n | Expr.mdata _ b => visitPost (e.updateMData! (← visit b))\n | Expr.proj _ _ b => visitPost (e.updateProj! (← visit b))\n | _ => visitPost e\n visit input |>.run", "start": [ 28, 1 ], "end": [ 67, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Core.betaReduce", "code": "def betaReduce (e : Expr) : CoreM Expr :=\n transform e (pre := fun e => return if e.isHeadBetaTarget then .visit e.headBeta else .continue)", "start": [ 69, 1 ], "end": [ 70, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.transform", "code": "partial def transform {m} [Monad m] [MonadLiftT MetaM m] [MonadControlT MetaM m]\n (input : Expr)\n (pre : Expr β†’ m TransformStep := fun _ => return .continue)\n (post : Expr β†’ m TransformStep := fun e => return .done e)\n (usedLetOnly := false)\n (skipConstInApp := false)\n : m Expr := do\n let _ : STWorld IO.RealWorld m := ⟨⟩\n let _ : MonadLiftT (ST IO.RealWorld) m := { monadLift := fun x => liftM (m := MetaM) (liftM (m := ST IO.RealWorld) x) }\n let rec visit (e : Expr) : MonadCacheT ExprStructEq Expr m Expr :=\n checkCache { val := e : ExprStructEq } fun _ => Meta.withIncRecDepth do\n let rec visitPost (e : Expr) : MonadCacheT ExprStructEq Expr m Expr := do\n match (← post e) with\n | .done e => pure e\n | .visit e => visit e\n | .continue e? => pure (e?.getD e)\n let rec visitLambda (fvars : Array Expr) (e : Expr) : MonadCacheT ExprStructEq Expr m Expr := do\n match e with\n | Expr.lam n d b c =>\n withLocalDecl n c (← visit (d.instantiateRev fvars)) fun x =>\n visitLambda (fvars.push x) b\n | e => visitPost (← mkLambdaFVars (usedLetOnly := usedLetOnly) fvars (← visit (e.instantiateRev fvars)))\n let rec visitForall (fvars : Array Expr) (e : Expr) : MonadCacheT ExprStructEq Expr m Expr := do\n match e with\n | Expr.forallE n d b c =>\n withLocalDecl n c (← visit (d.instantiateRev fvars)) fun x =>\n visitForall (fvars.push x) b\n | e => visitPost (← mkForallFVars (usedLetOnly := usedLetOnly) fvars (← visit (e.instantiateRev fvars)))\n let rec visitLet (fvars : Array Expr) (e : Expr) : MonadCacheT ExprStructEq Expr m Expr := do\n match e with\n | Expr.letE n t v b _ =>\n withLetDecl n (← visit (t.instantiateRev fvars)) (← visit (v.instantiateRev fvars)) fun x =>\n visitLet (fvars.push x) b\n | e => visitPost (← mkLetFVars (usedLetOnly := usedLetOnly) fvars (← visit (e.instantiateRev fvars)))\n let visitApp (e : Expr) : MonadCacheT ExprStructEq Expr m Expr :=\n e.withApp fun f args => do\n if skipConstInApp && f.isConst then\n visitPost (mkAppN f (← args.mapM visit))\n else\n visitPost (mkAppN (← visit f) (← args.mapM visit))\n match (← pre e) with\n | .done e => pure e\n | .visit e => visit e\n | .continue e? =>\n let e := e?.getD e\n match e with\n | Expr.forallE .. => visitForall #[] e\n | Expr.lam .. => visitLambda #[] e\n | Expr.letE .. => visitLet #[] e\n | Expr.app .. => visitApp e\n | Expr.mdata _ b => visitPost (e.updateMData! (← visit b))\n | Expr.proj _ _ b => visitPost (e.updateProj! (← visit b))\n | _ => visitPost e\n visit input |>.run", "start": [ 76, 1 ], "end": [ 137, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.zetaReduce", "code": "def zetaReduce (e : Expr) : MetaM Expr := do\n let pre (e : Expr) : MetaM TransformStep := do\n match e with\n | Expr.fvar fvarId =>\n match (← getLCtx).find? fvarId with\n | none => return TransformStep.done e\n | some localDecl =>\n if let some value := localDecl.value? then\n return TransformStep.visit value\n else\n return TransformStep.done e\n | _ => return .continue\n transform e (pre := pre) (usedLetOnly := true)", "start": [ 140, 1 ], "end": [ 152, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.unfoldDeclsFrom", "code": "def unfoldDeclsFrom (biggerEnv : Environment) (e : Expr) : CoreM Expr := do\n withoutModifyingEnv do\n let env ← getEnv\n setEnv biggerEnv let pre (e : Expr) : CoreM TransformStep := do\n match e with\n | Expr.const declName us .. =>\n if env.contains declName then\n return TransformStep.done e\n else if let some info := biggerEnv.find? declName then\n if info.hasValue then\n return TransformStep.visit (← instantiateValueLevelParams info us)\n else\n return TransformStep.done e\n else\n return TransformStep.done e\n | _ => return .continue\n Core.transform e (pre := pre)", "start": [ 154, 1 ], "end": [ 172, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.eraseInaccessibleAnnotations", "code": "def eraseInaccessibleAnnotations (e : Expr) : CoreM Expr :=\n Core.transform e (post := fun e => return TransformStep.done <| if let some e := inaccessible? e then e else e)", "start": [ 174, 1 ], "end": [ 175, 114 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.erasePatternRefAnnotations", "code": "def erasePatternRefAnnotations (e : Expr) : CoreM Expr :=\n Core.transform e (post := fun e => return TransformStep.done <| if let some (_, e) := patternWithRef? e then e else e)", "start": [ 177, 1 ], "end": [ 178, 121 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/WHNF.lean
[ ".lake/packages/lean4/src/lean/Lean/Structure.lean", ".lake/packages/lean4/src/lean/Lean/Util/Recognizers.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Match/MatcherInfo.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Match/MatchPatternAttr.lean", ".lake/packages/lean4/src/lean/Lean/Meta/CtorRecognizer.lean", ".lake/packages/lean4/src/lean/Lean/Meta/FunInfo.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Offset.lean", ".lake/packages/lean4/src/lean/Lean/Meta/GetUnfoldableConst.lean" ]
[ { "full_name": "Lean.Meta.getStructuralRecArgPos?", "code": "@[extern \"lean_get_structural_rec_arg_pos\"]\nopaque getStructuralRecArgPos? (declName : Name) : CoreM (Option Nat)", "start": [ 22, 1 ], "end": [ 28, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.smartUnfoldingSuffix", "code": "def smartUnfoldingSuffix := \"_sunfold\"", "start": [ 30, 1 ], "end": [ 30, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSmartUnfoldingNameFor", "code": "@[inline] def mkSmartUnfoldingNameFor (declName : Name) : Name :=\n Name.mkStr declName smartUnfoldingSuffix", "start": [ 32, 1 ], "end": [ 33, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.hasSmartUnfoldingDecl", "code": "def hasSmartUnfoldingDecl (env : Environment) (declName : Name) : Bool :=\n env.contains (mkSmartUnfoldingNameFor declName)", "start": [ 35, 1 ], "end": [ 36, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.markSmartUnfoldingMatch", "code": "def markSmartUnfoldingMatch (e : Expr) : Expr :=\n mkAnnotation `sunfoldMatch e", "start": [ 43, 1 ], "end": [ 45, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.smartUnfoldingMatch?", "code": "def smartUnfoldingMatch? (e : Expr) : Option Expr :=\n annotation? `sunfoldMatch e", "start": [ 47, 1 ], "end": [ 48, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.markSmartUnfoldingMatchAlt", "code": "def markSmartUnfoldingMatchAlt (e : Expr) : Expr :=\n mkAnnotation `sunfoldMatchAlt e", "start": [ 50, 1 ], "end": [ 52, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.smartUnfoldingMatchAlt?", "code": "def smartUnfoldingMatchAlt? (e : Expr) : Option Expr :=\n annotation? `sunfoldMatchAlt e", "start": [ 54, 1 ], "end": [ 55, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isAuxDef", "code": "def isAuxDef (constName : Name) : MetaM Bool := do\n let env ← getEnv\n return isAuxRecursor env constName || isNoConfusion env constName", "start": [ 61, 1 ], "end": [ 63, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchConstAux", "code": "@[inline] private def matchConstAux {Ξ±} (e : Expr) (failK : Unit β†’ MetaM Ξ±) (k : ConstantInfo β†’ List Level β†’ MetaM Ξ±) : MetaM Ξ± := do\n let .const name lvls := e\n | failK ()\n let (some cinfo) ← getUnfoldableConst? name\n | failK ()\n k cinfo lvls", "start": [ 65, 1 ], "end": [ 70, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getFirstCtor", "code": "private def getFirstCtor (d : Name) : MetaM (Option Name) := do\n let some (ConstantInfo.inductInfo { ctors := ctor::_, ..}) ← getUnfoldableConstNoEx? d |\n return none\n return some ctor", "start": [ 76, 1 ], "end": [ 79, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkNullaryCtor", "code": "private def mkNullaryCtor (type : Expr) (nparams : Nat) : MetaM (Option Expr) := do\n let .const d lvls := type.getAppFn\n | return none\n let (some ctor) ← getFirstCtor d | pure none\n return mkAppN (mkConst ctor lvls) (type.getAppArgs.shrink nparams)", "start": [ 81, 1 ], "end": [ 85, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getRecRuleFor", "code": "private def getRecRuleFor (recVal : RecursorVal) (major : Expr) : Option RecursorRule :=\n match major.getAppFn with\n | .const fn _ => recVal.rules.find? fun r => r.ctor == fn\n | _ => none", "start": [ 87, 1 ], "end": [ 90, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.toCtorWhenK", "code": "private def toCtorWhenK (recVal : RecursorVal) (major : Expr) : MetaM Expr := do\n let majorType ← inferType major\n let majorType ← instantiateMVars (← whnf majorType)\n let majorTypeI := majorType.getAppFn\n if !majorTypeI.isConstOf recVal.getInduct then\n return major\n else if majorType.hasExprMVar && majorType.getAppArgs[recVal.numParams:].any Expr.hasExprMVar then\n return major\n else do\n let (some newCtorApp) ← mkNullaryCtor majorType recVal.numParams | pure major\n let newType ← inferType newCtorApp\n \n if (← withAtLeastTransparency TransparencyMode.default <| withNewMCtxDepth <| isDefEq majorType newType) then\n return newCtorApp\n else\n return major", "start": [ 92, 1 ], "end": [ 113, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkProjFn", "code": "def mkProjFn (ctorVal : ConstructorVal) (us : List Level) (params : Array Expr) (i : Nat) (major : Expr) : CoreM Expr := do\n match getStructureInfo? (← getEnv) ctorVal.induct with\n | none => return mkProj ctorVal.induct i major\n | some info => match info.getProjFn? i with\n | none => return mkProj ctorVal.induct i major\n | some projFn => return mkApp (mkAppN (mkConst projFn us) params) major", "start": [ 115, 1 ], "end": [ 124, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.toCtorWhenStructure", "code": "private def toCtorWhenStructure (inductName : Name) (major : Expr) : MetaM Expr := do\n unless (← useEtaStruct inductName) do\n return major\n let env ← getEnv\n if !isStructureLike env inductName then\n return major\n else if let some _ ← isConstructorApp? major then\n return major\n else\n let majorType ← inferType major\n let majorType ← instantiateMVars (← whnf majorType)\n let majorTypeI := majorType.getAppFn\n if !majorTypeI.isConstOf inductName then\n return major\n match majorType.getAppFn with\n | Expr.const d us =>\n if (← whnfD (← inferType majorType)) == mkSort levelZero then\n return major else\n let some ctorName ← getFirstCtor d | pure major\n let ctorInfo ← getConstInfoCtor ctorName\n let params := majorType.getAppArgs.shrink ctorInfo.numParams\n let mut result := mkAppN (mkConst ctorName us) params\n for i in [:ctorInfo.numFields] do\n result := mkApp result (← mkProjFn ctorInfo us params i major)\n return result\n | _ => return major", "start": [ 126, 1 ], "end": [ 158, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isWFRec", "code": "private def isWFRec (declName : Name) : Bool :=\n declName == ``Acc.rec || declName == ``WellFounded.rec", "start": [ 162, 1 ], "end": [ 163, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.cleanupNatOffsetMajor", "code": "private def cleanupNatOffsetMajor (e : Expr) : MetaM Expr := do\n let some (e, k) ← isOffset? e | return e\n if k = 0 then\n return e\n else if k = 1 then\n return mkNatSucc e\n else\n return mkNatSucc (mkNatAdd e (toExpr (k - 1)))", "start": [ 165, 1 ], "end": [ 179, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceRec", "code": "private def reduceRec (recVal : RecursorVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit β†’ MetaM Ξ±) (successK : Expr β†’ MetaM Ξ±) : MetaM Ξ± :=\n let majorIdx := recVal.getMajorIdx\n if h : majorIdx < recArgs.size then do\n let major := recArgs.get ⟨majorIdx, h⟩\n let mut major ← if isWFRec recVal.name && (← getTransparency) == .default then\n withTransparency .all <| whnf major\n else\n whnf major\n if recVal.k then\n major ← toCtorWhenK recVal major\n major := major.toCtorIfLit\n major ← cleanupNatOffsetMajor major\n major ← toCtorWhenStructure recVal.getInduct major\n match getRecRuleFor recVal major with\n | some rule =>\n let majorArgs := major.getAppArgs\n if recLvls.length != recVal.levelParams.length then\n failK ()\n else\n let rhs := rule.rhs.instantiateLevelParams recVal.levelParams recLvls\n let rhs := mkAppRange rhs 0 (recVal.numParams+recVal.numMotives+recVal.numMinors) recArgs\n \n let nparams := majorArgs.size - rule.nfields\n let rhs := mkAppRange rhs nparams majorArgs.size majorArgs\n let rhs := mkAppRange rhs (majorIdx + 1) recArgs.size recArgs\n successK rhs\n | none => failK ()\n else\n failK ()", "start": [ 181, 1 ], "end": [ 217, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceQuotRec", "code": "private def reduceQuotRec (recVal : QuotVal) (recArgs : Array Expr) (failK : Unit β†’ MetaM Ξ±) (successK : Expr β†’ MetaM Ξ±) : MetaM Ξ± :=\n let process (majorPos argPos : Nat) : MetaM Ξ± :=\n if h : majorPos < recArgs.size then do\n let major := recArgs.get ⟨majorPos, h⟩\n let major ← whnf major\n match major with\n | Expr.app (Expr.app (Expr.app (Expr.const majorFn _) _) _) majorArg => do\n let some (ConstantInfo.quotInfo { kind := QuotKind.ctor, .. }) ← getUnfoldableConstNoEx? majorFn | failK ()\n let f := recArgs[argPos]!\n let r := mkApp f majorArg\n let recArity := majorPos + 1\n successK <| mkAppRange r recArity recArgs.size recArgs\n | _ => failK ()\n else\n failK ()\n match recVal.kind with\n | QuotKind.lift => process 5 3\n | QuotKind.ind => process 4 3\n | _ => failK ()", "start": [ 223, 1 ], "end": [ 242, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isRecStuck?", "code": "private partial def isRecStuck? (recVal : RecursorVal) (recArgs : Array Expr) : MetaM (Option MVarId) :=\n if recVal.k then\n return none\n else do\n let majorIdx := recVal.getMajorIdx\n if h : majorIdx < recArgs.size then do\n let major := recArgs.get ⟨majorIdx, h⟩\n let major ← whnf major\n getStuckMVar? major\n else\n return none", "start": [ 249, 3 ], "end": [ 260, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isQuotRecStuck?", "code": "private partial def isQuotRecStuck? (recVal : QuotVal) (recArgs : Array Expr) : MetaM (Option MVarId) :=\n let process? (majorPos : Nat) : MetaM (Option MVarId) :=\n if h : majorPos < recArgs.size then do\n let major := recArgs.get ⟨majorPos, h⟩\n let major ← whnf major\n getStuckMVar? major\n else\n return none\n match recVal.kind with\n | QuotKind.lift => process? 5\n | QuotKind.ind => process? 4\n | _ => return none", "start": [ 262, 3 ], "end": [ 273, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getStuckMVar?", "code": "partial def getStuckMVar? (e : Expr) : MetaM (Option MVarId) := do\n match e with\n | .mdata _ e => getStuckMVar? e\n | .proj _ _ e => getStuckMVar? (← whnf e)\n | .mvar .. =>\n let e ← instantiateMVars e\n match e with\n | .mvar mvarId => return some mvarId\n | _ => getStuckMVar? e\n | .app f .. =>\n let f := f.getAppFn\n match f with\n | .mvar .. =>\n let e ← instantiateMVars e\n match e.getAppFn with\n | .mvar mvarId => return some mvarId\n | _ => getStuckMVar? e\n | .const fName _ =>\n match (← getUnfoldableConstNoEx? fName) with\n | some <| .recInfo recVal => isRecStuck? recVal e.getAppArgs\n | some <| .quotInfo recVal => isQuotRecStuck? recVal e.getAppArgs\n | _ =>\n unless e.hasExprMVar do return none\n let some projInfo ← getProjectionFnInfo? fName | return none\n unless projInfo.fromClass do return none\n let args := e.getAppArgs\n if let some major := args.get? projInfo.numParams then\n if let some mvarId ← getStuckMVar? major then\n return mvarId\n \n let info ← getFunInfo f\n for pinfo in info.paramInfo, arg in args do\n if pinfo.isExplicit then\n if let some mvarId ← getStuckMVar? arg then\n return some mvarId\n return none\n | .proj _ _ e => getStuckMVar? (← whnf e)\n | _ => return none\n | _ => return none", "start": [ 275, 3 ], "end": [ 322, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.ProjReductionKind", "code": "inductive ProjReductionKind where\n \n | no\n \n | yes\n \n | yesWithDelta\n \n | yesWithDeltaI\n deriving DecidableEq, Inhabited, Repr", "start": [ 329, 1 ], "end": [ 355, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.WhnfCoreConfig", "code": "structure WhnfCoreConfig where\n \n iota : Bool := true\n \n beta : Bool := true\n \n proj : ProjReductionKind := .yesWithDelta\n \n zeta : Bool := true\n \n zetaDelta : Bool := true", "start": [ 357, 1 ], "end": [ 384, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfEasyCases", "code": "@[specialize] partial def whnfEasyCases (e : Expr) (k : Expr β†’ MetaM Expr) (config : WhnfCoreConfig := {}) : MetaM Expr := do\n match e with\n | .forallE .. => return e\n | .lam .. => return e\n | .sort .. => return e\n | .lit .. => return e\n | .bvar .. => panic! \"loose bvar in expression\"\n | .letE .. => k e\n | .const .. => k e\n | .app .. => k e\n | .proj .. => k e\n | .mdata _ e => whnfEasyCases e k config\n | .fvar fvarId =>\n let decl ← fvarId.getDecl\n match decl with\n | .cdecl .. => return e\n | .ldecl (value := v) .. =>\n unless config.zetaDelta || decl.isImplementationDetail do return e\n if (← getConfig).trackZetaDelta then\n modify fun s => { s with zetaDeltaFVarIds := s.zetaDeltaFVarIds.insert fvarId }\n whnfEasyCases v k config\n | .mvar mvarId =>\n match (← getExprMVarAssignment? mvarId) with\n | some v => whnfEasyCases v k config\n | none => return e", "start": [ 386, 1 ], "end": [ 413, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.deltaDefinition", "code": "@[specialize] private def deltaDefinition (c : ConstantInfo) (lvls : List Level)\n (failK : Unit β†’ MetaM Ξ±) (successK : Expr β†’ MetaM Ξ±) : MetaM Ξ± := do\n if c.levelParams.length != lvls.length then\n failK ()\n else\n successK (← instantiateValueLevelParams c lvls)", "start": [ 415, 1 ], "end": [ 420, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.deltaBetaDefinition", "code": "@[specialize] private def deltaBetaDefinition (c : ConstantInfo) (lvls : List Level) (revArgs : Array Expr)\n (failK : Unit β†’ MetaM Ξ±) (successK : Expr β†’ MetaM Ξ±) (preserveMData := false) : MetaM Ξ± := do\n if c.levelParams.length != lvls.length then\n failK ()\n else\n let val ← instantiateValueLevelParams c lvls\n let val := val.betaRev revArgs (preserveMData := preserveMData)\n successK val", "start": [ 422, 1 ], "end": [ 429, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.ReduceMatcherResult", "code": "inductive ReduceMatcherResult where\n | reduced (val : Expr)\n | stuck (val : Expr)\n | notMatcher\n | partialApp", "start": [ 431, 1 ], "end": [ 435, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.canUnfoldAtMatcher", "code": "def canUnfoldAtMatcher (cfg : Config) (info : ConstantInfo) : CoreM Bool := do\n match cfg.transparency with\n | .all => return true\n | .default => return !(← isIrreducible info.name)\n | _ =>\n if (← isReducible info.name) || isGlobalInstance (← getEnv) info.name then\n return true\n else if hasMatchPatternAttribute (← getEnv) info.name then\n return true\n else\n return info.name == ``ite\n || info.name == ``dite\n || info.name == ``decEq\n || info.name == ``Nat.decEq\n || info.name == ``Char.ofNat || info.name == ``Char.ofNatAux\n || info.name == ``String.decEq || info.name == ``List.hasDecEq\n || info.name == ``Fin.ofNat\n || info.name == ``Fin.ofNat' || info.name == ``UInt8.ofNat || info.name == ``UInt8.decEq\n || info.name == ``UInt16.ofNat || info.name == ``UInt16.decEq\n || info.name == ``UInt32.ofNat || info.name == ``UInt32.decEq\n || info.name == ``UInt64.ofNat || info.name == ``UInt64.decEq\n \n || info.name == ``HMod.hMod || info.name == ``Mod.mod", "start": [ 437, 1 ], "end": [ 489, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfMatcher", "code": "private def whnfMatcher (e : Expr) : MetaM Expr := do\n \n if (← getTransparency) matches .instances | .reducible then\n withTransparency .instances <| withReader (fun ctx => { ctx with canUnfold? := canUnfoldAtMatcher }) do\n whnf e\n else\n whnf e", "start": [ 491, 1 ], "end": [ 505, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceMatcher?", "code": "def reduceMatcher? (e : Expr) : MetaM ReduceMatcherResult := do\n let .const declName declLevels := e.getAppFn\n | return .notMatcher\n let some info ← getMatcherInfo? declName\n | return .notMatcher\n let args := e.getAppArgs\n let prefixSz := info.numParams + 1 + info.numDiscrs\n if args.size < prefixSz + info.numAlts then\n return ReduceMatcherResult.partialApp\n let constInfo ← getConstInfo declName\n let f ← instantiateValueLevelParams constInfo declLevels\n let auxApp := mkAppN f args[0:prefixSz]\n let auxAppType ← inferType auxApp\n forallBoundedTelescope auxAppType info.numAlts fun hs _ => do\n let auxApp ← whnfMatcher (mkAppN auxApp hs)\n let auxAppFn := auxApp.getAppFn\n let mut i := prefixSz\n for h in hs do\n if auxAppFn == h then\n let result := mkAppN args[i]! auxApp.getAppArgs\n let result := mkAppN result args[prefixSz + info.numAlts:args.size]\n return ReduceMatcherResult.reduced result.headBeta\n i := i + 1\n return ReduceMatcherResult.stuck auxApp", "start": [ 507, 1 ], "end": [ 530, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.projectCore?", "code": "def projectCore? (e : Expr) (i : Nat) : MetaM (Option Expr) := do\n let e := e.toCtorIfLit\n matchConstCtor e.getAppFn (fun _ => pure none) fun ctorVal _ =>\n let numArgs := e.getAppNumArgs\n let idx := ctorVal.numParams + i\n if idx < numArgs then\n return some (e.getArg! idx)\n else\n return none", "start": [ 532, 1 ], "end": [ 540, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.project?", "code": "def project? (e : Expr) (i : Nat) : MetaM (Option Expr) := do\n projectCore? (← whnf e) i", "start": [ 542, 1 ], "end": [ 543, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceProj?", "code": "def reduceProj? (e : Expr) : MetaM (Option Expr) := do\n match e with\n | .proj _ i c => project? c i\n | _ => return none", "start": [ 545, 1 ], "end": [ 549, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfDelayedAssigned?", "code": "private def whnfDelayedAssigned? (f' : Expr) (e : Expr) : MetaM (Option Expr) := do\n if f'.isMVar then\n match (← getDelayedMVarAssignment? f'.mvarId!) with\n | none => return none\n | some { fvars, mvarIdPending } =>\n let args := e.getAppArgs\n if fvars.size > args.size then\n return none\n else\n let newVal ← instantiateMVars (mkMVar mvarIdPending)\n if newVal.hasExprMVar then\n return none\n else\n let newVal := newVal.abstract fvars\n let result := newVal.instantiateRevRange 0 fvars.size args\n return mkAppRange result fvars.size args.size args\n else\n return none", "start": [ 551, 1 ], "end": [ 574, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfCore", "code": "partial def whnfCore (e : Expr) (config : WhnfCoreConfig := {}): MetaM Expr :=\n go e\nwhere\n go (e : Expr) : MetaM Expr :=\n whnfEasyCases e (config := config) fun e => do\n trace[Meta.whnf] e\n match e with\n | .const .. => pure e\n | .letE _ _ v b _ => if config.zeta then go <| b.instantiate1 v else return e\n | .app f .. =>\n if config.zeta then\n if let some (args, _, _, v, b) := e.letFunAppArgs? then\n return (← go <| mkAppN (b.instantiate1 v) args)\n let f := f.getAppFn\n let f' ← go f\n if config.beta && f'.isLambda then\n let revArgs := e.getAppRevArgs\n go <| f'.betaRev revArgs\n else if let some eNew ← whnfDelayedAssigned? f' e then\n go eNew\n else\n let e := if f == f' then e else e.updateFn f'\n unless config.iota do return e\n match (← reduceMatcher? e) with\n | .reduced eNew => go eNew\n | .partialApp => pure e\n | .stuck _ => pure e\n | .notMatcher =>\n matchConstAux f' (fun _ => return e) fun cinfo lvls =>\n match cinfo with\n | .recInfo rec => reduceRec rec lvls e.getAppArgs (fun _ => return e) (fun e => do recordUnfold cinfo.name; go e)\n | .quotInfo rec => reduceQuotRec rec e.getAppArgs (fun _ => return e) (fun e => do recordUnfold cinfo.name; go e)\n | c@(.defnInfo _) => do\n if (← isAuxDef c.name) then\n recordUnfold c.name\n deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => return e) go\n else\n return e\n | _ => return e\n | .proj _ i c =>\n let k (c : Expr) := do\n match (← projectCore? c i) with\n | some e => go e\n | none => return e\n match config.proj with\n | .no => return e\n | .yes => k (← go c)\n | .yesWithDelta => k (← whnf c)\n | .yesWithDeltaI => k (← whnfAtMostI c)\n | _ => unreachable!", "start": [ 576, 1 ], "end": [ 631, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.smartUnfoldingReduce?", "code": "partial def smartUnfoldingReduce? (e : Expr) : MetaM (Option Expr) :=\n go e |>.run\nwhere\n go (e : Expr) : OptionT MetaM Expr := do\n match e with\n | .letE n t v b _ => withLetDecl n t (← go v) fun x => do mkLetFVars #[x] (← go (b.instantiate1 x))\n | .lam .. => lambdaTelescope e fun xs b => do mkLambdaFVars xs (← go b)\n | .app f a .. => return mkApp (← go f) (← go a)\n | .proj _ _ s => return e.updateProj! (← go s)\n | .mdata _ b =>\n if let some m := smartUnfoldingMatch? e then\n goMatch m\n else\n return e.updateMData! (← go b)\n | _ => return e\n\n goMatch (e : Expr) : OptionT MetaM Expr := do\n match (← reduceMatcher? e) with\n | ReduceMatcherResult.reduced e =>\n if let some alt := smartUnfoldingMatchAlt? e then\n return alt\n else\n go e\n | ReduceMatcherResult.stuck e' =>\n let mvarId ← getStuckMVar? e'\n \n if (← Meta.synthPending mvarId) then\n goMatch e\n else\n failure\n | _ => failure", "start": [ 633, 1 ], "end": [ 693, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.unfoldProjInst?", "code": "partial def unfoldProjInst? (e : Expr) : MetaM (Option Expr) := do\n match e.getAppFn with\n | .const declName .. =>\n match (← getProjectionFnInfo? declName) with\n | some { fromClass := true, .. } =>\n match (← withDefault <| unfoldDefinition? e) with\n | none => return none\n | some e =>\n match (← withReducibleAndInstances <| reduceProj? e.getAppFn) with\n | none => return none\n | some r => recordUnfold declName; return mkAppN r e.getAppArgs |>.headBeta\n | _ => return none\n | _ => return none", "start": [ 697, 3 ], "end": [ 712, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.unfoldProjInstWhenInstances?", "code": "partial def unfoldProjInstWhenInstances? (e : Expr) : MetaM (Option Expr) := do\n if (← getTransparency) != TransparencyMode.instances then\n return none\n else\n unfoldProjInst? e", "start": [ 714, 3 ], "end": [ 723, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.unfoldDefinition?", "code": "partial def unfoldDefinition? (e : Expr) : MetaM (Option Expr) :=\n match e with\n | .app f _ =>\n matchConstAux f.getAppFn (fun _ => unfoldProjInstWhenInstances? e) fun fInfo fLvls => do\n if fInfo.levelParams.length != fLvls.length then\n return none\n else\n let unfoldDefault (_ : Unit) : MetaM (Option Expr) := do\n if fInfo.hasValue then\n recordUnfold fInfo.name\n deltaBetaDefinition fInfo fLvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))\n else\n return none\n if smartUnfolding.get (← getOptions) then\n match ((← getEnv).find? (mkSmartUnfoldingNameFor fInfo.name)) with\n | some fAuxInfo@(.defnInfo _) =>\n deltaBetaDefinition fAuxInfo fLvls e.getAppRevArgs (preserveMData := true) (fun _ => pure none) fun e₁ => do\n let some r ← smartUnfoldingReduce? e₁ | return none\n \n let some recArgPos ← getStructuralRecArgPos? fInfo.name\n | recordUnfold fInfo.name; return some r\n let numArgs := e.getAppNumArgs\n if recArgPos >= numArgs then return none\n let recArg := e.getArg! recArgPos numArgs\n if !(← isConstructorApp (← whnfMatcher recArg)) then return none\n recordUnfold fInfo.name\n return some r\n | _ =>\n if (← getMatcherInfo? fInfo.name).isSome then\n return none\n else\n unfoldDefault ()\n else\n unfoldDefault ()\n | .const declName lvls => do\n if smartUnfolding.get (← getOptions) && (← getEnv).contains (mkSmartUnfoldingNameFor declName) then\n return none\n else\n let some cinfo ← getUnfoldableConstNoEx? declName | pure none\n unless cinfo.hasValue do return none\n deltaDefinition cinfo lvls\n (fun _ => pure none)\n (fun e => do recordUnfold declName; pure (some e))\n | _ => return none", "start": [ 725, 3 ], "end": [ 808, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.unfoldDefinition", "code": "def unfoldDefinition (e : Expr) : MetaM Expr := do\n let some e ← unfoldDefinition? e | throwError \"failed to unfold definition{indentExpr e}\"\n return e", "start": [ 811, 1 ], "end": [ 813, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfHeadPred", "code": "@[specialize] partial def whnfHeadPred (e : Expr) (pred : Expr β†’ MetaM Bool) : MetaM Expr :=\n whnfEasyCases e fun e => do\n let e ← whnfCore e\n if (← pred e) then\n match (← unfoldDefinition? e) with\n | some e => whnfHeadPred e pred\n | none => return e\n else\n return e", "start": [ 815, 1 ], "end": [ 823, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfUntil", "code": "def whnfUntil (e : Expr) (declName : Name) : MetaM (Option Expr) := do\n let e ← whnfHeadPred e (fun e => return !e.isAppOf declName)\n if e.isAppOf declName then\n return e\n else\n return none", "start": [ 825, 1 ], "end": [ 830, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceRecMatcher?", "code": "def reduceRecMatcher? (e : Expr) : MetaM (Option Expr) := do\n if !e.isApp then\n return none\n else match (← reduceMatcher? e) with\n | .reduced e => return e\n | _ => matchConstAux e.getAppFn (fun _ => pure none) fun cinfo lvls => do\n match cinfo with\n | .recInfo Β«recΒ» => reduceRec Β«recΒ» lvls e.getAppArgs (fun _ => pure none) (fun e => do recordUnfold cinfo.name; pure (some e))\n | .quotInfo Β«recΒ» => reduceQuotRec Β«recΒ» e.getAppArgs (fun _ => pure none) (fun e => do recordUnfold cinfo.name; pure (some e))\n | c@(.defnInfo _) =>\n if (← isAuxDef c.name) then\n deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => pure none) (fun e => do recordUnfold c.name; pure (some e))\n else\n return none\n | _ => return none", "start": [ 832, 1 ], "end": [ 847, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceBoolNativeUnsafe", "code": "unsafe def reduceBoolNativeUnsafe (constName : Name) : MetaM Bool := evalConstCheck Bool `Bool constName", "start": [ 849, 1 ], "end": [ 849, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceNatNativeUnsafe", "code": "unsafe def reduceNatNativeUnsafe (constName : Name) : MetaM Nat := evalConstCheck Nat `Nat constName", "start": [ 850, 1 ], "end": [ 850, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceBoolNative", "code": "@[implemented_by reduceBoolNativeUnsafe] opaque reduceBoolNative (constName : Name) : MetaM Bool", "start": [ 851, 1 ], "end": [ 851, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceNatNative", "code": "@[implemented_by reduceNatNativeUnsafe] opaque reduceNatNative (constName : Name) : MetaM Nat", "start": [ 852, 1 ], "end": [ 852, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceNative?", "code": "def reduceNative? (e : Expr) : MetaM (Option Expr) :=\n match e with\n | Expr.app (Expr.const fName _) (Expr.const argName _) =>\n if fName == ``Lean.reduceBool then do\n return toExpr (← reduceBoolNative argName)\n else if fName == ``Lean.reduceNat then do\n return toExpr (← reduceNatNative argName)\n else\n return none\n | _ =>\n return none", "start": [ 854, 1 ], "end": [ 864, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.withNatValue", "code": "@[inline] def withNatValue (a : Expr) (k : Nat β†’ MetaM (Option Ξ±)) : MetaM (Option Ξ±) := do\n if !a.hasExprMVar && a.hasFVar then\n return none\n let a ← instantiateMVars a\n if a.hasExprMVar || a.hasFVar then\n return none\n let a ← whnf a\n match a with\n | .const ``Nat.zero _ => k 0\n | .lit (.natVal v) => k v\n | _ => return none", "start": [ 866, 1 ], "end": [ 876, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceUnaryNatOp", "code": "def reduceUnaryNatOp (f : Nat β†’ Nat) (a : Expr) : MetaM (Option Expr) :=\n withNatValue a fun a =>\n return mkRawNatLit <| f a", "start": [ 878, 1 ], "end": [ 880, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceBinNatOp", "code": "def reduceBinNatOp (f : Nat β†’ Nat β†’ Nat) (a b : Expr) : MetaM (Option Expr) :=\n withNatValue a fun a =>\n withNatValue b fun b => do\n trace[Meta.isDefEq.whnf.reduceBinOp] \"{a} op {b}\"\n return mkRawNatLit <| f a b", "start": [ 882, 1 ], "end": [ 886, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceBinNatPred", "code": "def reduceBinNatPred (f : Nat β†’ Nat β†’ Bool) (a b : Expr) : MetaM (Option Expr) := do\n withNatValue a fun a =>\n withNatValue b fun b =>\n return toExpr <| f a b", "start": [ 888, 1 ], "end": [ 891, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceNat?", "code": "def reduceNat? (e : Expr) : MetaM (Option Expr) :=\n match e with\n | .app (.const fn _) a =>\n if fn == ``Nat.succ then\n reduceUnaryNatOp Nat.succ a\n else\n return none\n | .app (.app (.const fn _) a1) a2 =>\n match fn with\n | ``Nat.add => reduceBinNatOp Nat.add a1 a2\n | ``Nat.sub => reduceBinNatOp Nat.sub a1 a2\n | ``Nat.mul => reduceBinNatOp Nat.mul a1 a2\n | ``Nat.div => reduceBinNatOp Nat.div a1 a2\n | ``Nat.mod => reduceBinNatOp Nat.mod a1 a2\n | ``Nat.pow => reduceBinNatOp Nat.pow a1 a2\n | ``Nat.gcd => reduceBinNatOp Nat.gcd a1 a2\n | ``Nat.beq => reduceBinNatPred Nat.beq a1 a2\n | ``Nat.ble => reduceBinNatPred Nat.ble a1 a2\n | ``Nat.land => reduceBinNatOp Nat.land a1 a2\n | ``Nat.lor => reduceBinNatOp Nat.lor a1 a2\n | ``Nat.xor => reduceBinNatOp Nat.xor a1 a2\n | ``Nat.shiftLeft => reduceBinNatOp Nat.shiftLeft a1 a2\n | ``Nat.shiftRight => reduceBinNatOp Nat.shiftRight a1 a2\n | _ => return none\n | _ =>\n return none", "start": [ 893, 1 ], "end": [ 918, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.useWHNFCache", "code": "@[inline] private def useWHNFCache (e : Expr) : MetaM Bool := do\n if e.hasFVar || e.hasExprMVar || (← read).canUnfold?.isSome then\n return false\n else\n match (← getConfig).transparency with\n | .default => return true\n | .all => return true\n | _ => return false", "start": [ 921, 1 ], "end": [ 930, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.cached?", "code": "@[inline] private def cached? (useCache : Bool) (e : Expr) : MetaM (Option Expr) := do\n if useCache then\n match (← getConfig).transparency with\n | .default => return (← get).cache.whnfDefault.find? e\n | .all => return (← get).cache.whnfAll.find? e\n | _ => unreachable!\n else\n return none", "start": [ 932, 1 ], "end": [ 939, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.cache", "code": "private def cache (useCache : Bool) (e r : Expr) : MetaM Expr := do\n if useCache then\n match (← getConfig).transparency with\n | .default => modify fun s => { s with cache.whnfDefault := s.cache.whnfDefault.insert e r }\n | .all => modify fun s => { s with cache.whnfAll := s.cache.whnfAll.insert e r }\n | _ => unreachable!\n return r", "start": [ 941, 1 ], "end": [ 947, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.whnfImp", "code": "@[export lean_whnf]\npartial def whnfImp (e : Expr) : MetaM Expr :=\n withIncRecDepth <| whnfEasyCases e fun e => do\n let useCache ← useWHNFCache e\n match (← cached? useCache e) with\n | some e' => pure e'\n | none =>\n withTraceNode `Meta.whnf (fun _ => return m!\"Non-easy whnf: {e}\") do\n checkSystem \"whnf\"\n let e' ← whnfCore e\n match (← reduceNat? e') with\n | some v => cache useCache e v\n | none =>\n match (← reduceNative? e') with\n | some v => cache useCache e v\n | none =>\n match (← unfoldDefinition? e') with\n | some e'' => cache useCache e (← whnfImp e'')\n | none => cache useCache e e'", "start": [ 949, 1 ], "end": [ 967, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceProjOf?", "code": "def reduceProjOf? (e : Expr) (p : Name β†’ Bool) : MetaM (Option Expr) := do\n if !e.isApp then\n pure none\n else match e.getAppFn with\n | .const name .. => do\n let env ← getEnv\n match env.getProjectionStructureName? name with\n | some structName =>\n if p structName then\n Meta.unfoldDefinition? e\n else\n pure none\n | none => pure none\n | _ => pure none", "start": [ 969, 1 ], "end": [ 983, 21 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/DiscrTreeTypes.lean
[ ".lake/packages/lean4/src/lean/Lean/ToExpr.lean", ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.Meta.DiscrTree.Key", "code": "inductive Key where\n | const : Name β†’ Nat β†’ Key\n | fvar : FVarId β†’ Nat β†’ Key\n | lit : Literal β†’ Key\n | star : Key\n | other : Key\n | arrow : Key\n | proj : Name β†’ Nat β†’ Nat β†’ Key\n deriving Inhabited, BEq, Repr", "start": [ 15, 1 ], "end": [ 26, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Key.hash", "code": "protected def Key.hash : Key β†’ UInt64\n | .const n a => mixHash 5237 $ mixHash (hash n) (hash a)\n | .fvar n a => mixHash 3541 $ mixHash (hash n) (hash a)\n | .lit v => mixHash 1879 $ hash v\n | .star => 7883\n | .other => 2411\n | .arrow => 17\n | .proj s i a => mixHash (hash a) $ mixHash (hash s) (hash i)", "start": [ 28, 1 ], "end": [ 35, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie", "code": "inductive Trie (Ξ± : Type) where\n | node (vs : Array Ξ±) (children : Array (Key Γ— Trie Ξ±)) : Trie Ξ±", "start": [ 50, 1 ], "end": [ 54, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree", "code": "structure DiscrTree (Ξ± : Type) where\n root : PersistentHashMap Key (Trie Ξ±) := {}", "start": [ 92, 1 ], "end": [ 96, 46 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Do.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Term.lean" ]
[ { "full_name": "Lean.Parser.doElemParser", "code": "@[inline] def doElemParser (rbp : Nat := 0) : Parser :=\n categoryParser `doElem rbp", "start": [ 15, 1 ], "end": [ 16, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.leftArrow", "code": "def leftArrow : Parser := unicodeSymbol \"← \" \"<- \"", "start": [ 19, 1 ], "end": [ 19, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.liftMethod", "code": "@[builtin_term_parser] def liftMethod := leading_parser:minPrec\n leftArrow >> termParser", "start": [ 20, 1 ], "end": [ 21, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doSeqItem", "code": "def doSeqItem := leading_parser\n ppLine >> doElemParser >> optional \"; \"", "start": [ 23, 1 ], "end": [ 24, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doSeqIndent", "code": "def doSeqIndent := leading_parser\n many1Indent doSeqItem", "start": [ 25, 1 ], "end": [ 26, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doSeqBracketed", "code": "def doSeqBracketed := leading_parser\n \"{\" >> withoutPosition (many1 doSeqItem) >> ppLine >> \"}\"", "start": [ 27, 1 ], "end": [ 28, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doSeq", "code": "def doSeq :=\n withAntiquot (mkAntiquot \"doSeq\" decl_name% (isPseudoKind := true)) <|\n doSeqBracketed <|> doSeqIndent", "start": [ 29, 1 ], "end": [ 35, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.termBeforeDo", "code": "def termBeforeDo := withForbidden \"do\" termParser", "start": [ 36, 1 ], "end": [ 40, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.notFollowedByRedefinedTermToken", "code": "def notFollowedByRedefinedTermToken :=\n notFollowedBy (\"set_option\" <|> \"open\" <|> \"if\" <|> \"match\" <|> \"match_expr\" <|> \"let\" <|> \"let_expr\" <|> \"have\" <|>\n \"do\" <|> \"dbg_trace\" <|> \"assert!\" <|> \"for\" <|> \"unless\" <|> \"return\" <|> symbol \"try\")\n \"token at 'do' element\"", "start": [ 48, 1 ], "end": [ 55, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doLet", "code": "@[builtin_doElem_parser] def doLet := leading_parser\n \"let \" >> optional \"mut \" >> letDecl", "start": [ 57, 1 ], "end": [ 58, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doLetElse", "code": "@[builtin_doElem_parser] def doLetElse := leading_parser\n \"let \" >> optional \"mut \" >> termParser >> \" := \" >> termParser >>\n checkColGt >> \" | \" >> doSeq", "start": [ 59, 1 ], "end": [ 61, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doLetExpr", "code": "@[builtin_doElem_parser] def doLetExpr := leading_parser\n \"let_expr \" >> matchExprPat >> \" := \" >> termParser >>\n checkColGt >> \" | \" >> doSeq", "start": [ 63, 1 ], "end": [ 65, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doLetMetaExpr", "code": "@[builtin_doElem_parser] def doLetMetaExpr := leading_parser\n \"let_expr \" >> matchExprPat >> \" ← \" >> termParser >>\n checkColGt >> \" | \" >> doSeq", "start": [ 67, 1 ], "end": [ 69, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doLetRec", "code": "@[builtin_doElem_parser] def doLetRec := leading_parser\n group (\"let \" >> nonReservedSymbol \"rec \") >> letRecDecls", "start": [ 71, 1 ], "end": [ 72, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIdDecl", "code": "def doIdDecl := leading_parser\n atomic (ident >> optType >> ppSpace >> leftArrow) >>\n doElemParser", "start": [ 73, 1 ], "end": [ 75, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doPatDecl", "code": "def doPatDecl := leading_parser\n atomic (termParser >> ppSpace >> leftArrow) >>\n doElemParser >> optional (checkColGt >> \" | \" >> doSeq)", "start": [ 76, 1 ], "end": [ 78, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doLetArrow", "code": "@[builtin_doElem_parser] def doLetArrow := leading_parser\n withPosition (\"let \" >> optional \"mut \" >> (doIdDecl <|> doPatDecl))", "start": [ 79, 1 ], "end": [ 80, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.letIdDeclNoBinders", "code": "def letIdDeclNoBinders := node ``letIdDecl <|\n atomic (ident >> pushNone >> optType >> \" := \") >> termParser", "start": [ 84, 1 ], "end": [ 85, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doReassign", "code": "@[builtin_doElem_parser] def doReassign := leading_parser\n notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl)", "start": [ 87, 1 ], "end": [ 88, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doReassignArrow", "code": "@[builtin_doElem_parser] def doReassignArrow := leading_parser\n notFollowedByRedefinedTermToken >> (doIdDecl <|> doPatDecl)", "start": [ 89, 1 ], "end": [ 90, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doHave", "code": "@[builtin_doElem_parser] def doHave := leading_parser\n \"have\" >> Term.haveDecl", "start": [ 91, 1 ], "end": [ 92, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.elseIf", "code": "def elseIf := atomic (group (withPosition (\"else \" >> checkLineEq >> \" if \")))", "start": [ 123, 1 ], "end": [ 123, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIfLetPure", "code": "def doIfLetPure := leading_parser \" := \" >> termParser", "start": [ 125, 1 ], "end": [ 125, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIfLetBind", "code": "def doIfLetBind := leading_parser \" ← \" >> termParser", "start": [ 126, 1 ], "end": [ 126, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIfLet", "code": "def doIfLet := leading_parser (withAnonymousAntiquot := false)\n \"let \" >> termParser >> (doIfLetPure <|> doIfLetBind)", "start": [ 127, 1 ], "end": [ 128, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIfProp", "code": "def doIfProp := leading_parser (withAnonymousAntiquot := false)\n optIdent >> termParser", "start": [ 129, 1 ], "end": [ 130, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIfCond", "code": "def doIfCond :=\n withAntiquot (mkAntiquot \"doIfCond\" decl_name% (anonymous := false) (isPseudoKind := true)) <|\n doIfLet <|> doIfProp", "start": [ 131, 1 ], "end": [ 133, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doIf", "code": "@[builtin_doElem_parser] def doIf := leading_parser withResetCache <| withPositionAfterLinebreak <| ppRealGroup <|\n ppRealFill (ppIndent (\"if \" >> doIfCond >> \" then\") >> ppSpace >> doSeq) >>\n many (checkColGe \"'else if' in 'do' must be indented\" >>\n group (ppDedent ppSpace >> ppRealFill (elseIf >> doIfCond >> \" then \" >> doSeq))) >>\n optional (checkColGe \"'else' in 'do' must be indented\" >>\n ppDedent ppSpace >> ppRealFill (\"else \" >> doSeq))", "start": [ 136, 1 ], "end": [ 141, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doUnless", "code": "@[builtin_doElem_parser] def doUnless := leading_parser\n \"unless \" >> withForbidden \"do\" termParser >> \" do \" >> doSeq", "start": [ 142, 1 ], "end": [ 143, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doForDecl", "code": "def doForDecl := leading_parser\n optional (atomic (ident >> \" : \")) >> termParser >> \" in \" >> withForbidden \"do\" termParser", "start": [ 144, 1 ], "end": [ 145, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doFor", "code": "@[builtin_doElem_parser] def doFor := leading_parser\n \"for \" >> sepBy1 doForDecl \", \" >> \"do \" >> doSeq", "start": [ 146, 1 ], "end": [ 154, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doMatchAlts", "code": "def doMatchAlts := ppDedent <| matchAlts (rhsParser := doSeq)", "start": [ 156, 1 ], "end": [ 156, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doMatch", "code": "@[builtin_doElem_parser] def doMatch := leading_parser:leadPrec\n \"match \" >> optional Term.generalizingParam >> optional Term.motive >>\n sepBy1 matchDiscr \", \" >> \" with\" >> doMatchAlts", "start": [ 157, 1 ], "end": [ 159, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doMatchExprAlts", "code": "def doMatchExprAlts := ppDedent <| matchExprAlts (rhsParser := doSeq)", "start": [ 161, 1 ], "end": [ 161, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.optMetaFalse", "code": "def optMetaFalse :=\n optional (atomic (\"(\" >> nonReservedSymbol \"meta\" >> \" := \" >> nonReservedSymbol \"false\" >> \") \"))", "start": [ 162, 1 ], "end": [ 163, 102 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doMatchExpr", "code": "@[builtin_doElem_parser] def doMatchExpr := leading_parser:leadPrec\n \"match_expr \" >> optMetaFalse >> termParser >> \" with\" >> doMatchExprAlts", "start": [ 164, 1 ], "end": [ 165, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doCatch", "code": "def doCatch := leading_parser\n ppDedent ppLine >> atomic (\"catch \" >> binderIdent) >> optional (\" : \" >> termParser) >> darrow >> doSeq", "start": [ 167, 1 ], "end": [ 168, 107 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doCatchMatch", "code": "def doCatchMatch := leading_parser\n ppDedent ppLine >> \"catch \" >> doMatchAlts", "start": [ 169, 1 ], "end": [ 170, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doFinally", "code": "def doFinally := leading_parser\n ppDedent ppLine >> \"finally \" >> doSeq", "start": [ 171, 1 ], "end": [ 172, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doTry", "code": "@[builtin_doElem_parser] def doTry := leading_parser\n \"try \" >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally", "start": [ 173, 1 ], "end": [ 174, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doBreak", "code": "@[builtin_doElem_parser] def doBreak := leading_parser \"break\"", "start": [ 176, 1 ], "end": [ 177, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doContinue", "code": "@[builtin_doElem_parser] def doContinue := leading_parser \"continue\"", "start": [ 178, 1 ], "end": [ 179, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doReturn", "code": "@[builtin_doElem_parser] def doReturn := leading_parser:leadPrec\n withPosition (\"return\" >> optional (ppSpace >> checkLineEq >> termParser))", "start": [ 180, 1 ], "end": [ 191, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doDbgTrace", "code": "@[builtin_doElem_parser] def doDbgTrace := leading_parser:leadPrec\n \"dbg_trace \" >> ((interpolatedStr termParser) <|> termParser)", "start": [ 192, 1 ], "end": [ 197, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doAssert", "code": "@[builtin_doElem_parser] def doAssert := leading_parser:leadPrec\n \"assert! \" >> termParser", "start": [ 198, 1 ], "end": [ 202, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doExpr", "code": "@[builtin_doElem_parser] def doExpr := leading_parser\n notFollowedByRedefinedTermToken >> termParser >>\n notFollowedBy (symbol \":=\" <|> symbol \"←\" <|> symbol \"<-\")\n \"unexpected token after 'expr' in 'do' block\"", "start": [ 220, 1 ], "end": [ 223, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.doNested", "code": "@[builtin_doElem_parser] def doNested := leading_parser\n \"do \" >> doSeq", "start": [ 224, 1 ], "end": [ 225, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.do", "code": "@[builtin_term_parser] def Β«doΒ» := leading_parser:argPrec\n ppAllowUngrouped >> \"do \" >> doSeq", "start": [ 227, 1 ], "end": [ 228, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.termUnless", "code": "@[builtin_term_parser] def termUnless := leading_parser\n \"unless \" >> withForbidden \"do\" termParser >> \" do \" >> doSeq", "start": [ 235, 1 ], "end": [ 237, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.termFor", "code": "@[builtin_term_parser] def termFor := leading_parser\n \"for \" >> sepBy1 doForDecl \", \" >> \" do \" >> doSeq", "start": [ 238, 1 ], "end": [ 239, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.termTry", "code": "@[builtin_term_parser] def termTry := leading_parser\n \"try \" >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally", "start": [ 240, 1 ], "end": [ 241, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.termReturn", "code": "@[builtin_term_parser] def termReturn := leading_parser:leadPrec\n withPosition (\"return\" >> optional (ppSpace >> checkLineEq >> termParser))", "start": [ 242, 1 ], "end": [ 247, 77 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/CollectMVars.lean
[ ".lake/packages/lean4/src/lean/Lean/Util/CollectMVars.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.collectMVars", "code": "partial def collectMVars (e : Expr) : StateRefT CollectMVars.State MetaM Unit := do\n let e ← instantiateMVars e\n let s ← get\n let resultSavedSize := s.result.size\n let s := e.collectMVars s\n set s\n for mvarId in s.result[resultSavedSize:] do\n match (← getDelayedMVarAssignment? mvarId) with\n | none => pure ()\n | some d => collectMVars (mkMVar d.mvarIdPending)", "start": [ 12, 1 ], "end": [ 30, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMVars", "code": "def getMVars (e : Expr) : MetaM (Array MVarId) := do\n let (_, s) ← (collectMVars e).run {}\n pure s.result", "start": [ 32, 1 ], "end": [ 35, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMVarsNoDelayed", "code": "def getMVarsNoDelayed (e : Expr) : MetaM (Array MVarId) := do\n let mvarIds ← getMVars e\n mvarIds.filterM fun mvarId => not <$> mvarId.isDelayedAssigned", "start": [ 37, 1 ], "end": [ 40, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.collectMVarsAtDecl", "code": "def collectMVarsAtDecl (d : Declaration) : StateRefT CollectMVars.State MetaM Unit :=\n d.forExprM collectMVars", "start": [ 42, 1 ], "end": [ 43, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMVarsAtDecl", "code": "def getMVarsAtDecl (d : Declaration) : MetaM (Array MVarId) := do\n let (_, s) ← (collectMVarsAtDecl d).run {}\n pure s.result", "start": [ 45, 1 ], "end": [ 47, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.getMVarDependencies", "code": "partial def _root_.Lean.MVarId.getMVarDependencies (mvarId : MVarId) (includeDelayed := false) :\n MetaM (HashSet MVarId) :=\n (Β·.snd) <$> (go mvarId).run {}\nwhere\n \n addMVars (e : Expr) : StateRefT (HashSet MVarId) MetaM Unit := do\n let mvars ← getMVars e\n let mut s ← get\n set ({} : HashSet MVarId) for mvarId in mvars do\n if ← pure includeDelayed <||> notM (mvarId.isDelayedAssigned) then\n s := s.insert mvarId\n set s\n mvars.forM go\n\n \n go (mvarId : MVarId) : StateRefT (HashSet MVarId) MetaM Unit :=\n withIncRecDepth do\n let mdecl ← mvarId.getDecl\n addMVars mdecl.type\n for ldecl in mdecl.lctx do\n addMVars ldecl.type\n if let (some val) := ldecl.value? then\n addMVars val\n if let (some ass) ← getDelayedMVarAssignment? mvarId then\n let pendingMVarId := ass.mvarIdPending\n if ← notM pendingMVarId.isAssignedOrDelayedAssigned then\n modify (Β·.insert pendingMVarId)\n go pendingMVarId", "start": [ 49, 1 ], "end": [ 82, 25 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/DiscrTree.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/DiscrTreeTypes.lean", ".lake/packages/lean4/src/lean/Lean/Meta/WHNF.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Transform.lean" ]
[ { "full_name": "Lean.Meta.DiscrTree.Key.ctorIdx", "code": "def Key.ctorIdx : Key β†’ Nat\n | .star => 0\n | .other => 1\n | .lit .. => 2\n | .fvar .. => 3\n | .const .. => 4\n | .arrow => 5\n | .proj .. => 6", "start": [ 52, 1 ], "end": [ 59, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Key.lt", "code": "def Key.lt : Key β†’ Key β†’ Bool\n | .lit v₁, .lit vβ‚‚ => v₁ < vβ‚‚\n | .fvar n₁ a₁, .fvar nβ‚‚ aβ‚‚ => Name.quickLt n₁.name nβ‚‚.name || (n₁ == nβ‚‚ && a₁ < aβ‚‚)\n | .const n₁ a₁, .const nβ‚‚ aβ‚‚ => Name.quickLt n₁ nβ‚‚ || (n₁ == nβ‚‚ && a₁ < aβ‚‚)\n | .proj s₁ i₁ a₁, .proj sβ‚‚ iβ‚‚ aβ‚‚ => Name.quickLt s₁ sβ‚‚ || (s₁ == sβ‚‚ && i₁ < iβ‚‚) || (s₁ == sβ‚‚ && i₁ == iβ‚‚ && a₁ < aβ‚‚)\n | k₁, kβ‚‚ => k₁.ctorIdx < kβ‚‚.ctorIdx", "start": [ 61, 1 ], "end": [ 66, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Key.format", "code": "def Key.format : Key β†’ Format\n | .star => \"*\"\n | .other => \"β—Ύ\"\n | .lit (.natVal v) => Std.format v\n | .lit (.strVal v) => repr v\n | .const k _ => Std.format k\n | .proj s i _ => Std.format s ++ \".\" ++ Std.format i\n | .fvar k _ => Std.format k.name\n | .arrow => \"β†’\"", "start": [ 71, 1 ], "end": [ 79, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.keysAsPattern", "code": "partial def keysAsPattern (keys : Array Key) : CoreM MessageData := do\n go (parenIfNonAtomic := false) |>.run' keys.toList\nwhere\n next? : StateRefT (List Key) CoreM (Option Key) := do\n let key :: keys ← get | return none\n set keys\n return some key\n\n mkApp (f : MessageData) (args : Array MessageData) (parenIfNonAtomic : Bool) : CoreM MessageData := do\n if args.isEmpty then\n return f\n else\n let mut r := f\n for arg in args do\n r := r ++ m!\" {arg}\"\n if parenIfNonAtomic then\n return m!\"({r})\"\n else\n return r\n\n go (parenIfNonAtomic := true) : StateRefT (List Key) CoreM MessageData := do\n let some key ← next? | return .nil\n match key with\n | .const declName nargs =>\n mkApp m!\"{← mkConstWithLevelParams declName}\" (← goN nargs) parenIfNonAtomic\n | .fvar fvarId nargs =>\n mkApp m!\"{mkFVar fvarId}\" (← goN nargs) parenIfNonAtomic\n | .proj _ i nargs =>\n mkApp m!\"{← go}.{i+1}\" (← goN nargs) parenIfNonAtomic\n | .arrow => return \"<arrow>\"\n | .star => return \"_\"\n | .other => return \"<other>\"\n | .lit (.natVal v) => return m!\"{v}\"\n | .lit (.strVal v) => return m!\"{v}\"\n\n goN (num : Nat) : StateRefT (List Key) CoreM (Array MessageData) := do\n let mut r := #[]\n for _ in [: num] do\n r := r.push (← go)\n return r", "start": [ 83, 1 ], "end": [ 126, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Key.arity", "code": "def Key.arity : Key β†’ Nat\n | .const _ a => a\n | .fvar _ a => a\n \n | .arrow => 0\n | .proj _ _ a => 1 + a\n | _ => 0", "start": [ 128, 1 ], "end": [ 148, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.empty", "code": "def empty : DiscrTree Ξ± := { root := {} }", "start": [ 152, 1 ], "end": [ 152, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.format", "code": "partial def Trie.format [ToFormat Ξ±] : Trie Ξ± β†’ Format\n | .node vs cs => Format.group $ Format.paren $\n \"node\" ++ (if vs.isEmpty then Format.nil else \" \" ++ Std.format vs)\n ++ Format.join (cs.toList.map fun ⟨k, c⟩ => Format.line ++ Format.paren (Std.format k ++ \" => \" ++ format c))", "start": [ 154, 1 ], "end": [ 157, 114 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.format", "code": "partial def format [ToFormat Ξ±] (d : DiscrTree Ξ±) : Format :=\n let (_, r) := d.root.foldl\n (fun (p : Bool Γ— Format) k c =>\n (false, p.2 ++ (if p.1 then Format.nil else Format.line) ++ Format.paren (Std.format k ++ \" => \" ++ Std.format c)))\n (true, Format.nil)\n Format.group r", "start": [ 161, 1 ], "end": [ 166, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.tmpMVarId", "code": "private def tmpMVarId : MVarId := { name := `_discr_tree_tmp }", "start": [ 170, 1 ], "end": [ 172, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.tmpStar", "code": "private def tmpStar := mkMVar tmpMVarId", "start": [ 173, 1 ], "end": [ 173, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.ignoreArg", "code": "private def ignoreArg (a : Expr) (i : Nat) (infos : Array ParamInfo) : MetaM Bool := do\n if h : i < infos.size then\n let info := infos.get ⟨i, h⟩\n if info.isInstImplicit then\n return true\n else if info.isImplicit || info.isStrictImplicit then\n return not (← isType a)\n else\n isProof a\n else\n isProof a", "start": [ 178, 1 ], "end": [ 218, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.pushArgsAux", "code": "private partial def pushArgsAux (infos : Array ParamInfo) : Nat β†’ Expr β†’ Array Expr β†’ MetaM (Array Expr)\n | i, .app f a, todo => do\n if (← ignoreArg a i infos) then\n pushArgsAux infos (i-1) f (todo.push tmpStar)\n else\n pushArgsAux infos (i-1) f (todo.push a)\n | _, _, todo => return todo", "start": [ 220, 1 ], "end": [ 226, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.isNumeral", "code": "private partial def isNumeral (e : Expr) : Bool :=\n if e.isRawNatLit then true\n else\n let f := e.getAppFn\n if !f.isConst then false\n else\n let fName := f.constName!\n if fName == ``Nat.succ && e.getAppNumArgs == 1 then isNumeral e.appArg!\n else if fName == ``OfNat.ofNat && e.getAppNumArgs == 3 then isNumeral (e.getArg! 1)\n else if fName == ``Nat.zero && e.getAppNumArgs == 0 then true\n else false", "start": [ 228, 1 ], "end": [ 244, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.toNatLit?", "code": "private partial def toNatLit? (e : Expr) : Option Literal :=\n if isNumeral e then\n if let some n := loop e then\n some (.natVal n)\n else\n none\n else\n none\nwhere\n loop (e : Expr) : OptionT Id Nat := do\n let f := e.getAppFn\n match f with\n | .lit (.natVal n) => return n\n | .const fName .. =>\n if fName == ``Nat.succ && e.getAppNumArgs == 1 then\n let r ← loop e.appArg!\n return r+1\n else if fName == ``OfNat.ofNat && e.getAppNumArgs == 3 then\n loop (e.getArg! 1)\n else if fName == ``Nat.zero && e.getAppNumArgs == 0 then\n return 0\n else\n failure\n | _ => failure", "start": [ 246, 1 ], "end": [ 269, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.isNatType", "code": "private def isNatType (e : Expr) : MetaM Bool :=\n return (← whnf e).isConstOf ``Nat", "start": [ 271, 1 ], "end": [ 272, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.isOffset", "code": "private def isOffset (fName : Name) (e : Expr) : MetaM Bool := do\n if fName == ``Nat.add && e.getAppNumArgs == 2 then\n return isNumeral e.appArg!\n else if fName == ``Add.add && e.getAppNumArgs == 4 then\n if (← isNatType (e.getArg! 0)) then return isNumeral e.appArg! else return false\n else if fName == ``HAdd.hAdd && e.getAppNumArgs == 6 then\n if (← isNatType (e.getArg! 1)) then return isNumeral e.appArg! else return false\n else\n return fName == ``Nat.succ && e.getAppNumArgs == 1", "start": [ 274, 1 ], "end": [ 290, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.shouldAddAsStar", "code": "private def shouldAddAsStar (fName : Name) (e : Expr) : MetaM Bool := do\n isOffset fName e", "start": [ 292, 1 ], "end": [ 303, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.mkNoindexAnnotation", "code": "def mkNoindexAnnotation (e : Expr) : Expr :=\n mkAnnotation `noindex e", "start": [ 305, 1 ], "end": [ 306, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.hasNoindexAnnotation", "code": "def hasNoindexAnnotation (e : Expr) : Bool :=\n annotation? `noindex e |>.isSome", "start": [ 308, 1 ], "end": [ 309, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.reduce", "code": "partial def reduce (e : Expr) (config : WhnfCoreConfig) : MetaM Expr := do\n let e ← whnfCore e config\n match (← unfoldDefinition? e) with\n | some e => reduce e config\n | none => match e.etaExpandedStrict? with\n | some e => reduce e config\n | none => return e", "start": [ 311, 1 ], "end": [ 323, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.isBadKey", "code": "private def isBadKey (fn : Expr) : Bool :=\n match fn with\n | .lit .. => false\n | .const .. => false\n | .fvar .. => false\n | .proj .. => false\n | .forallE .. => false\n | _ => true", "start": [ 325, 1 ], "end": [ 338, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.reduceUntilBadKey", "code": "private partial def reduceUntilBadKey (e : Expr) (config : WhnfCoreConfig) : MetaM Expr := do\n let e ← step e\n match e.etaExpandedStrict? with\n | some e => reduceUntilBadKey e config\n | none => return e\nwhere\n step (e : Expr) := do\n let e ← whnfCore e config\n match (← unfoldDefinition? e) with\n | some e' => if isBadKey e'.getAppFn then return e else step e'\n | none => return e", "start": [ 340, 1 ], "end": [ 354, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.reduceDT", "code": "def reduceDT (e : Expr) (root : Bool) (config : WhnfCoreConfig) : MetaM Expr :=\n if root then reduceUntilBadKey e config else reduce e config", "start": [ 356, 1 ], "end": [ 358, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.pushWildcards", "code": "private def pushWildcards (n : Nat) (todo : Array Expr) : Array Expr :=\n match n with\n | 0 => todo\n | n+1 => pushWildcards n (todo.push tmpStar)", "start": [ 362, 1 ], "end": [ 368, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.pushArgs", "code": "private def pushArgs (root : Bool) (todo : Array Expr) (e : Expr) (config : WhnfCoreConfig) (noIndexAtArgs : Bool) : MetaM (Key Γ— Array Expr) := do\n if hasNoindexAnnotation e then\n return (.star, todo)\n else\n let e ← reduceDT e root config\n let fn := e.getAppFn\n let push (k : Key) (nargs : Nat) (todo : Array Expr): MetaM (Key Γ— Array Expr) := do\n let info ← getFunInfoNArgs fn nargs\n let todo ← if noIndexAtArgs then\n pure <| pushWildcards nargs todo\n else\n pushArgsAux info.paramInfo (nargs-1) e todo\n return (k, todo)\n match fn with\n | .lit v =>\n return (.lit v, todo)\n | .const c _ =>\n unless root do\n if let some v := toNatLit? e then\n return (.lit v, todo)\n if (← shouldAddAsStar c e) then\n return (.star, todo)\n let nargs := e.getAppNumArgs\n push (.const c nargs) nargs todo\n | .proj s i a =>\n \n let a := if isClass (← getEnv) s then mkNoindexAnnotation a else a\n let nargs := e.getAppNumArgs\n push (.proj s i nargs) nargs (todo.push a)\n | .fvar fvarId =>\n let nargs := e.getAppNumArgs\n push (.fvar fvarId nargs) nargs todo\n | .mvar mvarId =>\n if mvarId == tmpMVarId then\n return (.star, todo)\n else if (← mvarId.isReadOnlyOrSyntheticOpaque) then\n return (.other, todo)\n else\n return (.star, todo)\n | .forallE .. => return (.arrow, todo)\n | _ => return (.other, todo)", "start": [ 370, 1 ], "end": [ 426, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.mkPathAux", "code": "@[inherit_doc pushArgs]\npartial def mkPathAux (root : Bool) (todo : Array Expr) (keys : Array Key) (config : WhnfCoreConfig) (noIndexAtArgs : Bool) : MetaM (Array Key) := do\n if todo.isEmpty then\n return keys\n else\n let e := todo.back\n let todo := todo.pop\n let (k, todo) ← pushArgs root todo e config noIndexAtArgs\n mkPathAux false todo (keys.push k) config noIndexAtArgs", "start": [ 428, 1 ], "end": [ 436, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.initCapacity", "code": "private def initCapacity := 8", "start": [ 438, 1 ], "end": [ 438, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.mkPath", "code": "@[inherit_doc pushArgs]\ndef mkPath (e : Expr) (config : WhnfCoreConfig) (noIndexAtArgs := false) : MetaM (Array Key) := do\n withReducible do\n let todo : Array Expr := .mkEmpty initCapacity\n let keys : Array Key := .mkEmpty initCapacity\n mkPathAux (root := true) (todo.push e) keys config noIndexAtArgs", "start": [ 440, 1 ], "end": [ 445, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.createNodes", "code": "private partial def createNodes (keys : Array Key) (v : Ξ±) (i : Nat) : Trie Ξ± :=\n if h : i < keys.size then\n let k := keys.get ⟨i, h⟩\n let c := createNodes keys v (i+1)\n .node #[] #[(k, c)]\n else\n .node #[v] #[]", "start": [ 447, 1 ], "end": [ 453, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.insertVal", "code": "private def insertVal [BEq Ξ±] (vs : Array Ξ±) (v : Ξ±) : Array Ξ± :=\n loop 0\nwhere\n loop (i : Nat) : Array Ξ± :=\n if h : i < vs.size then\n if v == vs[i] then\n vs.set ⟨i,h⟩ v\n else\n loop (i+1)\n else\n vs.push v\n termination_by vs.size - i", "start": [ 455, 1 ], "end": [ 472, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.insertAux", "code": "private partial def insertAux [BEq Ξ±] (keys : Array Key) (v : Ξ±) : Nat β†’ Trie Ξ± β†’ Trie Ξ±\n | i, .node vs cs =>\n if h : i < keys.size then\n let k := keys.get ⟨i, h⟩\n let c := Id.run $ cs.binInsertM\n (fun a b => a.1 < b.1)\n (fun ⟨_, s⟩ => let c := insertAux keys v (i+1) s; (k, c)) (fun _ => let c := createNodes keys v (i+1); (k, c))\n (k, default)\n .node vs c\n else\n .node (insertVal vs v) cs", "start": [ 474, 1 ], "end": [ 485, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.insertCore", "code": "def insertCore [BEq Ξ±] (d : DiscrTree Ξ±) (keys : Array Key) (v : Ξ±) : DiscrTree Ξ± :=\n if keys.isEmpty then panic! \"invalid key sequence\"\n else\n let k := keys[0]!\n match d.root.find? k with\n | none =>\n let c := createNodes keys v 1\n { root := d.root.insert k c }\n | some c =>\n let c := insertAux keys v 1 c\n { root := d.root.insert k c }", "start": [ 487, 1 ], "end": [ 497, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.insert", "code": "def insert [BEq Ξ±] (d : DiscrTree Ξ±) (e : Expr) (v : Ξ±) (config : WhnfCoreConfig) (noIndexAtArgs := false) : MetaM (DiscrTree Ξ±) := do\n let keys ← mkPath e config noIndexAtArgs\n return d.insertCore keys v", "start": [ 499, 1 ], "end": [ 501, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.insertIfSpecific", "code": "def insertIfSpecific [BEq Ξ±] (d : DiscrTree Ξ±) (e : Expr) (v : Ξ±) (config : WhnfCoreConfig) (noIndexAtArgs := false) : MetaM (DiscrTree Ξ±) := do\n let keys ← mkPath e config noIndexAtArgs\n return if keys == #[Key.star] || keys == #[Key.const `Eq 3, Key.star, Key.star, Key.star] then\n d\n else\n d.insertCore keys v", "start": [ 503, 1 ], "end": [ 512, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getKeyArgs", "code": "private def getKeyArgs (e : Expr) (isMatch root : Bool) (config : WhnfCoreConfig) : MetaM (Key Γ— Array Expr) := do\n let e ← reduceDT e root config\n unless root do\n if let some v := toNatLit? e then\n return (.lit v, #[])\n match e.getAppFn with\n | .lit v => return (.lit v, #[])\n | .const c _ =>\n if (← getConfig).isDefEqStuckEx && e.hasExprMVar then\n if (← isReducible c) then\n \n Meta.throwIsDefEqStuck\n else if let some matcherInfo := isMatcherAppCore? (← getEnv) e then\n let args := e.getAppArgs\n for arg in args[matcherInfo.getFirstDiscrPos: matcherInfo.getFirstDiscrPos + matcherInfo.numDiscrs] do\n if arg.hasExprMVar then\n Meta.throwIsDefEqStuck\n else if (← isRec c) then\n \n Meta.throwIsDefEqStuck\n let nargs := e.getAppNumArgs\n return (.const c nargs, e.getAppRevArgs)\n | .fvar fvarId =>\n let nargs := e.getAppNumArgs\n return (.fvar fvarId nargs, e.getAppRevArgs)\n | .mvar mvarId =>\n if isMatch then\n return (.other, #[])\n else do\n let ctx ← read\n if ctx.config.isDefEqStuckEx then\n \n return (.star, #[])\n else if (← mvarId.isReadOnlyOrSyntheticOpaque) then\n return (.other, #[])\n else\n return (.star, #[])\n | .proj s i a .. =>\n let nargs := e.getAppNumArgs\n return (.proj s i nargs, #[a] ++ e.getAppRevArgs)\n | .forallE .. => return (.arrow, #[])\n | _ => return (.other, #[])", "start": [ 514, 1 ], "end": [ 585, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchKeyArgs", "code": "private abbrev getMatchKeyArgs (e : Expr) (root : Bool) (config : WhnfCoreConfig) : MetaM (Key Γ— Array Expr) :=\n getKeyArgs e (isMatch := true) (root := root) (config := config)", "start": [ 587, 1 ], "end": [ 588, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getUnifyKeyArgs", "code": "private abbrev getUnifyKeyArgs (e : Expr) (root : Bool) (config : WhnfCoreConfig) : MetaM (Key Γ— Array Expr) :=\n getKeyArgs e (isMatch := false) (root := root) (config := config)", "start": [ 590, 1 ], "end": [ 591, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getStarResult", "code": "private def getStarResult (d : DiscrTree Ξ±) : Array Ξ± :=\n let result : Array Ξ± := .mkEmpty initCapacity\n match d.root.find? .star with\n | none => result\n | some (.node vs _) => result ++ vs", "start": [ 593, 1 ], "end": [ 597, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.findKey", "code": "private abbrev findKey (cs : Array (Key Γ— Trie Ξ±)) (k : Key) : Option (Key Γ— Trie Ξ±) :=\n cs.binSearch (k, default) (fun a b => a.1 < b.1)", "start": [ 599, 1 ], "end": [ 600, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchLoop", "code": "private partial def getMatchLoop (todo : Array Expr) (c : Trie Ξ±) (result : Array Ξ±) (config : WhnfCoreConfig) : MetaM (Array Ξ±) := do\n match c with\n | .node vs cs =>\n if todo.isEmpty then\n return result ++ vs\n else if cs.isEmpty then\n return result\n else\n let e := todo.back\n let todo := todo.pop\n let first := cs[0]! \n let (k, args) ← getMatchKeyArgs e (root := false) config\n \n let visitStar (result : Array Ξ±) : MetaM (Array Ξ±) :=\n if first.1 == .star then\n getMatchLoop todo first.2 result config\n else\n return result\n let visitNonStar (k : Key) (args : Array Expr) (result : Array Ξ±) : MetaM (Array Ξ±) :=\n match findKey cs k with\n | none => return result\n | some c => getMatchLoop (todo ++ args) c.2 result config\n let result ← visitStar result\n match k with\n | .star => return result\n | _ => visitNonStar k args result", "start": [ 602, 1 ], "end": [ 629, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchRoot", "code": "private def getMatchRoot (d : DiscrTree Ξ±) (k : Key) (args : Array Expr) (result : Array Ξ±) (config : WhnfCoreConfig) : MetaM (Array Ξ±) :=\n match d.root.find? k with\n | none => return result\n | some c => getMatchLoop args c result config", "start": [ 631, 1 ], "end": [ 634, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchCore", "code": "private def getMatchCore (d : DiscrTree Ξ±) (e : Expr) (config : WhnfCoreConfig) : MetaM (Key Γ— Array Ξ±) :=\n withReducible do\n let result := getStarResult d\n let (k, args) ← getMatchKeyArgs e (root := true) config\n match k with\n | .star => return (k, result)\n | _ => return (k, (← getMatchRoot d k args result config))", "start": [ 636, 1 ], "end": [ 642, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatch", "code": "def getMatch (d : DiscrTree Ξ±) (e : Expr) (config : WhnfCoreConfig) : MetaM (Array Ξ±) :=\n return (← getMatchCore d e config).2", "start": [ 644, 1 ], "end": [ 648, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchWithExtra", "code": "partial def getMatchWithExtra (d : DiscrTree Ξ±) (e : Expr) (config : WhnfCoreConfig) : MetaM (Array (Ξ± Γ— Nat)) := do\n let (k, result) ← getMatchCore d e config\n let result := result.map (Β·, 0)\n if !e.isApp then\n return result\n else if !(← mayMatchPrefix k) then\n return result\n else\n go e.appFn! 1 result\nwhere\n mayMatchPrefix (k : Key) : MetaM Bool :=\n let cont (k : Key) : MetaM Bool :=\n if d.root.find? k |>.isSome then\n return true\n else\n mayMatchPrefix k\n match k with\n | .const f (n+1) => cont (.const f n)\n | .fvar f (n+1) => cont (.fvar f n)\n | .proj s i (n+1) => cont (.proj s i n)\n | _ => return false\n\n go (e : Expr) (numExtra : Nat) (result : Array (Ξ± Γ— Nat)) : MetaM (Array (Ξ± Γ— Nat)) := do\n let result := result ++ (← getMatchCore d e config).2.map (., numExtra)\n if e.isApp then\n go e.appFn! (numExtra + 1) result\n else\n return result", "start": [ 650, 1 ], "end": [ 680, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchKeyRootFor", "code": "def getMatchKeyRootFor (e : Expr) (config : WhnfCoreConfig) : MetaM (Key Γ— Nat) := do\n let e ← reduceDT e (root := true) config\n let numArgs := e.getAppNumArgs\n let key := match e.getAppFn with\n | .lit v => .lit v\n | .fvar fvarId => .fvar fvarId numArgs\n | .mvar _ => .other\n | .proj s i _ .. => .proj s i numArgs\n | .forallE .. => .arrow\n | .const c _ =>\n .const c numArgs\n | _ => .other\n return (key, numArgs)", "start": [ 682, 1 ], "end": [ 699, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getAllValuesForKey", "code": "private partial def getAllValuesForKey (d : DiscrTree Ξ±) (k : Key) (result : Array Ξ±) : Array Ξ± :=\n match d.root.find? k with\n | none => result\n | some trie => go trie result\nwhere\n go (trie : Trie Ξ±) (result : Array Ξ±) : Array Ξ± := Id.run do\n match trie with\n | .node vs cs =>\n let mut result := result ++ vs\n for (_, trie) in cs do\n result := go trie result\n return result", "start": [ 701, 1 ], "end": [ 715, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getMatchLiberal", "code": "def getMatchLiberal (d : DiscrTree Ξ±) (e : Expr) (config : WhnfCoreConfig) : MetaM (Array Ξ± Γ— Nat) := do\n withReducible do\n let result := getStarResult d\n let (k, numArgs) ← getMatchKeyRootFor e config\n match k with\n | .star => return (result, numArgs)\n | _ => return (getAllValuesForKey d k result, numArgs)", "start": [ 717, 1 ], "end": [ 729, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.getUnify", "code": "partial def getUnify (d : DiscrTree Ξ±) (e : Expr) (config : WhnfCoreConfig) : MetaM (Array Ξ±) :=\n withReducible do\n let (k, args) ← getUnifyKeyArgs e (root := true) config\n match k with\n | .star => d.root.foldlM (init := #[]) fun result k c => process k.arity #[] c result\n | _ =>\n let result := getStarResult d\n match d.root.find? k with\n | none => return result\n | some c => process 0 args c result\nwhere\n process (skip : Nat) (todo : Array Expr) (c : Trie Ξ±) (result : Array Ξ±) : MetaM (Array Ξ±) := do\n match skip, c with\n | skip+1, .node _ cs =>\n if cs.isEmpty then\n return result\n else\n cs.foldlM (init := result) fun result ⟨k, c⟩ => process (skip + k.arity) todo c result\n | 0, .node vs cs => do\n if todo.isEmpty then\n return result ++ vs\n else if cs.isEmpty then\n return result\n else\n let e := todo.back\n let todo := todo.pop\n let (k, args) ← getUnifyKeyArgs e (root := false) config\n let visitStar (result : Array Ξ±) : MetaM (Array Ξ±) :=\n let first := cs[0]!\n if first.1 == .star then\n process 0 todo first.2 result\n else\n return result\n let visitNonStar (k : Key) (args : Array Expr) (result : Array Ξ±) : MetaM (Array Ξ±) :=\n match findKey cs k with\n | none => return result\n | some c => process 0 (todo ++ args) c.2 result\n match k with\n | .star => cs.foldlM (init := result) fun result ⟨k, c⟩ => process k.arity todo c result\n | _ => visitNonStar k args (← visitStar result)", "start": [ 731, 1 ], "end": [ 770, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.foldM", "code": "partial def foldM [Monad m] (initialKeys : Array Key)\n (f : Οƒ β†’ Array Key β†’ Ξ± β†’ m Οƒ) : (init : Οƒ) β†’ Trie Ξ± β†’ m Οƒ\n | init, Trie.node vs children => do\n let s ← vs.foldlM (init := init) fun s v => f s initialKeys v\n children.foldlM (init := s) fun s (k, t) =>\n t.foldM (initialKeys.push k) f s", "start": [ 777, 1 ], "end": [ 785, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.fold", "code": "@[inline]\ndef fold (initialKeys : Array Key) (f : Οƒ β†’ Array Key β†’ Ξ± β†’ Οƒ) (init : Οƒ) (t : Trie Ξ±) : Οƒ :=\n Id.run <| t.foldM initialKeys (init := init) fun s k a => return f s k a", "start": [ 787, 1 ], "end": [ 792, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.foldValuesM", "code": "partial def foldValuesM [Monad m] (f : Οƒ β†’ Ξ± β†’ m Οƒ) : (init : Οƒ) β†’ Trie Ξ± β†’ m Οƒ\n | init, node vs children => do\n let s ← vs.foldlM (init := init) f\n children.foldlM (init := s) fun s (_, c) => c.foldValuesM (init := s) f", "start": [ 794, 1 ], "end": [ 800, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.foldValues", "code": "@[inline]\ndef foldValues (f : Οƒ β†’ Ξ± β†’ Οƒ) (init : Οƒ) (t : Trie Ξ±) : Οƒ :=\n Id.run <| t.foldValuesM (init := init) f", "start": [ 802, 1 ], "end": [ 807, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.size", "code": "partial def size : Trie Ξ± β†’ Nat\n | Trie.node vs children =>\n children.foldl (init := vs.size) fun n (_, c) => n + size c", "start": [ 809, 1 ], "end": [ 814, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.foldM", "code": "@[inline]\ndef foldM [Monad m] (f : Οƒ β†’ Array Key β†’ Ξ± β†’ m Οƒ) (init : Οƒ)\n (t : DiscrTree Ξ±) : m Οƒ :=\n t.root.foldlM (init := init) fun s k t => t.foldM #[k] (init := s) f", "start": [ 819, 1 ], "end": [ 825, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.fold", "code": "@[inline]\ndef fold (f : Οƒ β†’ Array Key β†’ Ξ± β†’ Οƒ) (init : Οƒ) (t : DiscrTree Ξ±) : Οƒ :=\n Id.run <| t.foldM (init := init) fun s keys a => return f s keys a", "start": [ 827, 1 ], "end": [ 832, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.foldValuesM", "code": "@[inline]\ndef foldValuesM [Monad m] (f : Οƒ β†’ Ξ± β†’ m Οƒ) (init : Οƒ) (t : DiscrTree Ξ±) :\n m Οƒ :=\n t.root.foldlM (init := init) fun s _ t => t.foldValuesM (init := s) f", "start": [ 834, 1 ], "end": [ 840, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.foldValues", "code": "@[inline]\ndef foldValues (f : Οƒ β†’ Ξ± β†’ Οƒ) (init : Οƒ) (t : DiscrTree Ξ±) : Οƒ :=\n Id.run <| t.foldValuesM (init := init) f", "start": [ 842, 1 ], "end": [ 847, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.containsValueP", "code": "@[inline]\ndef containsValueP (t : DiscrTree Ξ±) (f : Ξ± β†’ Bool) : Bool :=\n t.foldValues (init := false) fun r a => r || f a", "start": [ 849, 1 ], "end": [ 854, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.values", "code": "@[inline]\ndef values (t : DiscrTree Ξ±) : Array Ξ± :=\n t.foldValues (init := #[]) fun as a => as.push a", "start": [ 856, 1 ], "end": [ 861, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.toArray", "code": "@[inline]\ndef toArray (t : DiscrTree Ξ±) : Array (Array Key Γ— Ξ±) :=\n t.fold (init := #[]) fun as keys a => as.push (keys, a)", "start": [ 863, 1 ], "end": [ 868, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.size", "code": "@[inline]\ndef size (t : DiscrTree Ξ±) : Nat :=\n t.root.foldl (init := 0) fun n _ t => n + t.size", "start": [ 870, 1 ], "end": [ 875, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.Trie.mapArraysM", "code": "partial def Trie.mapArraysM (t : DiscrTree.Trie Ξ±) (f : Array Ξ± β†’ m (Array Ξ²)) :\n m (DiscrTree.Trie Ξ²) :=\n match t with\n | .node vs children =>\n return .node (← f vs) (← children.mapM fun (k, t') => do pure (k, ← t'.mapArraysM f))", "start": [ 879, 1 ], "end": [ 884, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.mapArraysM", "code": "def mapArraysM (d : DiscrTree Ξ±) (f : Array Ξ± β†’ m (Array Ξ²)) : m (DiscrTree Ξ²) := do\n pure { root := ← d.root.mapM (fun t => t.mapArraysM f) }", "start": [ 886, 1 ], "end": [ 888, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DiscrTree.mapArrays", "code": "def mapArrays (d : DiscrTree Ξ±) (f : Array Ξ± β†’ Array Ξ²) : DiscrTree Ξ² :=\n Id.run <| d.mapArraysM fun A => pure (f A)", "start": [ 890, 1 ], "end": [ 892, 45 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Command.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Term.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Do.lean" ]
[ { "full_name": "Lean.Parser.Term.quot", "code": "@[builtin_term_parser] def Term.quot := leading_parser\n \"`(\" >> withoutPosition (incQuotDepth termParser) >> \")\"", "start": [ 13, 1 ], "end": [ 15, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.precheckedQuot", "code": "@[builtin_term_parser] def Term.precheckedQuot := leading_parser\n \"`\" >> Term.quot", "start": [ 16, 1 ], "end": [ 17, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.skipUntil", "code": "private def skipUntil (pred : Char β†’ Bool) : Parser where\n fn :=\n andthenFn\n (takeUntilFn pred)\n (takeWhileFn Char.isWhitespace)", "start": [ 21, 1 ], "end": [ 26, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.skipUntilWs", "code": "private def skipUntilWs : Parser := skipUntil Char.isWhitespace", "start": [ 28, 1 ], "end": [ 29, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.skipUntilWsOrDelim", "code": "private def skipUntilWsOrDelim : Parser := skipUntil fun c =>\n c.isWhitespace || c == '(' || c == ')' || c == ':' || c == '{' || c == '}' || c == '|'", "start": [ 31, 1 ], "end": [ 34, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.quot", "code": "@[builtin_term_parser low] def quot := leading_parser\n \"`(\" >> withoutPosition (incQuotDepth (many1Unbox commandParser)) >> \")\"", "start": [ 36, 1 ], "end": [ 45, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.moduleDoc", "code": "@[builtin_command_parser]\ndef moduleDoc := leading_parser ppDedent <|\n \"", "start": [ 47, 1 ], "end": [ 54, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.namedPrio", "code": "def namedPrio := leading_parser\n atomic (\" (\" >> nonReservedSymbol \"priority\") >> \" := \" >> withoutPosition priorityParser >> \")\"", "start": [ 56, 1 ], "end": [ 57, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optNamedPrio", "code": "def optNamedPrio := optional namedPrio", "start": [ 58, 1 ], "end": [ 58, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.private", "code": "def Β«privateΒ» := leading_parser \"private \"", "start": [ 60, 1 ], "end": [ 60, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.protected", "code": "def Β«protectedΒ» := leading_parser \"protected \"", "start": [ 61, 1 ], "end": [ 61, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.visibility", "code": "def visibility := Β«privateΒ» <|> Β«protectedΒ»", "start": [ 62, 1 ], "end": [ 62, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.noncomputable", "code": "def Β«noncomputableΒ» := leading_parser \"noncomputable \"", "start": [ 63, 1 ], "end": [ 63, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.unsafe", "code": "def Β«unsafeΒ» := leading_parser \"unsafe \"", "start": [ 64, 1 ], "end": [ 64, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.partial", "code": "def Β«partialΒ» := leading_parser \"partial \"", "start": [ 65, 1 ], "end": [ 65, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.nonrec", "code": "def Β«nonrecΒ» := leading_parser \"nonrec \"", "start": [ 66, 1 ], "end": [ 66, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declModifiers", "code": "def declModifiers (inline : Bool) := leading_parser\n optional docComment >>\n optional (Term.Β«attributesΒ» >> if inline then skip else ppDedent ppLine) >>\n optional visibility >>\n optional Β«noncomputableΒ» >>\n optional Β«unsafeΒ» >>\n optional (Β«partialΒ» <|> Β«nonrecΒ»)", "start": [ 68, 1 ], "end": [ 87, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declId", "code": "def declId := leading_parser\n ident >> optional (\".{\" >> sepBy1 (recover ident (skipUntil (fun c => c.isWhitespace || c ∈ [',', '}']))) \", \" >> \"}\")", "start": [ 88, 1 ], "end": [ 90, 121 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declSig", "code": "def declSig := leading_parser\n many (ppSpace >> (Term.binderIdent <|> Term.bracketedBinder)) >> Term.typeSpec", "start": [ 91, 1 ], "end": [ 93, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optDeclSig", "code": "def optDeclSig := leading_parser\n many (ppSpace >> (Term.binderIdent <|> Term.bracketedBinder)) >> Term.optType", "start": [ 94, 1 ], "end": [ 96, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declBody", "code": "def declBody : Parser :=\n \n lookahead (setExpected [] \"by\") >> termParser leadPrec <|>\n termParser", "start": [ 97, 1 ], "end": [ 122, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declBody.parenthesizer", "code": "@[combinator_parenthesizer declBody] def declBody.parenthesizer : Parenthesizer :=\n Parenthesizer.categoryParser.parenthesizer `term 0", "start": [ 127, 1 ], "end": [ 128, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declValSimple", "code": "def declValSimple := leading_parser\n \" :=\" >> ppHardLineUnlessUngrouped >> declBody >> Termination.suffix >> optional Term.whereDecls", "start": [ 130, 1 ], "end": [ 131, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declValEqns", "code": "def declValEqns := leading_parser\n Term.matchAltsWhereDecls", "start": [ 132, 1 ], "end": [ 133, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.whereStructField", "code": "def whereStructField := leading_parser\n Term.letDecl", "start": [ 134, 1 ], "end": [ 135, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.whereStructInst", "code": "def whereStructInst := leading_parser\n ppIndent ppSpace >> \"where\" >> sepByIndent (ppGroup whereStructField) \"; \" (allowTrailingSep := true) >>\n optional Term.whereDecls", "start": [ 136, 1 ], "end": [ 138, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declVal", "code": "def declVal :=\n withAntiquot (mkAntiquot \"declVal\" `Lean.Parser.Command.declVal (isPseudoKind := true)) <|\n declValSimple <|> declValEqns <|> whereStructInst", "start": [ 139, 1 ], "end": [ 149, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.abbrev", "code": "def Β«abbrevΒ» := leading_parser\n \"abbrev \" >> declId >> ppIndent optDeclSig >> declVal", "start": [ 150, 1 ], "end": [ 151, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optDefDeriving", "code": "def optDefDeriving :=\n optional (ppDedent ppLine >> atomic (\"deriving \" >> notSymbol \"instance\") >> sepBy1 ident \", \")", "start": [ 152, 1 ], "end": [ 153, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.definition", "code": "def definition := leading_parser\n \"def \" >> recover declId skipUntilWsOrDelim >> ppIndent optDeclSig >> declVal >> optDefDeriving", "start": [ 154, 1 ], "end": [ 155, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.theorem", "code": "def Β«theoremΒ» := leading_parser\n \"theorem \" >> recover declId skipUntilWsOrDelim >> ppIndent declSig >> declVal", "start": [ 156, 1 ], "end": [ 157, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.opaque", "code": "def Β«opaqueΒ» := leading_parser\n \"opaque \" >> recover declId skipUntilWsOrDelim >> ppIndent declSig >> optional declValSimple", "start": [ 158, 1 ], "end": [ 159, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.instance", "code": "def Β«instanceΒ» := leading_parser\n Term.attrKind >> \"instance\" >> optNamedPrio >>\n optional (ppSpace >> declId) >> ppIndent declSig >> declVal", "start": [ 162, 1 ], "end": [ 164, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.axiom", "code": "def Β«axiomΒ» := leading_parser\n \"axiom \" >> recover declId skipUntilWsOrDelim >> ppIndent declSig", "start": [ 165, 1 ], "end": [ 166, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.example", "code": "def Β«exampleΒ» := leading_parser\n \"example\" >> ppIndent optDeclSig >> declVal", "start": [ 168, 1 ], "end": [ 169, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.ctor", "code": "def ctor := leading_parser\n atomic (optional docComment >> \"\\n| \") >>\n ppGroup (declModifiers true >> rawIdent >> optDeclSig)", "start": [ 170, 1 ], "end": [ 172, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.derivingClasses", "code": "def derivingClasses := sepBy1 (group (ident >> optional (\" with \" >> ppIndent Term.structInst))) \", \"", "start": [ 173, 1 ], "end": [ 173, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optDeriving", "code": "def optDeriving := leading_parser\n optional (ppLine >> atomic (\"deriving \" >> notSymbol \"instance\") >> derivingClasses)", "start": [ 174, 1 ], "end": [ 175, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.computedField", "code": "def computedField := leading_parser\n declModifiers true >> ident >> \" : \" >> termParser >> Term.matchAlts", "start": [ 176, 1 ], "end": [ 177, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.computedFields", "code": "def computedFields := leading_parser\n \"with\" >> manyIndent (ppLine >> ppGroup computedField)", "start": [ 178, 1 ], "end": [ 179, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.inductive", "code": "def Β«inductiveΒ» := leading_parser\n \"inductive \" >> recover declId skipUntilWsOrDelim >> ppIndent optDeclSig >> optional (symbol \" :=\" <|> \" where\") >>\n many ctor >> optional (ppDedent ppLine >> computedFields) >> optDeriving", "start": [ 180, 1 ], "end": [ 200, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.classInductive", "code": "def classInductive := leading_parser\n atomic (group (symbol \"class \" >> \"inductive \")) >>\n recover declId skipUntilWsOrDelim >> ppIndent optDeclSig >>\n optional (symbol \" :=\" <|> \" where\") >> many ctor >> optDeriving", "start": [ 201, 1 ], "end": [ 204, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structExplicitBinder", "code": "def structExplicitBinder := leading_parser\n atomic (declModifiers true >> \"(\") >>\n withoutPosition (many1 ident >> ppIndent optDeclSig >>\n optional (Term.binderTactic <|> Term.binderDefault)) >> \")\"", "start": [ 205, 1 ], "end": [ 208, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structImplicitBinder", "code": "def structImplicitBinder := leading_parser\n atomic (declModifiers true >> \"{\") >> withoutPosition (many1 ident >> declSig) >> \"}\"", "start": [ 209, 1 ], "end": [ 210, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structInstBinder", "code": "def structInstBinder := leading_parser\n atomic (declModifiers true >> \"[\") >> withoutPosition (many1 ident >> declSig) >> \"]\"", "start": [ 211, 1 ], "end": [ 212, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structSimpleBinder", "code": "def structSimpleBinder := leading_parser\n atomic (declModifiers true >> ident) >> optDeclSig >>\n optional (Term.binderTactic <|> Term.binderDefault)", "start": [ 213, 1 ], "end": [ 215, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structFields", "code": "def structFields := leading_parser\n manyIndent <|\n ppLine >> checkColGe >> ppGroup (\n structExplicitBinder <|> structImplicitBinder <|>\n structInstBinder <|> structSimpleBinder)", "start": [ 216, 1 ], "end": [ 220, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structCtor", "code": "def structCtor := leading_parser\n atomic (ppIndent (declModifiers true >> ident >> \" :: \"))", "start": [ 221, 1 ], "end": [ 222, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structureTk", "code": "def structureTk := leading_parser\n \"structure \"", "start": [ 223, 1 ], "end": [ 224, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.classTk", "code": "def classTk := leading_parser\n \"class \"", "start": [ 225, 1 ], "end": [ 226, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.extends", "code": "def Β«extendsΒ» := leading_parser\n \" extends \" >> sepBy1 termParser \", \"", "start": [ 227, 1 ], "end": [ 228, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.structure", "code": "def Β«structureΒ» := leading_parser\n (structureTk <|> classTk) >>\n declId >>\n ppIndent (many (ppSpace >> Term.bracketedBinder) >> optional Β«extendsΒ» >> Term.optType) >>\n optional ((symbol \" := \" <|> \" where \") >> optional structCtor >> structFields) >>\n optDeriving", "start": [ 229, 1 ], "end": [ 235, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declaration", "code": "@[builtin_command_parser] def declaration := leading_parser\n declModifiers false >>\n (Β«abbrevΒ» <|> definition <|> Β«theoremΒ» <|> Β«opaqueΒ» <|> Β«instanceΒ» <|> Β«axiomΒ» <|> Β«exampleΒ» <|>\n Β«inductiveΒ» <|> classInductive <|> Β«structureΒ»)", "start": [ 236, 1 ], "end": [ 239, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.deriving", "code": "@[builtin_command_parser] def Β«derivingΒ» := leading_parser\n \"deriving \" >> \"instance \" >> derivingClasses >> \" for \" >> sepBy1 (recover ident skip) \", \"", "start": [ 240, 1 ], "end": [ 241, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.noncomputableSection", "code": "@[builtin_command_parser] def noncomputableSection := leading_parser\n \"noncomputable \" >> \"section\" >> optional (ppSpace >> checkColGt >> ident)", "start": [ 242, 1 ], "end": [ 243, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.section", "code": "@[builtin_command_parser] def Β«sectionΒ» := leading_parser\n \"section\" >> optional (ppSpace >> checkColGt >> ident)", "start": [ 244, 1 ], "end": [ 251, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.namespace", "code": "@[builtin_command_parser] def Β«namespaceΒ» := leading_parser\n \"namespace \" >> checkColGt >> ident", "start": [ 252, 1 ], "end": [ 269, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.end", "code": "@[builtin_command_parser] def Β«endΒ» := leading_parser\n \"end\" >> optional (ppSpace >> checkColGt >> ident)", "start": [ 270, 1 ], "end": [ 275, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.variable", "code": "@[builtin_command_parser] def Β«variableΒ» := leading_parser\n \"variable\" >> many1 (ppSpace >> checkColGt >> Term.bracketedBinder)", "start": [ 276, 1 ], "end": [ 373, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.universe", "code": "@[builtin_command_parser] def Β«universeΒ» := leading_parser\n \"universe\" >> many1 (ppSpace >> checkColGt >> ident)", "start": [ 374, 1 ], "end": [ 433, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.check", "code": "@[builtin_command_parser] def check := leading_parser\n \"#check \" >> termParser", "start": [ 434, 1 ], "end": [ 435, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.check_failure", "code": "@[builtin_command_parser] def check_failure := leading_parser\n \"#check_failure \" >> termParser", "start": [ 436, 1 ], "end": [ 437, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.eval", "code": "@[builtin_command_parser] def eval := leading_parser\n \"#eval \" >> termParser", "start": [ 438, 1 ], "end": [ 439, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.synth", "code": "@[builtin_command_parser] def synth := leading_parser\n \"#synth \" >> termParser", "start": [ 440, 1 ], "end": [ 441, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.exit", "code": "@[builtin_command_parser] def exit := leading_parser\n \"#exit\"", "start": [ 442, 1 ], "end": [ 443, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.print", "code": "@[builtin_command_parser] def print := leading_parser\n \"#print \" >> (ident <|> strLit)", "start": [ 444, 1 ], "end": [ 445, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.printAxioms", "code": "@[builtin_command_parser] def printAxioms := leading_parser\n \"#print \" >> nonReservedSymbol \"axioms \" >> ident", "start": [ 446, 1 ], "end": [ 447, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.printEqns", "code": "@[builtin_command_parser] def printEqns := leading_parser\n \"#print \" >> (nonReservedSymbol \"equations \" <|> nonReservedSymbol \"eqns \") >> ident", "start": [ 448, 1 ], "end": [ 449, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.printTacTags", "code": "@[builtin_command_parser] def printTacTags := leading_parser\n \"#print \" >> nonReservedSymbol \"tactic \" >> nonReservedSymbol \"tags\"", "start": [ 450, 1 ], "end": [ 454, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.init_quot", "code": "@[builtin_command_parser] def Β«init_quotΒ» := leading_parser\n \"init_quot\"", "start": [ 455, 1 ], "end": [ 456, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optionValue", "code": "def optionValue := nonReservedSymbol \"true\" <|> nonReservedSymbol \"false\" <|> strLit <|> numLit", "start": [ 457, 1 ], "end": [ 457, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.set_option", "code": "@[builtin_command_parser] def Β«set_optionΒ» := leading_parser\n \"set_option \" >> identWithPartialTrailingDot >> ppSpace >> optionValue", "start": [ 458, 1 ], "end": [ 474, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.eraseAttr", "code": "def eraseAttr := leading_parser\n \"-\" >> rawIdent", "start": [ 475, 1 ], "end": [ 476, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.attribute", "code": "@[builtin_command_parser] def Β«attributeΒ» := leading_parser\n \"attribute \" >> \"[\" >>\n withoutPosition (sepBy1 (eraseAttr <|> Term.attrInstance) \", \") >>\n \"]\" >> many1 (ppSpace >> ident)", "start": [ 477, 1 ], "end": [ 480, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.export", "code": "@[builtin_command_parser] def Β«exportΒ» := leading_parser\n \"export \" >> ident >> \" (\" >> many1 ident >> \")\"", "start": [ 481, 1 ], "end": [ 506, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.import", "code": "@[builtin_command_parser] def Β«importΒ» := leading_parser\n \"import\"", "start": [ 507, 1 ], "end": [ 508, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openHiding", "code": "def openHiding := leading_parser\n ppSpace >> atomic (ident >> \" hiding\") >> many1 (ppSpace >> checkColGt >> ident)", "start": [ 509, 1 ], "end": [ 510, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openRenamingItem", "code": "def openRenamingItem := leading_parser\n ident >> unicodeSymbol \" β†’ \" \" -> \" >> checkColGt >> ident", "start": [ 511, 1 ], "end": [ 512, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openRenaming", "code": "def openRenaming := leading_parser\n ppSpace >> atomic (ident >> \" renaming \") >> sepBy1 openRenamingItem \", \"", "start": [ 513, 1 ], "end": [ 514, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openOnly", "code": "def openOnly := leading_parser\n ppSpace >> atomic (ident >> \" (\") >> many1 ident >> \")\"", "start": [ 515, 1 ], "end": [ 516, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openSimple", "code": "def openSimple := leading_parser\n many1 (ppSpace >> checkColGt >> ident)", "start": [ 517, 1 ], "end": [ 518, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openScoped", "code": "def openScoped := leading_parser\n \" scoped\" >> many1 (ppSpace >> checkColGt >> ident)", "start": [ 519, 1 ], "end": [ 520, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.openDecl", "code": "def openDecl :=\n withAntiquot (mkAntiquot \"openDecl\" `Lean.Parser.Command.openDecl (isPseudoKind := true)) <|\n openHiding <|> openRenaming <|> openOnly <|> openSimple <|> openScoped", "start": [ 521, 1 ], "end": [ 524, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.open", "code": "@[builtin_command_parser] def Β«openΒ» := leading_parser\n withPosition (\"open\" >> openDecl)", "start": [ 525, 1 ], "end": [ 638, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.mutual", "code": "@[builtin_command_parser] def Β«mutualΒ» := leading_parser\n \"mutual\" >> many1 (ppLine >> notSymbol \"end\" >> commandParser) >>\n ppDedent (ppLine >> \"end\")", "start": [ 640, 1 ], "end": [ 642, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.initializeKeyword", "code": "def initializeKeyword := leading_parser\n \"initialize \" <|> \"builtin_initialize \"", "start": [ 643, 1 ], "end": [ 644, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.initialize", "code": "@[builtin_command_parser] def Β«initializeΒ» := leading_parser\n declModifiers false >> initializeKeyword >>\n optional (atomic (ident >> Term.typeSpec >> ppSpace >> Term.leftArrow)) >> Term.doSeq", "start": [ 645, 1 ], "end": [ 647, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.in", "code": "@[builtin_command_parser] def Β«inΒ» := trailing_parser\n withOpen (ppDedent (\" in \" >> commandParser))", "start": [ 649, 1 ], "end": [ 650, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.addDocString", "code": "@[builtin_command_parser] def addDocString := leading_parser\n docComment >> \"add_decl_doc \" >> ident", "start": [ 652, 1 ], "end": [ 675, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.register_tactic_tag", "code": "@[builtin_command_parser] def Β«register_tactic_tagΒ» := leading_parser\n optional (docComment >> ppLine) >>\n \"register_tactic_tag \" >> ident >> strLit", "start": [ 677, 1 ], "end": [ 684, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.tactic_extension", "code": "@[builtin_command_parser] def Β«tactic_extensionΒ» := leading_parser\n optional (docComment >> ppLine) >>\n \"tactic_extension \" >> ident", "start": [ 686, 1 ], "end": [ 694, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.genInjectiveTheorems", "code": "@[builtin_command_parser] def genInjectiveTheorems := leading_parser\n \"gen_injective_theorems% \" >> ident", "start": [ 697, 1 ], "end": [ 702, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.eoi", "code": "@[run_builtin_parser_attribute_hooks] def eoi : Parser := leading_parser \"\"", "start": [ 704, 1 ], "end": [ 705, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declModifiersF", "code": "@[run_builtin_parser_attribute_hooks, inherit_doc declModifiers]\nabbrev declModifiersF := declModifiers false", "start": [ 710, 1 ], "end": [ 711, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.declModifiersT", "code": "@[run_builtin_parser_attribute_hooks, inherit_doc declModifiers]\nabbrev declModifiersT := declModifiers true", "start": [ 712, 1 ], "end": [ 713, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.open", "code": "@[builtin_term_parser] def Β«openΒ» := leading_parser:leadPrec\n \"open\" >> Command.openDecl >> withOpenDecl (\" in \" >> termParser)", "start": [ 728, 1 ], "end": [ 733, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Term.set_option", "code": "@[builtin_term_parser] def Β«set_optionΒ» := leading_parser:leadPrec\n \"set_option \" >> identWithPartialTrailingDot >> ppSpace >> Command.optionValue >> \" in \" >> termParser", "start": [ 735, 1 ], "end": [ 740, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.open", "code": "@[builtin_tactic_parser] def Β«openΒ» := leading_parser:leadPrec\n \"open \" >> Command.openDecl >> withOpenDecl (\" in \" >> tacticSeq)", "start": [ 744, 1 ], "end": [ 747, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.set_option", "code": "@[builtin_tactic_parser] def Β«set_optionΒ» := leading_parser:leadPrec\n \"set_option \" >> identWithPartialTrailingDot >> ppSpace >> Command.optionValue >> \" in \" >> tacticSeq", "start": [ 749, 1 ], "end": [ 752, 104 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Check.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/InferType.lean" ]
[ { "full_name": "Lean.Meta.ensureType", "code": "private def ensureType (e : Expr) : MetaM Unit := do\n discard <| getLevel e", "start": [ 16, 1 ], "end": [ 17, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwLetTypeMismatchMessage", "code": "def throwLetTypeMismatchMessage {Ξ±} (fvarId : FVarId) : MetaM Ξ± := do\n let lctx ← getLCtx\n match lctx.find? fvarId with\n | some (LocalDecl.ldecl _ _ _ t v _ _) => do\n let vType ← inferType v\n throwError \"invalid let declaration, term{indentExpr v}\\nhas type{indentExpr vType}\\nbut is expected to have type{indentExpr t}\"\n | _ => unreachable!", "start": [ 19, 1 ], "end": [ 25, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.checkConstant", "code": "private def checkConstant (constName : Name) (us : List Level) : MetaM Unit := do\n let cinfo ← getConstInfo constName\n unless us.length == cinfo.levelParams.length do\n throwIncorrectNumberOfLevels constName us", "start": [ 27, 1 ], "end": [ 30, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getFunctionDomain", "code": "private def getFunctionDomain (f : Expr) : MetaM (Expr Γ— BinderInfo) := do\n let fType ← inferType f\n let fType ← whnfD fType\n match fType with\n | Expr.forallE _ d _ c => return (d, c)\n | _ => throwFunctionExpected f", "start": [ 32, 1 ], "end": [ 37, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addPPExplicitToExposeDiff", "code": "partial def addPPExplicitToExposeDiff (a b : Expr) : MetaM (Expr Γ— Expr) := do\n if (← getOptions).getBool `pp.all false || (← getOptions).getBool `pp.explicit false then\n return (a, b)\n else\n visit (← instantiateMVars a) (← instantiateMVars b)\nwhere\n visit (a b : Expr) : MetaM (Expr Γ— Expr) := do\n try\n if !a.isApp || !b.isApp then\n return (a, b)\n else if a.getAppNumArgs != b.getAppNumArgs then\n return (a, b)\n else if not (← isDefEq a.getAppFn b.getAppFn) then\n return (a, b)\n else\n let fType ← inferType a.getAppFn\n forallBoundedTelescope fType a.getAppNumArgs fun xs _ => do\n let mut as := a.getAppArgs\n let mut bs := b.getAppArgs\n if let some (as', bs') ← hasExplicitDiff? xs as bs then\n return (mkAppN a.getAppFn as', mkAppN b.getAppFn bs')\n else\n for i in [:as.size] do\n unless (← isDefEq as[i]! bs[i]!) do\n let (ai, bi) ← visit as[i]! bs[i]!\n as := as.set! i ai\n bs := bs.set! i bi\n let a := mkAppN a.getAppFn as\n let b := mkAppN b.getAppFn bs\n return (a.setAppPPExplicit, b.setAppPPExplicit)\n catch _ =>\n return (a, b)\n\n hasExplicitDiff? (xs as bs : Array Expr) : MetaM (Option (Array Expr Γ— Array Expr)) := do\n for i in [:xs.size] do\n let localDecl ← xs[i]!.fvarId!.getDecl\n if localDecl.binderInfo.isExplicit then\n unless (← isDefEq as[i]! bs[i]!) do\n let (ai, bi) ← visit as[i]! bs[i]!\n return some (as.set! i ai, bs.set! i bi)\n return none", "start": [ 39, 1 ], "end": [ 113, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHasTypeButIsExpectedMsg", "code": "def mkHasTypeButIsExpectedMsg (givenType expectedType : Expr) : MetaM MessageData := do\n try\n let givenTypeType ← inferType givenType\n let expectedTypeType ← inferType expectedType\n let (givenType, expectedType) ← addPPExplicitToExposeDiff givenType expectedType\n let (givenTypeType, expectedTypeType) ← addPPExplicitToExposeDiff givenTypeType expectedTypeType\n return m!\"has type{indentD m!\"{givenType} : {givenTypeType}\"}\\nbut is expected to have type{indentD m!\"{expectedType} : {expectedTypeType}\"}\"\n catch _ =>\n let (givenType, expectedType) ← addPPExplicitToExposeDiff givenType expectedType\n return m!\"has type{indentExpr givenType}\\nbut is expected to have type{indentExpr expectedType}\"", "start": [ 115, 1 ], "end": [ 127, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwAppTypeMismatch", "code": "def throwAppTypeMismatch (f a : Expr) : MetaM Ξ± := do\n let (expectedType, binfo) ← getFunctionDomain f\n let mut e := mkApp f a\n unless binfo.isExplicit do\n e := e.setAppPPExplicit\n let aType ← inferType a\n throwError \"application type mismatch{indentExpr e}\\nargument{indentExpr a}\\n{← mkHasTypeButIsExpectedMsg aType expectedType}\"", "start": [ 129, 1 ], "end": [ 135, 129 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.checkApp", "code": "def checkApp (f a : Expr) : MetaM Unit := do\n let fType ← inferType f\n let fType ← whnf fType\n match fType with\n | Expr.forallE _ d _ _ =>\n let aType ← inferType a\n unless (← isDefEq d aType) do\n throwAppTypeMismatch f a\n | _ => throwFunctionExpected (mkApp f a)", "start": [ 137, 1 ], "end": [ 145, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.checkAux", "code": "private partial def checkAux (e : Expr) : MetaM Unit := do\n check e |>.run\nwhere\n check (e : Expr) : MonadCacheT ExprStructEq Unit MetaM Unit :=\n checkCache { val := e : ExprStructEq } fun _ => do\n match e with\n | .forallE .. => checkForall e\n | .lam .. => checkLambdaLet e\n | .letE .. => checkLambdaLet e\n | .const c lvls => checkConstant c lvls\n | .app f a => check f; check a; checkApp f a\n | .mdata _ e => check e\n | .proj _ _ e => check e\n | _ => return ()\n\n checkLambdaLet (e : Expr) : MonadCacheT ExprStructEq Unit MetaM Unit :=\n lambdaLetTelescope e fun xs b => do\n xs.forM fun x => do\n let xDecl ← getFVarLocalDecl x;\n match xDecl with\n | .cdecl (type := t) .. =>\n ensureType t\n check t\n | .ldecl (type := t) (value := v) .. =>\n ensureType t\n check t\n let vType ← inferType v\n unless (← isDefEq t vType) do throwLetTypeMismatchMessage x.fvarId!\n check v\n check b\n\n checkForall (e : Expr) : MonadCacheT ExprStructEq Unit MetaM Unit :=\n forallTelescope e fun xs b => do\n xs.forM fun x => do\n let xDecl ← getFVarLocalDecl x\n ensureType xDecl.type\n check xDecl.type\n ensureType b\n check b", "start": [ 147, 1 ], "end": [ 185, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.check", "code": "def check (e : Expr) : MetaM Unit :=\n withTraceNode `Meta.check (fun res =>\n return m!\"{if res.isOk then checkEmoji else crossEmoji} {e}\") do\n try\n withTransparency TransparencyMode.all $ checkAux e\n catch ex =>\n trace[Meta.check] ex.toMessageData\n throw ex", "start": [ 187, 1 ], "end": [ 197, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isTypeCorrect", "code": "def isTypeCorrect (e : Expr) : MetaM Bool := do\n try\n check e\n pure true\n catch _ =>\n pure false", "start": [ 199, 1 ], "end": [ 207, 15 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Init/Data/Array/InsertionSort.lean
[ ".lake/packages/lean4/src/lean/Init/Data/Array/Basic.lean" ]
[ { "full_name": "Array.insertionSort", "code": "@[inline] def Array.insertionSort (a : Array Ξ±) (lt : Ξ± β†’ Ξ± β†’ Bool) : Array Ξ± :=\n traverse a 0 a.size\nwhere\n @[specialize] traverse (a : Array Ξ±) (i : Nat) (fuel : Nat) : Array Ξ± :=\n match fuel with\n | 0 => a\n | fuel+1 =>\n if h : i < a.size then\n traverse (swapLoop a i h) (i+1) fuel\n else\n a\n @[specialize] swapLoop (a : Array Ξ±) (j : Nat) (h : j < a.size) : Array Ξ± :=\n match (generalizing := false) he:j with | 0 => a\n | j'+1 =>\n have h' : j' < a.size := by subst j; exact Nat.lt_trans (Nat.lt_succ_self _) h\n if lt a[j] a[j'] then\n swapLoop (a.swap ⟨j, h⟩ ⟨j', h'⟩) j' (by rw [size_swap]; assumption; done)\n else\n a", "start": [ 9, 1 ], "end": [ 28, 10 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/AbstractMVars.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.AbstractMVars.State", "code": "structure State where\n ngen : NameGenerator\n lctx : LocalContext\n mctx : MetavarContext\n nextParamIdx : Nat := 0\n paramNames : Array Name := #[]\n fvars : Array Expr := #[]\n lmap : HashMap LMVarId Level := {}\n emap : HashMap MVarId Expr := {}\n abstractLevels : Bool", "start": [ 12, 1 ], "end": [ 21, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.AbstractMVars.M", "code": "abbrev M := StateM State", "start": [ 23, 1 ], "end": [ 23, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.AbstractMVars.mkFreshId", "code": "def mkFreshId : M Name := do\n let s ← get\n let fresh := s.ngen.curr\n modify fun s => { s with ngen := s.ngen.next }\n pure fresh", "start": [ 30, 1 ], "end": [ 34, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.AbstractMVars.mkFreshFVarId", "code": "def mkFreshFVarId : M FVarId :=\n return { name := (← mkFreshId) }", "start": [ 36, 1 ], "end": [ 37, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.AbstractMVars.abstractLevelMVars", "code": "private partial def abstractLevelMVars (u : Level) : M Level := do\n if !(← get).abstractLevels then\n return u\n if !u.hasMVar then\n return u\n else\n match u with\n | Level.zero => return u\n | Level.param _ => return u\n | Level.succ v => return u.updateSucc! (← abstractLevelMVars v)\n | Level.max v w => return u.updateMax! (← abstractLevelMVars v) (← abstractLevelMVars w)\n | Level.imax v w => return u.updateIMax! (← abstractLevelMVars v) (← abstractLevelMVars w)\n | Level.mvar mvarId =>\n let s ← get\n let depth := s.mctx.getLevelDepth mvarId;\n if depth != s.mctx.depth then\n return u else\n match s.lmap.find? mvarId with\n | some u => pure u\n | none =>\n let paramId := Name.mkNum `_abstMVar s.nextParamIdx\n let u := mkLevelParam paramId\n modify fun s => { s with nextParamIdx := s.nextParamIdx + 1, lmap := s.lmap.insert mvarId u, paramNames := s.paramNames.push paramId }\n return u", "start": [ 39, 1 ], "end": [ 63, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.AbstractMVars.abstractExprMVars", "code": "partial def abstractExprMVars (e : Expr) : M Expr := do\n if !e.hasMVar then\n return e\n else\n match e with\n | e@(Expr.lit _) => return e\n | e@(Expr.bvar _) => return e\n | e@(Expr.fvar _) => return e\n | e@(Expr.sort u) => return e.updateSort! (← abstractLevelMVars u)\n | e@(Expr.const _ us) => return e.updateConst! (← us.mapM abstractLevelMVars)\n | e@(Expr.proj _ _ s) => return e.updateProj! (← abstractExprMVars s)\n | e@(Expr.app f a) => return e.updateApp! (← abstractExprMVars f) (← abstractExprMVars a)\n | e@(Expr.mdata _ b) => return e.updateMData! (← abstractExprMVars b)\n | e@(Expr.lam _ d b _) => return e.updateLambdaE! (← abstractExprMVars d) (← abstractExprMVars b)\n | e@(Expr.forallE _ d b _) => return e.updateForallE! (← abstractExprMVars d) (← abstractExprMVars b)\n | e@(Expr.letE _ t v b _) => return e.updateLet! (← abstractExprMVars t) (← abstractExprMVars v) (← abstractExprMVars b)\n | e@(Expr.mvar mvarId) =>\n let decl := (← getMCtx).getDecl mvarId\n if decl.depth != (← getMCtx).depth then\n return e\n else\n let eNew ← instantiateMVars e\n if e != eNew then\n abstractExprMVars eNew\n else\n match (← get).emap.find? mvarId with\n | some e =>\n return e\n | none =>\n let type ← abstractExprMVars decl.type\n let fvarId ← mkFreshFVarId\n let fvar := mkFVar fvarId;\n let userName ← if decl.userName.isAnonymous then\n pure <| (`x).appendIndexAfter (← get).fvars.size\n else\n pure decl.userName\n modify fun s => {\n s with\n emap := s.emap.insert mvarId fvar,\n fvars := s.fvars.push fvar,\n lctx := s.lctx.mkLocalDecl fvarId userName type }\n return fvar", "start": [ 65, 1 ], "end": [ 106, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.abstractMVars", "code": "def abstractMVars (e : Expr) (levels : Bool := true): MetaM AbstractMVarsResult := do\n let e ← instantiateMVars e\n let (e, s) := AbstractMVars.abstractExprMVars e\n { mctx := (← getMCtx), lctx := (← getLCtx), ngen := (← getNGen), abstractLevels := levels }\n setNGen s.ngen\n setMCtx s.mctx\n let e := s.lctx.mkLambda s.fvars e\n pure { paramNames := s.paramNames, numMVars := s.fvars.size, expr := e }", "start": [ 110, 1 ], "end": [ 137, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.openAbstractMVarsResult", "code": "def openAbstractMVarsResult (a : AbstractMVarsResult) : MetaM (Array Expr Γ— Array BinderInfo Γ— Expr) := do\n let us ← a.paramNames.mapM fun _ => mkFreshLevelMVar\n let e := a.expr.instantiateLevelParamsArray a.paramNames us\n lambdaMetaTelescope e (some a.numMVars)", "start": [ 139, 1 ], "end": [ 142, 42 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Instances.lean
[ ".lake/packages/lean4/src/lean/Lean/ScopedEnvExtension.lean", ".lake/packages/lean4/src/lean/Lean/Meta/DiscrTree.lean", ".lake/packages/lean4/src/lean/Lean/Meta/GlobalInstances.lean", ".lake/packages/lean4/src/lean/Lean/Meta/CollectMVars.lean" ]
[ { "full_name": "Lean.Meta.InstanceKey", "code": "abbrev InstanceKey := DiscrTree.Key", "start": [ 41, 1 ], "end": [ 41, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.InstanceEntry", "code": "structure InstanceEntry where\n keys : Array InstanceKey\n val : Expr\n priority : Nat\n globalName? : Option Name := none\n \n synthOrder : Array Nat\n \n attrKind : AttributeKind\n deriving Inhabited", "start": [ 43, 1 ], "end": [ 57, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.InstanceTree", "code": "abbrev InstanceTree := DiscrTree InstanceEntry", "start": [ 67, 1 ], "end": [ 67, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Instances", "code": "structure Instances where\n discrTree : InstanceTree := DiscrTree.empty\n instanceNames : PHashMap Name InstanceEntry := {}\n erased : PHashSet Name := {}\n deriving Inhabited", "start": [ 69, 1 ], "end": [ 73, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.tcDtConfig", "code": "def tcDtConfig : WhnfCoreConfig := {}", "start": [ 75, 1 ], "end": [ 76, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addInstanceEntry", "code": "def addInstanceEntry (d : Instances) (e : InstanceEntry) : Instances :=\n match e.globalName? with\n | some n => { d with discrTree := d.discrTree.insertCore e.keys e, instanceNames := d.instanceNames.insert n e, erased := d.erased.erase n }\n | none => { d with discrTree := d.discrTree.insertCore e.keys e }", "start": [ 78, 1 ], "end": [ 81, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Instances.eraseCore", "code": "def Instances.eraseCore (d : Instances) (declName : Name) : Instances :=\n { d with erased := d.erased.insert declName, instanceNames := d.instanceNames.erase declName }", "start": [ 83, 1 ], "end": [ 84, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Instances.erase", "code": "def Instances.erase [Monad m] [MonadError m] (d : Instances) (declName : Name) : m Instances := do\n unless d.instanceNames.contains declName do\n throwError \"'{declName}' does not have [instance] attribute\"\n return d.eraseCore declName", "start": [ 86, 1 ], "end": [ 89, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkInstanceKey", "code": "private def mkInstanceKey (e : Expr) : MetaM (Array InstanceKey) := do\n let type ← inferType e\n withNewMCtxDepth do\n let (_, _, type) ← forallMetaTelescopeReducing type\n DiscrTree.mkPath type tcDtConfig", "start": [ 97, 1 ], "end": [ 101, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.computeSynthOrder", "code": "private partial def computeSynthOrder (inst : Expr) : MetaM (Array Nat) :=\n withReducible do\n let instTy ← inferType inst\n\n let rec getSemiOutParamPositionsOf (classTy : Expr) : MetaM (Array Nat) := do\n if let .const className .. := classTy.getAppFn then\n forallTelescopeReducing (← inferType classTy.getAppFn) fun args _ => do\n let mut pos := (getOutParamPositions? (← getEnv) className).getD #[]\n for arg in args, i in [:args.size] do\n if (← inferType arg).isAppOf ``semiOutParam then\n pos := pos.push i\n return pos\n else\n return #[]\n\n let (argMVars, argBIs, ty) ← forallMetaTelescopeReducing instTy\n let ty ← whnf ty\n forallTelescopeReducing instTy fun argVars _ => do\n\n let rec assignMVarsIn (e : Expr) : MetaM Unit := do\n for mvarId in ← getMVars e do\n if let some i := argMVars.findIdx? (Β·.mvarId! == mvarId) then\n mvarId.assign argVars[i]!\n assignMVarsIn (← inferType (.mvar mvarId))\n\n let tyOutParams ← getSemiOutParamPositionsOf ty\n let tyArgs := ty.getAppArgs\n for tyArg in tyArgs, i in [:tyArgs.size] do\n unless tyOutParams.contains i do assignMVarsIn tyArg\n\n let mut synthed := #[]\n let mut toSynth := List.range argMVars.size |>.filter (argBIs[Β·]! == .instImplicit) |>.toArray\n while !toSynth.isEmpty do\n let next? ← toSynth.findM? fun i => do\n forallTelescopeReducing (← instantiateMVars (← inferType argMVars[i]!)) fun _ argTy => do\n let argTy ← whnf argTy\n let argOutParams ← getSemiOutParamPositionsOf argTy\n let argTyArgs := argTy.getAppArgs\n for i in [:argTyArgs.size], argTyArg in argTyArgs do\n if !argOutParams.contains i && argTyArg.hasExprMVar then\n return false\n return true\n let next ←\n match next? with\n | some next => pure next\n | none =>\n if synthInstance.checkSynthOrder.get (← getOptions) then\n let typeLines := (\"\" : MessageData).joinSep <| Array.toList <| ← toSynth.mapM fun i => do\n let ty ← instantiateMVars (← inferType argMVars[i]!)\n return indentExpr (ty.setPPExplicit true)\n logError m!\"cannot find synthesization order for instance {inst} with type{indentExpr instTy}\\nall remaining arguments have metavariables:{typeLines}\"\n pure toSynth[0]!\n synthed := synthed.push next\n toSynth := toSynth.filter (Β· != next)\n assignMVarsIn (← inferType argMVars[next]!)\n assignMVarsIn argMVars[next]!\n\n if synthInstance.checkSynthOrder.get (← getOptions) then\n let ty ← instantiateMVars ty\n if ty.hasExprMVar then\n logError m!\"instance does not provide concrete values for (semi-)out-params{indentExpr (ty.setPPExplicit true)}\"\n\n trace[Meta.synthOrder] \"synthesizing the arguments of {inst} in the order {synthed}:{(\"\" : MessageData).joinSep (← synthed.mapM fun i => return indentExpr (← inferType argVars[i]!)).toList}\"\n\n return synthed", "start": [ 103, 1 ], "end": [ 192, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addInstance", "code": "def addInstance (declName : Name) (attrKind : AttributeKind) (prio : Nat) : MetaM Unit := do\n let c ← mkConstWithLevelParams declName\n let keys ← mkInstanceKey c\n addGlobalInstance declName attrKind\n let synthOrder ← computeSynthOrder c\n instanceExtension.add { keys, val := c, priority := prio, globalName? := declName, attrKind, synthOrder } attrKind", "start": [ 194, 1 ], "end": [ 199, 117 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getGlobalInstancesIndex", "code": "def getGlobalInstancesIndex : CoreM (DiscrTree InstanceEntry) :=\n return Meta.instanceExtension.getState (← getEnv) |>.discrTree", "start": [ 214, 1 ], "end": [ 215, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getErasedInstances", "code": "def getErasedInstances : CoreM (PHashSet Name) :=\n return Meta.instanceExtension.getState (← getEnv) |>.erased", "start": [ 217, 1 ], "end": [ 218, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstanceCore", "code": "def isInstanceCore (env : Environment) (declName : Name) : Bool :=\n Meta.instanceExtension.getState env |>.instanceNames.contains declName", "start": [ 220, 1 ], "end": [ 221, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isInstance", "code": "def isInstance (declName : Name) : CoreM Bool :=\n return isInstanceCore (← getEnv) declName", "start": [ 223, 1 ], "end": [ 224, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getInstancePriority?", "code": "def getInstancePriority? (declName : Name) : CoreM (Option Nat) := do\n let some entry := Meta.instanceExtension.getState (← getEnv) |>.instanceNames.find? declName | return none\n return entry.priority", "start": [ 226, 1 ], "end": [ 228, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getInstanceAttrKind?", "code": "def getInstanceAttrKind? (declName : Name) : CoreM (Option AttributeKind) := do\n let some entry := Meta.instanceExtension.getState (← getEnv) |>.instanceNames.find? declName | return none\n return entry.attrKind", "start": [ 230, 1 ], "end": [ 232, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DefaultInstanceEntry", "code": "structure DefaultInstanceEntry where\n className : Name\n instanceName : Name\n priority : Nat", "start": [ 236, 1 ], "end": [ 239, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.PrioritySet", "code": "abbrev PrioritySet := RBTree Nat (fun x y => compare y x)", "start": [ 241, 1 ], "end": [ 241, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.DefaultInstances", "code": "structure DefaultInstances where\n defaultInstances : NameMap (List (Name Γ— Nat)) := {}\n priorities : PrioritySet := {}\n deriving Inhabited", "start": [ 243, 1 ], "end": [ 246, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addDefaultInstanceEntry", "code": "def addDefaultInstanceEntry (d : DefaultInstances) (e : DefaultInstanceEntry) : DefaultInstances :=\n let d := { d with priorities := d.priorities.insert e.priority }\n match d.defaultInstances.find? e.className with\n | some insts => { d with defaultInstances := d.defaultInstances.insert e.className <| (e.instanceName, e.priority) :: insts }\n | none => { d with defaultInstances := d.defaultInstances.insert e.className [(e.instanceName, e.priority)] }", "start": [ 248, 1 ], "end": [ 252, 118 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addDefaultInstance", "code": "def addDefaultInstance (declName : Name) (prio : Nat := 0) : MetaM Unit := do\n match (← getEnv).find? declName with\n | none => throwError \"unknown constant '{declName}'\"\n | some info =>\n forallTelescopeReducing info.type fun _ type => do\n match type.getAppFn with\n | Expr.const className _ =>\n unless isClass (← getEnv) className do\n throwError \"invalid default instance '{declName}', it has type '({className} ...)', but {className}' is not a type class\"\n setEnv <| defaultInstanceExtension.addEntry (← getEnv) { className := className, instanceName := declName, priority := prio }\n | _ => throwError \"invalid default instance '{declName}', type must be of the form '(C ...)' where 'C' is a type class\"", "start": [ 260, 1 ], "end": [ 270, 126 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getDefaultInstancesPriorities", "code": "def getDefaultInstancesPriorities [Monad m] [MonadEnv m] : m PrioritySet :=\n return defaultInstanceExtension.getState (← getEnv) |>.priorities", "start": [ 283, 1 ], "end": [ 284, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getDefaultInstances", "code": "def getDefaultInstances [Monad m] [MonadEnv m] (className : Name) : m (List (Name Γ— Nat)) :=\n return defaultInstanceExtension.getState (← getEnv) |>.defaultInstances.find? className |>.getD []", "start": [ 286, 1 ], "end": [ 287, 101 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Util.lean
[ ".lake/packages/lean4/src/lean/Lean/KeyedDeclsAttribute.lean", ".lake/packages/lean4/src/lean/Lean/Elab/Exception.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Command.lean" ]
[ { "full_name": "Lean.Syntax.prettyPrint", "code": "def Syntax.prettyPrint (stx : Syntax) : Format :=\n match stx.unsetTrailing.reprint with | some str => format str.toFormat\n | none => format stx", "start": [ 13, 1 ], "end": [ 16, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MacroScopesView.format", "code": "def MacroScopesView.format (view : MacroScopesView) (mainModule : Name) : Format :=\n Std.format <|\n if view.scopes.isEmpty then\n view.name\n else if view.mainModule == mainModule then\n view.scopes.foldl Name.mkNum (view.name ++ view.imported)\n else\n view.scopes.foldl Name.mkNum (view.name ++ view.imported ++ view.mainModule)", "start": [ 18, 1 ], "end": [ 25, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MacroScopesView.equalScope", "code": "def MacroScopesView.equalScope (a b : MacroScopesView) : Bool :=\n a.scopes == b.scopes && a.mainModule == b.mainModule && a.imported == b.imported", "start": [ 27, 1 ], "end": [ 32, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.expandOptNamedPrio", "code": "def expandOptNamedPrio (stx : Syntax) : MacroM Nat :=\n if stx.isNone then\n return eval_prio default\n else match stx[0] with\n | `(Parser.Command.namedPrio| (priority := $prio)) => evalPrio prio\n | _ => Macro.throwUnsupported", "start": [ 36, 1 ], "end": [ 41, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.MacroStackElem", "code": "structure MacroStackElem where\n before : Syntax\n after : Syntax", "start": [ 43, 1 ], "end": [ 45, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.MacroStack", "code": "abbrev MacroStack := List MacroStackElem", "start": [ 47, 1 ], "end": [ 47, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.getBetterRef", "code": "def getBetterRef (ref : Syntax) (macroStack : MacroStack) : Syntax :=\n match ref.getPos? with\n | some _ => ref\n | none =>\n match macroStack.find? (Β·.before.getPos? != none) with\n | some elem => elem.before\n | none => ref", "start": [ 49, 1 ], "end": [ 56, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.addMacroStack", "code": "def addMacroStack {m} [Monad m] [MonadOptions m] (msgData : MessageData) (macroStack : MacroStack) : m MessageData := do\n if !pp.macroStack.get (← getOptions) then pure msgData else\n match macroStack with\n | [] => pure msgData\n | stack@(top::_) =>\n let msgData := msgData ++ Format.line ++ \"with resulting expansion\" ++ indentD top.after\n pure $ stack.foldl\n (fun (msgData : MessageData) (elem : MacroStackElem) =>\n msgData ++ Format.line ++ \"while expanding\" ++ indentD elem.before)\n msgData", "start": [ 64, 1 ], "end": [ 73, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.checkSyntaxNodeKind", "code": "def checkSyntaxNodeKind [Monad m] [MonadEnv m] [MonadError m] (k : Name) : m Name := do\n if Parser.isValidSyntaxNodeKind (← getEnv) k then pure k\n else throwError \"failed\"", "start": [ 75, 1 ], "end": [ 77, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.checkSyntaxNodeKindAtNamespaces", "code": "def checkSyntaxNodeKindAtNamespaces [Monad m] [MonadEnv m] [MonadError m] (k : Name) : Name β†’ m Name\n | n@(.str p _) => checkSyntaxNodeKind (n ++ k) <|> checkSyntaxNodeKindAtNamespaces k p\n | .anonymous => checkSyntaxNodeKind k\n | _ => throwError \"failed\"", "start": [ 79, 1 ], "end": [ 82, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.checkSyntaxNodeKindAtCurrentNamespaces", "code": "def checkSyntaxNodeKindAtCurrentNamespaces (k : Name) : AttrM Name := do\n let ctx ← read\n checkSyntaxNodeKindAtNamespaces k ctx.currNamespace", "start": [ 84, 1 ], "end": [ 86, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.syntaxNodeKindOfAttrParam", "code": "def syntaxNodeKindOfAttrParam (defaultParserNamespace : Name) (stx : Syntax) : AttrM SyntaxNodeKind := do\n let k ← Attribute.Builtin.getId stx\n checkSyntaxNodeKindAtCurrentNamespaces k\n <|>\n checkSyntaxNodeKind (defaultParserNamespace ++ k)\n <|>\n throwError \"invalid syntax node kind '{k}'\"", "start": [ 88, 1 ], "end": [ 94, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.evalSyntaxConstantUnsafe", "code": "private unsafe def evalSyntaxConstantUnsafe (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax :=\n env.evalConstCheck Syntax opts `Lean.Syntax constName", "start": [ 96, 1 ], "end": [ 97, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.evalSyntaxConstant", "code": "@[implemented_by evalSyntaxConstantUnsafe]\nopaque evalSyntaxConstant (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax := throw \"\"", "start": [ 99, 1 ], "end": [ 100, 121 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.mkElabAttribute", "code": "unsafe def mkElabAttribute (Ξ³) (attrBuiltinName attrName : Name) (parserNamespace : Name) (typeName : Name) (kind : String)\n (attrDeclName : Name := by exact decl_name%) : IO (KeyedDeclsAttribute Ξ³) :=\n KeyedDeclsAttribute.init {\n builtinName := attrBuiltinName\n name := attrName\n descr := kind ++ \" elaborator\"\n valueTypeName := typeName\n evalKey := fun _ stx => do\n let kind ← syntaxNodeKindOfAttrParam parserNamespace stx\n \n if (← getEnv).contains kind && (← getInfoState).enabled then\n addConstInfo stx[1] kind none\n return kind\n onAdded := fun builtin declName => do\n if builtin then\n declareBuiltinDocStringAndRanges declName\n } attrDeclName", "start": [ 102, 1 ], "end": [ 118, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.mkMacroAttributeUnsafe", "code": "unsafe def mkMacroAttributeUnsafe (ref : Name) : IO (KeyedDeclsAttribute Macro) :=\n mkElabAttribute Macro `builtin_macro `macro Name.anonymous `Lean.Macro \"macro\" ref", "start": [ 120, 1 ], "end": [ 121, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.mkMacroAttribute", "code": "@[implemented_by mkMacroAttributeUnsafe]\nopaque mkMacroAttribute (ref : Name) : IO (KeyedDeclsAttribute Macro)", "start": [ 123, 1 ], "end": [ 124, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.expandMacroImpl?", "code": "def expandMacroImpl? (env : Environment) : Syntax β†’ MacroM (Option (Name Γ— Except Macro.Exception Syntax)) := fun stx => do\n for e in macroAttribute.getEntries env stx.getKind do\n try\n let stx' ← withFreshMacroScope (e.value stx)\n return (e.declName, Except.ok stx')\n catch\n | Macro.Exception.unsupportedSyntax => pure ()\n | ex => return (e.declName, Except.error ex)\n return none", "start": [ 128, 1 ], "end": [ 140, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.MonadMacroAdapter", "code": "class MonadMacroAdapter (m : Type β†’ Type) where\n getCurrMacroScope : m MacroScope\n getNextMacroScope : m MacroScope\n setNextMacroScope : MacroScope β†’ m Unit", "start": [ 142, 1 ], "end": [ 145, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.liftMacroM", "code": "def liftMacroM [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m] [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLiftT IO m] (x : MacroM Ξ±) : m Ξ± := do\n let env ← getEnv\n let currNamespace ← getCurrNamespace\n let openDecls ← getOpenDecls\n let methods := Macro.mkMethods {\n expandMacro? := fun stx => do\n match (← expandMacroImpl? env stx) with\n | some (_, stx?) => liftExcept stx?\n | none => return none\n hasDecl := fun declName => return env.contains declName\n getCurrNamespace := return currNamespace\n resolveNamespace := fun n => return ResolveName.resolveNamespace env currNamespace openDecls n\n resolveGlobalName := fun n => return ResolveName.resolveGlobalName env currNamespace openDecls n\n }\n match x { methods := methods\n ref := ← getRef\n currMacroScope := ← MonadMacroAdapter.getCurrMacroScope\n mainModule := env.mainModule\n currRecDepth := ← MonadRecDepth.getRecDepth\n maxRecDepth := ← MonadRecDepth.getMaxRecDepth\n } { macroScope := (← MonadMacroAdapter.getNextMacroScope) } with\n | EStateM.Result.error Macro.Exception.unsupportedSyntax _ => throwUnsupportedSyntax\n | EStateM.Result.error (Macro.Exception.error ref msg) _ =>\n if msg == maxRecDepthErrorMessage then\n throwMaxRecDepthAt ref\n else\n throwErrorAt ref msg\n | EStateM.Result.ok a s =>\n MonadMacroAdapter.setNextMacroScope s.macroScope\n s.traceMsgs.reverse.forM fun (clsName, msg) => trace clsName fun _ => msg\n return a", "start": [ 154, 1 ], "end": [ 186, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.adaptMacro", "code": "@[inline] def adaptMacro {m : Type β†’ Type} [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m] [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLiftT IO m] (x : Macro) (stx : Syntax) : m Syntax :=\n liftMacroM (x stx)", "start": [ 188, 1 ], "end": [ 189, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.mkUnusedBaseName", "code": "partial def mkUnusedBaseName (baseName : Name) : MacroM Name := do\n let currNamespace ← Macro.getCurrNamespace\n if ← Macro.hasDecl (currNamespace ++ baseName) then\n let rec loop (idx : Nat) := do\n let name := baseName.appendIndexAfter idx\n if ← Macro.hasDecl (currNamespace ++ name) then\n loop (idx+1)\n else\n return name\n loop 1\n else\n return baseName", "start": [ 191, 1 ], "end": [ 202, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.logException", "code": "def logException [Monad m] [MonadLog m] [AddMessageContext m] [MonadOptions m] [MonadLiftT IO m] (ex : Exception) : m Unit := do\n match ex with\n | Exception.error ref msg => logErrorAt ref msg\n | Exception.internal id _ =>\n unless isAbortExceptionId id || id == Core.interruptExceptionId do\n let name ← id.getName\n logError m!\"internal exception: {name}\"", "start": [ 204, 1 ], "end": [ 210, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.withLogging", "code": "def withLogging [Monad m] [MonadLog m] [MonadExcept Exception m] [AddMessageContext m] [MonadOptions m] [MonadLiftT IO m]\n (x : m Unit) : m Unit := do\n try x catch ex => logException ex", "start": [ 212, 1 ], "end": [ 217, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.nestedExceptionToMessageData", "code": "def nestedExceptionToMessageData [Monad m] [MonadLog m] (ex : Exception) : m MessageData := do\n let pos ← getRefPos\n match ex.getRef.getPos? with\n | none => return ex.toMessageData\n | some exPos =>\n if pos == exPos then\n return ex.toMessageData\n else\n let exPosition := (← getFileMap).toPosition exPos\n return m!\"{exPosition.line}:{exPosition.column} {ex.toMessageData}\"", "start": [ 219, 1 ], "end": [ 228, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.throwErrorWithNestedErrors", "code": "def throwErrorWithNestedErrors [MonadError m] [Monad m] [MonadLog m] (msg : MessageData) (exs : Array Exception) : m Ξ± := do\n throwError \"{msg}, errors {toMessageList (← exs.mapM fun | ex => nestedExceptionToMessageData ex)}\"", "start": [ 230, 1 ], "end": [ 231, 102 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/DecLevel.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/InferType.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.DecLevelContext", "code": "structure DecLevelContext where\n \n canAssignMVars : Bool := true", "start": [ 12, 1 ], "end": [ 17, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.decAux?", "code": "private partial def decAux? : Level β†’ ReaderT DecLevelContext MetaM (Option Level)\n | Level.zero => return none\n | Level.param _ => return none\n | Level.mvar mvarId => do\n match (← getLevelMVarAssignment? mvarId) with\n | some u => decAux? u\n | none =>\n if (← mvarId.isReadOnly) || !(← read).canAssignMVars then\n return none\n else\n let u ← mkFreshLevelMVar\n trace[Meta.isLevelDefEq.step] \"decAux?, {mkLevelMVar mvarId} := {mkLevelSucc u}\"\n assignLevelMVar mvarId (mkLevelSucc u)\n return u\n | Level.succ u => return u\n | u =>\n let processMax (u v : Level) : ReaderT DecLevelContext MetaM (Option Level) := do\n \n withReader (fun _ => { canAssignMVars := false }) do\n match (← decAux? u) with\n | none => return none\n | some u => do\n match (← decAux? v) with\n | none => return none\n | some v => return mkLevelMax' u v\n match u with\n | Level.max u v => processMax u v\n \n | Level.imax u v => processMax u v\n | _ => unreachable!", "start": [ 19, 1 ], "end": [ 52, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.decLevel?", "code": "def decLevel? (u : Level) : MetaM (Option Level) := do\n let mctx ← getMCtx\n match (← decAux? u |>.run {}) with\n | some v => return some v\n | none => do\n modify fun s => { s with mctx := mctx }\n return none", "start": [ 54, 1 ], "end": [ 60, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.decLevel", "code": "def decLevel (u : Level) : MetaM Level := do\n match (← decLevel? u) with\n | some u => return u\n | none => throwError \"invalid universe level, {u} is not greater than 0\"", "start": [ 62, 1 ], "end": [ 65, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getDecLevel", "code": "def getDecLevel (type : Expr) : MetaM Level := do\n decLevel (← getLevel type)", "start": [ 67, 1 ], "end": [ 71, 29 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/SynthInstance.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Instances.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AbstractMVars.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/InsertionSort.lean", ".lake/packages/lean4/src/lean/Lean/Util/Profile.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Check.lean" ]
[ { "full_name": "Lean.Meta.SynthInstance.getMaxHeartbeats", "code": "def getMaxHeartbeats (opts : Options) : Nat :=\n synthInstance.maxHeartbeats.get opts * 1000", "start": [ 36, 1 ], "end": [ 37, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.Instance", "code": "structure Instance where\n val : Expr\n synthOrder : Array Nat\n deriving Inhabited", "start": [ 39, 1 ], "end": [ 42, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.GeneratorNode", "code": "structure GeneratorNode where\n mvar : Expr\n key : Expr\n mctx : MetavarContext\n instances : Array Instance\n currInstanceIdx : Nat\n \n typeHasMVars : Bool\n deriving Inhabited", "start": [ 44, 1 ], "end": [ 58, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.ConsumerNode", "code": "structure ConsumerNode where\n mvar : Expr\n key : Expr\n mctx : MetavarContext\n subgoals : List Expr\n size : Nat deriving Inhabited", "start": [ 60, 1 ], "end": [ 66, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.Waiter", "code": "inductive Waiter where\n | consumerNode : ConsumerNode β†’ Waiter\n | root : Waiter", "start": [ 68, 1 ], "end": [ 70, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.Waiter.isRoot", "code": "def Waiter.isRoot : Waiter β†’ Bool\n | .consumerNode _ => false\n | .root => true", "start": [ 72, 1 ], "end": [ 74, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.MkTableKey.State", "code": "structure State where\n nextIdx : Nat := 0\n lmap : HashMap LMVarId Level := {}\n emap : HashMap MVarId Expr := {}\n mctx : MetavarContext", "start": [ 98, 1 ], "end": [ 102, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.MkTableKey.M", "code": "abbrev M := StateM State", "start": [ 104, 1 ], "end": [ 104, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.MkTableKey.normLevel", "code": "partial def normLevel (u : Level) : M Level := do\n if !u.hasMVar then\n return u\n else match u with\n | .succ v => return u.updateSucc! (← normLevel v)\n | .max v w => return u.updateMax! (← normLevel v) (← normLevel w)\n | .imax v w => return u.updateIMax! (← normLevel v) (← normLevel w)\n | .mvar mvarId =>\n if (← getMCtx).getLevelDepth mvarId != (← getMCtx).depth then\n return u\n else\n let s ← get\n match (← get).lmap.find? mvarId with\n | some u' => pure u'\n | none =>\n let u' := mkLevelParam <| Name.mkNum `_tc s.nextIdx\n modify fun s => { s with nextIdx := s.nextIdx + 1, lmap := s.lmap.insert mvarId u' }\n return u'\n | u => return u", "start": [ 111, 1 ], "end": [ 129, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.MkTableKey.normExpr", "code": "partial def normExpr (e : Expr) : M Expr := do\n if !e.hasMVar then\n pure e\n else match e with\n | .const _ us => return e.updateConst! (← us.mapM normLevel)\n | .sort u => return e.updateSort! (← normLevel u)\n | .app f a => return e.updateApp! (← normExpr f) (← normExpr a)\n | .letE _ t v b _ => return e.updateLet! (← normExpr t) (← normExpr v) (← normExpr b)\n | .forallE _ d b _ => return e.updateForallE! (← normExpr d) (← normExpr b)\n | .lam _ d b _ => return e.updateLambdaE! (← normExpr d) (← normExpr b)\n | .mdata _ b => return e.updateMData! (← normExpr b)\n | .proj _ _ b => return e.updateProj! (← normExpr b)\n | .mvar mvarId =>\n if !(← mvarId.isAssignable) then\n return e\n else\n let s ← get\n match s.emap.find? mvarId with\n | some e' => pure e'\n | none => do\n let e' := mkFVar { name := Name.mkNum `_tc s.nextIdx }\n modify fun s => { s with nextIdx := s.nextIdx + 1, emap := s.emap.insert mvarId e' }\n return e'\n | _ => return e", "start": [ 131, 1 ], "end": [ 154, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.mkTableKey", "code": "def mkTableKey [Monad m] [MonadMCtx m] (e : Expr) : m Expr := do\n let (r, s) := MkTableKey.normExpr e |>.run { mctx := (← getMCtx) }\n setMCtx s.mctx\n return r", "start": [ 158, 1 ], "end": [ 162, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.Answer", "code": "structure Answer where\n result : AbstractMVarsResult\n resultType : Expr\n size : Nat\n deriving Inhabited", "start": [ 164, 1 ], "end": [ 168, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.TableEntry", "code": "structure TableEntry where\n waiters : Array Waiter\n answers : Array Answer := #[]", "start": [ 170, 1 ], "end": [ 172, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.Context", "code": "structure Context where\n maxResultSize : Nat\n maxHeartbeats : Nat", "start": [ 174, 1 ], "end": [ 176, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.State", "code": "structure State where\n result? : Option AbstractMVarsResult := none\n generatorStack : Array GeneratorNode := #[]\n resumeStack : Array (ConsumerNode Γ— Answer) := #[]\n tableEntries : HashMap Expr TableEntry := {}", "start": [ 178, 1 ], "end": [ 189, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.SynthM", "code": "abbrev SynthM := ReaderT Context $ StateRefT State MetaM", "start": [ 191, 1 ], "end": [ 191, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.checkSystem", "code": "def checkSystem : SynthM Unit := do\n Core.checkInterrupted\n Core.checkMaxHeartbeatsCore \"typeclass\" `synthInstance.maxHeartbeats (← read).maxHeartbeats", "start": [ 193, 1 ], "end": [ 195, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.getInstances", "code": "def getInstances (type : Expr) : MetaM (Array Instance) := do\n let localInstances ← getLocalInstances\n forallTelescopeReducing type fun _ type => do\n let className? ← isClass? type\n match className? with\n | none => throwError \"type class instance expected{indentExpr type}\"\n | some className =>\n let globalInstances ← getGlobalInstancesIndex\n let result ← globalInstances.getUnify type tcDtConfig\n let result := result.insertionSort fun e₁ eβ‚‚ => e₁.priority < eβ‚‚.priority\n let erasedInstances ← getErasedInstances\n let mut result ← result.filterMapM fun e => match e.val with\n | .const constName us =>\n if erasedInstances.contains constName then\n return none\n else\n return some {\n val := e.val.updateConst! (← us.mapM (fun _ => mkFreshLevelMVar))\n synthOrder := e.synthOrder\n }\n | _ => panic! \"global instance is not a constant\"\n for linst in localInstances do\n if linst.className == className then\n let synthOrder ← forallTelescopeReducing (← inferType linst.fvar) fun xs _ => do\n if xs.isEmpty then return #[]\n let mut order := #[]\n for i in [:xs.size], x in xs do\n if (← getFVarLocalDecl x).binderInfo == .instImplicit then\n order := order.push i\n return order\n result := result.push { val := linst.fvar, synthOrder }\n trace[Meta.synthInstance.instances] result.map (Β·.val)\n return result", "start": [ 200, 1 ], "end": [ 236, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.mkGeneratorNode?", "code": "def mkGeneratorNode? (key mvar : Expr) : MetaM (Option GeneratorNode) := do\n let mvarType ← inferType mvar\n let mvarType ← instantiateMVars mvarType\n let instances ← getInstances mvarType\n if instances.isEmpty then\n return none\n else\n let mctx ← getMCtx\n return some {\n mvar, key, mctx, instances\n typeHasMVars := mvarType.hasMVar\n currInstanceIdx := instances.size\n }", "start": [ 238, 1 ], "end": [ 250, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.newSubgoal", "code": "def newSubgoal (mctx : MetavarContext) (key : Expr) (mvar : Expr) (waiter : Waiter) : SynthM Unit :=\n withMCtx mctx do withTraceNode' `Meta.synthInstance do\n match (← mkGeneratorNode? key mvar) with\n | none => pure ((), m!\"no instances for {key}\")\n | some node =>\n let entry : TableEntry := { waiters := #[waiter] }\n modify fun s =>\n { s with\n generatorStack := s.generatorStack.push node\n tableEntries := s.tableEntries.insert key entry }\n pure ((), m!\"new goal {key}\")", "start": [ 252, 1 ], "end": [ 265, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.findEntry?", "code": "def findEntry? (key : Expr) : SynthM (Option TableEntry) := do\n return (← get).tableEntries.find? key", "start": [ 267, 1 ], "end": [ 268, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.getEntry", "code": "def getEntry (key : Expr) : SynthM TableEntry := do\n match (← findEntry? key) with\n | none => panic! \"invalid key at synthInstance\"\n | some entry => pure entry", "start": [ 270, 1 ], "end": [ 273, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.mkTableKeyFor", "code": "def mkTableKeyFor (mctx : MetavarContext) (mvar : Expr) : SynthM Expr :=\n withMCtx mctx do\n let mvarType ← inferType mvar\n let mvarType ← instantiateMVars mvarType\n mkTableKey mvarType", "start": [ 275, 1 ], "end": [ 284, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.SubgoalsResult", "code": "structure SubgoalsResult where\n subgoals : List Expr\n instVal : Expr\n instTypeBody : Expr", "start": [ 286, 1 ], "end": [ 295, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.getSubgoals", "code": "def getSubgoals (lctx : LocalContext) (localInsts : LocalInstances) (xs : Array Expr) (inst : Instance) : MetaM SubgoalsResult := do\n let mut instVal := inst.val\n let mut instType ← inferType instVal\n let mut mvars := #[]\n let mut subst := #[]\n repeat do\n if let .forallE _ d b _ := instType then\n let d := d.instantiateRev subst\n let mvar ← mkFreshExprMVarAt lctx localInsts (← mkForallFVars xs d)\n subst := subst.push (mkAppN mvar xs)\n instVal := mkApp instVal (mkAppN mvar xs)\n instType := b\n mvars := mvars.push mvar\n else\n instType ← whnf (instType.instantiateRev subst)\n instVal := instVal.instantiateRev subst\n subst := #[]\n unless instType.isForall do break\n return {\n instVal := instVal.instantiateRev subst\n instTypeBody := instType.instantiateRev subst\n subgoals := inst.synthOrder.map (mvars[Β·]!) |>.toList\n }", "start": [ 297, 1 ], "end": [ 334, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.tryResolve", "code": "def tryResolve (mvar : Expr) (inst : Instance) : MetaM (Option (MetavarContext Γ— List Expr)) := do\n if (← isDiagnosticsEnabled) then\n if let .const declName _ := inst.val.getAppFn then\n recordInstance declName\n let mvarType ← inferType mvar\n let lctx ← getLCtx\n let localInsts ← getLocalInstances\n forallTelescopeReducing mvarType fun xs mvarTypeBody => do\n let { subgoals, instVal, instTypeBody } ← getSubgoals lctx localInsts xs inst\n withTraceNode `Meta.synthInstance.tryResolve (withMCtx (← getMCtx) do\n return m!\"{exceptOptionEmoji Β·} {← instantiateMVars mvarTypeBody} β‰Ÿ {← instantiateMVars instTypeBody}\") do\n if (← isDefEq mvarTypeBody instTypeBody) then\n \n let instVal ← mkLambdaFVars xs instVal (etaReduce := true)\n if (← isDefEq mvar instVal) then\n return some ((← getMCtx), subgoals)\n return none", "start": [ 336, 1 ], "end": [ 372, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.tryAnswer", "code": "def tryAnswer (mctx : MetavarContext) (mvar : Expr) (answer : Answer) : SynthM (Option MetavarContext) :=\n withMCtx mctx do\n let (_, _, val) ← openAbstractMVarsResult answer.result\n if (← isDefEq mvar val) then\n return some (← getMCtx)\n else\n return none", "start": [ 374, 1 ], "end": [ 383, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.wakeUp", "code": "def wakeUp (answer : Answer) : Waiter β†’ SynthM Unit\n | .root => do\n \n if answer.result.numMVars == 0 then\n modify fun s => { s with result? := answer.result }\n else\n let (_, _, answerExpr) ← openAbstractMVarsResult answer.result\n trace[Meta.synthInstance] \"skip answer containing metavariables {answerExpr}\"\n | .consumerNode cNode =>\n modify fun s => { s with resumeStack := s.resumeStack.push (cNode, answer) }", "start": [ 385, 1 ], "end": [ 398, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.isNewAnswer", "code": "def isNewAnswer (oldAnswers : Array Answer) (answer : Answer) : Bool :=\n oldAnswers.all fun oldAnswer =>\n oldAnswer.resultType != answer.resultType", "start": [ 400, 1 ], "end": [ 404, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.mkAnswer", "code": "private def mkAnswer (cNode : ConsumerNode) : MetaM Answer :=\n withMCtx cNode.mctx do\n let val ← instantiateMVars cNode.mvar\n trace[Meta.synthInstance.newAnswer] \"size: {cNode.size}, val: {val}\"\n let result ← abstractMVars val let resultType ← inferType result.expr\n return { result, resultType, size := cNode.size + 1 }", "start": [ 406, 1 ], "end": [ 412, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.addAnswer", "code": "def addAnswer (cNode : ConsumerNode) : SynthM Unit := do\n withMCtx cNode.mctx do\n if cNode.size β‰₯ (← read).maxResultSize then\n trace[Meta.synthInstance.answer] \"{crossEmoji} {← instantiateMVars (← inferType cNode.mvar)}{Format.line}(size: {cNode.size} β‰₯ {(← read).maxResultSize})\"\n else\n withTraceNode `Meta.synthInstance.answer\n (fun _ => return m!\"{checkEmoji} {← instantiateMVars (← inferType cNode.mvar)}\") do\n let answer ← mkAnswer cNode\n let key := cNode.key\n let { waiters, answers } ← getEntry key\n if isNewAnswer answers answer then\n let newEntry := { waiters, answers := answers.push answer }\n modify fun s => { s with tableEntries := s.tableEntries.insert key newEntry }\n waiters.forM (wakeUp answer)", "start": [ 414, 1 ], "end": [ 432, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.hasUnusedArguments", "code": "private def hasUnusedArguments : Expr β†’ Bool\n | .forallE _ _ b _ => !b.hasLooseBVar 0 || hasUnusedArguments b\n | _ => false", "start": [ 434, 1 ], "end": [ 441, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.removeUnusedArguments?", "code": "private def removeUnusedArguments? (mctx : MetavarContext) (mvar : Expr) : MetaM (Option (Expr Γ— Expr)) :=\n withMCtx mctx do\n let mvarType ← instantiateMVars (← inferType mvar)\n if !hasUnusedArguments mvarType then\n return none\n else\n forallTelescope mvarType fun xs body => do\n let ys ← xs.foldrM (init := []) fun x ys => do\n if body.containsFVar x.fvarId! then\n return x :: ys\n else if (← ys.anyM fun y => return (← inferType y).containsFVar x.fvarId!) then\n return x :: ys\n else\n return ys\n let ys := ys.toArray\n let mvarType' ← mkForallFVars ys body\n withLocalDeclD `redf mvarType' fun f => do\n let transformer ← mkLambdaFVars #[f] (← mkLambdaFVars xs (mkAppN f ys) (etaReduce := true)) (etaReduce := true)\n trace[Meta.synthInstance.unusedArgs] \"{mvarType}\\nhas unused arguments, reduced type{indentExpr mvarType'}\\nTransformer{indentExpr transformer}\"\n return some (mvarType', transformer)", "start": [ 443, 1 ], "end": [ 484, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.consume", "code": "def consume (cNode : ConsumerNode) : SynthM Unit := do\n \n let cNode := { cNode with\n subgoals := ← withMCtx cNode.mctx do\n cNode.subgoals.filterM (not <$> Β·.mvarId!.isAssigned)\n }\n match cNode.subgoals with\n | [] => addAnswer cNode\n | mvar::_ =>\n let waiter := Waiter.consumerNode cNode\n let key ← mkTableKeyFor cNode.mctx mvar\n let entry? ← findEntry? key\n match entry? with\n | none =>\n match (← removeUnusedArguments? cNode.mctx mvar) with\n | none => newSubgoal cNode.mctx key mvar waiter\n | some (mvarType', transformer) =>\n let key' ← withMCtx cNode.mctx <| mkTableKey mvarType'\n match (← findEntry? key') with\n | none =>\n let (mctx', mvar') ← withMCtx cNode.mctx do\n let mvar' ← mkFreshExprMVar mvarType'\n return (← getMCtx, mvar')\n newSubgoal mctx' key' mvar' (Waiter.consumerNode { cNode with mctx := mctx', subgoals := mvar'::cNode.subgoals })\n | some entry' =>\n let answers' ← entry'.answers.mapM fun a => withMCtx cNode.mctx do\n let trAnswr := Expr.betaRev transformer #[← instantiateMVars a.result.expr]\n let trAnswrType ← inferType trAnswr\n pure { a with result.expr := trAnswr, resultType := trAnswrType }\n modify fun s =>\n { s with\n resumeStack := answers'.foldl (fun s answer => s.push (cNode, answer)) s.resumeStack,\n tableEntries := s.tableEntries.insert key' { entry' with waiters := entry'.waiters.push waiter } }\n | some entry => modify fun s =>\n { s with\n resumeStack := entry.answers.foldl (fun s answer => s.push (cNode, answer)) s.resumeStack,\n tableEntries := s.tableEntries.insert key { entry with waiters := entry.waiters.push waiter } }", "start": [ 486, 1 ], "end": [ 534, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.getTop", "code": "def getTop : SynthM GeneratorNode :=\n return (← get).generatorStack.back", "start": [ 536, 1 ], "end": [ 537, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.modifyTop", "code": "@[inline] def modifyTop (f : GeneratorNode β†’ GeneratorNode) : SynthM Unit :=\n modify fun s => { s with generatorStack := s.generatorStack.modify (s.generatorStack.size - 1) f }", "start": [ 539, 1 ], "end": [ 540, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.generate", "code": "def generate : SynthM Unit := do\n let gNode ← getTop\n if gNode.currInstanceIdx == 0 then\n modify fun s => { s with generatorStack := s.generatorStack.pop }\n else\n let key := gNode.key\n let idx := gNode.currInstanceIdx - 1\n let inst := gNode.instances.get! idx\n let mctx := gNode.mctx\n let mvar := gNode.mvar\n \n if backward.synthInstance.canonInstances.get (← getOptions) then\n unless gNode.typeHasMVars do\n if let some entry := (← get).tableEntries.find? key then\n if entry.answers.any fun answer => answer.result.numMVars == 0 then\n \n modify fun s => { s with generatorStack := s.generatorStack.pop }\n return\n discard do withMCtx mctx do\n withTraceNode `Meta.synthInstance\n (return m!\"{exceptOptionEmoji Β·} apply {inst.val} to {← instantiateMVars (← inferType mvar)}\") do\n modifyTop fun gNode => { gNode with currInstanceIdx := idx }\n if let some (mctx, subgoals) ← tryResolve mvar inst then\n consume { key, mvar, subgoals, mctx, size := 0 }\n return some ()\n return none", "start": [ 542, 1 ], "end": [ 578, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.getNextToResume", "code": "def getNextToResume : SynthM (ConsumerNode Γ— Answer) := do\n let r := (← get).resumeStack.back\n modify fun s => { s with resumeStack := s.resumeStack.pop }\n return r", "start": [ 580, 1 ], "end": [ 583, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.resume", "code": "def resume : SynthM Unit := do\n let (cNode, answer) ← getNextToResume\n match cNode.subgoals with\n | [] => panic! \"resume found no remaining subgoals\"\n | mvar::rest =>\n match (← tryAnswer cNode.mctx mvar answer) with\n | none => return ()\n | some mctx =>\n withMCtx mctx do\n let goal ← inferType cNode.mvar\n let subgoal ← inferType mvar\n withTraceNode `Meta.synthInstance.resume\n (fun _ => withMCtx cNode.mctx do\n return m!\"propagating {← instantiateMVars answer.resultType} to subgoal {← instantiateMVars subgoal} of {← instantiateMVars goal}\") do\n trace[Meta.synthInstance.resume] \"size: {cNode.size + answer.size}\"\n consume { key := cNode.key, mvar := cNode.mvar, subgoals := rest, mctx, size := cNode.size + answer.size }", "start": [ 585, 1 ], "end": [ 603, 113 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.step", "code": "def step : SynthM Bool := do\n checkSystem\n let s ← get\n if !s.resumeStack.isEmpty then\n resume\n return true\n else if !s.generatorStack.isEmpty then\n generate\n return true\n else\n return false", "start": [ 605, 1 ], "end": [ 615, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.getResult", "code": "def getResult : SynthM (Option AbstractMVarsResult) :=\n return (← get).result?", "start": [ 617, 1 ], "end": [ 618, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.synth", "code": "partial def synth : SynthM (Option AbstractMVarsResult) := do\n if (← step) then\n match (← getResult) with\n | none => synth\n | some result => return result\n else\n return none", "start": [ 620, 1 ], "end": [ 626, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SynthInstance.main", "code": "def main (type : Expr) (maxResultSize : Nat) : MetaM (Option AbstractMVarsResult) :=\n withCurrHeartbeats do\n let mvar ← mkFreshExprMVar type\n let key ← mkTableKey type\n let action : SynthM (Option AbstractMVarsResult) := do\n newSubgoal (← getMCtx) key mvar Waiter.root\n synth\n tryCatchRuntimeEx\n (action.run { maxResultSize := maxResultSize, maxHeartbeats := getMaxHeartbeats (← getOptions) } |>.run' {})\n fun ex =>\n if ex.isRuntime then\n throwError \"failed to synthesize{indentExpr type}\\n{ex.toMessageData}\\n{useDiagnosticMsg}\"\n else\n throw ex", "start": [ 628, 1 ], "end": [ 641, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.preprocess", "code": "private def preprocess (type : Expr) : MetaM Expr :=\n forallTelescopeReducing type fun xs type => do\n let type ← whnf type\n mkForallFVars xs type", "start": [ 658, 1 ], "end": [ 661, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.preprocessArgs", "code": "private partial def preprocessArgs (type : Expr) (i : Nat) (args : Array Expr) (outParamsPos : Array Nat) : MetaM (Array Expr) := do\n if h : i < args.size then\n let type ← whnf type\n match type with\n | .forallE _ d b _ => do\n let arg := args.get ⟨i, h⟩\n \n let arg ← if outParamsPos.contains i then mkFreshExprMVar d else pure arg\n let args := args.set ⟨i, h⟩ arg\n preprocessArgs (b.instantiate1 arg) (i+1) args outParamsPos\n | _ =>\n throwError \"type class resolution failed, insufficient number of arguments\" else\n return args", "start": [ 663, 1 ], "end": [ 679, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.preprocessOutParam", "code": "private def preprocessOutParam (type : Expr) : MetaM Expr :=\n forallTelescope type fun xs typeBody => do\n match typeBody.getAppFn with\n | c@(.const declName _) =>\n let env ← getEnv\n if let some outParamsPos := getOutParamPositions? env declName then\n unless outParamsPos.isEmpty do\n let args := typeBody.getAppArgs\n let cType ← inferType c\n let args ← preprocessArgs cType 0 args outParamsPos\n return (← mkForallFVars xs (mkAppN c args))\n return type\n | _ =>\n return type", "start": [ 681, 1 ], "end": [ 694, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.assignOutParams", "code": "private def assignOutParams (type : Expr) (result : Expr) : MetaM Bool := do\n let resultType ← inferType result\n \n let defEq ← withDefault <| withAssignableSyntheticOpaque <| isDefEq type resultType\n unless defEq do\n trace[Meta.synthInstance] \"{crossEmoji} result type{indentExpr resultType}\\nis not definitionally equal to{indentExpr type}\"\n return defEq", "start": [ 701, 1 ], "end": [ 709, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.applyAbstractResult?", "code": "private def applyAbstractResult? (type : Expr) (abstResult? : Option AbstractMVarsResult) : MetaM (Option Expr) := do\n let some abstResult := abstResult? | return none\n let (_, _, result) ← openAbstractMVarsResult abstResult\n unless (← assignOutParams type result) do return none\n let result ← instantiateMVars result\n \n check result\n return some result", "start": [ 711, 1 ], "end": [ 745, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.applyCachedAbstractResult?", "code": "private def applyCachedAbstractResult? (type : Expr) (abstResult? : Option AbstractMVarsResult) : MetaM (Option Expr) := do\n let some abstResult := abstResult? | return none\n if abstResult.numMVars == 0 && abstResult.paramNames.isEmpty then\n \n unless (← assignOutParams type abstResult.expr) do\n return none\n return some abstResult.expr\n else\n applyAbstractResult? type abstResult?", "start": [ 747, 1 ], "end": [ 763, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.cacheResult", "code": "private def cacheResult (cacheKey : SynthInstanceCacheKey) (abstResult? : Option AbstractMVarsResult) (result? : Option Expr) : MetaM Unit := do\n match result? with\n | none => modify fun s => { s with cache.synthInstance := s.cache.synthInstance.insert cacheKey none }\n | some result =>\n let some abstResult := abstResult? | return ()\n if abstResult.numMVars == 0 && abstResult.paramNames.isEmpty then\n modify fun s => { s with cache.synthInstance := s.cache.synthInstance.insert cacheKey (some { expr := result, paramNames := #[], numMVars := 0 }) }\n else\n modify fun s => { s with cache.synthInstance := s.cache.synthInstance.insert cacheKey (some abstResult) }", "start": [ 765, 1 ], "end": [ 776, 112 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.synthInstance?", "code": "def synthInstance? (type : Expr) (maxResultSize? : Option Nat := none) : MetaM (Option Expr) := do profileitM Exception \"typeclass inference\" (← getOptions) (decl := type.getAppFn.constName?.getD .anonymous) do\n let opts ← getOptions\n let maxResultSize := maxResultSize?.getD (synthInstance.maxSize.get opts)\n withTraceNode `Meta.synthInstance\n (return m!\"{exceptOptionEmoji Β·} {← instantiateMVars type}\") do\n withConfig (fun config => { config with isDefEqStuckEx := true, transparency := TransparencyMode.instances,\n foApprox := true, ctxApprox := true, constApprox := false, univApprox := false }) do\n withReader (fun ctx => { ctx with inTypeClassResolution := true }) do\n let localInsts ← getLocalInstances\n let type ← instantiateMVars type\n let type ← preprocess type\n let cacheKey := { localInsts, type, synthPendingDepth := (← read).synthPendingDepth }\n match (← get).cache.synthInstance.find? cacheKey with\n | some abstResult? =>\n let result? ← applyCachedAbstractResult? type abstResult?\n trace[Meta.synthInstance] \"result {result?} (cached)\"\n return result?\n | none =>\n let abstResult? ← withNewMCtxDepth (allowLevelAssignments := true) do\n let normType ← preprocessOutParam type\n SynthInstance.main normType maxResultSize\n let result? ← applyAbstractResult? type abstResult?\n trace[Meta.synthInstance] \"result {result?}\"\n cacheResult cacheKey abstResult? result?\n return result?", "start": [ 778, 1 ], "end": [ 802, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.trySynthInstance", "code": "def trySynthInstance (type : Expr) (maxResultSize? : Option Nat := none) : MetaM (LOption Expr) := do\n catchInternalId isDefEqStuckExceptionId\n (toLOptionM <| synthInstance? type maxResultSize?)\n (fun _ => pure LOption.undef)", "start": [ 804, 1 ], "end": [ 810, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwFailedToSynthesize", "code": "def throwFailedToSynthesize (type : Expr) : MetaM Expr :=\n throwError \"failed to synthesize{indentExpr type}\\n{useDiagnosticMsg}\"", "start": [ 812, 1 ], "end": [ 813, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.synthInstance", "code": "def synthInstance (type : Expr) (maxResultSize? : Option Nat := none) : MetaM Expr :=\n catchInternalId isDefEqStuckExceptionId\n (do\n let result? ← synthInstance? type maxResultSize?\n match result? with\n | some result => pure result\n | none => throwFailedToSynthesize type)\n (fun _ => throwFailedToSynthesize type)", "start": [ 815, 1 ], "end": [ 822, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.synthPendingImp", "code": "@[export lean_synth_pending]\nprivate def synthPendingImp (mvarId : MVarId) : MetaM Bool := withIncRecDepth <| mvarId.withContext do\n let mvarDecl ← mvarId.getDecl\n match mvarDecl.kind with\n | .syntheticOpaque => return false\n | _ =>\n \n match (← isClass? mvarDecl.type) with\n | none =>\n return false\n | some _ =>\n let max := maxSynthPendingDepth.get (← getOptions)\n if (← read).synthPendingDepth > max then\n trace[Meta.synthPending] \"too many nested synthPending invocations\"\n recordSynthPendingFailure mvarDecl.type\n return false\n else\n withReader (fun ctx => { ctx with synthPendingDepth := ctx.synthPendingDepth + 1 }) do\n trace[Meta.synthPending] \"synthPending {mkMVar mvarId}\"\n let val? ← catchInternalId isDefEqStuckExceptionId (synthInstance? mvarDecl.type (maxResultSize? := none)) (fun _ => pure none)\n match val? with\n | none =>\n return false\n | some val =>\n if (← mvarId.isAssigned) then\n return false\n else\n mvarId.assign val\n return true", "start": [ 824, 1 ], "end": [ 853, 26 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Init/System/Promise.lean
[ ".lake/packages/lean4/src/lean/Init/System/IO.lean" ]
[ { "full_name": "IO.PromisePointed", "code": "private opaque PromisePointed : NonemptyType.{0}", "start": [ 13, 1 ], "end": [ 13, 49 ], "kind": "commanddeclaration" }, { "full_name": "IO.PromiseImpl", "code": "private structure PromiseImpl (Ξ± : Type) : Type where\n prom : PromisePointed.type\n h : Nonempty Ξ±", "start": [ 15, 1 ], "end": [ 17, 20 ], "kind": "commanddeclaration" }, { "full_name": "IO.Promise", "code": "def Promise (Ξ± : Type) : Type := PromiseImpl Ξ±", "start": [ 19, 1 ], "end": [ 33, 47 ], "kind": "commanddeclaration" }, { "full_name": "IO.Promise.new", "code": "@[extern \"lean_io_promise_new\"]\nopaque Promise.new [Nonempty Ξ±] : BaseIO (Promise Ξ±)", "start": [ 38, 1 ], "end": [ 40, 53 ], "kind": "commanddeclaration" }, { "full_name": "IO.Promise.resolve", "code": "@[extern \"lean_io_promise_resolve\"]\nopaque Promise.resolve (value : Ξ±) (promise : @& Promise Ξ±) : BaseIO Unit", "start": [ 42, 1 ], "end": [ 48, 74 ], "kind": "commanddeclaration" }, { "full_name": "IO.Promise.result", "code": "@[extern \"lean_io_promise_result\"]\nopaque Promise.result (promise : Promise Ξ±) : Task Ξ± :=\n have : Nonempty Ξ± := promise.h\n Classical.choice inferInstance", "start": [ 50, 1 ], "end": [ 58, 33 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Linter/Basic.lean
[ ".lake/packages/lean4/src/lean/Lean/Data/Options.lean" ]
[ { "full_name": "Lean.Linter.getLinterAll", "code": "def getLinterAll (o : Options) (defValue := linter.all.defValue) : Bool := o.get linter.all.name defValue", "start": [ 16, 1 ], "end": [ 16, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Linter.getLinterValue", "code": "def getLinterValue (opt : Lean.Option Bool) (o : Options) : Bool := o.get opt.name (getLinterAll o opt.defValue)", "start": [ 18, 1 ], "end": [ 18, 113 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Attributes.lean
[ ".lake/packages/lean4/src/lean/Lean/Elab/Util.lean" ]
[ { "full_name": "Lean.Elab.Attribute", "code": "structure Attribute where\n kind : AttributeKind := AttributeKind.global\n name : Name\n stx : Syntax := Syntax.missing\n deriving Inhabited", "start": [ 10, 1 ], "end": [ 14, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.toAttributeKind", "code": "def toAttributeKind (attrKindStx : Syntax) : MacroM AttributeKind := do\n if attrKindStx[0].isNone then\n return AttributeKind.global\n else if attrKindStx[0][0].getKind == ``Lean.Parser.Term.scoped then\n if (← Macro.getCurrNamespace).isAnonymous then\n throw <| Macro.Exception.error (← getRef) \"scoped attributes must be used inside namespaces\"\n return AttributeKind.scoped\n else\n return AttributeKind.local", "start": [ 24, 1 ], "end": [ 37, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.mkAttrKindGlobal", "code": "def mkAttrKindGlobal : Syntax :=\n mkNode ``Lean.Parser.Term.attrKind #[mkNullNode]", "start": [ 39, 1 ], "end": [ 40, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.elabAttr", "code": "def elabAttr [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadMacroAdapter m] [MonadRecDepth m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLiftT IO m] (attrInstance : Syntax) : m Attribute := do\n \n let attrKind ← liftMacroM <| toAttributeKind attrInstance[0]\n let attr := attrInstance[1]\n let attr ← liftMacroM <| expandMacros attr\n let attrName ← if attr.getKind == ``Parser.Attr.simple then\n pure attr[0].getId.eraseMacroScopes\n else match attr.getKind with\n | .str _ s => pure <| Name.mkSimple s\n | _ => throwErrorAt attr \"unknown attribute\"\n let .ok _impl := getAttributeImpl (← getEnv) attrName\n | throwError \"unknown attribute [{attrName}]\"\n \n return { kind := attrKind, name := attrName, stx := attr }", "start": [ 42, 1 ], "end": [ 56, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.elabAttrs", "code": "def elabAttrs [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadMacroAdapter m] [MonadRecDepth m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLog m] [MonadLiftT IO m] (attrInstances : Array Syntax) : m (Array Attribute) := do\n let mut attrs := #[]\n for attr in attrInstances do\n try\n attrs := attrs.push (← withRef attr do elabAttr attr)\n catch ex =>\n logException ex\n return attrs", "start": [ 58, 1 ], "end": [ 65, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.elabDeclAttrs", "code": "def elabDeclAttrs [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadMacroAdapter m] [MonadRecDepth m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] [MonadLog m] [MonadLiftT IO m] (stx : Syntax) : m (Array Attribute) :=\n elabAttrs stx[1].getSepArgs", "start": [ 68, 1 ], "end": [ 69, 30 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean
[ ".lake/packages/lean4/src/lean/Lean/Structure.lean", ".lake/packages/lean4/src/lean/Lean/Util/Recognizers.lean", ".lake/packages/lean4/src/lean/Lean/Meta/SynthInstance.lean", ".lake/packages/lean4/src/lean/Lean/Meta/DecLevel.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Check.lean" ]
[ { "full_name": "Lean.Meta.mkId", "code": "def mkId (e : Expr) : MetaM Expr := do\n let type ← inferType e\n let u ← getLevel type\n return mkApp2 (mkConst ``id [u]) type e", "start": [ 15, 1 ], "end": [ 19, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkExpectedTypeHint", "code": "def mkExpectedTypeHint (e : Expr) (expectedType : Expr) : MetaM Expr := do\n let u ← getLevel expectedType\n return mkApp2 (mkConst ``id [u]) expectedType e", "start": [ 21, 1 ], "end": [ 26, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLetFun", "code": "def mkLetFun (x : Expr) (v : Expr) (e : Expr) : MetaM Expr := do\n let f ← mkLambdaFVars #[x] e\n let ety ← inferType e\n let Ξ± ← inferType x\n let Ξ² ← mkLambdaFVars #[x] ety\n let u1 ← getLevel Ξ±\n let u2 ← getLevel ety\n return mkAppN (.const ``letFun [u1, u2]) #[Ξ±, Ξ², v, f]", "start": [ 28, 1 ], "end": [ 39, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEq", "code": "def mkEq (a b : Expr) : MetaM Expr := do\n let aType ← inferType a\n let u ← getLevel aType\n return mkApp3 (mkConst ``Eq [u]) aType a b", "start": [ 41, 1 ], "end": [ 45, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHEq", "code": "def mkHEq (a b : Expr) : MetaM Expr := do\n let aType ← inferType a\n let bType ← inferType b\n let u ← getLevel aType\n return mkApp4 (mkConst ``HEq [u]) aType a bType b", "start": [ 47, 1 ], "end": [ 52, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqHEq", "code": "def mkEqHEq (a b : Expr) : MetaM Expr := do\n let aType ← inferType a\n let bType ← inferType b\n let u ← getLevel aType\n if (← isDefEq aType bType) then\n return mkApp3 (mkConst ``Eq [u]) aType a b\n else\n return mkApp4 (mkConst ``HEq [u]) aType a bType b", "start": [ 54, 1 ], "end": [ 64, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqRefl", "code": "def mkEqRefl (a : Expr) : MetaM Expr := do\n let aType ← inferType a\n let u ← getLevel aType\n return mkApp2 (mkConst ``Eq.refl [u]) aType a", "start": [ 66, 1 ], "end": [ 70, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHEqRefl", "code": "def mkHEqRefl (a : Expr) : MetaM Expr := do\n let aType ← inferType a\n let u ← getLevel aType\n return mkApp2 (mkConst ``HEq.refl [u]) aType a", "start": [ 72, 1 ], "end": [ 76, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAbsurd", "code": "def mkAbsurd (e : Expr) (hp hnp : Expr) : MetaM Expr := do\n let p ← inferType hp\n let u ← getLevel e\n return mkApp4 (mkConst ``absurd [u]) p e hp hnp", "start": [ 78, 1 ], "end": [ 82, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkFalseElim", "code": "def mkFalseElim (e : Expr) (h : Expr) : MetaM Expr := do\n let u ← getLevel e\n return mkApp2 (mkConst ``False.elim [u]) e h", "start": [ 84, 1 ], "end": [ 87, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.infer", "code": "private def infer (h : Expr) : MetaM Expr := do\n let hType ← inferType h\n whnfD hType", "start": [ 89, 1 ], "end": [ 91, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.hasTypeMsg", "code": "private def hasTypeMsg (e type : Expr) : MessageData :=\n m!\"{indentExpr e}\\nhas type{indentExpr type}\"", "start": [ 93, 1 ], "end": [ 94, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwAppBuilderException", "code": "private def throwAppBuilderException {Ξ±} (op : Name) (msg : MessageData) : MetaM Ξ± :=\n throwError \"AppBuilder for '{op}', {msg}\"", "start": [ 96, 1 ], "end": [ 97, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqSymm", "code": "def mkEqSymm (h : Expr) : MetaM Expr := do\n if h.isAppOf ``Eq.refl then\n return h\n else\n let hType ← infer h\n match hType.eq? with\n | some (Ξ±, a, b) =>\n let u ← getLevel Ξ±\n return mkApp4 (mkConst ``Eq.symm [u]) Ξ± a b h\n | none => throwAppBuilderException ``Eq.symm (\"equality proof expected\" ++ hasTypeMsg h hType)", "start": [ 99, 1 ], "end": [ 109, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqTrans", "code": "def mkEqTrans (h₁ hβ‚‚ : Expr) : MetaM Expr := do\n if h₁.isAppOf ``Eq.refl then\n return hβ‚‚\n else if hβ‚‚.isAppOf ``Eq.refl then\n return h₁\n else\n let hType₁ ← infer h₁\n let hTypeβ‚‚ ← infer hβ‚‚\n match hType₁.eq?, hTypeβ‚‚.eq? with\n | some (Ξ±, a, b), some (_, _, c) =>\n let u ← getLevel Ξ±\n return mkApp6 (mkConst ``Eq.trans [u]) Ξ± a b c h₁ hβ‚‚\n | none, _ => throwAppBuilderException ``Eq.trans (\"equality proof expected\" ++ hasTypeMsg h₁ hType₁)\n | _, none => throwAppBuilderException ``Eq.trans (\"equality proof expected\" ++ hasTypeMsg hβ‚‚ hTypeβ‚‚)", "start": [ 111, 1 ], "end": [ 125, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqTrans?", "code": "def mkEqTrans? (h₁? hβ‚‚? : Option Expr) : MetaM (Option Expr) :=\n match h₁?, hβ‚‚? with\n | none, none => return none\n | none, some h => return h\n | some h, none => return h\n | some h₁, some hβ‚‚ => mkEqTrans h₁ hβ‚‚", "start": [ 127, 1 ], "end": [ 136, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHEqSymm", "code": "def mkHEqSymm (h : Expr) : MetaM Expr := do\n if h.isAppOf ``HEq.refl then\n return h\n else\n let hType ← infer h\n match hType.heq? with\n | some (Ξ±, a, Ξ², b) =>\n let u ← getLevel Ξ±\n return mkApp5 (mkConst ``HEq.symm [u]) Ξ± Ξ² a b h\n | none =>\n throwAppBuilderException ``HEq.symm (\"heterogeneous equality proof expected\" ++ hasTypeMsg h hType)", "start": [ 138, 1 ], "end": [ 149, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHEqTrans", "code": "def mkHEqTrans (h₁ hβ‚‚ : Expr) : MetaM Expr := do\n if h₁.isAppOf ``HEq.refl then\n return hβ‚‚\n else if hβ‚‚.isAppOf ``HEq.refl then\n return h₁\n else\n let hType₁ ← infer h₁\n let hTypeβ‚‚ ← infer hβ‚‚\n match hType₁.heq?, hTypeβ‚‚.heq? with\n | some (Ξ±, a, Ξ², b), some (_, _, Ξ³, c) =>\n let u ← getLevel Ξ±\n return mkApp8 (mkConst ``HEq.trans [u]) Ξ± Ξ² Ξ³ a b c h₁ hβ‚‚\n | none, _ => throwAppBuilderException ``HEq.trans (\"heterogeneous equality proof expected\" ++ hasTypeMsg h₁ hType₁)\n | _, none => throwAppBuilderException ``HEq.trans (\"heterogeneous equality proof expected\" ++ hasTypeMsg hβ‚‚ hTypeβ‚‚)", "start": [ 151, 1 ], "end": [ 165, 120 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqOfHEq", "code": "def mkEqOfHEq (h : Expr) : MetaM Expr := do\n let hType ← infer h\n match hType.heq? with\n | some (Ξ±, a, Ξ², b) =>\n unless (← isDefEq Ξ± Ξ²) do\n throwAppBuilderException ``eq_of_heq m!\"heterogeneous equality types are not definitionally equal{indentExpr Ξ±}\\nis not definitionally equal to{indentExpr Ξ²}\"\n let u ← getLevel Ξ±\n return mkApp4 (mkConst ``eq_of_heq [u]) Ξ± a b h\n | _ =>\n throwAppBuilderException ``eq_of_heq m!\"heterogeneous equality proof expected{indentExpr h}\"", "start": [ 167, 1 ], "end": [ 177, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isRefl?", "code": "def isRefl? (e : Expr) : Option Expr := do\n if e.isAppOfArity ``Eq.refl 2 then\n some e.appArg!\n else\n none", "start": [ 179, 1 ], "end": [ 186, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.congrArg?", "code": "def congrArg? (e : Expr) : MetaM (Option (Expr Γ— Expr Γ— Expr)) := do\n if e.isAppOfArity ``congrArg 6 then\n let #[Ξ±, _Ξ², _a, _b, f, h] := e.getAppArgs | unreachable!\n return some (Ξ±, f, h)\n if e.isAppOfArity ``congrFun 6 then\n let #[Ξ±, Ξ², _f, _g, h, a] := e.getAppArgs | unreachable!\n let Ξ±' ← withLocalDecl `x .default Ξ± fun x => do\n mkForallFVars #[x] (Ξ².beta #[x])\n let f' ← withLocalDecl `x .default Ξ±' fun f => do\n mkLambdaFVars #[f] (f.app a)\n return some (Ξ±', f', h)\n return none", "start": [ 188, 1 ], "end": [ 203, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkCongrArg", "code": "partial def mkCongrArg (f h : Expr) : MetaM Expr := do\n if let some a := isRefl? h then\n mkEqRefl (mkApp f a)\n else if let some (Ξ±, f₁, h₁) ← congrArg? h then\n let f' ← withLocalDecl `x .default Ξ± fun x => do\n mkLambdaFVars #[x] (f.beta #[f₁.beta #[x]])\n mkCongrArg f' h₁\n else\n let hType ← infer h\n let fType ← infer f\n match fType.arrow?, hType.eq? with\n | some (Ξ±, Ξ²), some (_, a, b) =>\n let u ← getLevel Ξ±\n let v ← getLevel Ξ²\n return mkApp6 (mkConst ``congrArg [u, v]) Ξ± Ξ² a b f h\n | none, _ => throwAppBuilderException ``congrArg (\"non-dependent function expected\" ++ hasTypeMsg f fType)\n | _, none => throwAppBuilderException ``congrArg (\"equality proof expected\" ++ hasTypeMsg h hType)", "start": [ 205, 1 ], "end": [ 223, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkCongrFun", "code": "def mkCongrFun (h a : Expr) : MetaM Expr := do\n if let some f := isRefl? h then\n mkEqRefl (mkApp f a)\n else if let some (Ξ±, f₁, h₁) ← congrArg? h then\n let f' ← withLocalDecl `x .default Ξ± fun x => do\n mkLambdaFVars #[x] (f₁.beta #[x, a])\n mkCongrArg f' h₁\n else\n let hType ← infer h\n match hType.eq? with\n | some (ρ, f, g) => do\n let ρ ← whnfD ρ\n match ρ with\n | Expr.forallE n Ξ± Ξ² _ =>\n let Ξ²' := Lean.mkLambda n BinderInfo.default Ξ± Ξ²\n let u ← getLevel Ξ±\n let v ← getLevel (mkApp Ξ²' a)\n return mkApp6 (mkConst ``congrFun [u, v]) Ξ± Ξ²' f g h a\n | _ => throwAppBuilderException ``congrFun (\"equality proof between functions expected\" ++ hasTypeMsg h hType)\n | _ => throwAppBuilderException ``congrFun (\"equality proof expected\" ++ hasTypeMsg h hType)", "start": [ 225, 1 ], "end": [ 246, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkCongr", "code": "def mkCongr (h₁ hβ‚‚ : Expr) : MetaM Expr := do\n if h₁.isAppOf ``Eq.refl then\n mkCongrArg h₁.appArg! hβ‚‚\n else if hβ‚‚.isAppOf ``Eq.refl then\n mkCongrFun h₁ hβ‚‚.appArg!\n else\n let hType₁ ← infer h₁\n let hTypeβ‚‚ ← infer hβ‚‚\n match hType₁.eq?, hTypeβ‚‚.eq? with\n | some (ρ, f, g), some (Ξ±, a, b) =>\n let ρ ← whnfD ρ\n match ρ.arrow? with\n | some (_, Ξ²) => do\n let u ← getLevel Ξ±\n let v ← getLevel Ξ²\n return mkApp8 (mkConst ``congr [u, v]) Ξ± Ξ² f g a b h₁ hβ‚‚\n | _ => throwAppBuilderException ``congr (\"non-dependent function expected\" ++ hasTypeMsg h₁ hType₁)\n | none, _ => throwAppBuilderException ``congr (\"equality proof expected\" ++ hasTypeMsg h₁ hType₁)\n | _, none => throwAppBuilderException ``congr (\"equality proof expected\" ++ hasTypeMsg hβ‚‚ hTypeβ‚‚)", "start": [ 248, 1 ], "end": [ 267, 102 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppMFinal", "code": "private def mkAppMFinal (methodName : Name) (f : Expr) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do\n instMVars.forM fun mvarId => do\n let mvarDecl ← mvarId.getDecl\n let mvarVal ← synthInstance mvarDecl.type\n mvarId.assign mvarVal\n let result ← instantiateMVars (mkAppN f args)\n if (← hasAssignableMVar result) then throwAppBuilderException methodName (\"result contains metavariables\" ++ indentExpr result)\n return result", "start": [ 269, 1 ], "end": [ 276, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppMArgs", "code": "private partial def mkAppMArgs (f : Expr) (fType : Expr) (xs : Array Expr) : MetaM Expr :=\n let rec loop (type : Expr) (i : Nat) (j : Nat) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do\n if i >= xs.size then\n mkAppMFinal `mkAppM f args instMVars\n else match type with\n | Expr.forallE n d b bi =>\n let d := d.instantiateRevRange j args.size args\n match bi with\n | BinderInfo.implicit =>\n let mvar ← mkFreshExprMVar d MetavarKind.natural n\n loop b i j (args.push mvar) instMVars\n | BinderInfo.strictImplicit =>\n let mvar ← mkFreshExprMVar d MetavarKind.natural n\n loop b i j (args.push mvar) instMVars\n | BinderInfo.instImplicit =>\n let mvar ← mkFreshExprMVar d MetavarKind.synthetic n\n loop b i j (args.push mvar) (instMVars.push mvar.mvarId!)\n | _ =>\n let x := xs[i]!\n let xType ← inferType x\n if (← isDefEq d xType) then\n loop b (i+1) j (args.push x) instMVars\n else\n throwAppTypeMismatch (mkAppN f args) x\n | type =>\n let type := type.instantiateRevRange j args.size args\n let type ← whnfD type\n if type.isForall then\n loop type i args.size args instMVars\n else\n throwAppBuilderException `mkAppM m!\"too many explicit arguments provided to{indentExpr f}\\narguments{indentD xs}\"\n loop fType 0 0 #[] #[]", "start": [ 278, 1 ], "end": [ 309, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkFun", "code": "private def mkFun (constName : Name) : MetaM (Expr Γ— Expr) := do\n let cinfo ← getConstInfo constName\n let us ← cinfo.levelParams.mapM fun _ => mkFreshLevelMVar\n let f := mkConst constName us\n let fType ← instantiateTypeLevelParams cinfo us\n return (f, fType)", "start": [ 311, 1 ], "end": [ 316, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.withAppBuilderTrace", "code": "private def withAppBuilderTrace [ToMessageData Ξ±] [ToMessageData Ξ²]\n (f : Ξ±) (xs : Ξ²) (k : MetaM Expr) : MetaM Expr :=\n let emoji | .ok .. => checkEmoji | .error .. => crossEmoji\n withTraceNode `Meta.appBuilder (return m!\"{emoji Β·} f: {f}, xs: {xs}\") do\n try\n let res ← k\n trace[Meta.appBuilder.result] res\n pure res\n catch ex =>\n trace[Meta.appBuilder.error] ex.toMessageData\n throw ex", "start": [ 318, 1 ], "end": [ 328, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppM", "code": "def mkAppM (constName : Name) (xs : Array Expr) : MetaM Expr := do\n withAppBuilderTrace constName xs do withNewMCtxDepth do\n let (f, fType) ← mkFun constName\n mkAppMArgs f fType xs", "start": [ 330, 1 ], "end": [ 342, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppM'", "code": "def mkAppM' (f : Expr) (xs : Array Expr) : MetaM Expr := do\n let fType ← inferType f\n withAppBuilderTrace f xs do withNewMCtxDepth do\n mkAppMArgs f fType xs", "start": [ 344, 1 ], "end": [ 348, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppOptMAux", "code": "private partial def mkAppOptMAux (f : Expr) (xs : Array (Option Expr)) : Nat β†’ Array Expr β†’ Nat β†’ Array MVarId β†’ Expr β†’ MetaM Expr\n | i, args, j, instMVars, Expr.forallE n d b bi => do\n let d := d.instantiateRevRange j args.size args\n if h : i < xs.size then\n match xs.get ⟨i, h⟩ with\n | none =>\n match bi with\n | BinderInfo.instImplicit => do\n let mvar ← mkFreshExprMVar d MetavarKind.synthetic n\n mkAppOptMAux f xs (i+1) (args.push mvar) j (instMVars.push mvar.mvarId!) b\n | _ => do\n let mvar ← mkFreshExprMVar d MetavarKind.natural n\n mkAppOptMAux f xs (i+1) (args.push mvar) j instMVars b\n | some x =>\n let xType ← inferType x\n if (← isDefEq d xType) then\n mkAppOptMAux f xs (i+1) (args.push x) j instMVars b\n else\n throwAppTypeMismatch (mkAppN f args) x\n else\n mkAppMFinal `mkAppOptM f args instMVars\n | i, args, j, instMVars, type => do\n let type := type.instantiateRevRange j args.size args\n let type ← whnfD type\n if type.isForall then\n mkAppOptMAux f xs i args args.size instMVars type\n else if i == xs.size then\n mkAppMFinal `mkAppOptM f args instMVars\n else do\n let xs : Array Expr := xs.foldl (fun r x? => match x? with | none => r | some x => r.push x) #[]\n throwAppBuilderException `mkAppOptM (\"too many arguments provided to\" ++ indentExpr f ++ Format.line ++ \"arguments\" ++ xs)", "start": [ 350, 1 ], "end": [ 380, 129 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppOptM", "code": "def mkAppOptM (constName : Name) (xs : Array (Option Expr)) : MetaM Expr := do\n withAppBuilderTrace constName xs do withNewMCtxDepth do\n let (f, fType) ← mkFun constName\n mkAppOptMAux f xs 0 #[] 0 #[] fType", "start": [ 382, 1 ], "end": [ 399, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAppOptM'", "code": "def mkAppOptM' (f : Expr) (xs : Array (Option Expr)) : MetaM Expr := do\n let fType ← inferType f\n withAppBuilderTrace f xs do withNewMCtxDepth do\n mkAppOptMAux f xs 0 #[] 0 #[] fType", "start": [ 401, 1 ], "end": [ 405, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqNDRec", "code": "def mkEqNDRec (motive h1 h2 : Expr) : MetaM Expr := do\n if h2.isAppOf ``Eq.refl then\n return h1\n else\n let h2Type ← infer h2\n match h2Type.eq? with\n | none => throwAppBuilderException ``Eq.ndrec (\"equality proof expected\" ++ hasTypeMsg h2 h2Type)\n | some (Ξ±, a, b) =>\n let u2 ← getLevel Ξ±\n let motiveType ← infer motive\n match motiveType with\n | Expr.forallE _ _ (Expr.sort u1) _ =>\n return mkAppN (mkConst ``Eq.ndrec [u1, u2]) #[Ξ±, a, motive, h1, b, h2]\n | _ => throwAppBuilderException ``Eq.ndrec (\"invalid motive\" ++ indentExpr motive)", "start": [ 407, 1 ], "end": [ 420, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqRec", "code": "def mkEqRec (motive h1 h2 : Expr) : MetaM Expr := do\n if h2.isAppOf ``Eq.refl then\n return h1\n else\n let h2Type ← infer h2\n match h2Type.eq? with\n | none => throwAppBuilderException ``Eq.rec (\"equality proof expected\" ++ indentExpr h2)\n | some (Ξ±, a, b) =>\n let u2 ← getLevel Ξ±\n let motiveType ← infer motive\n match motiveType with\n | Expr.forallE _ _ (Expr.forallE _ _ (Expr.sort u1) _) _ =>\n return mkAppN (mkConst ``Eq.rec [u1, u2]) #[Ξ±, a, motive, h1, b, h2]\n | _ =>\n throwAppBuilderException ``Eq.rec (\"invalid motive\" ++ indentExpr motive)", "start": [ 422, 1 ], "end": [ 436, 82 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqMP", "code": "def mkEqMP (eqProof pr : Expr) : MetaM Expr :=\n mkAppM ``Eq.mp #[eqProof, pr]", "start": [ 438, 1 ], "end": [ 439, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqMPR", "code": "def mkEqMPR (eqProof pr : Expr) : MetaM Expr :=\n mkAppM ``Eq.mpr #[eqProof, pr]", "start": [ 441, 1 ], "end": [ 442, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkNoConfusion", "code": "def mkNoConfusion (target : Expr) (h : Expr) : MetaM Expr := do\n let type ← inferType h\n let type ← whnf type\n match type.eq? with\n | none => throwAppBuilderException `noConfusion (\"equality expected\" ++ hasTypeMsg h type)\n | some (Ξ±, a, b) =>\n let Ξ± ← whnfD Ξ±\n matchConstInduct Ξ±.getAppFn (fun _ => throwAppBuilderException `noConfusion (\"inductive type expected\" ++ indentExpr Ξ±)) fun v us => do\n let u ← getLevel target\n return mkAppN (mkConst (Name.mkStr v.name \"noConfusion\") (u :: us)) (Ξ±.getAppArgs ++ #[target, a, b, h])", "start": [ 444, 1 ], "end": [ 453, 111 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkPure", "code": "def mkPure (monad : Expr) (e : Expr) : MetaM Expr :=\n mkAppOptM ``Pure.pure #[monad, none, none, e]", "start": [ 455, 1 ], "end": [ 457, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkProjection", "code": "partial def mkProjection (s : Expr) (fieldName : Name) : MetaM Expr := do\n let type ← inferType s\n let type ← whnf type\n match type.getAppFn with\n | Expr.const structName us =>\n let env ← getEnv\n unless isStructure env structName do\n throwAppBuilderException `mkProjection (\"structure expected\" ++ hasTypeMsg s type)\n match getProjFnForField? env structName fieldName with\n | some projFn =>\n let params := type.getAppArgs\n return mkApp (mkAppN (mkConst projFn us) params) s\n | none =>\n let fields := getStructureFields env structName\n let r? ← fields.findSomeM? fun fieldName' => do\n match isSubobjectField? env structName fieldName' with\n | none => pure none\n | some _ =>\n let parent ← mkProjection s fieldName'\n (do let r ← mkProjection parent fieldName; return some r)\n <|>\n pure none\n match r? with\n | some r => pure r\n | none => throwAppBuilderException `mkProjection (\"invalid field name '\" ++ toString fieldName ++ \"' for\" ++ hasTypeMsg s type)\n | _ => throwAppBuilderException `mkProjection (\"structure expected\" ++ hasTypeMsg s type)", "start": [ 459, 1 ], "end": [ 487, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkListLitAux", "code": "private def mkListLitAux (nil : Expr) (cons : Expr) : List Expr β†’ Expr\n | [] => nil\n | x::xs => mkApp (mkApp cons x) (mkListLitAux nil cons xs)", "start": [ 489, 1 ], "end": [ 491, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkListLit", "code": "def mkListLit (type : Expr) (xs : List Expr) : MetaM Expr := do\n let u ← getDecLevel type\n let nil := mkApp (mkConst ``List.nil [u]) type\n match xs with\n | [] => return nil\n | _ =>\n let cons := mkApp (mkConst ``List.cons [u]) type\n return mkListLitAux nil cons xs", "start": [ 493, 1 ], "end": [ 500, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkArrayLit", "code": "def mkArrayLit (type : Expr) (xs : List Expr) : MetaM Expr := do\n let u ← getDecLevel type\n let listLit ← mkListLit type xs\n return mkApp (mkApp (mkConst ``List.toArray [u]) type) listLit", "start": [ 502, 1 ], "end": [ 505, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSorry", "code": "def mkSorry (type : Expr) (synthetic : Bool) : MetaM Expr := do\n let u ← getLevel type\n return mkApp2 (mkConst ``sorryAx [u]) type (toExpr synthetic)", "start": [ 507, 1 ], "end": [ 509, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkDecide", "code": "def mkDecide (p : Expr) : MetaM Expr :=\n mkAppOptM ``Decidable.decide #[p, none]", "start": [ 511, 1 ], "end": [ 513, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkDecideProof", "code": "def mkDecideProof (p : Expr) : MetaM Expr := do\n let decP ← mkDecide p\n let decEqTrue ← mkEq decP (mkConst ``Bool.true)\n let h ← mkEqRefl (mkConst ``Bool.true)\n let h ← mkExpectedTypeHint h decEqTrue\n mkAppM ``of_decide_eq_true #[h]", "start": [ 515, 1 ], "end": [ 521, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLt", "code": "def mkLt (a b : Expr) : MetaM Expr :=\n mkAppM ``LT.lt #[a, b]", "start": [ 523, 1 ], "end": [ 525, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLe", "code": "def mkLe (a b : Expr) : MetaM Expr :=\n mkAppM ``LE.le #[a, b]", "start": [ 527, 1 ], "end": [ 529, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkDefault", "code": "def mkDefault (Ξ± : Expr) : MetaM Expr :=\n mkAppOptM ``Inhabited.default #[Ξ±, none]", "start": [ 531, 1 ], "end": [ 533, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkOfNonempty", "code": "def mkOfNonempty (Ξ± : Expr) : MetaM Expr := do\n mkAppOptM ``Classical.ofNonempty #[Ξ±, none]", "start": [ 535, 1 ], "end": [ 537, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSyntheticSorry", "code": "def mkSyntheticSorry (type : Expr) : MetaM Expr :=\n return mkApp2 (mkConst ``sorryAx [← getLevel type]) type (mkConst ``Bool.true)", "start": [ 539, 1 ], "end": [ 541, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkFunExt", "code": "def mkFunExt (h : Expr) : MetaM Expr :=\n mkAppM ``funext #[h]", "start": [ 543, 1 ], "end": [ 545, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkPropExt", "code": "def mkPropExt (h : Expr) : MetaM Expr :=\n mkAppM ``propext #[h]", "start": [ 547, 1 ], "end": [ 549, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLetCongr", "code": "def mkLetCongr (h₁ hβ‚‚ : Expr) : MetaM Expr :=\n mkAppM ``let_congr #[h₁, hβ‚‚]", "start": [ 551, 1 ], "end": [ 553, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLetValCongr", "code": "def mkLetValCongr (b h : Expr) : MetaM Expr :=\n mkAppM ``let_val_congr #[b, h]", "start": [ 555, 1 ], "end": [ 557, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLetBodyCongr", "code": "def mkLetBodyCongr (a h : Expr) : MetaM Expr :=\n mkAppM ``let_body_congr #[a, h]", "start": [ 559, 1 ], "end": [ 561, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkOfEqTrue", "code": "def mkOfEqTrue (h : Expr) : MetaM Expr :=\n mkAppM ``of_eq_true #[h]", "start": [ 563, 1 ], "end": [ 565, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqTrue", "code": "def mkEqTrue (h : Expr) : MetaM Expr :=\n mkAppM ``eq_true #[h]", "start": [ 567, 1 ], "end": [ 569, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqFalse", "code": "def mkEqFalse (h : Expr) : MetaM Expr :=\n mkAppM ``eq_false #[h]", "start": [ 571, 1 ], "end": [ 576, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkEqFalse'", "code": "def mkEqFalse' (h : Expr) : MetaM Expr :=\n mkAppM ``eq_false' #[h]", "start": [ 578, 1 ], "end": [ 583, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkImpCongr", "code": "def mkImpCongr (h₁ hβ‚‚ : Expr) : MetaM Expr :=\n mkAppM ``implies_congr #[h₁, hβ‚‚]", "start": [ 585, 1 ], "end": [ 586, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkImpCongrCtx", "code": "def mkImpCongrCtx (h₁ hβ‚‚ : Expr) : MetaM Expr :=\n mkAppM ``implies_congr_ctx #[h₁, hβ‚‚]", "start": [ 588, 1 ], "end": [ 589, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkImpDepCongrCtx", "code": "def mkImpDepCongrCtx (h₁ hβ‚‚ : Expr) : MetaM Expr :=\n mkAppM ``implies_dep_congr_ctx #[h₁, hβ‚‚]", "start": [ 591, 1 ], "end": [ 592, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkForallCongr", "code": "def mkForallCongr (h : Expr) : MetaM Expr :=\n mkAppM ``forall_congr #[h]", "start": [ 594, 1 ], "end": [ 595, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMonad?", "code": "def isMonad? (m : Expr) : MetaM (Option Expr) :=\n try\n let monadType ← mkAppM `Monad #[m]\n let result ← trySynthInstance monadType\n match result with\n | LOption.some inst => pure inst\n | _ => pure none\n catch _ =>\n pure none", "start": [ 597, 1 ], "end": [ 606, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkNumeral", "code": "def mkNumeral (type : Expr) (n : Nat) : MetaM Expr := do\n let u ← getDecLevel type\n let inst ← synthInstance (mkApp2 (mkConst ``OfNat [u]) type (mkRawNatLit n))\n return mkApp3 (mkConst ``OfNat.ofNat [u]) type (mkRawNatLit n) inst", "start": [ 608, 1 ], "end": [ 612, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkBinaryOp", "code": "private def mkBinaryOp (className : Name) (opName : Name) (a b : Expr) : MetaM Expr := do\n let aType ← inferType a\n let u ← getDecLevel aType\n let inst ← synthInstance (mkApp3 (mkConst className [u, u, u]) aType aType aType)\n return mkApp6 (mkConst opName [u, u, u]) aType aType aType inst a b", "start": [ 614, 1 ], "end": [ 624, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAdd", "code": "def mkAdd (a b : Expr) : MetaM Expr := mkBinaryOp ``HAdd ``HAdd.hAdd a b", "start": [ 626, 1 ], "end": [ 627, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSub", "code": "def mkSub (a b : Expr) : MetaM Expr := mkBinaryOp ``HSub ``HSub.hSub a b", "start": [ 629, 1 ], "end": [ 630, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkMul", "code": "def mkMul (a b : Expr) : MetaM Expr := mkBinaryOp ``HMul ``HMul.hMul a b", "start": [ 632, 1 ], "end": [ 633, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkBinaryRel", "code": "private def mkBinaryRel (className : Name) (rName : Name) (a b : Expr) : MetaM Expr := do\n let aType ← inferType a\n let u ← getDecLevel aType\n let inst ← synthInstance (mkApp (mkConst className [u]) aType)\n return mkApp4 (mkConst rName [u]) aType inst a b", "start": [ 635, 1 ], "end": [ 645, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLE", "code": "def mkLE (a b : Expr) : MetaM Expr := mkBinaryRel ``LE ``LE.le a b", "start": [ 647, 1 ], "end": [ 648, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkLT", "code": "def mkLT (a b : Expr) : MetaM Expr := mkBinaryRel ``LT ``LT.lt a b", "start": [ 650, 1 ], "end": [ 651, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkIffOfEq", "code": "def mkIffOfEq (h : Expr) : MetaM Expr := do\n if h.isAppOfArity ``propext 3 then\n return h.appArg!\n else\n mkAppM ``Iff.of_eq #[h]", "start": [ 653, 1 ], "end": [ 658, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAndIntroN", "code": "def mkAndIntroN : Array Expr β†’ MetaM Expr\n| #[] => return mkConst ``True.intro []\n| #[e] => return e\n| es => es.foldrM (start := es.size - 1) (fun a b => mkAppM ``And.intro #[a,b]) es.back", "start": [ 660, 1 ], "end": [ 668, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkProjAndN", "code": "def mkProjAndN (n i : Nat) (e : Expr) : Expr := Id.run do\n let mut value := e\n for _ in [:i] do\n value := mkProj ``And 1 value\n if i + 1 < n then\n value := mkProj ``And 0 value\n return value", "start": [ 671, 1 ], "end": [ 678, 15 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/AutoBound.lean
[ ".lake/packages/lean4/src/lean/Lean/Data/Options.lean" ]
[ { "full_name": "Lean.Elab.isValidAutoBoundSuffix", "code": "private def isValidAutoBoundSuffix (s : String) : Bool :=\n s.toSubstring.drop 1 |>.all fun c => c.isDigit || isSubScriptAlnum c || c == '_' || c == '\\''", "start": [ 24, 1 ], "end": [ 25, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.isValidAutoBoundImplicitName", "code": "def isValidAutoBoundImplicitName (n : Name) (relaxed : Bool) : Bool :=\n match n with\n | .str .anonymous s => s.length > 0 && (relaxed || isValidAutoBoundSuffix s)\n | _ => false", "start": [ 41, 1 ], "end": [ 44, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.isValidAutoBoundLevelName", "code": "def isValidAutoBoundLevelName (n : Name) (relaxed : Bool) : Bool :=\n match n with\n | .str .anonymous s => s.length > 0 && (relaxed || (s.front.isLower && isValidAutoBoundSuffix s))\n | _ => false", "start": [ 46, 1 ], "end": [ 49, 15 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Attributes.lean
[ ".lake/packages/lean4/src/lean/Lean/Attributes.lean" ]
[ { "full_name": "Lean.hasPPUsingAnonymousConstructorAttribute", "code": "def hasPPUsingAnonymousConstructorAttribute (env : Environment) (declName : Name) : Bool :=\n ppUsingAnonymousConstructorAttr.hasTag env declName", "start": [ 23, 1 ], "end": [ 27, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.hasPPNoDotAttribute", "code": "def hasPPNoDotAttribute (env : Environment) (declName : Name) : Bool :=\n ppNoDotAttr.hasTag env declName", "start": [ 29, 1 ], "end": [ 33, 34 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Options.lean
[ ".lake/packages/lean4/src/lean/Lean/Data/Options.lean" ]
[ { "full_name": "Lean.getPPMaxSteps", "code": "def getPPMaxSteps (o : Options) : Nat := o.get pp.maxSteps.name pp.maxSteps.defValue", "start": [ 223, 1 ], "end": [ 223, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAll", "code": "def getPPAll (o : Options) : Bool := o.get pp.all.name false", "start": [ 224, 1 ], "end": [ 224, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPFunBinderTypes", "code": "def getPPFunBinderTypes (o : Options) : Bool := o.get pp.funBinderTypes.name (getPPAll o)", "start": [ 225, 1 ], "end": [ 225, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPPiBinderTypes", "code": "def getPPPiBinderTypes (o : Options) : Bool := o.get pp.piBinderTypes.name pp.piBinderTypes.defValue", "start": [ 226, 1 ], "end": [ 226, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPLetVarTypes", "code": "def getPPLetVarTypes (o : Options) : Bool := o.get pp.letVarTypes.name (getPPAll o)", "start": [ 227, 1 ], "end": [ 227, 84 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPNumericTypes", "code": "def getPPNumericTypes (o : Options) : Bool := o.get pp.numericTypes.name pp.numericTypes.defValue", "start": [ 228, 1 ], "end": [ 228, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPNatLit", "code": "def getPPNatLit (o : Options) : Bool := o.get pp.natLit.name (getPPNumericTypes o && !getPPAll o)", "start": [ 229, 1 ], "end": [ 229, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPCoercions", "code": "def getPPCoercions (o : Options) : Bool := o.get pp.coercions.name (!getPPAll o)", "start": [ 230, 1 ], "end": [ 230, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPExplicit", "code": "def getPPExplicit (o : Options) : Bool := o.get pp.explicit.name (getPPAll o)", "start": [ 231, 1 ], "end": [ 231, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPNotation", "code": "def getPPNotation (o : Options) : Bool := o.get pp.notation.name (!getPPAll o)", "start": [ 232, 1 ], "end": [ 232, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPUnicodeFun", "code": "def getPPUnicodeFun (o : Options) : Bool := o.get pp.unicode.fun.name false", "start": [ 233, 1 ], "end": [ 233, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPMatch", "code": "def getPPMatch (o : Options) : Bool := o.get pp.match.name (!getPPAll o)", "start": [ 234, 1 ], "end": [ 234, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPFieldNotation", "code": "def getPPFieldNotation (o : Options) : Bool := o.get pp.fieldNotation.name (!getPPAll o)", "start": [ 235, 1 ], "end": [ 235, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPFieldNotationGeneralized", "code": "def getPPFieldNotationGeneralized (o : Options) : Bool := o.get pp.fieldNotation.generalized.name pp.fieldNotation.generalized.defValue", "start": [ 236, 1 ], "end": [ 236, 136 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPStructureInstances", "code": "def getPPStructureInstances (o : Options) : Bool := o.get pp.structureInstances.name (!getPPAll o)", "start": [ 237, 1 ], "end": [ 237, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPStructureInstancesFlatten", "code": "def getPPStructureInstancesFlatten (o : Options) : Bool := o.get pp.structureInstances.flatten.name pp.structureInstances.flatten.defValue", "start": [ 238, 1 ], "end": [ 238, 139 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPStructureInstanceType", "code": "def getPPStructureInstanceType (o : Options) : Bool := o.get pp.structureInstanceTypes.name (getPPAll o)", "start": [ 239, 1 ], "end": [ 239, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPTagAppFns", "code": "def getPPTagAppFns (o : Options) : Bool := o.get pp.tagAppFns.name (getPPAll o)", "start": [ 240, 1 ], "end": [ 240, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPUniverses", "code": "def getPPUniverses (o : Options) : Bool := o.get pp.universes.name (getPPAll o)", "start": [ 241, 1 ], "end": [ 241, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPFullNames", "code": "def getPPFullNames (o : Options) : Bool := o.get pp.fullNames.name (getPPAll o)", "start": [ 242, 1 ], "end": [ 242, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPPrivateNames", "code": "def getPPPrivateNames (o : Options) : Bool := o.get pp.privateNames.name (getPPAll o)", "start": [ 243, 1 ], "end": [ 243, 86 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPInstantiateMVars", "code": "def getPPInstantiateMVars (o : Options) : Bool := o.get pp.instantiateMVars.name pp.instantiateMVars.defValue", "start": [ 244, 1 ], "end": [ 244, 110 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPMVars", "code": "def getPPMVars (o : Options) : Bool := o.get pp.mvars.name pp.mvars.defValue", "start": [ 245, 1 ], "end": [ 245, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPMVarsWithType", "code": "def getPPMVarsWithType (o : Options) : Bool := o.get pp.mvars.withType.name pp.mvars.withType.defValue", "start": [ 246, 1 ], "end": [ 246, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPBeta", "code": "def getPPBeta (o : Options) : Bool := o.get pp.beta.name pp.beta.defValue", "start": [ 247, 1 ], "end": [ 247, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPSafeShadowing", "code": "def getPPSafeShadowing (o : Options) : Bool := o.get pp.safeShadowing.name pp.safeShadowing.defValue", "start": [ 248, 1 ], "end": [ 248, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPProofs", "code": "def getPPProofs (o : Options) : Bool := o.get pp.proofs.name (pp.proofs.defValue || getPPAll o)", "start": [ 249, 1 ], "end": [ 249, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPProofsWithType", "code": "def getPPProofsWithType (o : Options) : Bool := o.get pp.proofs.withType.name pp.proofs.withType.defValue", "start": [ 250, 1 ], "end": [ 250, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPProofsThreshold", "code": "def getPPProofsThreshold (o : Options) : Nat := o.get pp.proofs.threshold.name pp.proofs.threshold.defValue", "start": [ 251, 1 ], "end": [ 251, 108 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPMotivesPi", "code": "def getPPMotivesPi (o : Options) : Bool := o.get pp.motives.pi.name pp.motives.pi.defValue", "start": [ 252, 1 ], "end": [ 252, 91 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPMotivesNonConst", "code": "def getPPMotivesNonConst (o : Options) : Bool := o.get pp.motives.nonConst.name pp.motives.nonConst.defValue", "start": [ 253, 1 ], "end": [ 253, 109 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPMotivesAll", "code": "def getPPMotivesAll (o : Options) : Bool := o.get pp.motives.all.name pp.motives.all.defValue", "start": [ 254, 1 ], "end": [ 254, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPInstances", "code": "def getPPInstances (o : Options) : Bool := o.get pp.instances.name pp.instances.defValue", "start": [ 255, 1 ], "end": [ 255, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPInstanceTypes", "code": "def getPPInstanceTypes (o : Options) : Bool := o.get pp.instanceTypes.name pp.instanceTypes.defValue", "start": [ 256, 1 ], "end": [ 256, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPDeepTerms", "code": "def getPPDeepTerms (o : Options) : Bool := o.get pp.deepTerms.name (pp.deepTerms.defValue || getPPAll o)", "start": [ 257, 1 ], "end": [ 257, 105 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPDeepTermsThreshold", "code": "def getPPDeepTermsThreshold (o : Options) : Nat := o.get pp.deepTerms.threshold.name pp.deepTerms.threshold.defValue", "start": [ 258, 1 ], "end": [ 258, 117 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/SubExpr.lean
[ ".lake/packages/lean4/src/lean/Lean/Data/Json.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Data/RBMap.lean" ]
[ { "full_name": "Lean.SubExpr.Pos", "code": "def SubExpr.Pos := Nat", "start": [ 13, 1 ], "end": [ 22, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.maxChildren", "code": "def maxChildren := 4", "start": [ 26, 1 ], "end": [ 26, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.typeCoord", "code": "def typeCoord : Nat := maxChildren - 1", "start": [ 28, 1 ], "end": [ 30, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.asNat", "code": "def asNat : Pos β†’ Nat := id", "start": [ 32, 1 ], "end": [ 32, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.root", "code": "def root : Pos := (1 : Nat)", "start": [ 34, 1 ], "end": [ 35, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.isRoot", "code": "def isRoot (p : Pos) : Bool := p.asNat < maxChildren", "start": [ 39, 1 ], "end": [ 39, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.head", "code": "def head (p : Pos) : Nat :=\n if p.isRoot then panic! \"already at top\"\n else p.asNat % maxChildren", "start": [ 41, 1 ], "end": [ 44, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.tail", "code": "def tail (p : Pos) : Pos :=\n if p.isRoot then panic! \"already at top\"\n else (p.asNat - p.head) / maxChildren", "start": [ 46, 1 ], "end": [ 48, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.push", "code": "def push (p : Pos) (c : Nat) : Pos :=\n if c >= maxChildren then panic! s!\"invalid coordinate {c}\"\n else p.asNat * maxChildren + c", "start": [ 50, 1 ], "end": [ 52, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.foldl", "code": "partial def foldl (f : Ξ± β†’ Nat β†’ Ξ±) (init : Ξ±) (p : Pos) : Ξ± :=\n if p.isRoot then init else f (foldl f init p.tail) p.head", "start": [ 56, 1 ], "end": [ 58, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.foldr", "code": "partial def foldr (f : Nat β†’ Ξ± β†’ Ξ±) (p : Pos) (init : Ξ±) : Ξ± :=\n if p.isRoot then init else foldr f p.tail (f p.head init)", "start": [ 60, 1 ], "end": [ 62, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.foldlM", "code": "partial def foldlM [Monad M] (f : Ξ± β†’ Nat β†’ M Ξ±) (init : Ξ±) (p : Pos) : M Ξ± :=\n have : Inhabited (M Ξ±) := inferInstance\n if p.isRoot then pure init else do foldlM f init p.tail >>= (f Β· p.head)", "start": [ 64, 1 ], "end": [ 67, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.foldrM", "code": "partial def foldrM [Monad M] (f : Nat β†’ Ξ± β†’ M Ξ±) (p : Pos) (init : Ξ±) : M Ξ± :=\n if p.isRoot then pure init else f p.head init >>= foldrM f p.tail", "start": [ 69, 1 ], "end": [ 71, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.depth", "code": "def depth (p : Pos) :=\n p.foldr (init := 0) fun _ => Nat.succ", "start": [ 73, 1 ], "end": [ 74, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.all", "code": "def all (pred : Nat β†’ Bool) (p : Pos) : Bool :=\n OptionT.run (m := Id) (foldrM (fun n a => if pred n then pure a else failure) p ()) |>.isSome", "start": [ 76, 1 ], "end": [ 78, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.append", "code": "def append : Pos β†’ Pos β†’ Pos := foldl push", "start": [ 80, 1 ], "end": [ 80, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.ofArray", "code": "def ofArray (ps : Array Nat) : Pos :=\n ps.foldl push root", "start": [ 82, 1 ], "end": [ 86, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.toArray", "code": "def toArray (p : Pos) : Array Nat :=\n foldl Array.push #[] p", "start": [ 88, 1 ], "end": [ 91, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushBindingDomain", "code": "def pushBindingDomain (p : Pos) := p.push 0", "start": [ 93, 1 ], "end": [ 93, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushBindingBody", "code": "def pushBindingBody (p : Pos) := p.push 1", "start": [ 94, 1 ], "end": [ 94, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushLetVarType", "code": "def pushLetVarType (p : Pos) := p.push 0", "start": [ 95, 1 ], "end": [ 95, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushLetValue", "code": "def pushLetValue (p : Pos) := p.push 1", "start": [ 96, 1 ], "end": [ 96, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushLetBody", "code": "def pushLetBody (p : Pos) := p.push 2", "start": [ 97, 1 ], "end": [ 97, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushAppFn", "code": "def pushAppFn (p : Pos) := p.push 0", "start": [ 98, 1 ], "end": [ 98, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushAppArg", "code": "def pushAppArg (p : Pos) := p.push 1", "start": [ 99, 1 ], "end": [ 99, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushProj", "code": "def pushProj (p : Pos) := p.push 0", "start": [ 100, 1 ], "end": [ 100, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushType", "code": "def pushType (p : Pos) := p.push Pos.typeCoord", "start": [ 101, 1 ], "end": [ 101, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushNaryFn", "code": "def pushNaryFn (numArgs : Nat) (p : Pos) : Pos :=\n p.asNat * (maxChildren ^ numArgs)", "start": [ 103, 1 ], "end": [ 104, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushNaryArg", "code": "def pushNaryArg (numArgs argIdx : Nat) (p : Pos) : Pos :=\n show Nat from p.asNat * (maxChildren ^ (numArgs - argIdx)) + 1", "start": [ 106, 1 ], "end": [ 107, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushNthBindingDomain", "code": "def pushNthBindingDomain : (binderIdx : Nat) β†’ Pos β†’ Pos\n | 0, p => p.pushBindingDomain\n | (n+1), p => pushNthBindingDomain n p.pushBindingBody", "start": [ 109, 1 ], "end": [ 111, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.pushNthBindingBody", "code": "def pushNthBindingBody : (numBinders : Nat) β†’ Pos β†’ Pos\n | 0, p => p\n | (n+1), p => pushNthBindingBody n p.pushBindingBody", "start": [ 113, 1 ], "end": [ 115, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.toString", "code": "protected def toString (p : Pos) : String :=\n p.toArray.toList\n |>.map toString\n |> String.intercalate \"/\"\n |> (\"/\" ++ Β·)", "start": [ 117, 1 ], "end": [ 121, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.ofStringCoord", "code": "private def ofStringCoord : String β†’ Except String Nat\n | \"0\" => ok 0 | \"1\" => ok 1 | \"2\" => ok 2 | \"3\" => ok 3\n | c => error s!\"Invalid coordinate {c}\"", "start": [ 124, 1 ], "end": [ 126, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.fromString?", "code": "protected def fromString? : String β†’ Except String Pos\n | \"/\" => Except.ok Pos.root\n | s =>\n match String.splitOn s \"/\" with\n | \"\" :: tail => Pos.ofArray <$> tail.toArray.mapM ofStringCoord\n | ss => error s!\"malformed {ss}\"", "start": [ 129, 1 ], "end": [ 134, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.Pos.fromString!", "code": "protected def fromString! (s : String) : Pos :=\n match Pos.fromString? s with\n | .ok a => a\n | .error e => panic! e", "start": [ 136, 1 ], "end": [ 139, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr", "code": "structure SubExpr where\n \n expr : Expr\n \n pos : SubExpr.Pos\n deriving Inhabited", "start": [ 156, 1 ], "end": [ 163, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.mkRoot", "code": "def mkRoot (e : Expr) : SubExpr := ⟨e, Pos.root⟩", "start": [ 167, 1 ], "end": [ 167, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.isRoot", "code": "def isRoot (s : SubExpr) : Bool := s.pos.isRoot", "start": [ 169, 1 ], "end": [ 170, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.PosMap", "code": "abbrev PosMap (Ξ± : Type u) := RBMap Pos Ξ± compare", "start": [ 172, 1 ], "end": [ 173, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.bindingBody!", "code": "def bindingBody! : SubExpr β†’ SubExpr\n | ⟨.forallE _ _ b _, p⟩ => ⟨b, p.pushBindingBody⟩\n | ⟨.lam _ _ b _, p⟩ => ⟨b, p.pushBindingBody⟩\n | _ => panic! \"subexpr is not a binder\"", "start": [ 175, 1 ], "end": [ 178, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.bindingDomain!", "code": "def bindingDomain! : SubExpr β†’ SubExpr\n | ⟨.forallE _ t _ _, p⟩ => ⟨t, p.pushBindingDomain⟩\n | ⟨.lam _ t _ _, p⟩ => ⟨t, p.pushBindingDomain⟩\n | _ => panic! \"subexpr is not a binder\"", "start": [ 180, 1 ], "end": [ 183, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.GoalLocation", "code": "inductive GoalLocation where\n \n | hyp : FVarId β†’ GoalLocation\n \n | hypType : FVarId β†’ SubExpr.Pos β†’ GoalLocation\n \n | hypValue : FVarId β†’ SubExpr.Pos β†’ GoalLocation\n \n | target : SubExpr.Pos β†’ GoalLocation\n deriving FromJson, ToJson", "start": [ 190, 1 ], "end": [ 200, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.SubExpr.GoalsLocation", "code": "structure GoalsLocation where\n \n mvarId : MVarId\n loc : GoalLocation\n deriving FromJson, ToJson", "start": [ 202, 1 ], "end": [ 208, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.traverseAppWithPos", "code": "def Expr.traverseAppWithPos {M} [Monad M] (visit : Pos β†’ Expr β†’ M Expr) (p : Pos) (e : Expr) : M Expr :=\n match e with\n | .app f a =>\n e.updateApp!\n <$> traverseAppWithPos visit p.pushAppFn f\n <*> visit p.pushAppArg a\n | e => visit p e", "start": [ 213, 1 ], "end": [ 221, 19 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Tactic/Doc.lean
[ ".lake/packages/lean4/src/lean/Lean/Elab/InfoTree/Main.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Attr.lean", ".lake/packages/lean4/src/lean/Lean/DocString/Extension.lean", ".lake/packages/lean4/src/lean/Lean/Attributes.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Extension.lean" ]
[ { "full_name": "Lean.Parser.Tactic.Doc.isTactic", "code": "def isTactic (env : Environment) (kind : Name) : Bool := Id.run do\n let some tactics := (Lean.Parser.parserExtension.getState env).categories.find? `tactic\n | return false\n for (tac, _) in tactics.kinds do\n if kind == tac then return true\n return false", "start": [ 20, 1 ], "end": [ 26, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.alternativeOfTactic", "code": "def alternativeOfTactic (env : Environment) (tac : Name) : Option Name :=\n match env.getModuleIdxFor? tac with\n | some modIdx =>\n match (tacticAlternativeExt.getModuleEntries env modIdx).binSearch (tac, .anonymous) (Name.quickLt Β·.1 Β·.1) with\n | some (_, val) => some val\n | none => none\n | none => tacticAlternativeExt.getState env |>.find? tac", "start": [ 42, 1 ], "end": [ 52, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.aliases", "code": "def aliases [Monad m] [MonadEnv m] (tac : Name) : m NameSet := do\n let env ← getEnv\n let mut found := {}\n for (src, tgt) in tacticAlternativeExt.getState env do\n if tgt == tac then found := found.insert src\n for arr in tacticAlternativeExt.toEnvExtension.getState env |>.importedEntries do\n for (src, tgt) in arr do\n if tgt == tac then found := found.insert src\n pure found", "start": [ 54, 1 ], "end": [ 65, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.tagInfo", "code": "def tagInfo [Monad m] [MonadEnv m] (tag : Name) : m (Option (String Γ— Option String)) := do\n let env ← getEnv\n match env.getModuleIdxFor? tag with\n | some modIdx =>\n match (knownTacticTagExt.getModuleEntries env modIdx).binSearch (tag, default) (Name.quickLt Β·.1 Β·.1) with\n | some (_, val) => pure (some val)\n | none => pure none\n | none => pure (knownTacticTagExt.getState env |>.find? tag)", "start": [ 120, 1 ], "end": [ 130, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.allTags", "code": "def allTags [Monad m] [MonadEnv m] : m (List Name) := do\n let env ← getEnv\n let mut found : NameSet := {}\n for (tag, _) in knownTacticTagExt.getState env do\n found := found.insert tag\n for arr in knownTacticTagExt.toEnvExtension.getState env |>.importedEntries do\n for (tag, _) in arr do\n found := found.insert tag\n pure (found.toArray.qsort (Β·.toString < Β·.toString) |>.toList)", "start": [ 132, 1 ], "end": [ 141, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.allTagsWithInfo", "code": "def allTagsWithInfo [Monad m] [MonadEnv m] : m (List (Name Γ— String Γ— Option String)) := do\n let env ← getEnv\n let mut found : NameMap (String Γ— Option String) := {}\n for (tag, info) in knownTacticTagExt.getState env do\n found := found.insert tag info\n for arr in knownTacticTagExt.toEnvExtension.getState env |>.importedEntries do\n for (tag, info) in arr do\n found := found.insert tag info\n let arr := found.fold (init := #[]) (fun arr k v => arr.push (k, v))\n pure (arr.qsort (Β·.1.toString < Β·.1.toString) |>.toList)", "start": [ 143, 1 ], "end": [ 153, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.getTacticExtensions", "code": "def getTacticExtensions (env : Environment) (tactic : Name) : Array String := Id.run do\n let mut extensions := #[]\n for modArr in tacticDocExtExt.toEnvExtension.getState env |>.importedEntries do\n if let some (_, strs) := modArr.binSearch (tactic, #[]) (Name.quickLt Β·.1 Β·.1) then\n extensions := extensions ++ strs\n if let some strs := tacticDocExtExt.getState env |>.find? tactic then\n extensions := extensions ++ strs\n pure extensions", "start": [ 242, 1 ], "end": [ 251, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.getTacticExtensionString", "code": "def getTacticExtensionString (env : Environment) (tactic : Name) : String := Id.run do\n let exts := getTacticExtensions env tactic\n if exts.size == 0 then \"\"\n else \"\\n\\nExtensions:\\n\\n\" ++ String.join (exts.toList.map bullet) |>.trimRight\nwhere\n indentLine (str: String) : String :=\n (if str.all (Β·.isWhitespace) then str else \" \" ++ str) ++ \"\\n\"\n bullet (str : String) : String :=\n let lines := str.splitOn \"\\n\"\n match lines with\n | [] => \"\"\n | [l] => \" * \" ++ l ++ \"\\n\\n\"\n | l::ls => \" * \" ++ l ++ \"\\n\" ++ String.join (ls.map indentLine) ++ \"\\n\\n\"", "start": [ 253, 1 ], "end": [ 266, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.Doc.tacticDocsOnTactics", "code": "def tacticDocsOnTactics : ParserAttributeHook where\n postAdd (catName declName : Name) (_builtIn : Bool) := do\n if catName == `tactic then\n return\n if alternativeOfTactic (← getEnv) declName |>.isSome then\n throwError m!\"'{declName}' is not a tactic\"\n if let some tags := tacticTagExt.getState (← getEnv) |>.find? declName then\n if !tags.isEmpty then\n throwError m!\"'{declName}' is not a tactic\"", "start": [ 273, 1 ], "end": [ 287, 52 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Language/Basic.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Types.lean", ".lake/packages/lean4/src/lean/Lean/Message.lean", ".lake/packages/lean4/src/lean/Init/System/Promise.lean" ]
[ { "full_name": "Lean.Language.Snapshot.Diagnostics", "code": "structure Snapshot.Diagnostics where\n private mk ::\n \n msgLog : MessageLog\n \n interactiveDiagsRef? : Option (IO.Ref (Option Dynamic))\nderiving Inhabited", "start": [ 20, 1 ], "end": [ 37, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.Snapshot.Diagnostics.empty", "code": "def Snapshot.Diagnostics.empty : Snapshot.Diagnostics where\n msgLog := .empty\n interactiveDiagsRef? := none", "start": [ 39, 1 ], "end": [ 43, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.Snapshot", "code": "structure Snapshot where\n \n diagnostics : Snapshot.Diagnostics\n \n infoTree? : Option Elab.InfoTree := none\n \n isFatal := false\nderiving Inhabited", "start": [ 45, 1 ], "end": [ 60, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask", "code": "structure SnapshotTask (Ξ± : Type) where\n \n range? : Option String.Range\n \n task : Task Ξ±\nderiving Nonempty", "start": [ 62, 1 ], "end": [ 74, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.ofIO", "code": "def SnapshotTask.ofIO (range? : Option String.Range) (act : BaseIO Ξ±) : BaseIO (SnapshotTask Ξ±) := do\n return {\n range?\n task := (← BaseIO.asTask act)\n }", "start": [ 76, 1 ], "end": [ 81, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.pure", "code": "def SnapshotTask.pure (a : Ξ±) : SnapshotTask Ξ± where\n range? := none\n task := .pure a", "start": [ 83, 1 ], "end": [ 87, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.cancel", "code": "def SnapshotTask.cancel (t : SnapshotTask Ξ±) : BaseIO Unit :=\n IO.cancel t.task", "start": [ 89, 1 ], "end": [ 93, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.map", "code": "def SnapshotTask.map (t : SnapshotTask Ξ±) (f : Ξ± β†’ Ξ²) (range? : Option String.Range := t.range?)\n (sync := false) : SnapshotTask Ξ² :=\n { range?, task := t.task.map (sync := sync) f }", "start": [ 95, 1 ], "end": [ 98, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.bind", "code": "def SnapshotTask.bind (t : SnapshotTask Ξ±) (act : Ξ± β†’ SnapshotTask Ξ²)\n (range? : Option String.Range := t.range?) (sync := false) : SnapshotTask Ξ² :=\n { range?, task := t.task.bind (sync := sync) (act Β· |>.task) }", "start": [ 100, 1 ], "end": [ 105, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.bindIO", "code": "def SnapshotTask.bindIO (t : SnapshotTask Ξ±) (act : Ξ± β†’ BaseIO (SnapshotTask Ξ²))\n (range? : Option String.Range := t.range?) (sync := false) : BaseIO (SnapshotTask Ξ²) :=\n return {\n range?\n task := (← BaseIO.bindTask (sync := sync) t.task fun a => (Β·.task) <$> (act a))\n }", "start": [ 107, 1 ], "end": [ 115, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.get", "code": "def SnapshotTask.get (t : SnapshotTask Ξ±) : Ξ± :=\n t.task.get", "start": [ 117, 1 ], "end": [ 119, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTask.get?", "code": "def SnapshotTask.get? (t : SnapshotTask Ξ±) : BaseIO (Option Ξ±) :=\n return if (← IO.hasFinished t.task) then some t.task.get else none", "start": [ 121, 1 ], "end": [ 123, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SyntaxGuarded", "code": "structure SyntaxGuarded (Ξ± : Type) where\n \n stx : Syntax\n \n val : Ξ±", "start": [ 125, 1 ], "end": [ 132, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotBundle", "code": "structure SnapshotBundle (Ξ± : Type) where\n \n old? : Option (SyntaxGuarded (SnapshotTask Ξ±))\n \n new : IO.Promise Ξ±", "start": [ 134, 1 ], "end": [ 156, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.withAlwaysResolvedPromise", "code": "def withAlwaysResolvedPromise [Monad m] [MonadLiftT BaseIO m] [MonadFinally m] [Inhabited Ξ±]\n (act : IO.Promise Ξ± β†’ m Ξ²) : m Ξ² := do\n let p ← IO.Promise.new\n try\n act p\n finally\n p.resolve default", "start": [ 158, 1 ], "end": [ 170, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.withAlwaysResolvedPromises", "code": "def withAlwaysResolvedPromises [Monad m] [MonadLiftT BaseIO m] [MonadFinally m] [Inhabited Ξ±]\n (count : Nat) (act : Array (IO.Promise Ξ±) β†’ m Unit) : m Unit := do\n let ps ← List.iota count |>.toArray.mapM fun _ => IO.Promise.new\n try\n act ps\n finally\n for p in ps do\n p.resolve default", "start": [ 172, 1 ], "end": [ 186, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree", "code": "inductive SnapshotTree where\n \n | mk (element : Snapshot) (children : Array (SnapshotTask SnapshotTree))\nderiving Inhabited", "start": [ 188, 1 ], "end": [ 196, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree.element", "code": "abbrev SnapshotTree.element : SnapshotTree β†’ Snapshot\n | mk s _ => s", "start": [ 198, 1 ], "end": [ 200, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree.children", "code": "abbrev SnapshotTree.children : SnapshotTree β†’ Array (SnapshotTask SnapshotTree)\n | mk _ children => children", "start": [ 201, 1 ], "end": [ 203, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree.format", "code": "partial def SnapshotTree.format : SnapshotTree β†’ Format := go none\nwhere go range? s :=\n let range := match range? with\n | some range => f!\"{range.start}..{range.stop} \"\n | none => \"\"\n let element := f!\"{s.element.diagnostics.msgLog.unreported.size} diagnostics\"\n let children := Std.Format.prefixJoin .line <|\n s.children.toList.map fun c => go c.range? c.get\n .nestD f!\"β€’ {range}{element}{children}\"", "start": [ 205, 1 ], "end": [ 214, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.ToSnapshotTree", "code": "class ToSnapshotTree (Ξ± : Type) where\n \n toSnapshotTree : Ξ± β†’ SnapshotTree", "start": [ 216, 1 ], "end": [ 221, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotLeaf", "code": "structure SnapshotLeaf extends Snapshot\nderiving Nonempty, TypeName", "start": [ 229, 1 ], "end": [ 231, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.DynamicSnapshot", "code": "structure DynamicSnapshot where\n \n val : Dynamic\n \n tree : SnapshotTree", "start": [ 236, 1 ], "end": [ 241, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.DynamicSnapshot.ofTyped", "code": "def DynamicSnapshot.ofTyped [TypeName Ξ±] [ToSnapshotTree Ξ±] (val : Ξ±) : DynamicSnapshot where\n val := .mk val\n tree := ToSnapshotTree.toSnapshotTree val", "start": [ 246, 1 ], "end": [ 249, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.DynamicSnapshot.toTyped?", "code": "def DynamicSnapshot.toTyped? (Ξ± : Type) [TypeName Ξ±] (snap : DynamicSnapshot) :\n Option Ξ± :=\n snap.val.get? Ξ±", "start": [ 251, 1 ], "end": [ 254, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree.forM", "code": "@[specialize] partial def SnapshotTree.forM [Monad m] (s : SnapshotTree)\n (f : Snapshot β†’ m PUnit) : m PUnit := do\n match s with\n | mk element children =>\n f element\n children.forM (Β·.get.forM f)", "start": [ 259, 1 ], "end": [ 267, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.reportMessages", "code": "def reportMessages (msgLog : MessageLog) (opts : Options) (json := false) : IO Unit := do\n if json then\n msgLog.forM (Β·.toJson <&> (Β·.compress) >>= IO.println)\n else\n msgLog.forM (Β·.toString (includeEndPos := printMessageEndPos.get opts) >>= IO.print)", "start": [ 276, 1 ], "end": [ 281, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree.runAndReport", "code": "def SnapshotTree.runAndReport (s : SnapshotTree) (opts : Options) (json := false) : IO Unit := do\n s.forM (reportMessages Β·.diagnostics.msgLog opts json)", "start": [ 283, 1 ], "end": [ 289, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.SnapshotTree.getAll", "code": "def SnapshotTree.getAll (s : SnapshotTree) : Array Snapshot :=\n s.forM (m := StateM _) (fun s => modify (Β·.push s)) |>.run #[] |>.2", "start": [ 291, 1 ], "end": [ 293, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.ProcessingContext", "code": "structure ProcessingContext extends Parser.InputContext", "start": [ 295, 1 ], "end": [ 296, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.ProcessingT", "code": "abbrev ProcessingT m := ReaderT ProcessingContext m", "start": [ 298, 1 ], "end": [ 299, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.ProcessingM", "code": "abbrev ProcessingM := ProcessingT BaseIO", "start": [ 300, 1 ], "end": [ 301, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.Snapshot.Diagnostics.ofMessageLog", "code": "def Snapshot.Diagnostics.ofMessageLog (msgLog : Lean.MessageLog) :\n BaseIO Snapshot.Diagnostics := do\n return { msgLog, interactiveDiagsRef? := some (← IO.mkRef none) }", "start": [ 306, 1 ], "end": [ 312, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.diagnosticsOfHeaderError", "code": "def diagnosticsOfHeaderError (msg : String) : ProcessingM Snapshot.Diagnostics := do\n let msgLog := MessageLog.empty.add {\n fileName := \"<input>\"\n pos := ⟨1, 0⟩\n endPos := (← read).fileMap.toPosition (← read).fileMap.source.endPos\n data := msg\n }\n Snapshot.Diagnostics.ofMessageLog msgLog", "start": [ 314, 1 ], "end": [ 322, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Language.withHeaderExceptions", "code": "def withHeaderExceptions (ex : Snapshot β†’ Ξ±) (act : ProcessingT IO Ξ±) : ProcessingM Ξ± := do\n match (← (act (← read)).toBaseIO) with\n | .error e => return ex { diagnostics := (← diagnosticsOfHeaderError e.toString) }\n | .ok a => return a", "start": [ 324, 1 ], "end": [ 330, 22 ], "kind": "commanddeclaration" }, { "full_name": "Language.mkIncrementalProcessor", "code": "def Language.mkIncrementalProcessor (process : Option InitSnap β†’ ProcessingM InitSnap) :\n BaseIO (Parser.InputContext β†’ BaseIO InitSnap) := do\n let oldRef ← IO.mkRef none\n return fun ictx => do\n let snap ← process (← oldRef.get) { ictx with }\n oldRef.set (some snap)\n return snap", "start": [ 334, 1 ], "end": [ 343, 16 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Linter/Deprecated.lean
[ ".lake/packages/lean4/src/lean/Lean/Attributes.lean", ".lake/packages/lean4/src/lean/Lean/Linter/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Elab/InfoTree/Main.lean" ]
[ { "full_name": "Lean.Linter.DeprecationEntry", "code": "structure DeprecationEntry where\n newName? : Option Name := none\n text? : Option String := none\n since? : Option String := none\n deriving Inhabited", "start": [ 18, 1 ], "end": [ 22, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Linter.isDeprecated", "code": "def isDeprecated (env : Environment) (declName : Name) : Bool :=\n Option.isSome <| deprecatedAttr.getParam? env declName", "start": [ 37, 1 ], "end": [ 38, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MessageData.isDeprecationWarning", "code": "def _root_.Lean.MessageData.isDeprecationWarning (msg : MessageData) : Bool :=\n msg.hasTag (Β· == ``deprecatedAttr)", "start": [ 40, 1 ], "end": [ 41, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Linter.getDeprecatedNewName", "code": "def getDeprecatedNewName (env : Environment) (declName : Name) : Option Name := do\n (← deprecatedAttr.getParam? env declName).newName?", "start": [ 43, 1 ], "end": [ 44, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Linter.checkDeprecated", "code": "def checkDeprecated [Monad m] [MonadEnv m] [MonadLog m] [AddMessageContext m] [MonadOptions m] (declName : Name) : m Unit := do\n if getLinterValue linter.deprecated (← getOptions) then\n let some attr := deprecatedAttr.getParam? (← getEnv) declName | pure ()\n logWarning <| .tagged ``deprecatedAttr <| attr.text?.getD <|\n match attr.newName? with\n | none => s!\"`{declName}` has been deprecated\"\n | some newName => s!\"`{declName}` has been deprecated, use `{newName}` instead\"", "start": [ 46, 1 ], "end": [ 52, 86 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/PreDefinition/WF/TerminationHint.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Term.lean" ]
[ { "full_name": "Lean.Elab.WF.TerminationBy", "code": "structure TerminationBy where\n ref : Syntax\n vars : TSyntaxArray [`ident, ``Lean.Parser.Term.hole]\n body : Term\n \n synthetic : Bool := false\n deriving Inhabited", "start": [ 15, 1 ], "end": [ 27, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.DecreasingBy", "code": "structure DecreasingBy where\n ref : Syntax\n tactic : TSyntax ``Lean.Parser.Tactic.tacticSeq\n deriving Inhabited", "start": [ 29, 1 ], "end": [ 33, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.TerminationHints", "code": "structure TerminationHints where\n ref : Syntax\n terminationBy?? : Option Syntax\n terminationBy? : Option TerminationBy\n decreasingBy? : Option DecreasingBy\n \n extraParams : Nat\n deriving Inhabited", "start": [ 35, 1 ], "end": [ 53, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.TerminationHints.none", "code": "def TerminationHints.none : TerminationHints := ⟨.missing, .none, .none, .none, 0⟩", "start": [ 55, 1 ], "end": [ 55, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.TerminationHints.ensureNone", "code": "def TerminationHints.ensureNone (hints : TerminationHints) (reason : String): CoreM Unit := do\n match hints.terminationBy??, hints.terminationBy?, hints.decreasingBy? with\n | .none, .none, .none => pure ()\n | .none, .none, .some dec_by =>\n logErrorAt dec_by.ref m!\"unused `decreasing_by`, function is {reason}\"\n | .some term_by?, .none, .none =>\n logErrorAt term_by? m!\"unused `termination_by?`, function is {reason}\"\n | .none, .some term_by, .none =>\n logErrorAt term_by.ref m!\"unused `termination_by`, function is {reason}\"\n | _, _, _ =>\n logErrorAt hints.ref m!\"unused termination hints, function is {reason}\"", "start": [ 57, 1 ], "end": [ 68, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.TerminationHints.isNotNone", "code": "def TerminationHints.isNotNone (hints : TerminationHints) : Bool :=\n hints.terminationBy??.isSome ||\n hints.terminationBy?.isSome ||\n hints.decreasingBy?.isSome", "start": [ 70, 1 ], "end": [ 74, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.TerminationHints.rememberExtraParams", "code": "def TerminationHints.rememberExtraParams (headerParams : Nat) (hints : TerminationHints)\n (value : Expr) : TerminationHints :=\n { hints with extraParams := value.getNumHeadLambdas - headerParams }", "start": [ 76, 1 ], "end": [ 82, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.TerminationBy.checkVars", "code": "def TerminationBy.checkVars (funName : Name) (extraParams : Nat) (tb : TerminationBy) : MetaM Unit := do\n unless tb.synthetic do\n if tb.vars.size > extraParams then\n let mut msg := m!\"{parameters tb.vars.size} bound in `termination_by`, but the body of \" ++\n m!\"{funName} only binds {parameters extraParams}.\"\n if let `($ident:ident) := tb.vars[0]! then\n if ident.getId.isSuffixOf funName then\n msg := msg ++ m!\" (Since Lean v4.6.0, the `termination_by` clause no longer \" ++\n \"expects the function name here.)\"\n throwErrorAt tb.ref msg\n where\n parameters : Nat β†’ MessageData\n | 1 => \"one parameter\"\n | n => m!\"{n} parameters\"", "start": [ 84, 1 ], "end": [ 101, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.WF.elabTerminationHints", "code": "def elabTerminationHints {m} [Monad m] [MonadError m] (stx : TSyntax ``suffix) : m TerminationHints := do\n if let .missing := stx.raw then\n return { TerminationHints.none with ref := stx }\n match stx with\n | `(suffix| $[$t?]? $[$d?:decreasingBy]? ) => do\n let terminationBy?? : Option Syntax ← if let some t := t? then match t with\n | `(terminationBy?|termination_by?) => pure (some t)\n | _ => pure none\n else pure none\n let terminationBy? : Option TerminationBy ← if let some t := t? then match t with\n | `(terminationBy|termination_by => $_body) =>\n throwErrorAt t \"no extra parameters bounds, please omit the `=>`\"\n | `(terminationBy|termination_by $vars* => $body) => pure (some {ref := t, vars, body})\n | `(terminationBy|termination_by $body:term) => pure (some {ref := t, vars := #[], body})\n | `(terminationBy?|termination_by?) => pure none\n | _ => throwErrorAt t \"unexpected `termination_by` syntax\"\n else pure none\n let decreasingBy? ← d?.mapM fun d => match d with\n | `(decreasingBy|decreasing_by $tactic) => pure {ref := d, tactic}\n | _ => throwErrorAt d \"unexpected `decreasing_by` syntax\"\n return { ref := stx, terminationBy??, terminationBy?, decreasingBy?, extraParams := 0 }\n | _ => throwErrorAt stx s!\"Unexpected Termination.suffix syntax: {stx} of kind {stx.raw.getKind}\"", "start": [ 105, 1 ], "end": [ 128, 100 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/DeclModifiers.lean
[ ".lake/packages/lean4/src/lean/Lean/Elab/Attributes.lean", ".lake/packages/lean4/src/lean/Lean/Structure.lean" ]
[ { "full_name": "Lean.Elab.checkNotAlreadyDeclared", "code": "def checkNotAlreadyDeclared {m} [Monad m] [MonadEnv m] [MonadError m] [MonadInfoTree m] (declName : Name) : m Unit := do\n let env ← getEnv\n let addInfo declName := do\n pushInfoLeaf <| .ofTermInfo {\n elaborator := .anonymous, lctx := {}, expectedType? := none\n stx := (← getRef)\n expr := (← mkConstWithLevelParams declName)\n }\n if env.contains declName then\n addInfo declName\n match privateToUserName? declName with\n | none => throwError \"'{declName}' has already been declared\"\n | some declName => throwError \"private declaration '{declName}' has already been declared\"\n if isReservedName env declName then\n throwError \"'{declName}' is a reserved name\"\n if env.contains (mkPrivateName env declName) then\n addInfo (mkPrivateName env declName)\n throwError \"a private declaration '{declName}' has already been declared\"\n match privateToUserName? declName with\n | none => pure ()\n | some declName =>\n if env.contains declName then\n addInfo declName\n throwError \"a non-private declaration '{declName}' has already been declared\"", "start": [ 12, 1 ], "end": [ 40, 84 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Visibility", "code": "inductive Visibility where\n | regular | Β«protectedΒ» | Β«privateΒ»\n deriving Inhabited", "start": [ 42, 1 ], "end": [ 45, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.RecKind", "code": "inductive RecKind where\n | Β«partialΒ» | Β«nonrecΒ» | default\n deriving Inhabited", "start": [ 53, 1 ], "end": [ 56, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers", "code": "structure Modifiers where\n docString? : Option String := none\n visibility : Visibility := Visibility.regular\n isNoncomputable : Bool := false\n recKind : RecKind := RecKind.default\n isUnsafe : Bool := false\n attrs : Array Attribute := #[]\n deriving Inhabited", "start": [ 58, 1 ], "end": [ 66, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers.isPrivate", "code": "def Modifiers.isPrivate : Modifiers β†’ Bool\n | { visibility := .private, .. } => true\n | _ => false", "start": [ 68, 1 ], "end": [ 70, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers.isProtected", "code": "def Modifiers.isProtected : Modifiers β†’ Bool\n | { visibility := .protected, .. } => true\n | _ => false", "start": [ 72, 1 ], "end": [ 74, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers.isPartial", "code": "def Modifiers.isPartial : Modifiers β†’ Bool\n | { recKind := .partial, .. } => true\n | _ => false", "start": [ 76, 1 ], "end": [ 78, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers.isNonrec", "code": "def Modifiers.isNonrec : Modifiers β†’ Bool\n | { recKind := .nonrec, .. } => true\n | _ => false", "start": [ 80, 1 ], "end": [ 82, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers.addAttr", "code": "def Modifiers.addAttr (modifiers : Modifiers) (attr : Attribute) : Modifiers :=\n { modifiers with attrs := modifiers.attrs.push attr }", "start": [ 84, 1 ], "end": [ 86, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Modifiers.filterAttrs", "code": "def Modifiers.filterAttrs (modifiers : Modifiers) (p : Attribute β†’ Bool) : Modifiers :=\n { modifiers with attrs := modifiers.attrs.filter p }", "start": [ 88, 1 ], "end": [ 90, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.expandOptDocComment?", "code": "def expandOptDocComment? [Monad m] [MonadError m] (optDocComment : Syntax) : m (Option String) :=\n match optDocComment.getOptional? with\n | none => return none\n | some s => match s[1] with\n | .atom _ val => return some (val.extract 0 (val.endPos - ⟨2⟩))\n | _ => throwErrorAt s \"unexpected doc string{indentD s[1]}\"", "start": [ 109, 1 ], "end": [ 117, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.elabModifiers", "code": "def elabModifiers (stx : Syntax) : m Modifiers := do\n let docCommentStx := stx[0]\n let attrsStx := stx[1]\n let visibilityStx := stx[2]\n let noncompStx := stx[3]\n let unsafeStx := stx[4]\n let recKind :=\n if stx[5].isNone then\n RecKind.default\n else if stx[5][0].getKind == ``Parser.Command.partial then\n RecKind.partial\n else\n RecKind.nonrec\n let docString? ← match docCommentStx.getOptional? with\n | none => pure none\n | some s => pure (some (← getDocStringText ⟨s⟩))\n let visibility ← match visibilityStx.getOptional? with\n | none => pure Visibility.regular\n | some v =>\n let kind := v.getKind\n if kind == ``Parser.Command.private then pure Visibility.private\n else if kind == ``Parser.Command.protected then pure Visibility.protected\n else throwErrorAt v \"unexpected visibility modifier\"\n let attrs ← match attrsStx.getOptional? with\n | none => pure #[]\n | some attrs => elabDeclAttrs attrs\n return {\n docString?, visibility, recKind, attrs,\n isUnsafe := !unsafeStx.isNone\n isNoncomputable := !noncompStx.isNone\n }", "start": [ 123, 1 ], "end": [ 154, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.applyVisibility", "code": "def applyVisibility (visibility : Visibility) (declName : Name) : m Name := do\n match visibility with\n | .private =>\n let declName := mkPrivateName (← getEnv) declName\n checkNotAlreadyDeclared declName\n return declName\n | .protected =>\n checkNotAlreadyDeclared declName\n modifyEnv fun env => addProtected env declName\n return declName\n | _ =>\n checkNotAlreadyDeclared declName\n pure declName", "start": [ 156, 1 ], "end": [ 173, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.checkIfShadowingStructureField", "code": "def checkIfShadowingStructureField (declName : Name) : m Unit := do\n match declName with\n | Name.str pre .. =>\n if isStructure (← getEnv) pre then\n let fieldNames := getStructureFieldsFlattened (← getEnv) pre\n for fieldName in fieldNames do\n if pre ++ fieldName == declName then\n throwError \"invalid declaration name '{declName}', structure '{pre}' has field '{fieldName}'\"\n | _ => pure ()", "start": [ 175, 1 ], "end": [ 183, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.mkDeclName", "code": "def mkDeclName (currNamespace : Name) (modifiers : Modifiers) (shortName : Name) : m (Name Γ— Name) := do\n let mut shortName := shortName\n let mut currNamespace := currNamespace\n let view := extractMacroScopes shortName\n let name := view.name\n let isRootName := (`_root_).isPrefixOf name\n if name == `_root_ then\n throwError \"invalid declaration name `_root_`, `_root_` is a prefix used to refer to the 'root' namespace\"\n let declName := if isRootName then { view with name := name.replacePrefix `_root_ Name.anonymous }.review else currNamespace ++ shortName\n if isRootName then\n let .str p s := name | throwError \"invalid declaration name '{name}'\"\n shortName := Name.mkSimple s\n currNamespace := p.replacePrefix `_root_ Name.anonymous\n checkIfShadowingStructureField declName\n let declName ← applyVisibility modifiers.visibility declName\n match modifiers.visibility with\n | Visibility.protected =>\n match currNamespace with\n | .str _ s => return (declName, Name.mkSimple s ++ shortName)\n | _ =>\n if shortName.isAtomic then\n throwError \"protected declarations must be in a namespace\"\n return (declName, shortName)\n | _ => return (declName, shortName)", "start": [ 185, 1 ], "end": [ 208, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.expandDeclIdCore", "code": "def expandDeclIdCore (declId : Syntax) : Name Γ— Syntax :=\n if declId.isIdent then\n (declId.getId, mkNullNode)\n else\n let id := declId[0].getId\n let optUnivDeclStx := declId[1]\n (id, optUnivDeclStx)", "start": [ 210, 1 ], "end": [ 223, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.ExpandDeclIdResult", "code": "structure ExpandDeclIdResult where\n \n shortName : Name\n \n declName : Name\n \n levelNames : List Name", "start": [ 225, 1 ], "end": [ 232, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.expandDeclId", "code": "def expandDeclId (currNamespace : Name) (currLevelNames : List Name) (declId : Syntax) (modifiers : Modifiers) : m ExpandDeclIdResult := do\n let (shortName, optUnivDeclStx) := expandDeclIdCore declId\n let levelNames ← if optUnivDeclStx.isNone then\n pure currLevelNames\n else\n let extraLevels := optUnivDeclStx[1].getArgs.getEvenElems\n extraLevels.foldlM\n (fun levelNames idStx =>\n let id := idStx.getId\n if levelNames.elem id then\n withRef idStx <| throwAlreadyDeclaredUniverseLevel id\n else\n pure (id :: levelNames))\n currLevelNames\n let (declName, shortName) ← withRef declId <| mkDeclName currNamespace modifiers shortName\n addDocString' declName modifiers.docString?\n return { shortName := shortName, declName := declName, levelNames := levelNames }", "start": [ 234, 1 ], "end": [ 261, 84 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Coe.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/SynthInstance.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Transform.lean" ]
[ { "full_name": "Lean.Meta.isCoeDecl", "code": "def isCoeDecl (env : Environment) (declName : Name) : Bool :=\n coeDeclAttr.hasTag env declName", "start": [ 16, 1 ], "end": [ 21, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.expandCoe", "code": "partial def expandCoe (e : Expr) : MetaM Expr :=\n withReducibleAndInstances do\n transform e fun e => do\n let f := e.getAppFn\n if f.isConst then\n let declName := f.constName!\n if isCoeDecl (← getEnv) declName then\n if let some e ← unfoldDefinition? e then\n return .visit e.headBeta\n return .continue", "start": [ 23, 1 ], "end": [ 33, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.coerceSimple?", "code": "def coerceSimple? (expr expectedType : Expr) : MetaM (LOption Expr) := do\n let eType ← inferType expr\n let u ← getLevel eType\n let v ← getLevel expectedType\n let coeTInstType := mkAppN (mkConst ``CoeT [u, v]) #[eType, expr, expectedType]\n match ← trySynthInstance coeTInstType with\n | .some inst =>\n let result ← expandCoe (mkAppN (mkConst ``CoeT.coe [u, v]) #[eType, expr, expectedType, inst])\n unless ← isDefEq (← inferType result) expectedType do\n throwError \"could not coerce{indentExpr expr}\\nto{indentExpr expectedType}\\ncoerced expression has wrong type:{indentExpr result}\"\n return .some result\n | .undef => return .undef\n | .none => return .none", "start": [ 40, 1 ], "end": [ 53, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.coerceToFunction?", "code": "def coerceToFunction? (expr : Expr) : MetaM (Option Expr) := do\n let Ξ± ← inferType expr\n let u ← getLevel Ξ±\n let v ← mkFreshLevelMVar\n let Ξ³ ← mkFreshExprMVar (← mkArrow Ξ± (mkSort v))\n let .some inst ← trySynthInstance (mkApp2 (.const ``CoeFun [u,v]) Ξ± Ξ³) | return none\n let expanded ← expandCoe (mkApp4 (.const ``CoeFun.coe [u,v]) Ξ± Ξ³ inst expr)\n unless (← whnf (← inferType expanded)).isForall do\n throwError \"failed to coerce{indentExpr expr}\\nto a function, after applying `CoeFun.coe`, result is still not a function{indentExpr expanded}\\nthis is often due to incorrect `CoeFun` instances, the synthesized instance was{indentExpr inst}\"\n return expanded", "start": [ 55, 1 ], "end": [ 66, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.coerceToSort?", "code": "def coerceToSort? (expr : Expr) : MetaM (Option Expr) := do\n let Ξ± ← inferType expr\n let u ← getLevel Ξ±\n let v ← mkFreshLevelMVar\n let Ξ² ← mkFreshExprMVar (mkSort v)\n let .some inst ← trySynthInstance (mkApp2 (.const ``CoeSort [u,v]) Ξ± Ξ²) | return none\n let expanded ← expandCoe (mkApp4 (.const ``CoeSort.coe [u,v]) Ξ± Ξ² inst expr)\n unless (← whnf (← inferType expanded)).isSort do\n throwError \"failed to coerce{indentExpr expr}\\nto a type, after applying `CoeSort.coe`, result is still not a type{indentExpr expanded}\\nthis is often due to incorrect `CoeSort` instances, the synthesized instance was{indentExpr inst}\"\n return expanded", "start": [ 68, 1 ], "end": [ 79, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isTypeApp?", "code": "def isTypeApp? (type : Expr) : MetaM (Option (Expr Γ— Expr)) := do\n let type ← withReducible <| whnf type\n match type with\n | .app m Ξ± => return some ((← instantiateMVars m), (← instantiateMVars Ξ±))\n | _ => return none", "start": [ 81, 1 ], "end": [ 86, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isMonadApp", "code": "def isMonadApp (type : Expr) : MetaM Bool := do\n let some (m, _) ← isTypeApp? type | return false\n return (← isMonad? m).isSome", "start": [ 88, 1 ], "end": [ 94, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.coerceMonadLift?", "code": "def coerceMonadLift? (e expectedType : Expr) : MetaM (Option Expr) := do\n let expectedType ← instantiateMVars expectedType\n let eType ← instantiateMVars (← inferType e)\n let some (n, Ξ²) ← isTypeApp? expectedType | return none\n let some (m, Ξ±) ← isTypeApp? eType | return none\n if (← isDefEq m n) then\n let some monadInst ← isMonad? n | return none\n try expandCoe (← mkAppOptM ``Lean.Internal.coeM #[m, Ξ±, Ξ², none, monadInst, e]) catch _ => return none\n else if autoLift.get (← getOptions) then\n try\n let .forallE _ (.sort um₁) (.sort umβ‚‚) _ ← whnf (← inferType m) | return none\n let .forallE _ (.sort un₁) (.sort unβ‚‚) _ ← whnf (← inferType n) | return none\n let u ← decLevel um₁\n let .true ← isLevelDefEq u (← decLevel un₁) | return none\n let v ← decLevel umβ‚‚\n let w ← decLevel unβ‚‚\n let monadLiftType := mkAppN (.const ``MonadLiftT [u, v, w]) #[m, n]\n let .some monadLiftVal ← trySynthInstance monadLiftType | return none\n let u_1 ← getDecLevel Ξ±\n let u_2 ← getDecLevel eType\n let u_3 ← getDecLevel expectedType\n let eNew := mkAppN (Lean.mkConst ``liftM [u_1, u_2, u_3]) #[m, n, monadLiftVal, Ξ±, e]\n let eNewType ← inferType eNew\n if (← isDefEq expectedType eNewType) then\n return some eNew else\n let some monadInst ← isMonad? n | return none\n let u ← getLevel Ξ±\n let v ← getLevel Ξ²\n let coeTInstType := Lean.mkForall `a BinderInfo.default Ξ± <| mkAppN (mkConst ``CoeT [u, v]) #[Ξ±, mkBVar 0, Ξ²]\n let .some coeTInstVal ← trySynthInstance coeTInstType | return none\n let eNew ← expandCoe (mkAppN (Lean.mkConst ``Lean.Internal.liftCoeM [u_1, u_2, u_3]) #[m, n, Ξ±, Ξ², monadLiftVal, coeTInstVal, monadInst, e])\n let eNewType ← inferType eNew\n unless (← isDefEq expectedType eNewType) do return none\n return some eNew catch _ =>\n \n return none\n else\n return none", "start": [ 96, 1 ], "end": [ 197, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.coerce?", "code": "def coerce? (expr expectedType : Expr) : MetaM (LOption Expr) := do\n if let some lifted ← coerceMonadLift? expr expectedType then\n return .some lifted\n if (← whnfR expectedType).isForall then\n if let some fn ← coerceToFunction? expr then\n if ← isDefEq (← inferType fn) expectedType then\n return .some fn\n coerceSimple? expr expectedType", "start": [ 199, 1 ], "end": [ 210, 34 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Level.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Level.lean", ".lake/packages/lean4/src/lean/Lean/Elab/AutoBound.lean", ".lake/packages/lean4/src/lean/Lean/Elab/Exception.lean", ".lake/packages/lean4/src/lean/Lean/Log.lean" ]
[ { "full_name": "Lean.Elab.Level.Context", "code": "structure Context where\n options : Options\n ref : Syntax\n autoBoundImplicit : Bool", "start": [ 14, 1 ], "end": [ 17, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Level.State", "code": "structure State where\n ngen : NameGenerator\n mctx : MetavarContext\n levelNames : List Name", "start": [ 19, 1 ], "end": [ 22, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Level.LevelElabM", "code": "abbrev LevelElabM := ReaderT Context (EStateM Exception State)", "start": [ 24, 1 ], "end": [ 24, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Level.mkFreshLevelMVar", "code": "def mkFreshLevelMVar : LevelElabM Level := do\n let mvarId ← mkFreshLMVarId\n modify fun s => { s with mctx := s.mctx.addLevelMVarDecl mvarId }\n return mkLevelMVar mvarId", "start": [ 42, 1 ], "end": [ 45, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Level.checkUniverseOffset", "code": "private def checkUniverseOffset [Monad m] [MonadError m] [MonadOptions m] (n : Nat) : m Unit := do\n let max := maxUniverseOffset.get (← getOptions)\n unless n <= max do\n throwError \"maximum universe level offset threshold ({max}) has been reached, you can increase the limit using option `set_option maxUniverseOffset <limit>`, but you are probably misusing universe levels since offsets are usually small natural numbers\"", "start": [ 52, 1 ], "end": [ 55, 257 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Level.elabLevel", "code": "partial def elabLevel (stx : Syntax) : LevelElabM Level := withRef stx do\n let kind := stx.getKind\n if kind == ``Lean.Parser.Level.paren then\n elabLevel (stx.getArg 1)\n else if kind == ``Lean.Parser.Level.max then\n let args := stx.getArg 1 |>.getArgs\n args[:args.size - 1].foldrM (init := ← elabLevel args.back) fun stx lvl =>\n return mkLevelMax' (← elabLevel stx) lvl\n else if kind == ``Lean.Parser.Level.imax then\n let args := stx.getArg 1 |>.getArgs\n args[:args.size - 1].foldrM (init := ← elabLevel args.back) fun stx lvl =>\n return mkLevelIMax' (← elabLevel stx) lvl\n else if kind == ``Lean.Parser.Level.hole then\n mkFreshLevelMVar\n else if kind == numLitKind then\n match stx.isNatLit? with\n | some val => checkUniverseOffset val; return Level.ofNat val\n | none => throwIllFormedSyntax\n else if kind == identKind then\n let paramName := stx.getId\n unless (← get).levelNames.contains paramName do\n if (← read).autoBoundImplicit && isValidAutoBoundLevelName paramName (relaxedAutoImplicit.get (← read).options) then\n modify fun s => { s with levelNames := paramName :: s.levelNames }\n else\n throwError \"unknown universe level '{mkIdent paramName}'\"\n return mkLevelParam paramName\n else if kind == `Lean.Parser.Level.addLit then\n let lvl ← elabLevel (stx.getArg 0)\n match stx.getArg 2 |>.isNatLit? with\n | some val => checkUniverseOffset val; return lvl.addOffset val\n | none => throwIllFormedSyntax\n else\n throwError \"unexpected universe level syntax kind\"", "start": [ 57, 1 ], "end": [ 89, 55 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Config.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Elab.Term.setElabConfig", "code": "def setElabConfig (cfg : Meta.Config) : Meta.Config :=\n { cfg with foApprox := true, ctxApprox := true, constApprox := false, quasiPatternApprox := false }", "start": [ 11, 1 ], "end": [ 58, 102 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/FindLevelMVar.lean
[ ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.FindLevelMVar.Visitor", "code": "abbrev Visitor := Option LMVarId β†’ Option LMVarId", "start": [ 13, 1 ], "end": [ 13, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FindLevelMVar.visit", "code": "partial def visit (p : LMVarId β†’ Bool) (e : Expr) : Visitor := fun s =>\n if s.isSome || !e.hasLevelMVar then s else main p e s", "start": [ 16, 3 ], "end": [ 17, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FindLevelMVar.main", "code": "partial def main (p : LMVarId β†’ Bool) : Expr β†’ Visitor\n | .sort l => visitLevel p l\n | .const _ ls => ls.foldr (init := id) fun l acc => visitLevel p l ∘ acc\n | .forallE _ d b _ => visit p b ∘ visit p d\n | .lam _ d b _ => visit p b ∘ visit p d\n | .letE _ t v b _ => visit p b ∘ visit p v ∘ visit p t\n | .app f a => visit p a ∘ visit p f\n | .mdata _ b => visit p b\n | .proj _ _ e => visit p e\n | _ => id", "start": [ 19, 3 ], "end": [ 28, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FindLevelMVar.visitLevel", "code": "partial def visitLevel (p : LMVarId β†’ Bool) (l : Level) : Visitor := fun s =>\n if s.isSome || !l.hasMVar then s else mainLevel p l s", "start": [ 30, 3 ], "end": [ 31, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FindLevelMVar.mainLevel", "code": "partial def mainLevel (p : LMVarId β†’ Bool) : Level β†’ Visitor\n | .zero => id\n | .succ l => visitLevel p l\n | .max l₁ lβ‚‚ => visitLevel p l₁ ∘ visitLevel p lβ‚‚\n | .imax l₁ lβ‚‚ => visitLevel p l₁ ∘ visitLevel p lβ‚‚\n | .param _ => id\n | .mvar mvarId => fun s => if p mvarId then some mvarId else s", "start": [ 33, 3 ], "end": [ 39, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.findLevelMVar?", "code": "@[inline] def Expr.findLevelMVar? (e : Expr) (p : LMVarId β†’ Bool) : Option LMVarId :=\n FindLevelMVar.main p e none", "start": [ 44, 1 ], "end": [ 45, 30 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/FieldNotation.lean
[ ".lake/packages/lean4/src/lean/Lean/Structure.lean", ".lake/packages/lean4/src/lean/Lean/Meta/InferType.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Options.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Attributes.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Delaborator.projInfo", "code": "private def projInfo (c : Name) : MetaM (Name Γ— Nat Γ— Bool) := do\n let .str _ field := c | failure\n let field := Name.mkSimple field\n let env ← getEnv\n let some info := env.getProjectionFnInfo? c | failure\n guard <| !info.fromClass\n let some (.ctorInfo cVal) := env.find? info.ctorName | failure\n let isParentProj := (isSubobjectField? env cVal.induct field).isSome\n return (field, info.numParams, isParentProj)", "start": [ 19, 1 ], "end": [ 33, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.typeMatchesBaseName", "code": "private def typeMatchesBaseName (type : Expr) (baseName : Name) : MetaM Bool := do\n if type.cleanupAnnotations.isAppOf baseName then\n return true\n else\n return (← whnfR type).isAppOf baseName", "start": [ 35, 1 ], "end": [ 42, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.generalizedFieldInfo", "code": "private def generalizedFieldInfo (c : Name) (args : Array Expr) : MetaM (Name Γ— Nat) := do\n let .str _ field := c | failure\n let field := Name.mkSimple field\n let baseName := c.getPrefix\n guard <| !baseName.isAnonymous\n guard <| baseName != `Function\n let info ← getConstInfo c\n forallBoundedTelescope info.type args.size fun params _ => do\n for i in [0:params.size] do\n let fvarId := params[i]!.fvarId!\n if (← fvarId.getUserName) == `motive then\n failure\n if (← typeMatchesBaseName (← fvarId.getType) baseName) then\n guard (← fvarId.getBinderInfo).isExplicit\n guard <| (← instantiateMVars <| ← inferType args[i]!).consumeMData.isAppOf baseName\n return (field, i)\n else\n guard !(← fvarId.getBinderInfo).isExplicit\n failure", "start": [ 44, 1 ], "end": [ 76, 12 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.fieldNotationCandidate?", "code": "def fieldNotationCandidate? (f : Expr) (args : Array Expr) (useGeneralizedFieldNotation : Bool) : MetaM (Option (Name Γ— Nat)) := do\n let env ← getEnv\n let .const c .. := f.consumeMData | return none\n if c.getPrefix.isAnonymous then return none\n if hasPPNoDotAttribute env c then\n return none\n try\n let (field, numParams, _) ← projInfo c\n return (field, numParams)\n catch _ => pure ()\n if useGeneralizedFieldNotation then\n try\n guard !(← isProof f)\n return ← generalizedFieldInfo c args\n catch _ => pure ()\n return none", "start": [ 78, 1 ], "end": [ 102, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.parentProj?", "code": "def parentProj? (explicit : Bool) (e : Expr) : MetaM (Option Name) := do\n unless e.isApp do return none\n try\n let .const c .. := e.getAppFn | failure\n let (field, numParams, isParentProj) ← projInfo c\n if isParentProj && (!explicit || numParams == 0) && e.getAppNumArgs == numParams + 1 then\n return some field\n else\n return none\n catch _ =>\n return none", "start": [ 104, 1 ], "end": [ 118, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isParentProj", "code": "def isParentProj (explicit : Bool) (e : Expr) : MetaM Bool := do\n return (← parentProj? explicit e).isSome", "start": [ 120, 1 ], "end": [ 125, 43 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/CollectLevelParams.lean
[ ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.CollectLevelParams.State", "code": "structure State where\n visitedLevel : LevelSet := {}\n visitedExpr : ExprSet := {}\n params : Array Name := #[]", "start": [ 13, 1 ], "end": [ 16, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.Visitor", "code": "abbrev Visitor := State β†’ State", "start": [ 20, 1 ], "end": [ 20, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.visitLevel", "code": "partial def visitLevel (u : Level) : Visitor := fun s =>\n if !u.hasParam || s.visitedLevel.contains u then s\n else collect u { s with visitedLevel := s.visitedLevel.insert u }", "start": [ 23, 3 ], "end": [ 25, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.collect", "code": "partial def collect : Level β†’ Visitor\n | .succ v => visitLevel v\n | .max u v => visitLevel v ∘ visitLevel u\n | .imax u v => visitLevel v ∘ visitLevel u\n | .param n => fun s => { s with params := s.params.push n }\n | _ => id", "start": [ 27, 3 ], "end": [ 32, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.visitLevels", "code": "def visitLevels (us : List Level) : Visitor :=\n fun s => us.foldl (fun s u => visitLevel u s) s", "start": [ 35, 1 ], "end": [ 36, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.visitExpr", "code": "partial def visitExpr (e : Expr) : Visitor := fun s =>\n if !e.hasLevelParam then s\n else if s.visitedExpr.contains e then s\n else main e { s with visitedExpr := s.visitedExpr.insert e }", "start": [ 39, 3 ], "end": [ 42, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.main", "code": "partial def main : Expr β†’ Visitor\n | .proj _ _ s => visitExpr s\n | .forallE _ d b _ => visitExpr b ∘ visitExpr d\n | .lam _ d b _ => visitExpr b ∘ visitExpr d\n | .letE _ t v b _ => visitExpr b ∘ visitExpr v ∘ visitExpr t\n | .app f a => visitExpr a ∘ visitExpr f\n | .mdata _ b => visitExpr b\n | .const _ us => visitLevels us\n | .sort u => visitLevel u\n | _ => id", "start": [ 44, 3 ], "end": [ 53, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.State.getUnusedLevelParam", "code": "partial def State.getUnusedLevelParam (s : CollectLevelParams.State) (pre : Name := `v) : Level :=\n let v := mkLevelParam pre;\n if s.visitedLevel.contains v then\n let rec loop (i : Nat) :=\n let v := mkLevelParam (pre.appendIndexAfter i);\n if s.visitedLevel.contains v then loop (i+1) else v\n loop 1\n else\n v", "start": [ 56, 1 ], "end": [ 64, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.collectLevelParams", "code": "def collectLevelParams (s : CollectLevelParams.State) (e : Expr) : CollectLevelParams.State :=\n CollectLevelParams.main e s", "start": [ 68, 1 ], "end": [ 69, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.CollectLevelParams.State.collect", "code": "def CollectLevelParams.State.collect (s : CollectLevelParams.State) (e : Expr) : CollectLevelParams.State :=\n collectLevelParams s e", "start": [ 71, 1 ], "end": [ 72, 25 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/ReplaceLevel.lean
[ ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.Level.replace", "code": "partial def replace (f? : Level β†’ Option Level) (u : Level) : Level :=\n match f? u with\n | some v => v\n | none => match u with\n | max v₁ vβ‚‚ => mkLevelMax' (replace f? v₁) (replace f? vβ‚‚)\n | imax v₁ vβ‚‚ => mkLevelIMax' (replace f? v₁) (replace f? vβ‚‚)\n | succ v => mkLevelSucc (replace f? v)\n | _ => u", "start": [ 12, 1 ], "end": [ 19, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.cacheSize", "code": "abbrev cacheSize : USize := 8192 - 1", "start": [ 27, 1 ], "end": [ 27, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.State", "code": "structure State where\n keys : Array Expr results : Array Expr", "start": [ 29, 1 ], "end": [ 31, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.ReplaceM", "code": "abbrev ReplaceM := StateM State", "start": [ 33, 1 ], "end": [ 33, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.cache", "code": "unsafe def cache (i : USize) (key : Expr) (result : Expr) : ReplaceM Expr := do\n modify fun s => { keys := s.keys.uset i key lcProof, results := s.results.uset i result lcProof };\n pure result", "start": [ 35, 1 ], "end": [ 37, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.replaceUnsafeM", "code": "unsafe def replaceUnsafeM (f? : Level β†’ Option Level) (size : USize) (e : Expr) : ReplaceM Expr := do\n let rec visit (e : Expr) := do\n let c ← get\n let h := ptrAddrUnsafe e\n let i := h % size\n if ptrAddrUnsafe (c.keys.uget i lcProof) == h then\n pure <| c.results.uget i lcProof\n else match e with\n | Expr.forallE _ d b _ => cache i e <| e.updateForallE! (← visit d) (← visit b)\n | Expr.lam _ d b _ => cache i e <| e.updateLambdaE! (← visit d) (← visit b)\n | Expr.mdata _ b => cache i e <| e.updateMData! (← visit b)\n | Expr.letE _ t v b _ => cache i e <| e.updateLet! (← visit t) (← visit v) (← visit b)\n | Expr.app f a => cache i e <| e.updateApp! (← visit f) (← visit a)\n | Expr.proj _ _ b => cache i e <| e.updateProj! (← visit b)\n | Expr.sort u => cache i e <| e.updateSort! (u.replace f?)\n | Expr.const _ us => cache i e <| e.updateConst! (us.map (Level.replace f?))\n | e => pure e\n visit e", "start": [ 39, 1 ], "end": [ 56, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.initCache", "code": "unsafe def initCache : State :=\n { keys := mkArray cacheSize.toNat (cast lcProof ()), results := mkArray cacheSize.toNat default }", "start": [ 58, 1 ], "end": [ 60, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.ReplaceLevelImpl.replaceUnsafe", "code": "unsafe def replaceUnsafe (f? : Level β†’ Option Level) (e : Expr) : Expr :=\n (replaceUnsafeM f? cacheSize e).run' initCache", "start": [ 62, 1 ], "end": [ 63, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.replaceLevel", "code": "@[implemented_by ReplaceLevelImpl.replaceUnsafe]\npartial def replaceLevel (f? : Level β†’ Option Level) : Expr β†’ Expr\n | e@(Expr.forallE _ d b _) => let d := replaceLevel f? d; let b := replaceLevel f? b; e.updateForallE! d b\n | e@(Expr.lam _ d b _) => let d := replaceLevel f? d; let b := replaceLevel f? b; e.updateLambdaE! d b\n | e@(Expr.mdata _ b) => let b := replaceLevel f? b; e.updateMData! b\n | e@(Expr.letE _ t v b _) => let t := replaceLevel f? t; let v := replaceLevel f? v; let b := replaceLevel f? b; e.updateLet! t v b\n | e@(Expr.app f a) => let f := replaceLevel f? f; let a := replaceLevel f? a; e.updateApp! f a\n | e@(Expr.proj _ _ b) => let b := replaceLevel f? b; e.updateProj! b\n | e@(Expr.sort u) => e.updateSort! (u.replace f?)\n | e@(Expr.const _ us) => e.updateConst! (us.map (Level.replace f?))\n | e => e", "start": [ 67, 1 ], "end": [ 77, 36 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/FindMVar.lean
[ ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.FindMVar.Visitor", "code": "abbrev Visitor := Option MVarId β†’ Option MVarId", "start": [ 13, 1 ], "end": [ 13, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FindMVar.visit", "code": "partial def visit (p : MVarId β†’ Bool) (e : Expr) : Visitor := fun s =>\n if s.isSome || !e.hasExprMVar then s else main p e s", "start": [ 16, 3 ], "end": [ 17, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FindMVar.main", "code": "partial def main (p : MVarId β†’ Bool) : Expr β†’ Visitor\n | Expr.proj _ _ e => visit p e\n | Expr.forallE _ d b _ => visit p b ∘ visit p d\n | Expr.lam _ d b _ => visit p b ∘ visit p d\n | Expr.letE _ t v b _ => visit p b ∘ visit p v ∘ visit p t\n | Expr.app f a => visit p a ∘ visit p f\n | Expr.mdata _ b => visit p b\n | Expr.mvar mvarId => fun s => if s.isNone && p mvarId then some mvarId else s\n | _ => id", "start": [ 19, 3 ], "end": [ 27, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.findMVar?", "code": "@[inline] def Expr.findMVar? (e : Expr) (p : MVarId β†’ Bool) : Option MVarId :=\n FindMVar.main p e none", "start": [ 32, 1 ], "end": [ 33, 25 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/SubExpr.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Data/RBMap.lean", ".lake/packages/lean4/src/lean/Lean/SubExpr.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Delaborator.OptionsPerPos", "code": "abbrev OptionsPerPos := RBMap SubExpr.Pos Options compare", "start": [ 19, 1 ], "end": [ 19, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.getExpr", "code": "def getExpr : m Expr := return (← readThe SubExpr).expr", "start": [ 34, 1 ], "end": [ 34, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.getPos", "code": "def getPos : m Pos := return (← readThe SubExpr).pos", "start": [ 35, 1 ], "end": [ 35, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.descend", "code": "def descend (child : Expr) (childIdx : Nat) (x : m Ξ±) : m Ξ± :=\n withTheReader SubExpr (fun cfg => { cfg with expr := child, pos := cfg.pos.push childIdx }) x", "start": [ 37, 1 ], "end": [ 38, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withAppFn", "code": "def withAppFn (x : m Ξ±) : m Ξ± := do descend (← getExpr).appFn! 0 x", "start": [ 40, 1 ], "end": [ 40, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withAppArg", "code": "def withAppArg (x : m Ξ±) : m Ξ± := do descend (← getExpr).appArg! 1 x", "start": [ 41, 1 ], "end": [ 41, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withType", "code": "def withType (x : m Ξ±) : m Ξ± := do\n descend (← Meta.inferType (← getExpr)) Pos.typeCoord x", "start": [ 43, 1 ], "end": [ 44, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withAppFnArgs", "code": "partial def withAppFnArgs (xf : m Ξ±) (xa : Ξ± β†’ m Ξ±) : m Ξ± := do\n if (← getExpr).isApp then\n let acc ← withAppFn (withAppFnArgs xf xa)\n withAppArg (xa acc)\n else xf", "start": [ 46, 1 ], "end": [ 54, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withBoundedAppFnArgs", "code": "def withBoundedAppFnArgs (maxArgs : Nat) (xf : m Ξ±) (xa : Ξ± β†’ m Ξ±) : m Ξ± := do\n match maxArgs, (← getExpr) with\n | maxArgs' + 1, .app .. =>\n let acc ← withAppFn (withBoundedAppFnArgs maxArgs' xf xa)\n withAppArg (xa acc)\n | _, _ => xf", "start": [ 56, 1 ], "end": [ 66, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withBoundedAppFn", "code": "def withBoundedAppFn (maxArgs : Nat) (xf : m Ξ±) : m Ξ± := do\n let e ← getExpr\n let numArgs := min maxArgs e.getAppNumArgs\n let newPos := (← getPos).pushNaryFn numArgs\n withTheReader SubExpr (fun cfg => { cfg with expr := e.getBoundedAppFn numArgs, pos := newPos }) xf", "start": [ 68, 1 ], "end": [ 76, 102 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withBindingDomain", "code": "def withBindingDomain (x : m Ξ±) : m Ξ± := do descend (← getExpr).bindingDomain! 0 x", "start": [ 78, 1 ], "end": [ 78, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withBindingBody'", "code": "def withBindingBody' (n : Name) (v : Expr β†’ m Ξ²) (x : Ξ² β†’ m Ξ±) : m Ξ± := do\n let e ← getExpr\n Meta.withLocalDecl n e.binderInfo e.bindingDomain! fun fvar => do\n let b ← v fvar\n descend (e.bindingBody!.instantiate1 fvar) 1 (x b)", "start": [ 80, 1 ], "end": [ 90, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withBindingBody", "code": "def withBindingBody (n : Name) (x : m Ξ±) : m Ξ± :=\n withBindingBody' n (fun _ => pure ()) (fun _ => x)", "start": [ 92, 1 ], "end": [ 97, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withProj", "code": "def withProj (x : m Ξ±) : m Ξ± := do\n let Expr.proj _ _ e ← getExpr | unreachable!\n descend e 0 x", "start": [ 99, 1 ], "end": [ 101, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withMDataExpr", "code": "def withMDataExpr (x : m Ξ±) : m Ξ± := do\n let Expr.mdata _ e ← getExpr | unreachable!\n withTheReader SubExpr (fun ctx => { ctx with expr := e }) x", "start": [ 103, 1 ], "end": [ 105, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withLetVarType", "code": "def withLetVarType (x : m Ξ±) : m Ξ± := do\n let Expr.letE _ t _ _ _ ← getExpr | unreachable!\n descend t 0 x", "start": [ 107, 1 ], "end": [ 109, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withLetValue", "code": "def withLetValue (x : m Ξ±) : m Ξ± := do\n let Expr.letE _ _ v _ _ ← getExpr | unreachable!\n descend v 1 x", "start": [ 111, 1 ], "end": [ 113, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withLetBody", "code": "def withLetBody (x : m Ξ±) : m Ξ± := do\n let Expr.letE n t v b _ ← getExpr | unreachable!\n Meta.withLetDecl n t v fun fvar =>\n let b := b.instantiate1 fvar\n descend b 2 x", "start": [ 115, 1 ], "end": [ 119, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withNaryFn", "code": "def withNaryFn (x : m Ξ±) : m Ξ± := do\n let e ← getExpr\n let newPos := (← getPos).pushNaryFn e.getAppNumArgs\n withTheReader SubExpr (fun cfg => { cfg with expr := e.getAppFn, pos := newPos }) x", "start": [ 121, 1 ], "end": [ 124, 86 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.withNaryArg", "code": "def withNaryArg (argIdx : Nat) (x : m Ξ±) : m Ξ± := do\n let e ← getExpr\n let args := e.getAppArgs\n let newPos := (← getPos).pushNaryArg args.size argIdx\n withTheReader SubExpr (fun cfg => { cfg with expr := args[argIdx]!, pos := newPos }) x", "start": [ 126, 1 ], "end": [ 130, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.HoleIterator", "code": "structure HoleIterator where\n curr : Nat := 2\n top : Nat := Pos.maxChildren\n deriving Inhabited", "start": [ 134, 1 ], "end": [ 137, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.HoleIterator.toPos", "code": "def HoleIterator.toPos (iter : HoleIterator) : Pos :=\n iter.curr", "start": [ 145, 1 ], "end": [ 146, 12 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.HoleIterator.next", "code": "def HoleIterator.next (iter : HoleIterator) : HoleIterator :=\n if (iter.curr+1) == iter.top then\n ⟨2*iter.top, Pos.maxChildren*iter.top⟩\n else ⟨iter.curr+1, iter.top⟩", "start": [ 148, 1 ], "end": [ 151, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.SubExpr.nextExtraPos", "code": "def nextExtraPos : m Pos := do\n let iter ← getThe HoleIterator\n let pos := iter.toPos\n modifyThe HoleIterator HoleIterator.next\n return pos", "start": [ 153, 1 ], "end": [ 163, 13 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Module.lean
[ ".lake/packages/lean4/src/lean/Lean/Message.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Command.lean" ]
[ { "full_name": "Lean.Parser.Module.prelude", "code": "def Β«preludeΒ» := leading_parser \"prelude\"", "start": [ 14, 1 ], "end": [ 14, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Module.import", "code": "def Β«importΒ» := leading_parser \"import \" >> optional \"runtime\" >> identWithPartialTrailingDot", "start": [ 15, 1 ], "end": [ 15, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Module.header", "code": "def header := leading_parser optional (Β«preludeΒ» >> ppLine) >> many (Β«importΒ» >> ppLine) >> ppLine", "start": [ 16, 1 ], "end": [ 16, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Module.module", "code": "@[run_builtin_parser_attribute_hooks]\ndef module := leading_parser header >> many (commandParser >> ppLine >> ppLine)", "start": [ 17, 1 ], "end": [ 22, 84 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Module.updateTokens", "code": "def updateTokens (tokens : TokenTable) : TokenTable :=\n match addParserTokens tokens header.info with\n | Except.ok tables => tables\n | Except.error _ => unreachable!", "start": [ 24, 1 ], "end": [ 27, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.ModuleParserState", "code": "structure ModuleParserState where\n pos : String.Pos := 0\n recovering : Bool := false\n deriving Inhabited", "start": [ 31, 1 ], "end": [ 34, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.mkErrorMessage", "code": "private partial def mkErrorMessage (c : InputContext) (pos : String.Pos) (stk : SyntaxStack) (e : Parser.Error) : Message := Id.run do\n let mut pos := pos\n let mut endPos? := none\n let mut e := e\n unless e.unexpectedTk.isMissing do\n if let some r := e.unexpectedTk.getRange? then\n pos := r.start\n endPos? := some r.stop\n let unexpected := match e.unexpectedTk with\n | .ident .. => \"unexpected identifier\"\n | .atom _ v => s!\"unexpected token '{v}'\"\n | _ => \"unexpected token\" e := { e with unexpected }\n if let some trailing := lastTrailing stk then\n if trailing.stopPos == pos then\n pos := trailing.startPos\n { fileName := c.fileName\n pos := c.fileMap.toPosition pos\n endPos := c.fileMap.toPosition <$> endPos?\n keepFullRange := true\n data := toString e }\nwhere\n lastTrailing (s : SyntaxStack) : Option Substring :=\n s.toSubarray.findSomeRevM? (m := Id) fun stx =>\n if let .original (trailing := trailing) .. := stx.getTailInfo then pure (some trailing)\n else none", "start": [ 36, 1 ], "end": [ 65, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.parseHeader", "code": "def parseHeader (inputCtx : InputContext) : IO (Syntax Γ— ModuleParserState Γ— MessageLog) := do\n let dummyEnv ← mkEmptyEnvironment\n let p := andthenFn whitespace Module.header.fn\n let tokens := Module.updateTokens (getTokenTable dummyEnv)\n let s := p.run inputCtx { env := dummyEnv, options := {} } tokens (mkParserState inputCtx.input)\n let stx := if s.stxStack.isEmpty then .missing else s.stxStack.back\n let mut messages : MessageLog := {}\n for (pos, stk, err) in s.allErrors do\n messages := messages.add <| mkErrorMessage inputCtx pos stk err\n pure (stx, {pos := s.pos, recovering := s.hasError}, messages)", "start": [ 67, 1 ], "end": [ 76, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.mkEOI", "code": "private def mkEOI (pos : String.Pos) : Syntax :=\n let atom := mkAtom (SourceInfo.original \"\".toSubstring pos \"\".toSubstring pos) \"\"\n mkNode ``Command.eoi #[atom]", "start": [ 78, 1 ], "end": [ 80, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.isTerminalCommand", "code": "def isTerminalCommand (s : Syntax) : Bool :=\n s.isOfKind ``Command.exit || s.isOfKind ``Command.import || s.isOfKind ``Command.eoi", "start": [ 82, 1 ], "end": [ 83, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.consumeInput", "code": "private def consumeInput (inputCtx : InputContext) (pmctx : ParserModuleContext) (pos : String.Pos) : String.Pos :=\n let s : ParserState := { cache := initCacheForInput inputCtx.input, pos := pos }\n let s := tokenFn [] |>.run inputCtx pmctx (getTokenTable pmctx.env) s\n match s.errorMsg with\n | some _ => pos + ' '\n | none => s.pos", "start": [ 85, 1 ], "end": [ 90, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.topLevelCommandParserFn", "code": "def topLevelCommandParserFn : ParserFn :=\n commandParser.fn", "start": [ 92, 1 ], "end": [ 93, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.parseCommand", "code": "partial def parseCommand (inputCtx : InputContext) (pmctx : ParserModuleContext) (mps : ModuleParserState) (messages : MessageLog) : Syntax Γ— ModuleParserState Γ— MessageLog := Id.run do\n let mut pos := mps.pos\n let mut recovering := mps.recovering\n let mut messages := messages\n let mut stx := Syntax.missing repeat\n if inputCtx.input.atEnd pos then\n stx := mkEOI pos\n break\n let pos' := pos\n let p := andthenFn whitespace topLevelCommandParserFn\n let s := p.run inputCtx pmctx (getTokenTable pmctx.env) { cache := initCacheForInput inputCtx.input, pos }\n for (rpos, rstk, recovered) in s.recoveredErrors do\n messages := messages.add <| mkErrorMessage inputCtx rpos rstk recovered\n pos := s.pos\n if recovering && !s.stxStack.isEmpty && s.stxStack.back.isAntiquot then\n continue\n match s.errorMsg with\n | none =>\n stx := s.stxStack.back\n recovering := false\n break\n | some errorMsg =>\n if pos == pos' then\n pos := consumeInput inputCtx pmctx pos\n \n let ignore := s.stxStack.isEmpty || s.stxStack.back.getPos?.isNone\n unless recovering && ignore do\n messages := messages.add <| mkErrorMessage inputCtx s.pos s.stxStack errorMsg\n recovering := true\n if ignore then\n continue\n else\n stx := s.stxStack.back\n break\n return (stx, { pos, recovering }, messages)", "start": [ 95, 1 ], "end": [ 135, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.testParseModuleAux", "code": "partial def testParseModuleAux (env : Environment) (inputCtx : InputContext) (s : ModuleParserState) (msgs : MessageLog) (stxs : Array Syntax) : IO (Array Syntax) :=\n let rec parse (state : ModuleParserState) (msgs : MessageLog) (stxs : Array Syntax) :=\n match parseCommand inputCtx { env := env, options := {} } state msgs with\n | (stx, state, msgs) =>\n if isTerminalCommand stx then\n if !msgs.hasUnreported then\n pure stxs\n else do\n msgs.forM fun msg => msg.toString >>= IO.println\n throw (IO.userError \"failed to parse file\")\n else\n parse state msgs (stxs.push stx)\n parse s msgs stxs", "start": [ 139, 1 ], "end": [ 151, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.testParseModule", "code": "def testParseModule (env : Environment) (fname contents : String) : IO (TSyntax ``Parser.Module.module) := do\n let inputCtx := mkInputContext contents fname\n let (header, state, messages) ← parseHeader inputCtx\n let cmds ← testParseModuleAux env inputCtx state messages #[]\n let stx := mkNode `Lean.Parser.Module.module #[header, mkListNode cmds]\n pure ⟨stx.raw.updateLeading⟩", "start": [ 153, 1 ], "end": [ 158, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.testParseFile", "code": "def testParseFile (env : Environment) (fname : System.FilePath) : IO (TSyntax ``Parser.Module.module) := do\n let contents ← IO.FS.readFile fname\n testParseModule env fname.toString contents", "start": [ 160, 1 ], "end": [ 162, 46 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Tactic.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Term.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Tactic/Doc.lean" ]
[ { "full_name": "Lean.Parser.Tactic.unknown", "code": "@[builtin_tactic_parser] def Β«unknownΒ» := leading_parser\n withPosition (ident >> errorAtSavedPos \"unknown tactic\" true)", "start": [ 24, 1 ], "end": [ 25, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.nestedTactic", "code": "@[builtin_tactic_parser] def nestedTactic := tacticSeqBracketed", "start": [ 27, 1 ], "end": [ 27, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.matchRhs", "code": "def matchRhs := Term.hole <|> Term.syntheticHole <|> tacticSeq", "start": [ 29, 1 ], "end": [ 29, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.matchAlts", "code": "def matchAlts := Term.matchAlts (rhsParser := matchRhs)", "start": [ 30, 1 ], "end": [ 30, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.match", "code": "@[builtin_tactic_parser] def Β«matchΒ» := leading_parser:leadPrec\n \"match \" >> optional Term.generalizingParam >>\n optional Term.motive >> sepBy1 Term.matchDiscr \", \" >>\n \" with \" >> ppDedent matchAlts", "start": [ 32, 1 ], "end": [ 48, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.introMatch", "code": "@[builtin_tactic_parser] def introMatch := leading_parser\n nonReservedSymbol \"intro\" >> matchAlts", "start": [ 50, 1 ], "end": [ 68, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.decide", "code": "@[builtin_tactic_parser] def decide := leading_parser\n nonReservedSymbol \"decide\"", "start": [ 70, 1 ], "end": [ 126, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Tactic.nativeDecide", "code": "@[builtin_tactic_parser] def nativeDecide := leading_parser\n nonReservedSymbol \"native_decide\"", "start": [ 128, 1 ], "end": [ 142, 36 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser/Syntax.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Command.lean" ]
[ { "full_name": "Lean.Parser.precedenceParser", "code": "@[inline] def precedenceParser (rbp : Nat := 0) : Parser :=\n categoryParser `prec rbp", "start": [ 20, 1 ], "end": [ 21, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.syntaxParser", "code": "@[inline] def syntaxParser (rbp : Nat := 0) : Parser :=\n categoryParser `stx rbp", "start": [ 23, 1 ], "end": [ 24, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.precedence", "code": "def Β«precedenceΒ» := leading_parser\n \":\" >> precedenceParser maxPrec", "start": [ 26, 1 ], "end": [ 27, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.optPrecedence", "code": "def optPrecedence := optional (atomic Β«precedenceΒ»)", "start": [ 28, 1 ], "end": [ 28, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.numPrec", "code": "@[builtin_prec_parser] def numPrec := checkPrec maxPrec >> numLit", "start": [ 31, 1 ], "end": [ 31, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.paren", "code": "@[builtin_syntax_parser] def paren := leading_parser\n \"(\" >> withoutPosition (many1 syntaxParser) >> \")\"", "start": [ 33, 1 ], "end": [ 34, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.cat", "code": "@[builtin_syntax_parser] def cat := leading_parser\n ident >> optPrecedence", "start": [ 35, 1 ], "end": [ 36, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.unary", "code": "@[builtin_syntax_parser] def unary := leading_parser\n ident >> checkNoWsBefore >> \"(\" >> withoutPosition (many1 syntaxParser) >> \")\"", "start": [ 37, 1 ], "end": [ 38, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.binary", "code": "@[builtin_syntax_parser] def binary := leading_parser\n ident >> checkNoWsBefore >> \"(\" >> withoutPosition (many1 syntaxParser >> \", \" >> many1 syntaxParser) >> \")\"", "start": [ 39, 1 ], "end": [ 40, 111 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.sepBy", "code": "@[builtin_syntax_parser] def sepBy := leading_parser\n \"sepBy(\" >> withoutPosition (many1 syntaxParser >> \", \" >> strLit >>\n optional (\", \" >> many1 syntaxParser) >> optional (\", \" >> nonReservedSymbol \"allowTrailingSep\")) >> \")\"", "start": [ 41, 1 ], "end": [ 43, 109 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.sepBy1", "code": "@[builtin_syntax_parser] def sepBy1 := leading_parser\n \"sepBy1(\" >> withoutPosition (many1 syntaxParser >> \", \" >> strLit >>\n optional (\", \" >> many1 syntaxParser) >> optional (\", \" >> nonReservedSymbol \"allowTrailingSep\")) >> \")\"", "start": [ 44, 1 ], "end": [ 46, 109 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.atom", "code": "@[builtin_syntax_parser] def atom := leading_parser\n strLit", "start": [ 47, 1 ], "end": [ 48, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Syntax.nonReserved", "code": "@[builtin_syntax_parser] def nonReserved := leading_parser\n \"&\" >> strLit", "start": [ 49, 1 ], "end": [ 50, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.namedName", "code": "def namedName := leading_parser\n atomic (\" (\" >> nonReservedSymbol \"name\") >> \" := \" >> ident >> \")\"", "start": [ 56, 1 ], "end": [ 57, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optNamedName", "code": "def optNamedName := optional namedName", "start": [ 58, 1 ], "end": [ 58, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.prefix", "code": "def Β«prefixΒ» := leading_parser \"prefix\"", "start": [ 60, 1 ], "end": [ 60, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.infix", "code": "def Β«infixΒ» := leading_parser \"infix\"", "start": [ 61, 1 ], "end": [ 61, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.infixl", "code": "def Β«infixlΒ» := leading_parser \"infixl\"", "start": [ 62, 1 ], "end": [ 62, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.infixr", "code": "def Β«infixrΒ» := leading_parser \"infixr\"", "start": [ 63, 1 ], "end": [ 63, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.postfix", "code": "def Β«postfixΒ» := leading_parser \"postfix\"", "start": [ 64, 1 ], "end": [ 64, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.mixfixKind", "code": "def mixfixKind := Β«prefixΒ» <|> Β«infixΒ» <|> Β«infixlΒ» <|> Β«infixrΒ» <|> Β«postfixΒ»", "start": [ 65, 1 ], "end": [ 65, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.mixfix", "code": "@[builtin_command_parser] def Β«mixfixΒ» := leading_parser\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >> mixfixKind >>\n precedence >> optNamedName >> optNamedPrio >> ppSpace >> strLit >> darrow >> termParser", "start": [ 66, 1 ], "end": [ 68, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.identPrec", "code": "def identPrec := leading_parser ident >> optPrecedence", "start": [ 71, 1 ], "end": [ 71, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.optKind", "code": "def optKind : Parser := optional (\" (\" >> nonReservedSymbol \"kind\" >> \":=\" >> ident >> \")\")", "start": [ 73, 1 ], "end": [ 73, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.notationItem", "code": "def notationItem := ppSpace >> withAntiquot (mkAntiquot \"notationItem\" decl_name%) (strLit <|> identPrec)", "start": [ 75, 1 ], "end": [ 75, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.notation", "code": "@[builtin_command_parser] def Β«notationΒ» := leading_parser\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >>\n \"notation\" >> optPrecedence >> optNamedName >> optNamedPrio >> many notationItem >> darrow >> termParser", "start": [ 76, 1 ], "end": [ 78, 107 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.macro_rules", "code": "@[builtin_command_parser] def Β«macro_rulesΒ» := suppressInsideQuot <| leading_parser\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >>\n \"macro_rules\" >> optKind >> Term.matchAlts", "start": [ 79, 1 ], "end": [ 81, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.syntax", "code": "@[builtin_command_parser] def Β«syntaxΒ» := leading_parser\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >>\n \"syntax \" >> optPrecedence >> optNamedName >> optNamedPrio >> many1 (ppSpace >> syntaxParser argPrec) >> \" : \" >> ident", "start": [ 82, 1 ], "end": [ 84, 122 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.syntaxAbbrev", "code": "@[builtin_command_parser] def syntaxAbbrev := leading_parser\n optional docComment >> \"syntax \" >> ident >> \" := \" >> many1 syntaxParser", "start": [ 85, 1 ], "end": [ 86, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.catBehaviorBoth", "code": "def catBehaviorBoth := leading_parser nonReservedSymbol \"both\"", "start": [ 87, 1 ], "end": [ 87, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.catBehaviorSymbol", "code": "def catBehaviorSymbol := leading_parser nonReservedSymbol \"symbol\"", "start": [ 88, 1 ], "end": [ 88, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.catBehavior", "code": "def catBehavior := optional (\" (\" >> nonReservedSymbol \"behavior\" >> \" := \" >> (catBehaviorBoth <|> catBehaviorSymbol) >> \")\")", "start": [ 89, 1 ], "end": [ 89, 127 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.syntaxCat", "code": "@[builtin_command_parser] def syntaxCat := leading_parser\n optional docComment >> \"declare_syntax_cat \" >> ident >> catBehavior", "start": [ 90, 1 ], "end": [ 91, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.macroArg", "code": "def macroArg := leading_parser\n optional (atomic (ident >> checkNoWsBefore \"no space before ':'\" >> \":\")) >> syntaxParser argPrec", "start": [ 92, 1 ], "end": [ 93, 100 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.macroRhs", "code": "def macroRhs : Parser := leading_parser withPosition termParser", "start": [ 94, 1 ], "end": [ 94, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.macroTail", "code": "def macroTail := leading_parser atomic (\" : \" >> ident) >> darrow >> macroRhs", "start": [ 95, 1 ], "end": [ 95, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.macro", "code": "@[builtin_command_parser] def Β«macroΒ» := leading_parser suppressInsideQuot <|\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >>\n \"macro\" >> optPrecedence >> optNamedName >> optNamedPrio >> many1 (ppSpace >> macroArg) >> macroTail", "start": [ 96, 1 ], "end": [ 98, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.elab_rules", "code": "@[builtin_command_parser] def Β«elab_rulesΒ» := leading_parser suppressInsideQuot <|\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >>\n \"elab_rules\" >> optKind >> optional (\" : \" >> ident) >> optional (\" <= \" >> ident) >> Term.matchAlts", "start": [ 99, 1 ], "end": [ 101, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.elabArg", "code": "def elabArg := macroArg", "start": [ 102, 1 ], "end": [ 102, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.elabTail", "code": "def elabTail := leading_parser atomic (\" : \" >> ident >> optional (\" <= \" >> ident)) >> darrow >> withPosition termParser", "start": [ 103, 1 ], "end": [ 103, 122 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.elab", "code": "@[builtin_command_parser] def Β«elabΒ» := leading_parser suppressInsideQuot <|\n optional docComment >> optional Term.Β«attributesΒ» >> Term.attrKind >>\n \"elab\" >> optPrecedence >> optNamedName >> optNamedPrio >> many1 (ppSpace >> elabArg) >> elabTail", "start": [ 104, 1 ], "end": [ 106, 100 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Parser.Command.binderPredicate", "code": "@[builtin_command_parser] def binderPredicate := leading_parser\n optional docComment >> optional Term.attributes >> optional Term.attrKind >>\n \"binder_predicate\" >> optNamedName >> optNamedPrio >> ppSpace >> ident >> many (ppSpace >> macroArg) >> \" => \" >> termParser", "start": [ 108, 1 ], "end": [ 116, 128 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Term.lean
[ ".lake/packages/lean4/src/lean/Lean/Elab/Config.lean", ".lake/packages/lean4/src/lean/Lean/ReservedNameAction.lean", ".lake/packages/lean4/src/lean/Lean/Elab/Level.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Coe.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean", ".lake/packages/lean4/src/lean/Lean/Elab/DeclModifiers.lean", ".lake/packages/lean4/src/lean/Lean/Elab/PreDefinition/WF/TerminationHint.lean", ".lake/packages/lean4/src/lean/Lean/Linter/Deprecated.lean", ".lake/packages/lean4/src/lean/Lean/Language/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Meta/CollectMVars.lean" ]
[ { "full_name": "Lean.Elab.Term.SavedContext", "code": "structure SavedContext where\n declName? : Option Name\n options : Options\n openDecls : List OpenDecl\n macroStack : MacroStack\n errToSorry : Bool\n levelNames : List Name", "start": [ 22, 1 ], "end": [ 29, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.SyntheticMVarKind", "code": "inductive SyntheticMVarKind where\n \n | typeClass (extraErrorMsg? : Option MessageData)\n \n | coe (header? : Option String) (expectedType : Expr) (e : Expr) (f? : Option Expr)\n \n | tactic (tacticCode : Syntax) (ctx : SavedContext)\n \n | postponed (ctx : SavedContext)\n deriving Inhabited", "start": [ 31, 1 ], "end": [ 48, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.extraMsgToMsg", "code": "def extraMsgToMsg (extraErrorMsg? : Option MessageData) : MessageData :=\n if let some msg := extraErrorMsg? then m!\"\\n{msg}\" else .nil", "start": [ 50, 1 ], "end": [ 54, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.SyntheticMVarDecl", "code": "structure SyntheticMVarDecl where\n stx : Syntax\n kind : SyntheticMVarKind\n deriving Inhabited", "start": [ 63, 1 ], "end": [ 66, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.MVarErrorKind", "code": "inductive MVarErrorKind where\n \n | implicitArg (ctx : Expr)\n \n | hole\n \n | custom (msgData : MessageData)\n deriving Inhabited", "start": [ 68, 1 ], "end": [ 79, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.MVarErrorInfo", "code": "structure MVarErrorInfo where\n mvarId : MVarId\n ref : Syntax\n kind : MVarErrorKind\n deriving Inhabited", "start": [ 87, 1 ], "end": [ 94, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.LetRecToLift", "code": "structure LetRecToLift where\n ref : Syntax\n fvarId : FVarId\n attrs : Array Attribute\n shortDeclName : Name\n declName : Name\n lctx : LocalContext\n localInstances : LocalInstances\n type : Expr\n val : Expr\n mvarId : MVarId\n termination : WF.TerminationHints\n deriving Inhabited", "start": [ 96, 1 ], "end": [ 112, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.State", "code": "structure State where\n levelNames : List Name := []\n syntheticMVars : MVarIdMap SyntheticMVarDecl := {}\n pendingMVars : List MVarId := {}\n \n mvarErrorInfos : List MVarErrorInfo := []\n \n mvarArgNames : MVarIdMap Name := {}\n letRecsToLift : List LetRecToLift := []\n deriving Inhabited", "start": [ 114, 1 ], "end": [ 136, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.SavedState", "code": "structure SavedState where\n meta : Meta.SavedState\n Β«elabΒ» : State\n deriving Nonempty", "start": [ 138, 1 ], "end": [ 144, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.State", "code": "structure State where\n goals : List MVarId\n deriving Inhabited", "start": [ 150, 1 ], "end": [ 155, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.Snapshot", "code": "structure Snapshot where\n core : Core.State\n meta : Meta.State\n term : Term.State\n tactic : Tactic.State\n stx : Syntax", "start": [ 157, 1 ], "end": [ 168, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.CacheKey", "code": "structure CacheKey where\n mvarId : MVarId pos : String.Pos\n deriving BEq, Hashable, Inhabited", "start": [ 170, 1 ], "end": [ 176, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.Cache", "code": "structure Cache where\n pre : PHashMap CacheKey Snapshot := {}\n post : PHashMap CacheKey Snapshot := {}\n deriving Inhabited", "start": [ 178, 1 ], "end": [ 184, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.SavedState", "code": "structure SavedState where\n term : Term.SavedState\n tactic : State", "start": [ 189, 1 ], "end": [ 191, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticFinished", "code": "structure TacticFinished where\n \n state? : Option SavedState\nderiving Inhabited", "start": [ 193, 1 ], "end": [ 197, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticParsedSnapshotData", "code": "structure TacticParsedSnapshotData extends Language.Snapshot where\n \n stx : Syntax\n \n finished : Task TacticFinished\nderiving Inhabited", "start": [ 199, 1 ], "end": [ 205, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticParsedSnapshot", "code": "inductive TacticParsedSnapshot where\n | mk (data : TacticParsedSnapshotData) (next : Array (SnapshotTask TacticParsedSnapshot))\nderiving Inhabited", "start": [ 207, 1 ], "end": [ 210, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticParsedSnapshot.data", "code": "abbrev TacticParsedSnapshot.data : TacticParsedSnapshot β†’ TacticParsedSnapshotData\n | .mk data _ => data", "start": [ 211, 1 ], "end": [ 212, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticParsedSnapshot.next", "code": "abbrev TacticParsedSnapshot.next : TacticParsedSnapshot β†’ Array (SnapshotTask TacticParsedSnapshot)\n | .mk _ next => next", "start": [ 213, 1 ], "end": [ 216, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.Context", "code": "structure Context where\n declName? : Option Name := none\n \n auxDeclToFullName : FVarIdMap Name := {}\n macroStack : MacroStack := []\n \n mayPostpone : Bool := true\n \n errToSorry : Bool := true\n \n autoBoundImplicit : Bool := false\n autoBoundImplicits : PArray Expr := {}\n \n autoBoundImplicitForbidden : Name β†’ Bool := fun _ => false\n \n sectionVars : NameMap Name := {}\n \n sectionFVars : NameMap Expr := {}\n \n implicitLambda : Bool := true\n \n heedElabAsElim : Bool := true\n \n isNoncomputableSection : Bool := false\n \n ignoreTCFailures : Bool := false\n \n inPattern : Bool := false\n \n tacticCache? : Option (IO.Ref Tactic.Cache) := none\n \n tacSnap? : Option (Language.SnapshotBundle Tactic.TacticParsedSnapshot) := none\n \n saveRecAppSyntax : Bool := true\n \n holesAsSyntheticOpaque : Bool := false", "start": [ 226, 1 ], "end": [ 299, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.TermElabM", "code": "abbrev TermElabM := ReaderT Context $ StateRefT State MetaM", "start": [ 301, 1 ], "end": [ 301, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.TermElab", "code": "abbrev TermElab := Syntax β†’ Option Expr β†’ TermElabM Expr", "start": [ 302, 1 ], "end": [ 302, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.saveState", "code": "protected def saveState : TermElabM SavedState :=\n return { meta := (← Meta.saveState), Β«elabΒ» := (← get) }", "start": [ 318, 1 ], "end": [ 319, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.SavedState.restore", "code": "def SavedState.restore (s : SavedState) (restoreInfo : Bool := false) : TermElabM Unit := do\n let traceState ← getTraceState let infoState ← getInfoState s.meta.restore\n set s.elab\n setTraceState traceState\n unless restoreInfo do\n setInfoState infoState", "start": [ 321, 1 ], "end": [ 328, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withRestoreOrSaveFull", "code": "@[specialize, inherit_doc Core.withRestoreOrSaveFull]\ndef withRestoreOrSaveFull (reusableResult? : Option (Ξ± Γ— SavedState)) (act : TermElabM Ξ±) :\n TermElabM (Ξ± Γ— SavedState) := do\n if let some (_, state) := reusableResult? then\n set state.elab\n let reusableResult? := reusableResult?.map (fun (val, state) => (val, state.meta))\n let (a, meta) ← controlAt MetaM fun runInBase => do\n Meta.withRestoreOrSaveFull reusableResult? <| runInBase act\n return (a, { meta, Β«elabΒ» := (← get) })", "start": [ 330, 1 ], "end": [ 338, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withNarrowedTacticReuse", "code": "def withNarrowedTacticReuse [Monad m] [MonadWithReaderOf Context m]\n [MonadOptions m] [MonadRef m] (split : Syntax β†’ Syntax Γ— Syntax) (act : Syntax β†’ m Ξ±)\n (stx : Syntax) : m Ξ± := do\n let (outer, inner) := split stx\n let opts ← getOptions\n withTheReader Term.Context (fun ctx => { ctx with tacSnap? := ctx.tacSnap?.map fun tacSnap =>\n { tacSnap with old? := tacSnap.old?.bind fun old => do\n let (oldOuter, oldInner) := split old.stx\n guard <| outer.eqWithInfoAndTraceReuse opts oldOuter\n return { old with stx := oldInner }\n }\n }) do\n withRef inner do\n act inner", "start": [ 344, 1 ], "end": [ 369, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withNarrowedArgTacticReuse", "code": "def withNarrowedArgTacticReuse [Monad m] [MonadWithReaderOf Context m]\n [MonadOptions m] [MonadRef m] (argIdx : Nat) (act : Syntax β†’ m Ξ±) (stx : Syntax) : m Ξ± :=\n withNarrowedTacticReuse (fun stx => (mkNullNode stx.getArgs[:argIdx], stx[argIdx])) act stx", "start": [ 371, 1 ], "end": [ 382, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutTacticIncrementality", "code": "def withoutTacticIncrementality [Monad m] [MonadWithReaderOf Context m] [MonadOptions m]\n (cond : Bool) (act : m Ξ±) : m Ξ± := do\n let opts ← getOptions\n withTheReader Term.Context (fun ctx => { ctx with tacSnap? := ctx.tacSnap?.filter fun tacSnap => Id.run do\n if let some old := tacSnap.old? then\n if cond && opts.getBool `trace.Elab.reuse then\n dbg_trace \"reuse stopped: guard failed at {old.stx}\"\n return !cond\n }) act", "start": [ 384, 1 ], "end": [ 398, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutTacticReuse", "code": "def withoutTacticReuse [Monad m] [MonadWithReaderOf Context m] [MonadOptions m]\n (cond : Bool) (act : m Ξ±) : m Ξ± := do\n let opts ← getOptions\n withTheReader Term.Context (fun ctx => { ctx with tacSnap? := ctx.tacSnap?.map fun tacSnap =>\n { tacSnap with old? := tacSnap.old?.filter fun old => Id.run do\n if cond && opts.getBool `trace.Elab.reuse then\n dbg_trace \"reuse stopped: guard failed at {old.stx}\"\n return !cond }\n }) act", "start": [ 400, 1 ], "end": [ 409, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.TermElabResult", "code": "abbrev TermElabResult (Ξ± : Type) := EStateM.Result Exception SavedState Ξ±", "start": [ 411, 1 ], "end": [ 411, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.observing", "code": "def observing (x : TermElabM Ξ±) : TermElabM (TermElabResult Ξ±) := do\n let s ← saveState\n try\n let e ← x\n let sNew ← saveState\n s.restore (restoreInfo := true)\n return EStateM.Result.ok e sNew\n catch\n | ex@(.error ..) =>\n let sNew ← saveState\n s.restore (restoreInfo := true)\n return .error ex sNew\n | ex@(.internal id _) =>\n if id == postponeExceptionId then\n s.restore (restoreInfo := true)\n throw ex", "start": [ 413, 1 ], "end": [ 435, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.applyResult", "code": "def applyResult (result : TermElabResult Ξ±) : TermElabM Ξ± := do\n match result with\n | .ok a r => r.restore (restoreInfo := true); return a\n | .error ex r => r.restore (restoreInfo := true); throw ex", "start": [ 437, 1 ], "end": [ 443, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.commitIfDidNotPostpone", "code": "def commitIfDidNotPostpone (x : TermElabM Ξ±) : TermElabM Ξ± := do\n let r ← observing x\n applyResult r", "start": [ 445, 1 ], "end": [ 452, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.getLevelNames", "code": "def getLevelNames : TermElabM (List Name) :=\n return (← get).levelNames", "start": [ 454, 1 ], "end": [ 458, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.getFVarLocalDecl!", "code": "def getFVarLocalDecl! (fvar : Expr) : TermElabM LocalDecl := do\n match (← getLCtx).find? fvar.fvarId! with\n | some d => pure d\n | none => unreachable!", "start": [ 460, 1 ], "end": [ 467, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutSavingRecAppSyntax", "code": "def withoutSavingRecAppSyntax (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withReader (fun ctx => { ctx with saveRecAppSyntax := false }) x", "start": [ 477, 1 ], "end": [ 481, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkTermElabAttributeUnsafe", "code": "unsafe def mkTermElabAttributeUnsafe (ref : Name) : IO (KeyedDeclsAttribute TermElab) :=\n mkElabAttribute TermElab `builtin_term_elab `term_elab `Lean.Parser.Term `Lean.Elab.Term.TermElab \"term\" ref", "start": [ 483, 1 ], "end": [ 484, 111 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkTermElabAttribute", "code": "@[implemented_by mkTermElabAttributeUnsafe]\nopaque mkTermElabAttribute (ref : Name) : IO (KeyedDeclsAttribute TermElab)", "start": [ 486, 1 ], "end": [ 487, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.LVal", "code": "inductive LVal where\n | fieldIdx (ref : Syntax) (i : Nat)\n \n | fieldName (ref : Syntax) (name : String) (suffix? : Option Name) (fullRef : Syntax)", "start": [ 491, 1 ], "end": [ 501, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.LVal.getRef", "code": "def LVal.getRef : LVal β†’ Syntax\n | .fieldIdx ref _ => ref\n | .fieldName ref .. => ref", "start": [ 503, 1 ], "end": [ 505, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.LVal.isFieldName", "code": "def LVal.isFieldName : LVal β†’ Bool\n | .fieldName .. => true\n | _ => false", "start": [ 507, 1 ], "end": [ 509, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.getDeclName?", "code": "def getDeclName? : TermElabM (Option Name) := return (← read).declName?", "start": [ 516, 1 ], "end": [ 517, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.getLetRecsToLift", "code": "def getLetRecsToLift : TermElabM (List LetRecToLift) := return (← get).letRecsToLift", "start": [ 518, 1 ], "end": [ 519, 85 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.getMVarDecl", "code": "def getMVarDecl (mvarId : MVarId) : TermElabM MetavarDecl := return (← getMCtx).getDecl mvarId", "start": [ 520, 1 ], "end": [ 521, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withDeclName", "code": "def withDeclName (name : Name) (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withReader (fun ctx => { ctx with declName? := name }) <| withSaveParentDeclInfoContext x", "start": [ 526, 1 ], "end": [ 528, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.setLevelNames", "code": "def setLevelNames (levelNames : List Name) : TermElabM Unit :=\n modify fun s => { s with levelNames := levelNames }", "start": [ 530, 1 ], "end": [ 532, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withLevelNames", "code": "def withLevelNames (levelNames : List Name) (x : TermElabM Ξ±) : TermElabM Ξ± := do\n let levelNamesSaved ← getLevelNames\n setLevelNames levelNames\n try x finally setLevelNames levelNamesSaved", "start": [ 534, 1 ], "end": [ 538, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withAuxDecl", "code": "def withAuxDecl (shortDeclName : Name) (type : Expr) (declName : Name) (k : Expr β†’ TermElabM Ξ±) : TermElabM Ξ± :=\n withLocalDecl shortDeclName .default (kind := .auxDecl) type fun x =>\n withReader (fun ctx => { ctx with auxDeclToFullName := ctx.auxDeclToFullName.insert x.fvarId! declName }) do\n k x", "start": [ 540, 1 ], "end": [ 547, 10 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutErrToSorryImp", "code": "def withoutErrToSorryImp (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withReader (fun ctx => { ctx with errToSorry := false }) x", "start": [ 549, 1 ], "end": [ 550, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutErrToSorry", "code": "def withoutErrToSorry [MonadFunctorT TermElabM m] : m Ξ± β†’ m Ξ± :=\n monadMap (m := TermElabM) withoutErrToSorryImp", "start": [ 552, 1 ], "end": [ 557, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutHeedElabAsElimImp", "code": "def withoutHeedElabAsElimImp (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withReader (fun ctx => { ctx with heedElabAsElim := false }) x", "start": [ 559, 1 ], "end": [ 560, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutHeedElabAsElim", "code": "def withoutHeedElabAsElim [MonadFunctorT TermElabM m] : m Ξ± β†’ m Ξ± :=\n monadMap (m := TermElabM) withoutHeedElabAsElimImp", "start": [ 562, 1 ], "end": [ 568, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutModifyingElabMetaStateWithInfo", "code": "def withoutModifyingElabMetaStateWithInfo (x : TermElabM Ξ±) : TermElabM Ξ± := do\n let s ← get\n let sMeta ← getThe Meta.State\n try\n withSaveInfoContext x\n finally\n set s\n set sMeta", "start": [ 570, 1 ], "end": [ 584, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutModifyingStateWithInfoAndMessagesImpl", "code": "private def withoutModifyingStateWithInfoAndMessagesImpl (x : TermElabM Ξ±) : TermElabM Ξ± := do\n let saved ← saveState\n try\n withSaveInfoContext x\n finally\n let saved := { saved with meta.core.infoState := (← getInfoState), meta.core.messages := (← getThe Core.State).messages }\n restoreState saved", "start": [ 586, 1 ], "end": [ 595, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.throwErrorIfErrors", "code": "def throwErrorIfErrors : TermElabM Unit := do\n if (← MonadLog.hasErrors) then\n throwError \"Error(s)\"", "start": [ 597, 1 ], "end": [ 600, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.traceAtCmdPos", "code": "def traceAtCmdPos (cls : Name) (msg : Unit β†’ MessageData) : TermElabM Unit :=\n withRef Syntax.missing <| trace cls msg", "start": [ 602, 1 ], "end": [ 603, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.ppGoal", "code": "def ppGoal (mvarId : MVarId) : TermElabM Format :=\n Meta.ppGoal mvarId", "start": [ 605, 1 ], "end": [ 606, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.liftLevelM", "code": "def liftLevelM (x : LevelElabM Ξ±) : TermElabM Ξ± := do\n let ctx ← read\n let mctx ← getMCtx\n let ngen ← getNGen\n let lvlCtx : Level.Context := { options := (← getOptions), ref := (← getRef), autoBoundImplicit := ctx.autoBoundImplicit }\n match (x lvlCtx).run { ngen := ngen, mctx := mctx, levelNames := (← getLevelNames) } with\n | .ok a newS => setMCtx newS.mctx; setNGen newS.ngen; setLevelNames newS.levelNames; pure a\n | .error ex _ => throw ex", "start": [ 610, 1 ], "end": [ 617, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabLevel", "code": "def elabLevel (stx : Syntax) : TermElabM Level :=\n liftLevelM <| Level.elabLevel stx", "start": [ 619, 1 ], "end": [ 620, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withPushMacroExpansionStack", "code": "def withPushMacroExpansionStack (beforeStx afterStx : Syntax) (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withReader (fun ctx => { ctx with macroStack := { before := beforeStx, after := afterStx } :: ctx.macroStack }) x", "start": [ 622, 1 ], "end": [ 624, 116 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withMacroExpansion", "code": "def withMacroExpansion (beforeStx afterStx : Syntax) (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withMacroExpansionInfo beforeStx afterStx do\n withPushMacroExpansionStack beforeStx afterStx x", "start": [ 626, 1 ], "end": [ 629, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerSyntheticMVar", "code": "def registerSyntheticMVar (stx : Syntax) (mvarId : MVarId) (kind : SyntheticMVarKind) : TermElabM Unit := do\n modify fun s => { s with syntheticMVars := s.syntheticMVars.insert mvarId { stx, kind }, pendingMVars := mvarId :: s.pendingMVars }", "start": [ 631, 1 ], "end": [ 635, 134 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerSyntheticMVarWithCurrRef", "code": "def registerSyntheticMVarWithCurrRef (mvarId : MVarId) (kind : SyntheticMVarKind) : TermElabM Unit := do\n registerSyntheticMVar (← getRef) mvarId kind", "start": [ 637, 1 ], "end": [ 638, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerMVarErrorInfo", "code": "def registerMVarErrorInfo (mvarErrorInfo : MVarErrorInfo) : TermElabM Unit :=\n modify fun s => { s with mvarErrorInfos := mvarErrorInfo :: s.mvarErrorInfos }", "start": [ 640, 1 ], "end": [ 641, 81 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerMVarErrorHoleInfo", "code": "def registerMVarErrorHoleInfo (mvarId : MVarId) (ref : Syntax) : TermElabM Unit :=\n registerMVarErrorInfo { mvarId, ref, kind := .hole }", "start": [ 643, 1 ], "end": [ 644, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerMVarErrorImplicitArgInfo", "code": "def registerMVarErrorImplicitArgInfo (mvarId : MVarId) (ref : Syntax) (app : Expr) : TermElabM Unit := do\n registerMVarErrorInfo { mvarId, ref, kind := .implicitArg app }", "start": [ 646, 1 ], "end": [ 647, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerMVarErrorCustomInfo", "code": "def registerMVarErrorCustomInfo (mvarId : MVarId) (ref : Syntax) (msgData : MessageData) : TermElabM Unit := do\n registerMVarErrorInfo { mvarId, ref, kind := .custom msgData }", "start": [ 649, 1 ], "end": [ 650, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerCustomErrorIfMVar", "code": "def registerCustomErrorIfMVar (e : Expr) (ref : Syntax) (msgData : MessageData) : TermElabM Unit :=\n match e.getAppFn with\n | Expr.mvar mvarId => registerMVarErrorCustomInfo mvarId ref msgData\n | _ => pure ()", "start": [ 652, 1 ], "end": [ 655, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.registerMVarArgName", "code": "def registerMVarArgName (mvarId : MVarId) (argName : Name) : TermElabM Unit :=\n modify fun s => { s with mvarArgNames := s.mvarArgNames.insert mvarId argName }", "start": [ 657, 1 ], "end": [ 658, 82 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.throwMVarError", "code": "def throwMVarError (m : MessageData) : TermElabM Ξ± := do\n if (← MonadLog.hasErrors) then\n throwAbortTerm\n else\n throwError m", "start": [ 660, 1 ], "end": [ 669, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.MVarErrorInfo.logError", "code": "def MVarErrorInfo.logError (mvarErrorInfo : MVarErrorInfo) (extraMsg? : Option MessageData) : TermElabM Unit := do\n match mvarErrorInfo.kind with\n | MVarErrorKind.implicitArg app => do\n let app ← instantiateMVars app\n let msg ← addArgName \"don't know how to synthesize implicit argument\"\n let msg := msg ++ m!\"{indentExpr app.setAppPPExplicitForExposingMVars}\" ++ Format.line ++ \"context:\" ++ Format.line ++ MessageData.ofGoal mvarErrorInfo.mvarId\n logErrorAt mvarErrorInfo.ref (appendExtra msg)\n | MVarErrorKind.hole => do\n let msg ← addArgName \"don't know how to synthesize placeholder\" \" for argument\"\n let msg := msg ++ Format.line ++ \"context:\" ++ Format.line ++ MessageData.ofGoal mvarErrorInfo.mvarId\n logErrorAt mvarErrorInfo.ref (MessageData.tagged `Elab.synthPlaceholder <| appendExtra msg)\n | MVarErrorKind.custom msg =>\n logErrorAt mvarErrorInfo.ref (appendExtra msg)\nwhere\n \n addArgName (msg : MessageData) (extra : String := \"\") : TermElabM MessageData := do\n match (← get).mvarArgNames.find? mvarErrorInfo.mvarId with\n | none => return msg\n | some argName => return if argName.hasMacroScopes then msg else msg ++ extra ++ m!\" '{argName}'\"\n\n appendExtra (msg : MessageData) : MessageData :=\n match extraMsg? with\n | none => msg\n | some extraMsg => msg ++ extraMsg", "start": [ 671, 1 ], "end": [ 695, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.logUnassignedUsingErrorInfos", "code": "def logUnassignedUsingErrorInfos (pendingMVarIds : Array MVarId) (extraMsg? : Option MessageData := none) : TermElabM Bool := do\n if pendingMVarIds.isEmpty then\n return false\n else\n let hasOtherErrors ← MonadLog.hasErrors\n let mut hasNewErrors := false\n let mut alreadyVisited : MVarIdSet := {}\n let mut errors : Array MVarErrorInfo := #[]\n for mvarErrorInfo in (← get).mvarErrorInfos do\n let mvarId := mvarErrorInfo.mvarId\n unless alreadyVisited.contains mvarId do\n alreadyVisited := alreadyVisited.insert mvarId\n \n let mvarDeps ← getMVars (mkMVar mvarId)\n if mvarDeps.any pendingMVarIds.contains then do\n unless hasOtherErrors do\n errors := errors.push mvarErrorInfo\n hasNewErrors := true\n for error in errors do\n error.mvarId.withContext do\n error.logError extraMsg?\n return hasNewErrors", "start": [ 697, 1 ], "end": [ 728, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.ensureNoUnassignedMVars", "code": "def ensureNoUnassignedMVars (decl : Declaration) : TermElabM Unit := do\n let pendingMVarIds ← getMVarsAtDecl decl\n if (← logUnassignedUsingErrorInfos pendingMVarIds) then\n throwAbortCommand", "start": [ 730, 1 ], "end": [ 734, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutPostponing", "code": "def withoutPostponing (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withReader (fun ctx => { ctx with mayPostpone := false }) x", "start": [ 736, 1 ], "end": [ 740, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkExplicitBinder", "code": "def mkExplicitBinder (ident : Syntax) (type : Syntax) : Syntax :=\n mkNode ``Lean.Parser.Term.explicitBinder #[mkAtom \"(\", mkNullNode #[ident], mkNullNode #[mkAtom \":\", type], mkNullNode, mkAtom \")\"]", "start": [ 742, 1 ], "end": [ 744, 134 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.levelMVarToParam", "code": "def levelMVarToParam (e : Expr) (except : LMVarId β†’ Bool := fun _ => false) : TermElabM Expr := do\n let levelNames ← getLevelNames\n let r := (← getMCtx).levelMVarToParam (fun n => levelNames.elem n) except e `u 1\n setLevelNames (r.newParamNames.reverse.toList ++ levelNames)\n setMCtx r.mctx\n return r.expr", "start": [ 746, 1 ], "end": [ 755, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkFreshBinderName", "code": "def mkFreshBinderName [Monad m] [MonadQuotation m] : m Name :=\n withFreshMacroScope <| MonadQuotation.addMacroScope `x", "start": [ 757, 1 ], "end": [ 761, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkFreshIdent", "code": "def mkFreshIdent [Monad m] [MonadQuotation m] (ref : Syntax) (canonical := false) : m Ident :=\n return mkIdentFrom ref (← mkFreshBinderName) canonical", "start": [ 763, 1 ], "end": [ 768, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.applyAttributesCore", "code": "private def applyAttributesCore\n (declName : Name) (attrs : Array Attribute)\n (applicationTime? : Option AttributeApplicationTime) : TermElabM Unit := do profileitM Exception \"attribute application\" (← getOptions) do\n \n unless declName == .anonymous do\n for attr in attrs do\n withRef attr.stx do withLogging do\n let env ← getEnv\n match getAttributeImpl env attr.name with\n | Except.error errMsg => throwError errMsg\n | Except.ok attrImpl =>\n let runAttr := attrImpl.add declName attr.stx attr.kind\n let runAttr := do\n let elaborator := attrImpl.ref\n if (← getInfoState).enabled && (← getEnv).contains elaborator then\n withInfoContext (mkInfo := return .ofCommandInfo { elaborator, stx := attr.stx }) do\n try runAttr\n finally if attr.stx[0].isIdent || attr.stx[0].isAtom then\n pushInfoLeaf <| .ofCommandInfo { elaborator, stx := attr.stx[0] }\n else\n runAttr\n match applicationTime? with\n | none => runAttr\n | some applicationTime =>\n if applicationTime == attrImpl.applicationTime then\n runAttr", "start": [ 770, 1 ], "end": [ 801, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.applyAttributesAt", "code": "def applyAttributesAt (declName : Name) (attrs : Array Attribute) (applicationTime : AttributeApplicationTime) : TermElabM Unit :=\n applyAttributesCore declName attrs applicationTime", "start": [ 803, 1 ], "end": [ 805, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.applyAttributes", "code": "def applyAttributes (declName : Name) (attrs : Array Attribute) : TermElabM Unit :=\n applyAttributesCore declName attrs none", "start": [ 807, 1 ], "end": [ 808, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkTypeMismatchError", "code": "def mkTypeMismatchError (header? : Option String) (e : Expr) (eType : Expr) (expectedType : Expr) : TermElabM MessageData := do\n let header : MessageData := match header? with\n | some header => m!\"{header} \"\n | none => m!\"type mismatch{indentExpr e}\\n\"\n return m!\"{header}{← mkHasTypeButIsExpectedMsg eType expectedType}\"", "start": [ 810, 1 ], "end": [ 814, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.throwTypeMismatchError", "code": "def throwTypeMismatchError (header? : Option String) (expectedType : Expr) (eType : Expr) (e : Expr)\n (f? : Option Expr := none) (_extraMsg? : Option MessageData := none) : TermElabM Ξ± := do\n \n let extraMsg := Format.nil\n \n match f? with\n | none => throwError \"{← mkTypeMismatchError header? e eType expectedType}{extraMsg}\"\n | some f => Meta.throwAppTypeMismatch f e", "start": [ 816, 1 ], "end": [ 835, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutMacroStackAtErr", "code": "def withoutMacroStackAtErr (x : TermElabM Ξ±) : TermElabM Ξ± :=\n withTheReader Core.Context (fun (ctx : Core.Context) => { ctx with options := pp.macroStack.set ctx.options false }) x", "start": [ 837, 1 ], "end": [ 838, 121 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.ContainsPendingMVar.M", "code": "abbrev M := MonadCacheT Expr Unit (OptionT MetaM)", "start": [ 842, 1 ], "end": [ 842, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.ContainsPendingMVar.visit", "code": "partial def visit (e : Expr) : M Unit := do\n checkCache e fun _ => do\n match e with\n | .forallE _ d b _ => visit d; visit b\n | .lam _ d b _ => visit d; visit b\n | .letE _ t v b _ => visit t; visit v; visit b\n | .app f a => visit f; visit a\n | .mdata _ b => visit b\n | .proj _ _ b => visit b\n | .fvar fvarId .. =>\n match (← fvarId.getDecl) with\n | .cdecl .. => return ()\n | .ldecl (value := v) .. => visit v\n | .mvar mvarId .. =>\n let e' ← instantiateMVars e\n if e' != e then\n visit e'\n else\n match (← getDelayedMVarAssignment? mvarId) with\n | some d => visit (mkMVar d.mvarIdPending)\n | none => failure\n | _ => return ()", "start": [ 844, 1 ], "end": [ 866, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.containsPendingMVar", "code": "def containsPendingMVar (e : Expr) : MetaM Bool := do\n match (← ContainsPendingMVar.visit e |>.run.run) with\n | some _ => return false\n | none => return true", "start": [ 870, 1 ], "end": [ 874, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.synthesizeInstMVarCore", "code": "def synthesizeInstMVarCore (instMVar : MVarId) (maxResultSize? : Option Nat := none) (extraErrorMsg? : Option MessageData := none): TermElabM Bool := do\n let extraErrorMsg := extraMsgToMsg extraErrorMsg?\n let instMVarDecl ← getMVarDecl instMVar\n let type := instMVarDecl.type\n let type ← instantiateMVars type\n let result ← trySynthInstance type maxResultSize?\n match result with\n | LOption.some val =>\n if (← instMVar.isAssigned) then\n let oldVal ← instantiateMVars (mkMVar instMVar)\n unless (← isDefEq oldVal val) do\n if (← containsPendingMVar oldVal <||> containsPendingMVar val) then\n \n return false let oldValType ← inferType oldVal\n let valType ← inferType val\n unless (← isDefEq oldValType valType) do\n throwError \"synthesized type class instance type is not definitionally equal to expected type, synthesized{indentExpr val}\\nhas type{indentExpr valType}\\nexpected{indentExpr oldValType}{extraErrorMsg}\"\n throwError \"synthesized type class instance is not definitionally equal to expression inferred by typing rules, synthesized{indentExpr val}\\ninferred{indentExpr oldVal}{extraErrorMsg}\"\n else\n unless (← isDefEq (mkMVar instMVar) val) do\n throwError \"failed to assign synthesized type class instance{indentExpr val}{extraErrorMsg}\"\n return true\n | .undef => return false | .none =>\n if (← read).ignoreTCFailures then\n return false\n else\n throwError \"failed to synthesize{indentExpr type}{extraErrorMsg}\\n{useDiagnosticMsg}\"", "start": [ 876, 1 ], "end": [ 932, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkCoe", "code": "def mkCoe (expectedType : Expr) (e : Expr) (f? : Option Expr := none) (errorMsgHeader? : Option String := none) : TermElabM Expr := do\n withTraceNode `Elab.coe (fun _ => return m!\"adding coercion for {e} : {← inferType e} =?= {expectedType}\") do\n try\n withoutMacroStackAtErr do\n match ← coerce? e expectedType with\n | .some eNew => return eNew\n | .none => failure\n | .undef =>\n let mvarAux ← mkFreshExprMVar expectedType MetavarKind.syntheticOpaque\n registerSyntheticMVarWithCurrRef mvarAux.mvarId! (.coe errorMsgHeader? expectedType e f?)\n return mvarAux\n catch\n | .error _ msg => throwTypeMismatchError errorMsgHeader? expectedType (← inferType e) e f? msg\n | _ => throwTypeMismatchError errorMsgHeader? expectedType (← inferType e) e f?", "start": [ 934, 1 ], "end": [ 947, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.ensureHasType", "code": "def ensureHasType (expectedType? : Option Expr) (e : Expr)\n (errorMsgHeader? : Option String := none) (f? : Option Expr := none) : TermElabM Expr := do\n let some expectedType := expectedType? | return e\n if (← isDefEq (← inferType e) expectedType) then\n return e\n else\n mkCoe expectedType e f? errorMsgHeader?", "start": [ 949, 1 ], "end": [ 960, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkSyntheticSorryFor", "code": "private def mkSyntheticSorryFor (expectedType? : Option Expr) : TermElabM Expr := do\n let expectedType ← match expectedType? with\n | none => mkFreshTypeMVar\n | some expectedType => pure expectedType\n mkSyntheticSorry expectedType", "start": [ 962, 1 ], "end": [ 970, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.exceptionToSorry", "code": "def exceptionToSorry (ex : Exception) (expectedType? : Option Expr) : TermElabM Expr := do\n let syntheticSorry ← mkSyntheticSorryFor expectedType?\n logException ex\n pure syntheticSorry", "start": [ 972, 1 ], "end": [ 979, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.tryPostpone", "code": "def tryPostpone : TermElabM Unit := do\n if (← read).mayPostpone then\n throwPostpone", "start": [ 981, 1 ], "end": [ 984, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isMVarApp", "code": "def isMVarApp (e : Expr) : TermElabM Bool :=\n return (← whnfR e).getAppFn.isMVar", "start": [ 986, 1 ], "end": [ 988, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.tryPostponeIfMVar", "code": "def tryPostponeIfMVar (e : Expr) : TermElabM Unit := do\n if (← isMVarApp e) then\n tryPostpone", "start": [ 990, 1 ], "end": [ 993, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.tryPostponeIfNoneOrMVar", "code": "def tryPostponeIfNoneOrMVar (e? : Option Expr) : TermElabM Unit :=\n match e? with\n | some e => tryPostponeIfMVar e\n | none => tryPostpone", "start": [ 995, 1 ], "end": [ 999, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.tryPostponeIfHasMVars?", "code": "def tryPostponeIfHasMVars? (expectedType? : Option Expr) : TermElabM (Option Expr) := do\n tryPostponeIfNoneOrMVar expectedType?\n let some expectedType := expectedType? | return none\n let expectedType ← instantiateMVars expectedType\n if expectedType.hasExprMVar then\n tryPostpone\n return none\n return some expectedType", "start": [ 1001, 1 ], "end": [ 1012, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.tryPostponeIfHasMVars", "code": "def tryPostponeIfHasMVars (expectedType? : Option Expr) (msg : String) : TermElabM Expr := do\n let some expectedType ← tryPostponeIfHasMVars? expectedType? |\n throwError \"{msg}, expected type contains metavariables{indentD expectedType?}\"\n return expectedType", "start": [ 1014, 1 ], "end": [ 1021, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withExpectedType", "code": "def withExpectedType (expectedType? : Option Expr) (x : Expr β†’ TermElabM Expr) : TermElabM Expr := do\n tryPostponeIfNoneOrMVar expectedType?\n let some expectedType ← pure expectedType?\n | throwError \"expected type must be known\"\n x expectedType", "start": [ 1023, 1 ], "end": [ 1027, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.saveContext", "code": "def saveContext : TermElabM SavedContext :=\n return {\n macroStack := (← read).macroStack\n declName? := (← read).declName?\n options := (← getOptions)\n openDecls := (← getOpenDecls)\n errToSorry := (← read).errToSorry\n levelNames := (← get).levelNames\n }", "start": [ 1029, 1 ], "end": [ 1040, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withSavedContext", "code": "def withSavedContext (savedCtx : SavedContext) (x : TermElabM Ξ±) : TermElabM Ξ± := do\n withReader (fun ctx => { ctx with declName? := savedCtx.declName?, macroStack := savedCtx.macroStack, errToSorry := savedCtx.errToSorry }) <|\n withTheReader Core.Context (fun ctx => { ctx with options := savedCtx.options, openDecls := savedCtx.openDecls }) <|\n withLevelNames savedCtx.levelNames x", "start": [ 1042, 1 ], "end": [ 1048, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.postponeElabTermCore", "code": "private def postponeElabTermCore (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do\n trace[Elab.postpone] \"{stx} : {expectedType?}\"\n let mvar ← mkFreshExprMVar expectedType? MetavarKind.syntheticOpaque\n registerSyntheticMVar stx mvar.mvarId! (SyntheticMVarKind.postponed (← saveContext))\n return mvar", "start": [ 1050, 1 ], "end": [ 1059, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.getSyntheticMVarDecl?", "code": "def getSyntheticMVarDecl? (mvarId : MVarId) : TermElabM (Option SyntheticMVarDecl) :=\n return (← get).syntheticMVars.find? mvarId", "start": [ 1061, 1 ], "end": [ 1062, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkSaveInfoAnnotation", "code": "def mkSaveInfoAnnotation (e : Expr) : Expr :=\n if e.isMVar then\n mkAnnotation `save_info e\n else\n e", "start": [ 1064, 1 ], "end": [ 1085, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isSaveInfoAnnotation?", "code": "def isSaveInfoAnnotation? (e : Expr) : Option Expr :=\n annotation? `save_info e", "start": [ 1087, 1 ], "end": [ 1088, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.removeSaveInfoAnnotation", "code": "partial def removeSaveInfoAnnotation (e : Expr) : Expr :=\n match isSaveInfoAnnotation? e with\n | some e => removeSaveInfoAnnotation e\n | _ => e", "start": [ 1090, 1 ], "end": [ 1093, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isTacticOrPostponedHole?", "code": "def isTacticOrPostponedHole? (e : Expr) : TermElabM (Option MVarId) := do\n match e with\n | Expr.mvar mvarId =>\n match (← getSyntheticMVarDecl? mvarId) with\n | some { kind := .tactic .., .. } => return mvarId\n | some { kind := .postponed .., .. } => return mvarId\n | _ => return none\n | _ => pure none", "start": [ 1095, 1 ], "end": [ 1107, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkTermInfo", "code": "def mkTermInfo (elaborator : Name) (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (isBinder := false) : TermElabM (Sum Info MVarId) := do\n match (← isTacticOrPostponedHole? e) with\n | some mvarId => return Sum.inr mvarId\n | none =>\n let e := removeSaveInfoAnnotation e\n return Sum.inl <| Info.ofTermInfo { elaborator, lctx := lctx?.getD (← getLCtx), expr := e, stx, expectedType?, isBinder }", "start": [ 1109, 1 ], "end": [ 1114, 126 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.addTermInfo", "code": "def addTermInfo (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none)\n (lctx? : Option LocalContext := none) (elaborator := Name.anonymous)\n (isBinder := false) (force := false) : TermElabM Expr := do\n if (← read).inPattern && !force then\n return mkPatternWithRef e stx\n else\n withInfoContext' (pure ()) (fun _ => mkTermInfo elaborator stx e expectedType? lctx? isBinder) |> discard\n return e", "start": [ 1116, 1 ], "end": [ 1138, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.addTermInfo'", "code": "def addTermInfo' (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (elaborator := Name.anonymous) (isBinder := false) : TermElabM Unit :=\n discard <| addTermInfo stx e expectedType? lctx? elaborator isBinder", "start": [ 1140, 1 ], "end": [ 1141, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withInfoContext'", "code": "def withInfoContext' (stx : Syntax) (x : TermElabM Expr) (mkInfo : Expr β†’ TermElabM (Sum Info MVarId)) : TermElabM Expr := do\n if (← read).inPattern then\n let e ← x\n return mkPatternWithRef e stx\n else\n Elab.withInfoContext' x mkInfo", "start": [ 1143, 1 ], "end": [ 1148, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.postponeElabTerm", "code": "def postponeElabTerm (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do\n withInfoContext' stx (mkInfo := mkTermInfo .anonymous (expectedType? := expectedType?) stx) do\n postponeElabTermCore stx expectedType?", "start": [ 1150, 1 ], "end": [ 1157, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabUsingElabFnsAux", "code": "private def elabUsingElabFnsAux (s : SavedState) (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone : Bool)\n : List (KeyedDeclsAttribute.AttributeEntry TermElab) β†’ TermElabM Expr\n | [] => do throwError \"unexpected syntax{indentD stx}\"\n | (elabFn::elabFns) =>\n try\n withInfoContext' stx (mkInfo := mkTermInfo elabFn.declName (expectedType? := expectedType?) stx)\n (try\n elabFn.value stx expectedType?\n catch ex => match ex with\n | .error .. =>\n if (← read).errToSorry then\n exceptionToSorry ex expectedType?\n else\n throw ex\n | .internal id _ =>\n if (← read).errToSorry && id == abortTermExceptionId then\n exceptionToSorry ex expectedType?\n else if id == unsupportedSyntaxExceptionId then\n throw ex else if catchExPostpone && id == postponeExceptionId then\n \n s.restore\n postponeElabTermCore stx expectedType?\n else\n throw ex)\n catch ex => match ex with\n | .internal id _ =>\n if id == unsupportedSyntaxExceptionId then\n s.restore elabUsingElabFnsAux s stx expectedType? catchExPostpone elabFns\n else\n throw ex\n | _ => throw ex", "start": [ 1159, 1 ], "end": [ 1208, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabUsingElabFns", "code": "private def elabUsingElabFns (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone : Bool) : TermElabM Expr := do\n let s ← saveState\n let k := stx.getKind\n match termElabAttribute.getEntries (← getEnv) k with\n | [] => throwError \"elaboration function for '{k}' has not been implemented{indentD stx}\"\n | elabFns => elabUsingElabFnsAux s stx expectedType? catchExPostpone elabFns", "start": [ 1210, 1 ], "end": [ 1215, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isExplicit", "code": "private def isExplicit (stx : Syntax) : Bool :=\n match stx with\n | `(@$_) => true\n | _ => false", "start": [ 1222, 1 ], "end": [ 1225, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isExplicitApp", "code": "private def isExplicitApp (stx : Syntax) : Bool :=\n stx.getKind == ``Lean.Parser.Term.app && isExplicit stx[0]", "start": [ 1227, 1 ], "end": [ 1228, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isLambdaWithImplicit", "code": "private def isLambdaWithImplicit (stx : Syntax) : Bool :=\n match stx with\n | `(fun $binders* => $_) => binders.raw.any fun b => b.isOfKind ``Lean.Parser.Term.implicitBinder || b.isOfKind `Lean.Parser.Term.instBinder\n | _ => false", "start": [ 1230, 1 ], "end": [ 1236, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.dropTermParens", "code": "private partial def dropTermParens : Syntax β†’ Syntax := fun stx =>\n match stx with\n | `(($stx)) => dropTermParens stx\n | _ => stx", "start": [ 1238, 1 ], "end": [ 1241, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isHole", "code": "private def isHole (stx : Syntax) : Bool :=\n match stx with\n | `(_) => true\n | `(? _) => true\n | `(? $_:ident) => true\n | _ => false", "start": [ 1243, 1 ], "end": [ 1248, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isTacticBlock", "code": "private def isTacticBlock (stx : Syntax) : Bool :=\n match stx with\n | `(by $_:tacticSeq) => true\n | _ => false", "start": [ 1250, 1 ], "end": [ 1253, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isNoImplicitLambda", "code": "private def isNoImplicitLambda (stx : Syntax) : Bool :=\n match stx with\n | `(no_implicit_lambda% $_:term) => true\n | _ => false", "start": [ 1255, 1 ], "end": [ 1258, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isTypeAscription", "code": "private def isTypeAscription (stx : Syntax) : Bool :=\n match stx with\n | `(($_ : $[$_]?)) => true\n | _ => false", "start": [ 1260, 1 ], "end": [ 1263, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.hasNoImplicitLambdaAnnotation", "code": "def hasNoImplicitLambdaAnnotation (type : Expr) : Bool :=\n annotation? `noImplicitLambda type |>.isSome", "start": [ 1265, 1 ], "end": [ 1266, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkNoImplicitLambdaAnnotation", "code": "def mkNoImplicitLambdaAnnotation (type : Expr) : Expr :=\n if hasNoImplicitLambdaAnnotation type then\n type\n else\n mkAnnotation `noImplicitLambda type", "start": [ 1268, 1 ], "end": [ 1272, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.blockImplicitLambda", "code": "def blockImplicitLambda (stx : Syntax) : Bool :=\n let stx := dropTermParens stx\n isExplicit stx || isExplicitApp stx || isLambdaWithImplicit stx || isHole stx || isTacticBlock stx ||\n isNoImplicitLambda stx || isTypeAscription stx", "start": [ 1274, 1 ], "end": [ 1279, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.resolveLocalName", "code": "def resolveLocalName (n : Name) : TermElabM (Option (Expr Γ— List String)) := do\n let lctx ← getLCtx\n let auxDeclToFullName := (← read).auxDeclToFullName\n let currNamespace ← getCurrNamespace\n let view := extractMacroScopes n\n \n let matchLocalDecl? (localDecl : LocalDecl) (givenName : Name) : Option LocalDecl := do\n guard (localDecl.userName == givenName)\n return localDecl\n \n let matchAuxRecDecl? (localDecl : LocalDecl) (fullDeclName : Name) (givenNameView : MacroScopesView) : Option LocalDecl := do\n let fullDeclView := extractMacroScopes fullDeclName\n \n let fullDeclView := { fullDeclView with name := (privateToUserName? fullDeclView.name).getD fullDeclView.name }\n let fullDeclName := fullDeclView.review\n let localDeclNameView := extractMacroScopes localDecl.userName\n \n if currNamespace.isPrefixOf fullDeclName then\n \n guard (localDeclNameView.isSuffixOf givenNameView)\n guard (givenNameView.isSuffixOf fullDeclView)\n return localDecl\n else\n \n let rec go (ns : Name) : Option LocalDecl := do\n if { givenNameView with name := ns ++ givenNameView.name }.review == fullDeclName then\n return localDecl\n match ns with\n | .str pre .. => go pre\n | _ => failure\n return (← go currNamespace)\n \n let findLocalDecl? (givenNameView : MacroScopesView) (skipAuxDecl : Bool) : Option LocalDecl :=\n let givenName := givenNameView.review\n let localDecl? := lctx.decls.findSomeRev? fun localDecl? => do\n let localDecl ← localDecl?\n if localDecl.isAuxDecl then\n guard (not skipAuxDecl)\n if let some fullDeclName := auxDeclToFullName.find? localDecl.fvarId then\n matchAuxRecDecl? localDecl fullDeclName givenNameView\n else\n matchLocalDecl? localDecl givenName\n else\n matchLocalDecl? localDecl givenName\n if localDecl?.isSome || skipAuxDecl then\n localDecl?\n else\n lctx.decls.findSomeRev? fun localDecl? => do\n let localDecl ← localDecl?\n guard localDecl.isAuxDecl\n matchLocalDecl? localDecl givenName\n \n let rec loop (n : Name) (projs : List String) (globalDeclFound : Bool) := do\n let givenNameView := { view with name := n }\n let mut globalDeclFoundNext := globalDeclFound\n unless globalDeclFound do\n let r ← resolveGlobalName givenNameView.review\n let r := r.filter fun (_, fieldList) => fieldList.isEmpty\n unless r.isEmpty do\n globalDeclFoundNext := true\n \n match findLocalDecl? givenNameView (skipAuxDecl := globalDeclFound && not projs.isEmpty) with\n | some decl => return some (decl.toExpr, projs)\n | none => match n with\n | .str pre s => loop pre (s::projs) globalDeclFoundNext\n | _ => return none\n loop view.name [] (globalDeclFound := false)", "start": [ 1281, 1 ], "end": [ 1442, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isLocalIdent?", "code": "def isLocalIdent? (stx : Syntax) : TermElabM (Option Expr) :=\n match stx with\n | Syntax.ident _ _ val _ => do\n let r? ← resolveLocalName val\n match r? with\n | some (fvar, []) => return some fvar\n | _ => return none\n | _ => return none", "start": [ 1444, 1 ], "end": [ 1452, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.UseImplicitLambdaResult", "code": "inductive UseImplicitLambdaResult where\n | no\n | yes (expectedType : Expr)\n | postpone", "start": [ 1454, 1 ], "end": [ 1457, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.useImplicitLambda", "code": "private def useImplicitLambda (stx : Syntax) (expectedType? : Option Expr) : TermElabM UseImplicitLambdaResult := do\n if blockImplicitLambda stx then\n return .no\n let some expectedType := expectedType? | return .no\n if hasNoImplicitLambdaAnnotation expectedType then\n return .no\n let expectedType ← whnfForall expectedType\n let .forallE _ _ _ c := expectedType | return .no\n unless c.isImplicit || c.isInstImplicit do\n return .no\n if let some x ← isLocalIdent? stx then\n if (← isMVarApp (← inferType x)) then\n \n return .postpone\n return .yes expectedType", "start": [ 1459, 1 ], "end": [ 1501, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.decorateErrorMessageWithLambdaImplicitVars", "code": "private def decorateErrorMessageWithLambdaImplicitVars (ex : Exception) (impFVars : Array Expr) : TermElabM Exception := do\n match ex with\n | .error ref msg =>\n if impFVars.isEmpty then\n return Exception.error ref msg\n else\n let mut msg := m!\"{msg}\\nthe following variables have been introduced by the implicit lambda feature\"\n for impFVar in impFVars do\n let auxMsg := m!\"{impFVar} : {← inferType impFVar}\"\n let auxMsg ← addMessageContext auxMsg\n msg := m!\"{msg}{indentD auxMsg}\"\n msg := m!\"{msg}\\nyou can disable implicit lambdas using `@` or writing a lambda expression with `\\{}` or `[]` binder annotations.\"\n return Exception.error ref msg\n | _ => return ex", "start": [ 1503, 1 ], "end": [ 1516, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabImplicitLambdaAux", "code": "private def elabImplicitLambdaAux (stx : Syntax) (catchExPostpone : Bool) (expectedType : Expr) (impFVars : Array Expr) : TermElabM Expr := do\n let body ← elabUsingElabFns stx expectedType catchExPostpone\n try\n let body ← ensureHasType expectedType body\n let r ← mkLambdaFVars impFVars body\n trace[Elab.implicitForall] r\n return r\n catch ex =>\n throw (← decorateErrorMessageWithLambdaImplicitVars ex impFVars)", "start": [ 1518, 1 ], "end": [ 1526, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabImplicitLambda", "code": "private partial def elabImplicitLambda (stx : Syntax) (catchExPostpone : Bool) (type : Expr) : TermElabM Expr :=\n loop type #[]\nwhere\n loop (type : Expr) (fvars : Array Expr) : TermElabM Expr := do\n match (← whnfForall type) with\n | .forallE n d b c =>\n if c.isExplicit then\n elabImplicitLambdaAux stx catchExPostpone type fvars\n else withFreshMacroScope do\n let n ← MonadQuotation.addMacroScope n\n withLocalDecl n c d fun fvar => do\n let type := b.instantiate1 fvar\n loop type (fvars.push fvar)\n | _ =>\n elabImplicitLambdaAux stx catchExPostpone type fvars", "start": [ 1528, 1 ], "end": [ 1542, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabTermAux", "code": "private partial def elabTermAux (expectedType? : Option Expr) (catchExPostpone : Bool) (implicitLambda : Bool) : Syntax β†’ TermElabM Expr\n | .missing => mkSyntheticSorryFor expectedType?\n | stx => withFreshMacroScope <| withIncRecDepth do\n withTraceNode `Elab.step (fun _ => return m!\"expected type: {expectedType?}, term\\n{stx}\")\n (tag := stx.getKind.toString) do\n checkSystem \"elaborator\"\n let env ← getEnv\n let result ← match (← liftMacroM (expandMacroImpl? env stx)) with\n | some (decl, stxNew?) =>\n let stxNew ← liftMacroM <| liftExcept stxNew?\n withInfoContext' stx (mkInfo := mkTermInfo decl (expectedType? := expectedType?) stx) <|\n withMacroExpansion stx stxNew <|\n withRef stxNew <|\n elabTermAux expectedType? catchExPostpone implicitLambda stxNew\n | _ =>\n let useImplicitResult ← if implicitLambda && (← read).implicitLambda then useImplicitLambda stx expectedType? else pure .no\n match useImplicitResult with\n | .yes expectedType => elabImplicitLambda stx catchExPostpone expectedType\n | .no => elabUsingElabFns stx expectedType? catchExPostpone\n | .postpone =>\n \n if (← read).mayPostpone then\n if catchExPostpone then\n postponeElabTerm stx expectedType?\n else\n throwPostpone\n else\n elabUsingElabFns stx expectedType? catchExPostpone\n trace[Elab.step.result] result\n pure result", "start": [ 1544, 1 ], "end": [ 1577, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.addDotCompletionInfo", "code": "def addDotCompletionInfo (stx : Syntax) (e : Expr) (expectedType? : Option Expr) : TermElabM Unit := do\n addCompletionInfo <| CompletionInfo.dot { expr := e, stx, lctx := (← getLCtx), elaborator := .anonymous, expectedType? } (expectedType? := expectedType?)", "start": [ 1579, 1 ], "end": [ 1581, 156 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabTerm", "code": "def elabTerm (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone := true) (implicitLambda := true) : TermElabM Expr :=\n withRef stx <| elabTermAux expectedType? catchExPostpone implicitLambda stx", "start": [ 1583, 1 ], "end": [ 1601, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabTermEnsuringType", "code": "def elabTermEnsuringType (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone := true) (implicitLambda := true) (errorMsgHeader? : Option String := none) : TermElabM Expr := do\n let e ← elabTerm stx expectedType? catchExPostpone implicitLambda\n try\n withRef stx <| ensureHasType expectedType? e errorMsgHeader?\n catch ex =>\n if (← read).errToSorry && ex matches .error .. then\n exceptionToSorry ex expectedType?\n else\n throw ex", "start": [ 1603, 1 ], "end": [ 1618, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.commitIfNoErrors?", "code": "def commitIfNoErrors? (x : TermElabM Ξ±) : TermElabM (Option Ξ±) := do\n let saved ← saveState\n Core.resetMessageLog\n try\n let a ← x\n if (← MonadLog.hasErrors) then\n restoreState saved\n return none\n else\n Core.setMessageLog (saved.meta.core.messages ++ (← Core.getMessageLog))\n return a\n catch _ =>\n restoreState saved\n return none", "start": [ 1620, 1 ], "end": [ 1634, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.adaptExpander", "code": "def adaptExpander (exp : Syntax β†’ TermElabM Syntax) : TermElab := fun stx expectedType? => do\n let stx' ← exp stx\n withMacroExpansion stx stx' <| elabTerm stx' expectedType?", "start": [ 1636, 1 ], "end": [ 1639, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkInstMVar", "code": "def mkInstMVar (type : Expr) (extraErrorMsg? : Option MessageData := none) : TermElabM Expr := do\n let mvar ← mkFreshExprMVar type MetavarKind.synthetic\n let mvarId := mvar.mvarId!\n unless (← synthesizeInstMVarCore mvarId (extraErrorMsg? := extraErrorMsg?)) do\n registerSyntheticMVarWithCurrRef mvarId (.typeClass extraErrorMsg?)\n return mvar", "start": [ 1641, 1 ], "end": [ 1651, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.ensureType", "code": "def ensureType (e : Expr) : TermElabM Expr := do\n if (← isType e) then\n return e\n else\n let eType ← inferType e\n let u ← mkFreshLevelMVar\n if (← isDefEq eType (mkSort u)) then\n return e\n else if let some coerced ← coerceToSort? e then\n return coerced\n else\n if (← instantiateMVars e).hasSyntheticSorry then\n throwAbortTerm\n throwError \"type expected, got\\n ({← instantiateMVars e} : {← instantiateMVars eType})\"", "start": [ 1653, 1 ], "end": [ 1669, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.elabType", "code": "def elabType (stx : Syntax) : TermElabM Expr := do\n let u ← mkFreshLevelMVar\n let type ← elabTerm stx (mkSort u)\n withRef stx <| ensureType type", "start": [ 1671, 1 ], "end": [ 1675, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withAutoBoundImplicit", "code": "partial def withAutoBoundImplicit (k : TermElabM Ξ±) : TermElabM Ξ± := do\n let flag := autoImplicit.get (← getOptions)\n if flag then\n withReader (fun ctx => { ctx with autoBoundImplicit := flag, autoBoundImplicits := {} }) do\n let rec loop (s : SavedState) : TermElabM Ξ± := withIncRecDepth do\n checkSystem \"auto-implicit\"\n try\n k\n catch\n | ex => match isAutoBoundImplicitLocalException? ex with\n | some n =>\n s.restore (restoreInfo := true)\n withLocalDecl n .implicit (← mkFreshTypeMVar) fun x =>\n withReader (fun ctx => { ctx with autoBoundImplicits := ctx.autoBoundImplicits.push x } ) do\n loop (← saveState)\n | none => throw ex\n loop (← saveState)\n else\n k", "start": [ 1677, 1 ], "end": [ 1699, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withoutAutoBoundImplicit", "code": "def withoutAutoBoundImplicit (k : TermElabM Ξ±) : TermElabM Ξ± := do\n withReader (fun ctx => { ctx with autoBoundImplicit := false, autoBoundImplicits := {} }) k", "start": [ 1701, 1 ], "end": [ 1702, 94 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.withAutoBoundImplicitForbiddenPred", "code": "partial def withAutoBoundImplicitForbiddenPred (p : Name β†’ Bool) (x : TermElabM Ξ±) : TermElabM Ξ± := do\n withReader (fun ctx => { ctx with autoBoundImplicitForbidden := fun n => p n || ctx.autoBoundImplicitForbidden n }) x", "start": [ 1704, 1 ], "end": [ 1705, 120 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.collectUnassignedMVars", "code": "partial def collectUnassignedMVars (type : Expr) (init : Array Expr := #[]) (except : MVarId β†’ Bool := fun _ => false)\n : TermElabM (Array Expr) := do\n let mvarIds ← getMVars type\n if mvarIds.isEmpty then\n return init\n else\n go mvarIds.toList init init\nwhere\n go (mvarIds : List MVarId) (result visited : Array Expr) : TermElabM (Array Expr) := do\n match mvarIds with\n | [] => return result\n | mvarId :: mvarIds => do\n let visited := visited.push (mkMVar mvarId)\n if (← mvarId.isAssigned) then\n go mvarIds result visited\n else if result.contains (mkMVar mvarId) || except mvarId then\n go mvarIds result visited\n else\n let mvarType := (← getMVarDecl mvarId).type\n let mvarIdsNew ← getMVars mvarType\n let mvarIdsNew := mvarIdsNew.filter fun mvarId => !visited.contains (mkMVar mvarId)\n if mvarIdsNew.isEmpty then\n go mvarIds (result.push (mkMVar mvarId)) visited\n else\n go (mvarIdsNew.toList ++ mvarId :: mvarIds) result visited", "start": [ 1707, 1 ], "end": [ 1734, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.addAutoBoundImplicits", "code": "def addAutoBoundImplicits (xs : Array Expr) : TermElabM (Array Expr) := do\n let autos := (← read).autoBoundImplicits\n go autos.toList #[]\nwhere\n go (todo : List Expr) (autos : Array Expr) : TermElabM (Array Expr) := do\n match todo with\n | [] =>\n for auto in autos do\n if auto.isFVar then\n let localDecl ← auto.fvarId!.getDecl\n for x in xs do\n if (← localDeclDependsOn localDecl x.fvarId!) then\n throwError \"invalid auto implicit argument '{auto}', it depends on explicitly provided argument '{x}'\"\n return autos ++ xs\n | auto :: todo =>\n let autos ← collectUnassignedMVars (← inferType auto) autos\n go todo (autos.push auto)", "start": [ 1736, 1 ], "end": [ 1761, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.addAutoBoundImplicits'", "code": "def addAutoBoundImplicits' (xs : Array Expr) (type : Expr) (k : Array Expr β†’ Expr β†’ TermElabM Ξ±) : TermElabM Ξ± := do\n let xs ← addAutoBoundImplicits xs\n if xs.all (Β·.isFVar) then\n k xs type\n else\n forallBoundedTelescope (← mkForallFVars xs type) xs.size fun xs type => k xs type", "start": [ 1763, 1 ], "end": [ 1774, 86 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkAuxName", "code": "def mkAuxName (suffix : Name) : TermElabM Name := do\n match (← read).declName? with\n | none => throwError \"auxiliary declaration cannot be created when declaration name is not available\"\n | some declName => Lean.mkAuxName (declName ++ suffix) 1", "start": [ 1776, 1 ], "end": [ 1779, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.isLetRecAuxMVar", "code": "def isLetRecAuxMVar (mvarId : MVarId) : TermElabM Bool := do\n trace[Elab.letrec] \"mvarId: {mkMVar mvarId} letrecMVars: {(← get).letRecsToLift.map (mkMVar $ Β·.mvarId)}\"\n let mvarId ← getDelayedMVarRoot mvarId\n trace[Elab.letrec] \"mvarId root: {mkMVar mvarId}\"\n return (← get).letRecsToLift.any (Β·.mvarId == mvarId)", "start": [ 1783, 1 ], "end": [ 1789, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkConst", "code": "def mkConst (constName : Name) (explicitLevels : List Level := []) : TermElabM Expr := do\n Linter.checkDeprecated constName let cinfo ← getConstInfo constName\n if explicitLevels.length > cinfo.levelParams.length then\n throwError \"too many explicit universe levels for '{constName}'\"\n else\n let numMissingLevels := cinfo.levelParams.length - explicitLevels.length\n let us ← mkFreshLevelMVars numMissingLevels\n return Lean.mkConst constName (explicitLevels ++ us)", "start": [ 1791, 1 ], "end": [ 1803, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.mkConsts", "code": "private def mkConsts (candidates : List (Name Γ— List String)) (explicitLevels : List Level) : TermElabM (List (Expr Γ— List String)) := do\n candidates.foldlM (init := []) fun result (declName, projs) => do\n let const ← mkConst declName explicitLevels\n return (const, projs) :: result", "start": [ 1805, 1 ], "end": [ 1809, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.resolveName", "code": "def resolveName (stx : Syntax) (n : Name) (preresolved : List Syntax.Preresolved) (explicitLevels : List Level) (expectedType? : Option Expr := none) : TermElabM (List (Expr Γ— List String)) := do\n addCompletionInfo <| CompletionInfo.id stx stx.getId (danglingDot := false) (← getLCtx) expectedType?\n if let some (e, projs) ← resolveLocalName n then\n unless explicitLevels.isEmpty do\n throwError \"invalid use of explicit universe parameters, '{e}' is a local\"\n return [(e, projs)]\n let preresolved := preresolved.filterMap fun\n | .decl n projs => some (n, projs)\n | _ => none\n let ctx ← read\n if let some (e, projs) := preresolved.findSome? fun (n, projs) => ctx.sectionFVars.find? n |>.map (Β·, projs) then\n return [(e, projs)] if preresolved.isEmpty then\n process (← realizeGlobalName n)\n else\n process preresolved\nwhere\n process (candidates : List (Name Γ— List String)) : TermElabM (List (Expr Γ— List String)) := do\n if candidates.isEmpty then\n if (← read).autoBoundImplicit &&\n !(← read).autoBoundImplicitForbidden n &&\n isValidAutoBoundImplicitName n (relaxedAutoImplicit.get (← getOptions)) then\n throwAutoBoundImplicitLocal n\n else\n throwError \"unknown identifier '{Lean.mkConst n}'\"\n mkConsts candidates explicitLevels", "start": [ 1811, 1 ], "end": [ 1837, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.resolveName'", "code": "def resolveName' (ident : Syntax) (explicitLevels : List Level) (expectedType? : Option Expr := none) : TermElabM (List (Expr Γ— Syntax Γ— List Syntax)) := do\n match ident with\n | .ident _ _ n preresolved =>\n let r ← resolveName ident n preresolved explicitLevels expectedType?\n r.mapM fun (c, fields) => do\n let ids := ident.identComponents (nFields? := fields.length)\n return (c, ids.head!, ids.tail!)\n | _ => throwError \"identifier expected\"", "start": [ 1839, 1 ], "end": [ 1850, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.resolveId?", "code": "def resolveId? (stx : Syntax) (kind := \"term\") (withInfo := false) : TermElabM (Option Expr) := withRef stx do\n match stx with\n | .ident _ _ val preresolved =>\n let rs ← try resolveName stx val preresolved [] catch _ => pure []\n let rs := rs.filter fun ⟨_, projs⟩ => projs.isEmpty\n let fs := rs.map fun (f, _) => f\n match fs with\n | [] => return none\n | [f] =>\n let f ← if withInfo then addTermInfo stx f else pure f\n return some f\n | _ => throwError \"ambiguous {kind}, use fully qualified name, possible interpretations {fs}\"\n | _ => throwError \"identifier expected\"", "start": [ 1852, 1 ], "end": [ 1864, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.TermElabM.run", "code": "def TermElabM.run (x : TermElabM Ξ±) (ctx : Context := {}) (s : State := {}) : MetaM (Ξ± Γ— State) :=\n withConfig setElabConfig (x ctx |>.run s)", "start": [ 1867, 1 ], "end": [ 1868, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.TermElabM.run'", "code": "@[inline] def TermElabM.run' (x : TermElabM Ξ±) (ctx : Context := {}) (s : State := {}) : MetaM Ξ± :=\n (Β·.1) <$> x.run ctx s", "start": [ 1870, 1 ], "end": [ 1871, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.TermElabM.toIO", "code": "def TermElabM.toIO (x : TermElabM Ξ±)\n (ctxCore : Core.Context) (sCore : Core.State)\n (ctxMeta : Meta.Context) (sMeta : Meta.State)\n (ctx : Context) (s : State) : IO (Ξ± Γ— Core.State Γ— Meta.State Γ— State) := do\n let ((a, s), sCore, sMeta) ← (x.run ctx s).toIO ctxCore sCore ctxMeta sMeta\n return (a, sCore, sMeta, s)", "start": [ 1873, 1 ], "end": [ 1878, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.universeConstraintsCheckpoint", "code": "def universeConstraintsCheckpoint (x : TermElabM Ξ±) : TermElabM Ξ± := do\n let a ← x\n discard <| processPostponed (mayPostpone := true) (exceptionOnFailure := true)\n return a", "start": [ 1887, 1 ], "end": [ 1894, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.expandDeclId", "code": "def expandDeclId (currNamespace : Name) (currLevelNames : List Name) (declId : Syntax) (modifiers : Modifiers) : TermElabM ExpandDeclIdResult := do\n let r ← Elab.expandDeclId currNamespace currLevelNames declId modifiers\n if (← read).sectionVars.contains r.shortName then\n throwError \"invalid declaration name '{r.shortName}', there is a section variable with the same name\"\n return r", "start": [ 1896, 1 ], "end": [ 1900, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.exprToSyntax", "code": "def exprToSyntax (e : Expr) : TermElabM Term := withFreshMacroScope do\n let result ← `(?m)\n let eType ← inferType e\n let mvar ← elabTerm result eType\n mvar.mvarId!.assign e\n return result", "start": [ 1902, 1 ], "end": [ 1916, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.withoutModifyingStateWithInfoAndMessages", "code": "def withoutModifyingStateWithInfoAndMessages [MonadControlT TermElabM m] [Monad m] (x : m Ξ±) : m Ξ± := do\n controlAt TermElabM fun runInBase => withoutModifyingStateWithInfoAndMessagesImpl <| runInBase x", "start": [ 1921, 1 ], "end": [ 1922, 99 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.addBuiltinIncrementalElab", "code": "def addBuiltinIncrementalElab (decl : Name) : IO Unit := do\n builtinIncrementalElabs.modify fun s => s.insert decl", "start": [ 1937, 1 ], "end": [ 1938, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.isIncrementalElab", "code": "def isIncrementalElab [Monad m] [MonadEnv m] [MonadLiftT IO m] (decl : Name) : m Bool :=\n (return (← builtinIncrementalElabs.get (m := IO)).contains decl) <||>\n (return incrementalAttr.hasTag (← getEnv) decl)", "start": [ 1952, 1 ], "end": [ 1955, 50 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/TopDownAnalyze.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/SubExpr.lean", ".lake/packages/lean4/src/lean/Lean/Elab/Config.lean", ".lake/packages/lean4/src/lean/Lean/Util/FindMVar.lean", ".lake/packages/lean4/src/lean/Lean/Util/ReplaceLevel.lean", ".lake/packages/lean4/src/lean/Lean/Util/CollectLevelParams.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Options.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/FieldNotation.lean", ".lake/packages/lean4/src/lean/Lean/Data/RBMap.lean", ".lake/packages/lean4/src/lean/Lean/Meta/SynthInstance.lean", ".lake/packages/lean4/src/lean/Lean/Util/FindLevelMVar.lean", ".lake/packages/lean4/src/lean/Lean/Meta/CtorRecognizer.lean" ]
[ { "full_name": "Lean.getPPAnalyze", "code": "def getPPAnalyze (o : Options) : Bool := o.get pp.analyze.name pp.analyze.defValue", "start": [ 108, 1 ], "end": [ 108, 110 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeCheckInstances", "code": "def getPPAnalyzeCheckInstances (o : Options) : Bool := o.get pp.analyze.checkInstances.name pp.analyze.checkInstances.defValue", "start": [ 109, 1 ], "end": [ 109, 140 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTypeAscriptions", "code": "def getPPAnalyzeTypeAscriptions (o : Options) : Bool := o.get pp.analyze.typeAscriptions.name pp.analyze.typeAscriptions.defValue", "start": [ 110, 1 ], "end": [ 110, 142 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTrustSubst", "code": "def getPPAnalyzeTrustSubst (o : Options) : Bool := o.get pp.analyze.trustSubst.name pp.analyze.trustSubst.defValue", "start": [ 111, 1 ], "end": [ 111, 132 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTrustOfNat", "code": "def getPPAnalyzeTrustOfNat (o : Options) : Bool := o.get pp.analyze.trustOfNat.name pp.analyze.trustOfNat.defValue", "start": [ 112, 1 ], "end": [ 112, 132 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTrustOfScientific", "code": "def getPPAnalyzeTrustOfScientific (o : Options) : Bool := o.get pp.analyze.trustOfScientific.name pp.analyze.trustOfScientific.defValue", "start": [ 113, 1 ], "end": [ 113, 146 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTrustId", "code": "def getPPAnalyzeTrustId (o : Options) : Bool := o.get pp.analyze.trustId.name pp.analyze.trustId.defValue", "start": [ 114, 1 ], "end": [ 114, 126 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTrustSubtypeMk", "code": "def getPPAnalyzeTrustSubtypeMk (o : Options) : Bool := o.get pp.analyze.trustSubtypeMk.name pp.analyze.trustSubtypeMk.defValue", "start": [ 115, 1 ], "end": [ 115, 140 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeTrustKnownFOType2TypeHOFuns", "code": "def getPPAnalyzeTrustKnownFOType2TypeHOFuns (o : Options) : Bool := o.get pp.analyze.trustKnownFOType2TypeHOFuns.name pp.analyze.trustKnownFOType2TypeHOFuns.defValue", "start": [ 116, 1 ], "end": [ 116, 166 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeOmitMax", "code": "def getPPAnalyzeOmitMax (o : Options) : Bool := o.get pp.analyze.omitMax.name pp.analyze.omitMax.defValue", "start": [ 117, 1 ], "end": [ 117, 126 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeKnowsType", "code": "def getPPAnalyzeKnowsType (o : Options) : Bool := o.get pp.analyze.knowsType.name pp.analyze.knowsType.defValue", "start": [ 118, 1 ], "end": [ 118, 130 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalyzeExplicitHoles", "code": "def getPPAnalyzeExplicitHoles (o : Options) : Bool := o.get pp.analyze.explicitHoles.name pp.analyze.explicitHoles.defValue", "start": [ 119, 1 ], "end": [ 119, 138 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisSkip", "code": "def getPPAnalysisSkip (o : Options) : Bool := o.get `pp.analysis.skip false", "start": [ 121, 1 ], "end": [ 121, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisHole", "code": "def getPPAnalysisHole (o : Options) : Bool := o.get `pp.analysis.hole false", "start": [ 122, 1 ], "end": [ 122, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisNamedArg", "code": "def getPPAnalysisNamedArg (o : Options) : Bool := o.get `pp.analysis.namedArg false", "start": [ 123, 1 ], "end": [ 123, 91 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisLetVarType", "code": "def getPPAnalysisLetVarType (o : Options) : Bool := o.get `pp.analysis.letVarType false", "start": [ 124, 1 ], "end": [ 124, 93 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisNeedsType", "code": "def getPPAnalysisNeedsType (o : Options) : Bool := o.get `pp.analysis.needsType false", "start": [ 125, 1 ], "end": [ 125, 92 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisBlockImplicit", "code": "def getPPAnalysisBlockImplicit (o : Options) : Bool := o.get `pp.analysis.blockImplicit false", "start": [ 126, 1 ], "end": [ 126, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.getPPAnalysisNoDot", "code": "def getPPAnalysisNoDot (o : Options) : Bool := o.get `pp.analysis.noDot false", "start": [ 127, 1 ], "end": [ 127, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.returnsPi", "code": "def returnsPi (motive : Expr) : MetaM Bool := do\n lambdaTelescope motive fun _ b => return b.isForall", "start": [ 131, 1 ], "end": [ 132, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isNonConstFun", "code": "def isNonConstFun (motive : Expr) : MetaM Bool := do\n match motive with\n | Expr.lam _ _ b _ => isNonConstFun b\n | _ => return motive.hasLooseBVars", "start": [ 134, 1 ], "end": [ 137, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isSimpleHOFun", "code": "def isSimpleHOFun (motive : Expr) : MetaM Bool :=\n return not (← returnsPi motive) && not (← isNonConstFun motive)", "start": [ 139, 1 ], "end": [ 140, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isType2Type", "code": "def isType2Type (motive : Expr) : MetaM Bool := do\n match ← inferType motive with\n | Expr.forallE _ (Expr.sort ..) (Expr.sort ..) .. => return true\n | _ => return false", "start": [ 142, 1 ], "end": [ 145, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isFOLike", "code": "def isFOLike (motive : Expr) : MetaM Bool := do\n let f := motive.getAppFn\n return f.isFVar || f.isConst", "start": [ 147, 1 ], "end": [ 149, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isIdLike", "code": "def isIdLike (arg : Expr) : Bool :=\n match arg with\n | Expr.lam _ _ (Expr.bvar ..) .. => true\n | _ => false", "start": [ 151, 1 ], "end": [ 155, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isStructureInstance", "code": "def isStructureInstance (e : Expr) : MetaM Bool := do\n match (← isConstructorApp? e) with\n | some s => return isStructure (← getEnv) s.induct\n | none => return false", "start": [ 157, 1 ], "end": [ 160, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.hasMVarAtCurrDepth", "code": "partial def hasMVarAtCurrDepth (e : Expr) : MetaM Bool := do\n let mctx ← getMCtx\n return Option.isSome <| e.findMVar? fun mvarId =>\n match mctx.findDecl? mvarId with\n | some mdecl => mdecl.depth == mctx.depth\n | _ => false", "start": [ 164, 1 ], "end": [ 169, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.hasLevelMVarAtCurrDepth", "code": "partial def hasLevelMVarAtCurrDepth (e : Expr) : MetaM Bool := do\n let mctx ← getMCtx\n return Option.isSome <| e.findLevelMVar? fun mvarId =>\n mctx.findLevelDepth? mvarId == some mctx.depth", "start": [ 171, 1 ], "end": [ 174, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.valUnknown", "code": "private def valUnknown (e : Expr) : MetaM Bool := do\n hasMVarAtCurrDepth (← instantiateMVars e)", "start": [ 176, 1 ], "end": [ 177, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.typeUnknown", "code": "private def typeUnknown (e : Expr) : MetaM Bool := do\n valUnknown (← inferType e)", "start": [ 179, 1 ], "end": [ 180, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.isHBinOp", "code": "def isHBinOp (e : Expr) : Bool := Id.run do\n if e.getAppNumArgs != 6 then return false\n let f := e.getAppFn\n if !f.isConst then return false\n\n let ops := #[\n `HOr.hOr, `HXor.hXor, `HAnd.hAnd,\n `HAppend.hAppend, `HOrElse.hOrElse, `HAndThen.hAndThen,\n `HAdd.hAdd, `HSub.hSub, `HMul.hMul, `HDiv.hDiv, `HMod.hMod,\n `HShiftLeft.hShiftLeft, `HShiftRight]\n ops.any fun op => op == f.constName!", "start": [ 182, 1 ], "end": [ 196, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.replaceLPsWithVars", "code": "def replaceLPsWithVars (e : Expr) : MetaM Expr := do\n if !e.hasLevelParam then return e\n let lps := collectLevelParams {} e |>.params\n let mut replaceMap : HashMap Name Level := {}\n for lp in lps do replaceMap := replaceMap.insert lp (← mkFreshLevelMVar)\n return e.replaceLevel fun\n | Level.param n .. => replaceMap.find! n\n | l => if !l.hasParam then some l else none", "start": [ 198, 1 ], "end": [ 205, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.isDefEqAssigning", "code": "def isDefEqAssigning (t s : Expr) : MetaM Bool := do\n withReader (fun ctx => { ctx with config := { ctx.config with assignSyntheticOpaque := true }}) $\n Meta.isDefEq t s", "start": [ 207, 1 ], "end": [ 209, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.checkpointDefEq", "code": "def checkpointDefEq (t s : Expr) : MetaM Bool := do\n Meta.checkpointDefEq (mayPostpone := false) do\n isDefEqAssigning t s", "start": [ 211, 1 ], "end": [ 213, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.isHigherOrder", "code": "def isHigherOrder (type : Expr) : MetaM Bool := do\n forallTelescopeReducing type fun xs b => return xs.size > 0 && b.isSort", "start": [ 215, 1 ], "end": [ 216, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.isFunLike", "code": "def isFunLike (e : Expr) : MetaM Bool := do\n forallTelescopeReducing (← inferType e) fun xs _ => return xs.size > 0", "start": [ 218, 1 ], "end": [ 219, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.isSubstLike", "code": "def isSubstLike (e : Expr) : Bool :=\n e.isAppOfArity ``Eq.ndrec 6 || e.isAppOfArity ``Eq.rec 6", "start": [ 221, 1 ], "end": [ 222, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.nameNotRoundtrippable", "code": "def nameNotRoundtrippable (n : Name) : Bool :=\n n.hasMacroScopes || isPrivateName n || containsNum n\nwhere\n containsNum\n | Name.str p .. => containsNum p\n | Name.num .. => true\n | Name.anonymous => false", "start": [ 224, 1 ], "end": [ 230, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.mvarName", "code": "def mvarName (mvar : Expr) : MetaM Name :=\n return (← mvar.mvarId!.getDecl).userName", "start": [ 232, 1 ], "end": [ 233, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.containsBadMax", "code": "def containsBadMax : Level β†’ Bool\n | Level.succ u .. => containsBadMax u\n | Level.max u v .. => (u.hasParam && v.hasParam) || containsBadMax u || containsBadMax v\n | Level.imax u v .. => (u.hasParam && v.hasParam) || containsBadMax u || containsBadMax v\n | _ => false", "start": [ 235, 1 ], "end": [ 239, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.Context", "code": "structure Context where\n knowsType : Bool\n knowsLevel : Bool inBottomUp : Bool := false\n parentIsApp : Bool := false\n subExpr : SubExpr\n deriving Inhabited", "start": [ 243, 1 ], "end": [ 249, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.State", "code": "structure State where\n annotations : OptionsPerPos := {}\n postponed : Array (Expr Γ— Expr) := #[]", "start": [ 251, 1 ], "end": [ 253, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.AnalyzeM", "code": "abbrev AnalyzeM := ReaderT Context (StateRefT State MetaM)", "start": [ 255, 1 ], "end": [ 255, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.tryUnify", "code": "def tryUnify (e₁ eβ‚‚ : Expr) : AnalyzeM Unit := do\n try\n let r ← isDefEqAssigning e₁ eβ‚‚\n if !r then modify fun s => { s with postponed := s.postponed.push (e₁, eβ‚‚) }\n pure ()\n catch _ =>\n modify fun s => { s with postponed := s.postponed.push (e₁, eβ‚‚) }", "start": [ 263, 1 ], "end": [ 269, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.inspectOutParams", "code": "partial def inspectOutParams (arg mvar : Expr) : AnalyzeM Unit := do\n let argType ← inferType arg let mvarType ← inferType mvar\n let fType ← inferType argType.getAppFn let mType ← inferType mvarType.getAppFn\n inspectAux fType mType 0 argType.getAppArgs mvarType.getAppArgs\nwhere\n inspectAux (fType mType : Expr) (i : Nat) (args mvars : Array Expr) := do\n let fType ← whnf fType\n let mType ← whnf mType\n if not (i < args.size) then return ()\n match fType, mType with\n | Expr.forallE _ fd fb _, Expr.forallE _ _ mb _ => do\n if fd.isOutParam then\n tryUnify (args[i]!) (mvars[i]!)\n inspectAux (fb.instantiate1 args[i]!) (mb.instantiate1 mvars[i]!) (i+1) args mvars\n | _, _ => return ()", "start": [ 271, 1 ], "end": [ 289, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.isTrivialBottomUp", "code": "partial def isTrivialBottomUp (e : Expr) : AnalyzeM Bool := do\n let opts ← getOptions\n return e.isFVar\n || e.isConst || e.isMVar || e.isRawNatLit || e.isStringLit || e.isSort\n || (getPPAnalyzeTrustOfNat opts && e.isAppOfArity ``OfNat.ofNat 3)\n || (getPPAnalyzeTrustOfScientific opts && e.isAppOfArity ``OfScientific.ofScientific 5)", "start": [ 291, 1 ], "end": [ 296, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.canBottomUp", "code": "partial def canBottomUp (e : Expr) (mvar? : Option Expr := none) (fuel : Nat := 10) : AnalyzeM Bool := do\n match fuel with\n | 0 => return false\n | fuel + 1 =>\n if ← isTrivialBottomUp e then return true\n let f := e.getAppFn\n if !f.isConst && !f.isFVar then return false\n let args := e.getAppArgs\n let fType ← replaceLPsWithVars (← inferType e.getAppFn)\n let (mvars, bInfos, resultType) ← forallMetaBoundedTelescope fType e.getAppArgs.size\n for i in [:mvars.size] do\n if bInfos[i]! == BinderInfo.instImplicit then\n inspectOutParams args[i]! mvars[i]!\n else if bInfos[i]! == BinderInfo.default then\n if ← isTrivialBottomUp args[i]! then tryUnify args[i]! mvars[i]!\n else if ← typeUnknown mvars[i]! <&&> canBottomUp args[i]! (some mvars[i]!) fuel then tryUnify args[i]! mvars[i]!\n if ← (pure (isHBinOp e) <&&> (valUnknown mvars[0]! <||> valUnknown mvars[1]!)) then tryUnify mvars[0]! mvars[1]!\n if mvar?.isSome then tryUnify resultType (← inferType mvar?.get!)\n return !(← valUnknown resultType)", "start": [ 298, 1 ], "end": [ 319, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.withKnowing", "code": "def withKnowing (knowsType knowsLevel : Bool) (x : AnalyzeM Ξ±) : AnalyzeM Ξ± := do\n withReader (fun ctx => { ctx with knowsType := knowsType, knowsLevel := knowsLevel }) x", "start": [ 321, 1 ], "end": [ 322, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.checkKnowsType", "code": "def checkKnowsType : AnalyzeM Unit := do\n if not (← read).knowsType then\n throw $ Exception.internal analyzeFailureId", "start": [ 326, 1 ], "end": [ 328, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.annotateBoolAt", "code": "def annotateBoolAt (n : Name) (pos : Pos) : AnalyzeM Unit := do\n let opts := (← get).annotations.findD pos {} |>.setBool n true\n trace[pp.analyze.annotate] \"{pos} {n}\"\n modify fun s => { s with annotations := s.annotations.insert pos opts }", "start": [ 330, 1 ], "end": [ 333, 74 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.annotateBool", "code": "def annotateBool (n : Name) : AnalyzeM Unit := do\n annotateBoolAt n (← getPos)", "start": [ 335, 1 ], "end": [ 336, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.App.Context", "code": "structure App.Context where\n f : Expr\n fType : Expr\n args : Array Expr\n mvars : Array Expr\n bInfos : Array BinderInfo\n forceRegularApp : Bool", "start": [ 338, 1 ], "end": [ 344, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.App.State", "code": "structure App.State where\n bottomUps : Array Bool\n higherOrders : Array Bool\n funBinders : Array Bool\n provideds : Array Bool\n namedArgs : Array Name := #[]", "start": [ 346, 1 ], "end": [ 351, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.AnalyzeAppM", "code": "abbrev AnalyzeAppM := ReaderT App.Context (StateT App.State AnalyzeM)", "start": [ 353, 1 ], "end": [ 353, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.analyze", "code": "partial def analyze (parentIsApp : Bool := false) : AnalyzeM Unit := do\n checkSystem \"Delaborator.topDownAnalyze\"\n trace[pp.analyze] \"{(← read).knowsType}.{(← read).knowsLevel}\"\n let e ← getExpr\n let opts ← getOptions\n if ← (pure !e.isAtomic) <&&> pure !(getPPProofs opts) <&&> (try Meta.isProof e catch _ => pure false) then\n if getPPProofsWithType opts then\n withType $ withKnowing true true $ analyze\n return ()\n else\n withReader (fun ctx => { ctx with parentIsApp := parentIsApp }) do\n match (← getExpr) with\n | Expr.app .. => analyzeApp\n | Expr.forallE .. => analyzePi\n | Expr.lam .. => analyzeLam\n | Expr.const .. => analyzeConst\n | Expr.sort .. => analyzeSort\n | Expr.proj .. => analyzeProj\n | Expr.fvar .. => analyzeFVar\n | Expr.mdata .. => analyzeMData\n | Expr.letE .. => analyzeLet\n | Expr.lit .. => pure ()\n | Expr.mvar .. => pure ()\n | Expr.bvar .. => pure ()\n where\n analyzeApp := do\n let mut willKnowType := (← read).knowsType\n if !(← read).knowsType && !(← canBottomUp (← getExpr)) then\n annotateBool `pp.analysis.needsType\n withType $ withKnowing true false $ analyze\n willKnowType := true\n\n else if ← (pure !(← read).knowsType <||> pure (← read).inBottomUp) <&&> isStructureInstance (← getExpr) then\n withType do\n annotateBool `pp.structureInstanceTypes\n withKnowing true false $ analyze\n willKnowType := true\n\n withKnowing willKnowType true $ analyzeAppStaged (← getExpr).getAppFn (← getExpr).getAppArgs\n\n analyzeAppStaged (f : Expr) (args : Array Expr) : AnalyzeM Unit := do\n let fType ← replaceLPsWithVars (← inferType f)\n let (mvars, bInfos, resultType) ← forallMetaBoundedTelescope fType args.size\n let rest := args.extract mvars.size args.size\n let args := args.shrink mvars.size\n\n if (← read).knowsType then tryUnify (← inferType (mkAppN f args)) resultType\n\n if getPPFieldNotation (← getOptions) then\n if let some (_, idx) ← fieldNotationCandidate? f args (getPPFieldNotationGeneralized (← getOptions)) then\n if idx < args.size then\n withKnowing false false do\n if !(← canBottomUp args[idx]!) then\n annotateBool `pp.analysis.noDot\n else\n annotateBool `pp.analysis.noDot\n\n let forceRegularApp : Bool :=\n (getPPAnalyzeTrustSubst (← getOptions) && isSubstLike (← getExpr))\n || (getPPAnalyzeTrustSubtypeMk (← getOptions) && (← getExpr).isAppOfArity ``Subtype.mk 4)\n\n analyzeAppStagedCore { f, fType, args, mvars, bInfos, forceRegularApp } |>.run' {\n bottomUps := mkArray args.size false,\n higherOrders := mkArray args.size false,\n provideds := mkArray args.size false,\n funBinders := mkArray args.size false\n }\n\n if not rest.isEmpty then\n if !args.isEmpty then\n analyzeAppStaged (mkAppN f args) rest\n\n maybeAddBlockImplicit : AnalyzeM Unit := do\n if !(← read).parentIsApp then\n let type ← inferType (← getExpr)\n if type.isForall && type.bindingInfo! == BinderInfo.implicit then\n annotateBool `pp.analysis.blockImplicit\n\n analyzeConst : AnalyzeM Unit := do\n let Expr.const _ ls .. ← getExpr | unreachable!\n if !(← read).knowsLevel && !ls.isEmpty then\n unless getPPAnalyzeOmitMax (← getOptions) && ls.any containsBadMax do\n annotateBool `pp.universes\n maybeAddBlockImplicit\n\n analyzePi : AnalyzeM Unit := do\n withBindingDomain $ withKnowing true false analyze\n withBindingBody Name.anonymous analyze\n\n analyzeLam : AnalyzeM Unit := do\n if !(← read).knowsType then annotateBool `pp.funBinderTypes\n withBindingDomain $ withKnowing true false analyze\n withBindingBody Name.anonymous analyze\n\n analyzeLet : AnalyzeM Unit := do\n let Expr.letE _ _ v _ .. ← getExpr | unreachable!\n if !(← canBottomUp v) then\n annotateBool `pp.analysis.letVarType\n withLetVarType $ withKnowing true false analyze\n withLetValue $ withKnowing true true analyze\n else\n withReader (fun ctx => { ctx with inBottomUp := true }) do\n withLetValue $ withKnowing true true analyze\n\n withLetBody analyze\n\n analyzeSort : AnalyzeM Unit := pure ()\n analyzeProj : AnalyzeM Unit := withProj analyze\n analyzeFVar : AnalyzeM Unit := maybeAddBlockImplicit\n analyzeMData : AnalyzeM Unit := withMDataExpr analyze", "start": [ 357, 3 ], "end": [ 472, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.TopDownAnalyze.analyzeAppStagedCore", "code": "partial def analyzeAppStagedCore : AnalyzeAppM Unit := do\n collectBottomUps\n checkOutParams\n collectHigherOrders\n hBinOpHeuristic\n collectTrivialBottomUps\n discard <| processPostponed (mayPostpone := true)\n applyFunBinderHeuristic\n analyzeFn\n for i in [:(← read).args.size] do analyzeArg i\n maybeSetExplicit\n\n where\n collectBottomUps := do\n let { args, mvars, bInfos, ..} ← read\n for target in [fun _ => none, fun i => some mvars[i]!] do\n for i in [:args.size] do\n if bInfos[i]! == BinderInfo.default then\n if ← typeUnknown mvars[i]! <&&> canBottomUp args[i]! (target i) then\n tryUnify args[i]! mvars[i]!\n modify fun s => { s with bottomUps := s.bottomUps.set! i true }\n\n checkOutParams := do\n let { args, mvars, bInfos, ..} ← read\n for i in [:args.size] do\n if bInfos[i]! == BinderInfo.instImplicit then inspectOutParams args[i]! mvars[i]!\n\n collectHigherOrders := do\n let { args, mvars, bInfos, ..} ← read\n for i in [:args.size] do\n if not (bInfos[i]! == BinderInfo.implicit || bInfos[i]! == BinderInfo.strictImplicit) then continue\n if not (← isHigherOrder (← inferType args[i]!)) then continue\n if getPPAnalyzeTrustId (← getOptions) && isIdLike args[i]! then continue\n\n if getPPAnalyzeTrustKnownFOType2TypeHOFuns (← getOptions) && not (← valUnknown mvars[i]!)\n && (← isType2Type (args[i]!)) && (← isFOLike (args[i]!)) then continue\n\n tryUnify args[i]! mvars[i]!\n modify fun s => { s with higherOrders := s.higherOrders.set! i true }\n\n hBinOpHeuristic := do\n let { mvars, ..} ← read\n if ← (pure (isHBinOp (← getExpr)) <&&> (valUnknown mvars[0]! <||> valUnknown mvars[1]!)) then\n tryUnify mvars[0]! mvars[1]!\n\n collectTrivialBottomUps := do\n let { args, mvars, bInfos, ..} ← read\n for i in [:args.size] do\n if bInfos[i]! == BinderInfo.default then\n if ← valUnknown mvars[i]! <&&> isTrivialBottomUp args[i]! then\n tryUnify args[i]! mvars[i]!\n modify fun s => { s with bottomUps := s.bottomUps.set! i true }\n\n applyFunBinderHeuristic := do\n let { args, mvars, bInfos, .. } ← read\n\n let rec core (argIdx : Nat) (mvarType : Expr) : AnalyzeAppM Bool := do\n match ← getExpr, mvarType with\n | Expr.lam .., Expr.forallE _ t b .. =>\n let mut annotated := false\n for i in [:argIdx] do\n if ← pure (bInfos[i]! == BinderInfo.implicit) <&&> valUnknown mvars[i]! <&&> withNewMCtxDepth (checkpointDefEq t mvars[i]!) then\n annotateBool `pp.funBinderTypes\n tryUnify args[i]! mvars[i]!\n annotated := true\n break\n let annotatedBody ← withBindingBody Name.anonymous (core argIdx b)\n return annotated || annotatedBody\n\n | _, _ => return false\n\n for i in [:args.size] do\n if bInfos[i]! == BinderInfo.default then\n let b ← withNaryArg i (core i (← inferType mvars[i]!))\n if b then modify fun s => { s with funBinders := s.funBinders.set! i true }\n\n analyzeFn := do\n let {f, fType, forceRegularApp ..} ← read\n if !f.isApp then withKnowing false (forceRegularApp || !(← hasLevelMVarAtCurrDepth (← instantiateMVars fType))) $ withNaryFn (analyze (parentIsApp := true))\n\n annotateNamedArg (n : Name) : AnalyzeAppM Unit := do\n annotateBool `pp.analysis.namedArg\n modify fun s => { s with namedArgs := s.namedArgs.push n }\n\n analyzeArg (i : Nat) := do\n let { f, args, mvars, bInfos, forceRegularApp ..} ← read\n let { bottomUps, higherOrders, funBinders, ..} ← get\n let arg := args[i]!\n let argType ← inferType arg\n\n let processNaturalImplicit : AnalyzeAppM Unit := do\n if (← valUnknown mvars[i]! <||> pure higherOrders[i]!) && !forceRegularApp then\n annotateNamedArg (← mvarName mvars[i]!)\n modify fun s => { s with provideds := s.provideds.set! i true }\n else\n annotateBool `pp.analysis.skip\n\n withNaryArg (f.getAppNumArgs + i) do\n withTheReader Context (fun ctx => { ctx with inBottomUp := ctx.inBottomUp || bottomUps[i]! }) do\n\n match bInfos[i]! with\n | BinderInfo.default =>\n if ← pure (getPPAnalyzeExplicitHoles (← getOptions)) <&&> pure !(← valUnknown mvars[i]!) <&&> pure !(← readThe Context).inBottomUp <&&> pure !(← isFunLike arg) <&&> pure !funBinders[i]! <&&> checkpointDefEq mvars[i]! arg then\n annotateBool `pp.analysis.hole\n else\n modify fun s => { s with provideds := s.provideds.set! i true }\n\n | BinderInfo.implicit => processNaturalImplicit\n | BinderInfo.strictImplicit => processNaturalImplicit\n\n | BinderInfo.instImplicit =>\n let mut provided := true\n if !getPPInstances (← getOptions) then\n annotateBool `pp.analysis.skip\n provided := false\n else if getPPAnalyzeCheckInstances (← getOptions) then\n let instResult ← try trySynthInstance argType catch _ => pure LOption.undef\n match instResult with\n | LOption.some inst =>\n if ← checkpointDefEq inst arg then annotateBool `pp.analysis.skip; provided := false\n else annotateNamedArg (← mvarName mvars[i]!)\n | _ => annotateNamedArg (← mvarName mvars[i]!)\n else annotateBool `pp.analysis.skip; provided := false\n modify fun s => { s with provideds := s.provideds.set! i provided }\n if (← get).provideds[i]! then withKnowing (not (← typeUnknown mvars[i]!)) true analyze\n tryUnify mvars[i]! args[i]!\n\n maybeSetExplicit := do\n let { f, args, bInfos, ..} ← read\n if (← get).namedArgs.any nameNotRoundtrippable then\n annotateBool `pp.explicit\n for i in [:args.size] do\n if !(← get).provideds[i]! then\n withNaryArg (f.getAppNumArgs + i) do annotateBool `pp.analysis.hole\n if bInfos[i]! == BinderInfo.instImplicit && getPPInstanceTypes (← getOptions) then\n withType (withKnowing true false analyze)", "start": [ 474, 3 ], "end": [ 616, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.topDownAnalyze", "code": "def topDownAnalyze (e : Expr) : MetaM OptionsPerPos := do\n let sβ‚€ ← get\n withTraceNode `pp.analyze (fun _ => return e) do\n withReader (fun ctx => { ctx with config := Elab.Term.setElabConfig ctx.config }) do\n let Ο• : AnalyzeM OptionsPerPos := do withNewMCtxDepth analyze; pure (← get).annotations\n try\n let knowsType := getPPAnalyzeKnowsType (← getOptions)\n Ο• { knowsType := knowsType, knowsLevel := knowsType, subExpr := mkRoot e }\n |>.run' { : TopDownAnalyze.State }\n catch e =>\n trace[pp.analyze.error] \"failed {e.toMessageData}\"\n pure {}\n finally set sβ‚€", "start": [ 624, 1 ], "end": [ 636, 21 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/ForEachExprWhere.lean
[ ".lake/packages/lean4/src/lean/Lean/Util/MonadCache.lean", ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.ForEachExprWhere.cacheSize", "code": "abbrev cacheSize : USize := 8192 - 1", "start": [ 20, 1 ], "end": [ 20, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ForEachExprWhere.State", "code": "structure State where\n \n visited : Array Expr \n checked : HashSet Expr", "start": [ 22, 1 ], "end": [ 31, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ForEachExprWhere.initCache", "code": "unsafe def initCache : State := {\n visited := mkArray cacheSize.toNat (cast lcProof ())\n checked := {}\n}", "start": [ 33, 1 ], "end": [ 36, 2 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ForEachExprWhere.ForEachM", "code": "abbrev ForEachM {Ο‰ : Type} (m : Type β†’ Type) [STWorld Ο‰ m] := StateRefT' Ο‰ State m", "start": [ 38, 1 ], "end": [ 38, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ForEachExprWhere.visited", "code": "unsafe def visited (e : Expr) : ForEachM m Bool := do\n let s ← get\n let h := ptrAddrUnsafe e\n let i := h % cacheSize\n let k := s.visited.uget i lcProof\n if ptrAddrUnsafe k == h then\n return true\n else\n modify fun s => { s with visited := s.visited.uset i e lcProof }\n return false", "start": [ 42, 1 ], "end": [ 51, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ForEachExprWhere.checked", "code": "def checked (e : Expr) : ForEachM m Bool := do\n if (← get).checked.contains e then\n return true\n else\n modify fun s => { s with checked := s.checked.insert e }\n return false", "start": [ 53, 1 ], "end": [ 58, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ForEachExprWhere.visit", "code": "unsafe def visit (p : Expr β†’ Bool) (f : Expr β†’ m Unit) (e : Expr) (stopWhenVisited : Bool := false) : m Unit := do\n go e |>.run' initCache\nwhere\n go (e : Expr) : StateRefT' Ο‰ State m Unit := do\n unless (← visited e) do\n if p e then\n unless (← checked e) do\n f e\n if stopWhenVisited then\n return ()\n match e with\n | .forallE _ d b _ => go d; go b\n | .lam _ d b _ => go d; go b\n | .letE _ t v b _ => go t; go v; go b\n | .app f a => go f; go a\n | .mdata _ b => go b\n | .proj _ _ b => go b\n | _ => return ()", "start": [ 60, 1 ], "end": [ 78, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.forEachWhere", "code": "@[implemented_by ForEachExprWhere.visit]\nopaque Expr.forEachWhere {Ο‰ : Type} {m : Type β†’ Type} [STWorld Ο‰ m] [MonadLiftT (ST Ο‰) m] [Monad m] (p : Expr β†’ Bool) (f : Expr β†’ m Unit) (e : Expr) (stopWhenVisited : Bool := false) : m Unit", "start": [ 82, 1 ], "end": [ 88, 192 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Parser.lean
[ ".lake/packages/lean4/src/lean/Lean/Parser/Level.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Term.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Tactic/Doc.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Syntax.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Tactic.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Do.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Module.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Command.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Parenthesizer.mkAntiquot.parenthesizer", "code": "@[export lean_mk_antiquot_parenthesizer]\ndef mkAntiquot.parenthesizer (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPseudoKind := true) : Parenthesizer :=\n Parser.mkAntiquot.parenthesizer name kind anonymous isPseudoKind", "start": [ 63, 1 ], "end": [ 65, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.ident.parenthesizer", "code": "@[builtin_parenthesizer ident] def ident.parenthesizer : Parenthesizer := Parser.Term.ident.parenthesizer", "start": [ 69, 1 ], "end": [ 69, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.numLit.parenthesizer", "code": "@[builtin_parenthesizer num] def numLit.parenthesizer : Parenthesizer := Parser.Term.num.parenthesizer", "start": [ 70, 1 ], "end": [ 70, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.scientificLit.parenthesizer", "code": "@[builtin_parenthesizer scientific] def scientificLit.parenthesizer : Parenthesizer := Parser.Term.scientific.parenthesizer", "start": [ 71, 1 ], "end": [ 71, 124 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.charLit.parenthesizer", "code": "@[builtin_parenthesizer char] def charLit.parenthesizer : Parenthesizer := Parser.Term.char.parenthesizer", "start": [ 72, 1 ], "end": [ 72, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.strLit.parenthesizer", "code": "@[builtin_parenthesizer str] def strLit.parenthesizer : Parenthesizer := Parser.Term.str.parenthesizer", "start": [ 73, 1 ], "end": [ 73, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Parenthesizer.interpretParserDescr", "code": "@[export lean_pretty_printer_parenthesizer_interpret_parser_descr]\nunsafe def interpretParserDescr : ParserDescr β†’ CoreM Parenthesizer\n | ParserDescr.const n => getConstAlias parenthesizerAliasesRef n\n | ParserDescr.unary n d => return (← getUnaryAlias parenthesizerAliasesRef n) (← interpretParserDescr d)\n | ParserDescr.binary n d₁ dβ‚‚ => return (← getBinaryAlias parenthesizerAliasesRef n) (← interpretParserDescr d₁) (← interpretParserDescr dβ‚‚)\n | ParserDescr.node k prec d => return leadingNode.parenthesizer k prec (← interpretParserDescr d)\n | ParserDescr.nodeWithAntiquot n k d => return withAntiquot.parenthesizer (mkAntiquot.parenthesizer' n k (anonymous := true)) <|\n node.parenthesizer k (← interpretParserDescr d)\n | ParserDescr.sepBy p sep psep trail => return sepBy.parenthesizer (← interpretParserDescr p) sep (← interpretParserDescr psep) trail\n | ParserDescr.sepBy1 p sep psep trail => return sepBy1.parenthesizer (← interpretParserDescr p) sep (← interpretParserDescr psep) trail\n | ParserDescr.trailingNode k prec lhsPrec d => return trailingNode.parenthesizer k prec lhsPrec (← interpretParserDescr d)\n | ParserDescr.symbol tk => return symbol.parenthesizer tk\n | ParserDescr.nonReservedSymbol tk includeIdent => return nonReservedSymbol.parenthesizer tk includeIdent\n | ParserDescr.parser constName => combinatorParenthesizerAttribute.runDeclFor constName\n | ParserDescr.cat catName prec => return categoryParser.parenthesizer catName prec", "start": [ 77, 1 ], "end": [ 91, 104 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.mkAntiquot.formatter", "code": "@[export lean_mk_antiquot_formatter]\ndef mkAntiquot.formatter (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPseudoKind := true) : Formatter :=\n Parser.mkAntiquot.formatter name kind anonymous isPseudoKind", "start": [ 97, 1 ], "end": [ 99, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.ident.formatter", "code": "@[builtin_formatter ident] def ident.formatter : Formatter := Parser.Term.ident.formatter", "start": [ 101, 1 ], "end": [ 101, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.numLit.formatter", "code": "@[builtin_formatter num] def numLit.formatter : Formatter := Parser.Term.num.formatter", "start": [ 102, 1 ], "end": [ 102, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.scientificLit.formatter", "code": "@[builtin_formatter scientific] def scientificLit.formatter : Formatter := Parser.Term.scientific.formatter", "start": [ 103, 1 ], "end": [ 103, 108 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.charLit.formatter", "code": "@[builtin_formatter char] def charLit.formatter : Formatter := Parser.Term.char.formatter", "start": [ 104, 1 ], "end": [ 104, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.strLit.formatter", "code": "@[builtin_formatter str] def strLit.formatter : Formatter := Parser.Term.str.formatter", "start": [ 105, 1 ], "end": [ 105, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Formatter.interpretParserDescr", "code": "@[export lean_pretty_printer_formatter_interpret_parser_descr]\nunsafe def interpretParserDescr : ParserDescr β†’ CoreM Formatter\n | ParserDescr.const n => getConstAlias formatterAliasesRef n\n | ParserDescr.unary n d => return (← getUnaryAlias formatterAliasesRef n) (← interpretParserDescr d)\n | ParserDescr.binary n d₁ dβ‚‚ => return (← getBinaryAlias formatterAliasesRef n) (← interpretParserDescr d₁) (← interpretParserDescr dβ‚‚)\n | ParserDescr.node k _ d => return node.formatter k (← interpretParserDescr d)\n | ParserDescr.nodeWithAntiquot n k d => return withAntiquot.formatter (mkAntiquot.formatter' n k (anonymous := true)) <|\n node.formatter k (← interpretParserDescr d)\n | ParserDescr.sepBy p sep psep trail => return sepBy.formatter (← interpretParserDescr p) sep (← interpretParserDescr psep) trail\n | ParserDescr.sepBy1 p sep psep trail => return sepBy1.formatter (← interpretParserDescr p) sep (← interpretParserDescr psep) trail\n | ParserDescr.trailingNode k prec lhsPrec d => return trailingNode.formatter k prec lhsPrec (← interpretParserDescr d)\n | ParserDescr.symbol tk => return symbol.formatter tk\n | ParserDescr.nonReservedSymbol tk _ => return nonReservedSymbol.formatter tk\n | ParserDescr.parser constName => combinatorFormatterAttribute.runDeclFor constName\n | ParserDescr.cat catName _ => return categoryParser.formatter catName", "start": [ 109, 1 ], "end": [ 123, 95 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Basic.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/SubExpr.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/TopDownAnalyze.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Options.lean", ".lake/packages/lean4/src/lean/Lean/Elab/Term.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Delaborator.Context", "code": "structure Context where\n optionsPerPos : OptionsPerPos\n currNamespace : Name\n openDecls : List OpenDecl\n inPattern : Bool := false subExpr : SubExpr\n \n depth : Nat := 0", "start": [ 38, 1 ], "end": [ 45, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.State", "code": "structure State where\n \n steps : Nat := 0\n \n infos : PosMap Info := {}\n \n holeIter : SubExpr.HoleIterator := {}", "start": [ 47, 1 ], "end": [ 55, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.DelabM", "code": "abbrev DelabM := ReaderT Context (StateRefT State MetaM)", "start": [ 61, 1 ], "end": [ 61, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.Delab", "code": "abbrev Delab := DelabM Term", "start": [ 62, 1 ], "end": [ 62, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.orElse", "code": "@[inline] protected def orElse (d₁ : DelabM Ξ±) (dβ‚‚ : Unit β†’ DelabM Ξ±) : DelabM Ξ± := do\n catchInternalId delabFailureId d₁ fun _ => dβ‚‚ ()", "start": [ 67, 1 ], "end": [ 68, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.failure", "code": "protected def failure : DelabM Ξ± :=\n throw $ Exception.internal delabFailureId", "start": [ 70, 1 ], "end": [ 71, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.mkDelabAttribute", "code": "unsafe def mkDelabAttribute : IO (KeyedDeclsAttribute Delab) :=\n KeyedDeclsAttribute.init {\n builtinName := `builtin_delab,\n name := `delab,\n descr := \"Register a delaborator.\n\n [delab k] registers a declaration of type `Lean.PrettyPrinter.Delaborator.Delab` for the `Lean.Expr`\n constructor `k`. Multiple delaborators for a single constructor are tried in turn until\n the first success. If the term to be delaborated is an application of a constant `c`,\n elaborators for `app.c` are tried first; this is also done for `Expr.const`s (\\\"nullary applications\\\")\n to reduce special casing. If the term is an `Expr.mdata` with a single key `k`, `mdata.k`\n is tried first.\",\n valueTypeName := `Lean.PrettyPrinter.Delaborator.Delab\n evalKey := fun _ stx => do\n let stx ← Attribute.Builtin.getIdent stx\n let kind := stx.getId\n if (← Elab.getInfoState).enabled && kind.getRoot == `app then\n let c := kind.replacePrefix `app .anonymous\n if (← getEnv).contains c then\n Elab.addConstInfo stx c none\n pure kind\n } `Lean.PrettyPrinter.Delaborator.delabAttribute", "start": [ 102, 1 ], "end": [ 123, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabAttribute", "code": "@[builtin_init mkDelabAttribute] opaque delabAttribute : KeyedDeclsAttribute Delab", "start": [ 124, 1 ], "end": [ 124, 83 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.getExprKind", "code": "def getExprKind : DelabM Name := do\n let e ← getExpr\n pure $ match e with\n | Expr.bvar _ => `bvar\n | Expr.fvar _ => `fvar\n | Expr.mvar _ => `mvar\n | Expr.sort _ => `sort\n | Expr.const c _ =>\n `app ++ c\n | Expr.app fn _ => match fn.getAppFn with\n | Expr.const c _ => `app ++ c\n | _ => `app\n | Expr.lam _ _ _ _ => `lam\n | Expr.forallE _ _ _ _ => `forallE\n | Expr.letE _ _ _ _ _ => `letE\n | Expr.lit _ => `lit\n | Expr.mdata m _ => match m.entries with\n | [(key, _)] => `mdata ++ key\n | _ => `mdata\n | Expr.proj _ _ _ => `proj", "start": [ 126, 1 ], "end": [ 146, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.getOptionsAtCurrPos", "code": "def getOptionsAtCurrPos : DelabM Options := do\n let ctx ← read\n let mut opts ← getOptions\n if let some opts' := ctx.optionsPerPos.find? (← getPos) then\n for (k, v) in opts' do\n opts := opts.insert k v\n return opts", "start": [ 148, 1 ], "end": [ 154, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.getPPOption", "code": "def getPPOption (opt : Options β†’ Ξ±) : DelabM Ξ± := do\n return opt (← getOptionsAtCurrPos)", "start": [ 156, 1 ], "end": [ 158, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.whenPPOption", "code": "def whenPPOption (opt : Options β†’ Bool) (d : Delab) : Delab := do\n let b ← getPPOption opt\n if b then d else failure", "start": [ 160, 1 ], "end": [ 162, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.whenNotPPOption", "code": "def whenNotPPOption (opt : Options β†’ Bool) (d : Delab) : Delab := do\n let b ← getPPOption opt\n if b then failure else d", "start": [ 164, 1 ], "end": [ 166, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withOptionAtCurrPos", "code": "def withOptionAtCurrPos (k : Name) (v : DataValue) (x : DelabM Ξ±) : DelabM Ξ± := do\n let pos ← getPos\n withReader\n (fun ctx =>\n let opts' := ctx.optionsPerPos.find? pos |>.getD {} |>.insert k v\n { ctx with optionsPerPos := ctx.optionsPerPos.insert pos opts' })\n x", "start": [ 168, 1 ], "end": [ 175, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.annotatePos", "code": "def annotatePos (pos : Pos) (stx : Term) : Term :=\n ⟨stx.raw.setInfo (SourceInfo.synthetic ⟨pos⟩ ⟨pos⟩)⟩", "start": [ 177, 1 ], "end": [ 178, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.annotateCurPos", "code": "def annotateCurPos (stx : Term) : Delab :=\n return annotatePos (← getPos) stx", "start": [ 180, 1 ], "end": [ 181, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.addTermInfo", "code": "def addTermInfo (pos : Pos) (stx : Syntax) (e : Expr) (isBinder : Bool := false) : DelabM Unit := do\n let info := Info.ofTermInfo <| ← mkTermInfo stx e isBinder\n modify fun s => { s with infos := s.infos.insert pos info }\nwhere\n mkTermInfo stx e isBinder := return {\n elaborator := `Delab,\n stx := stx,\n lctx := (← getLCtx),\n expectedType? := none,\n expr := e,\n isBinder := isBinder\n }", "start": [ 183, 1 ], "end": [ 194, 3 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.addFieldInfo", "code": "def addFieldInfo (pos : Pos) (projName fieldName : Name) (stx : Syntax) (val : Expr) : DelabM Unit := do\n let info := Info.ofFieldInfo <| ← mkFieldInfo projName fieldName stx val\n modify fun s => { s with infos := s.infos.insert pos info }\nwhere\n mkFieldInfo projName fieldName stx val := return {\n projName := projName,\n fieldName := fieldName,\n lctx := (← getLCtx),\n val := val,\n stx := stx\n }", "start": [ 196, 1 ], "end": [ 206, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.annotateTermInfo", "code": "def annotateTermInfo (stx : Term) : Delab := do\n let stx ← annotateCurPos stx\n addTermInfo (← getPos) stx (← getExpr)\n pure stx", "start": [ 208, 1 ], "end": [ 215, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withAnnotateTermInfo", "code": "def withAnnotateTermInfo (d : Delab) : Delab := do\n let stx ← d\n annotateTermInfo stx", "start": [ 217, 1 ], "end": [ 223, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.getUnusedName", "code": "def getUnusedName (suggestion : Name) (body : Expr) : DelabM Name := do\n let suggestion := if suggestion.isAnonymous then `a else suggestion\n let suggestion := suggestion.eraseMacroScopes\n let lctx ← getLCtx\n if !lctx.usesUserName suggestion then\n return suggestion\n else if (← getPPOption getPPSafeShadowing) && !bodyUsesSuggestion lctx suggestion then\n return suggestion\n else\n return lctx.getUnusedName suggestion\nwhere\n bodyUsesSuggestion (lctx : LocalContext) (suggestion' : Name) : Bool :=\n Option.isSome <| body.find? fun\n | Expr.fvar fvarId =>\n match lctx.find? fvarId with\n | none => false\n | some decl => decl.userName == suggestion'\n | _ => false", "start": [ 225, 1 ], "end": [ 244, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.mkAnnotatedIdent", "code": "def mkAnnotatedIdent (n : Name) (e : Expr) : DelabM Ident := do\n let pos ← nextExtraPos\n let stx : Syntax := annotatePos pos (mkIdent n)\n addTermInfo pos stx e\n return ⟨stx⟩", "start": [ 246, 1 ], "end": [ 253, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withBindingBodyUnusedName", "code": "def withBindingBodyUnusedName {Ξ±} (d : Syntax β†’ DelabM Ξ±) : DelabM Ξ± := do\n let n ← getUnusedName (← getExpr).bindingName! (← getExpr).bindingBody!\n withBindingBody' n (mkAnnotatedIdent n) (d Β·)", "start": [ 255, 1 ], "end": [ 262, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.OmissionReason", "code": "inductive OmissionReason\n | deep\n | proof\n | maxSteps", "start": [ 264, 1 ], "end": [ 267, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.OmissionReason.toString", "code": "def OmissionReason.toString : OmissionReason β†’ String\n | deep => \"Term omitted due to its depth (see option `pp.deepTerms`).\"\n | proof => \"Proof omitted (see option `pp.proofs`).\"\n | maxSteps => \"Term omitted due to reaching the maximum number of steps allowed for pretty printing this expression (see option `pp.maxSteps`).\"", "start": [ 269, 1 ], "end": [ 272, 147 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.addOmissionInfo", "code": "def addOmissionInfo (pos : Pos) (stx : Syntax) (e : Expr) (reason : OmissionReason) : DelabM Unit := do\n let info := Info.ofOmissionInfo <| ← mkOmissionInfo stx e\n modify fun s => { s with infos := s.infos.insert pos info }\nwhere\n mkOmissionInfo stx e := return {\n toTermInfo := ← addTermInfo.mkTermInfo stx e (isBinder := false)\n reason := reason.toString\n }", "start": [ 274, 1 ], "end": [ 281, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withIncDepth", "code": "def withIncDepth (act : DelabM Ξ±) : DelabM Ξ± := fun ctx =>\n act { ctx with depth := ctx.depth + 1 }", "start": [ 283, 1 ], "end": [ 289, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.isShallowExpression", "code": "def isShallowExpression (threshold : Nat) (e : Expr) : Bool :=\n let threshold := min 254 threshold\n e.approxDepth.toNat ≀ threshold", "start": [ 291, 1 ], "end": [ 302, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.shouldOmitExpr", "code": "def shouldOmitExpr (e : Expr) : DelabM Bool := do\n if e.isAtomic then\n return false\n\n if (← getPPOption getPPDeepTerms) then\n return false\n\n let depth := (← read).depth\n let depthThreshold ← getPPOption getPPDeepTermsThreshold\n let depthExcess := depth - depthThreshold\n let threshold := depthThreshold/4 - depthExcess\n\n return depthExcess > 0 && !isShallowExpression threshold e", "start": [ 304, 1 ], "end": [ 326, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.shouldOmitProof", "code": "def shouldOmitProof (e : Expr) : DelabM Bool := do\n if e.isAtomic then\n return false\n\n if (← getPPOption getPPProofs) then\n return false\n\n unless (← try Meta.isProof e catch _ => pure false) do\n return false\n\n return !isShallowExpression (← getPPOption getPPProofsThreshold) e", "start": [ 328, 1 ], "end": [ 347, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.omission", "code": "def omission (reason : OmissionReason) : Delab := do\n let stx ← `(β‹―)\n let stx ← annotateCurPos stx\n addOmissionInfo (← getPos) stx (← getExpr) reason\n pure stx", "start": [ 349, 1 ], "end": [ 357, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabFor", "code": "partial def delabFor : Name β†’ Delab\n | Name.anonymous => failure\n | k =>\n (do annotateTermInfo (← (delabAttribute.getValues (← getEnv) k).firstM id))\n <|> if k.isAtomic then failure else delabFor k.getRoot", "start": [ 359, 1 ], "end": [ 364, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delab", "code": "partial def delab : Delab := do\n checkSystem \"delab\"\n\n if (← get).steps β‰₯ (← getPPOption getPPMaxSteps) then\n return ← omission .maxSteps\n modify fun s => {s with steps := s.steps + 1}\n\n let e ← getExpr\n\n if ← shouldOmitExpr e then\n return ← omission .deep\n\n if ← shouldOmitProof e then\n let pf ← omission .proof\n if ← getPPOption getPPProofsWithType then\n let stx ← withType delab\n return ← annotateCurPos (← `(($pf : $stx)))\n else\n return pf\n\n let k ← getExprKind\n let stx ← withIncDepth <| delabFor k <|> (liftM $ show MetaM _ from throwError \"don't know how to delaborate '{k}'\")\n if ← getPPOption getPPAnalyzeTypeAscriptions <&&> getPPOption getPPAnalysisNeedsType <&&> pure !e.isMData then\n let typeStx ← withType delab\n `(($stx : $typeStx)) >>= annotateCurPos\n else\n return stx", "start": [ 366, 1 ], "end": [ 392, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.mkAppUnexpanderAttribute", "code": "unsafe def mkAppUnexpanderAttribute : IO (KeyedDeclsAttribute Unexpander) :=\n KeyedDeclsAttribute.init {\n name := `app_unexpander,\n descr := \"Register an unexpander for applications of a given constant.\n\n[app_unexpander c] registers a `Lean.PrettyPrinter.Unexpander` for applications of the constant `c`. The unexpander is\npassed the result of pre-pretty printing the application *without* implicitly passed arguments. If `pp.explicit` is set\nto true or `pp.notation` is set to false, it will not be called at all.\",\n valueTypeName := `Lean.PrettyPrinter.Unexpander\n evalKey := fun _ stx => do\n Elab.realizeGlobalConstNoOverloadWithInfo (← Attribute.Builtin.getIdent stx)\n } `Lean.PrettyPrinter.Delaborator.appUnexpanderAttribute", "start": [ 394, 1 ], "end": [ 405, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.appUnexpanderAttribute", "code": "@[builtin_init mkAppUnexpanderAttribute] opaque appUnexpanderAttribute : KeyedDeclsAttribute Unexpander", "start": [ 406, 1 ], "end": [ 406, 104 ], "kind": "commanddeclaration" }, { "full_name": "delabCore", "code": "def delabCore (e : Expr) (optionsPerPos : OptionsPerPos := {}) (delab : DelabM Ξ±) :\n MetaM (Ξ± Γ— PosMap Elab.Info) := do\n \n let e ← Meta.erasePatternRefAnnotations e\n trace[PrettyPrinter.delab.input] \"{Std.format e}\"\n let mut opts ← getOptions\n if pp.proofs.get? opts == none &&\n !e.isConst then\n try if ← Meta.isProof e then opts := pp.proofs.set opts true\n catch _ => pure ()\n withOptions (fun _ => opts) do\n let e ← if getPPInstantiateMVars opts then instantiateMVars e else pure e\n let e ← if getPPBeta opts then Core.betaReduce e else pure e\n let optionsPerPos ←\n if !getPPAll opts && getPPAnalyze opts && optionsPerPos.isEmpty then\n topDownAnalyze e\n else pure optionsPerPos\n let (stx, {infos := infos, ..}) ← catchInternalId Delaborator.delabFailureId\n (delab\n { optionsPerPos := optionsPerPos\n currNamespace := (← getCurrNamespace)\n openDecls := (← getOpenDecls)\n subExpr := SubExpr.mkRoot e\n inPattern := opts.getInPattern }\n |>.run { : Delaborator.State })\n (fun _ => unreachable!)\n return (stx, infos)", "start": [ 413, 1 ], "end": [ 442, 24 ], "kind": "commanddeclaration" }, { "full_name": "delab", "code": "def delab (e : Expr) (optionsPerPos : OptionsPerPos := {}) : MetaM Term := do\n let (stx, _) ← delabCore e optionsPerPos Delaborator.delab\n return stx", "start": [ 444, 1 ], "end": [ 447, 13 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/CoeAttr.lean
[ ".lake/packages/lean4/src/lean/Lean/Attributes.lean", ".lake/packages/lean4/src/lean/Lean/ScopedEnvExtension.lean", ".lake/packages/lean4/src/lean/Lean/Meta/FunInfo.lean" ]
[ { "full_name": "Lean.Meta.CoeFnType", "code": "inductive CoeFnType\n \n | coe\n \n | coeFun\n \n | coeSort\n deriving Inhabited, Repr, DecidableEq", "start": [ 26, 1 ], "end": [ 34, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.CoeFnInfo", "code": "structure CoeFnInfo where\n \n numArgs : Nat\n \n coercee : Nat\n \n type : CoeFnType\n deriving Inhabited, Repr", "start": [ 43, 1 ], "end": [ 51, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getCoeFnInfo?", "code": "def getCoeFnInfo? (fn : Name) : CoreM (Option CoeFnInfo) :=\n return (coeExt.getState (← getEnv)).find? fn", "start": [ 65, 1 ], "end": [ 67, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.registerCoercion", "code": "def registerCoercion (name : Name) (info : Option CoeFnInfo := none) : MetaM Unit := do\n let info ← match info with | some info => pure info | none => do\n let fnInfo ← getFunInfo (← mkConstWithLevelParams name)\n let some coercee := fnInfo.paramInfo.findIdx? (Β·.binderInfo.isExplicit)\n | throwError \"{name} has no explicit arguments\"\n pure { numArgs := coercee + 1, coercee, type := .coe }\n modifyEnv fun env => coeExt.addEntry env (name, info)", "start": [ 69, 1 ], "end": [ 76, 56 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Util.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/PPGoal.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Util/ForEachExprWhere.lean" ]
[ { "full_name": "Lean.MVarId.getTag", "code": "def _root_.Lean.MVarId.getTag (mvarId : MVarId) : MetaM Name :=\n return (← mvarId.getDecl).userName", "start": [ 14, 1 ], "end": [ 16, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMVarTag", "code": "@[deprecated MVarId.getTag (since := \"2022-07-15\")]\ndef getMVarTag (mvarId : MVarId) : MetaM Name :=\n mvarId.getTag", "start": [ 18, 1 ], "end": [ 20, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.setTag", "code": "def _root_.Lean.MVarId.setTag (mvarId : MVarId) (tag : Name) : MetaM Unit := do\n modify fun s => { s with mctx := s.mctx.setMVarUserName mvarId tag }", "start": [ 22, 1 ], "end": [ 23, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.setMVarTag", "code": "@[deprecated MVarId.setTag (since := \"2022-07-15\")]\ndef setMVarTag (mvarId : MVarId) (tag : Name) : MetaM Unit := do\n mvarId.setTag tag", "start": [ 25, 1 ], "end": [ 27, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.appendTag", "code": "def appendTag (tag : Name) (suffix : Name) : Name :=\n tag.modifyBase (Β· ++ suffix.eraseMacroScopes)", "start": [ 29, 1 ], "end": [ 30, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.appendTagSuffix", "code": "def appendTagSuffix (mvarId : MVarId) (suffix : Name) : MetaM Unit := do\n let tag ← mvarId.getTag\n mvarId.setTag (appendTag tag suffix)", "start": [ 32, 1 ], "end": [ 34, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkFreshExprSyntheticOpaqueMVar", "code": "def mkFreshExprSyntheticOpaqueMVar (type : Expr) (tag : Name := Name.anonymous) : MetaM Expr :=\n mkFreshExprMVar type MetavarKind.syntheticOpaque tag", "start": [ 36, 1 ], "end": [ 37, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwTacticEx", "code": "def throwTacticEx (tacticName : Name) (mvarId : MVarId) (msg? : Option MessageData := none) : MetaM Ξ± :=\n match msg? with\n | none => throwError \"tactic '{tacticName}' failed\\n{mvarId}\"\n | some msg => throwError \"tactic '{tacticName}' failed, {msg}\\n{mvarId}\"", "start": [ 39, 1 ], "end": [ 42, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwNestedTacticEx", "code": "def throwNestedTacticEx {Ξ±} (tacticName : Name) (ex : Exception) : MetaM Ξ± := do\n throwError \"tactic '{tacticName}' failed, nested error:\\n{ex.toMessageData}\"", "start": [ 44, 1 ], "end": [ 45, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.checkNotAssigned", "code": "def _root_.Lean.MVarId.checkNotAssigned (mvarId : MVarId) (tacticName : Name) : MetaM Unit := do\n if (← mvarId.isAssigned) then\n throwTacticEx tacticName mvarId \"metavariable has already been assigned\"", "start": [ 47, 1 ], "end": [ 50, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.checkNotAssigned", "code": "@[deprecated MVarId.checkNotAssigned (since := \"2022-07-15\")]\ndef checkNotAssigned (mvarId : MVarId) (tacticName : Name) : MetaM Unit := do\n mvarId.checkNotAssigned tacticName", "start": [ 52, 1 ], "end": [ 54, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.getType", "code": "def _root_.Lean.MVarId.getType (mvarId : MVarId) : MetaM Expr :=\n return (← mvarId.getDecl).type", "start": [ 56, 1 ], "end": [ 58, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMVarType", "code": "@[deprecated MVarId.getType (since := \"2022-07-15\")]\ndef getMVarType (mvarId : MVarId) : MetaM Expr :=\n mvarId.getType", "start": [ 60, 1 ], "end": [ 62, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.getType'", "code": "def _root_.Lean.MVarId.getType' (mvarId : MVarId) : MetaM Expr := do\n instantiateMVars (← whnf (← mvarId.getType))", "start": [ 64, 1 ], "end": [ 70, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getMVarType'", "code": "@[deprecated MVarId.getType' (since := \"2022-07-15\")]\ndef getMVarType' (mvarId : MVarId) : MetaM Expr := do\n mvarId.getType'", "start": [ 72, 1 ], "end": [ 74, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.admit", "code": "def _root_.Lean.MVarId.admit (mvarId : MVarId) (synthetic := true) : MetaM Unit :=\n mvarId.withContext do\n mvarId.checkNotAssigned `admit\n let mvarType ← mvarId.getType\n let val ← mkSorry mvarType synthetic\n mvarId.assign val", "start": [ 78, 1 ], "end": [ 84, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.admit", "code": "@[deprecated MVarId.admit (since := \"2022-07-15\")]\ndef admit (mvarId : MVarId) (synthetic := true) : MetaM Unit :=\n mvarId.admit synthetic", "start": [ 86, 1 ], "end": [ 88, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.headBetaType", "code": "def _root_.Lean.MVarId.headBetaType (mvarId : MVarId) : MetaM Unit := do\n mvarId.setType (← mvarId.getType).headBeta", "start": [ 90, 1 ], "end": [ 92, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.headBetaMVarType", "code": "@[deprecated MVarId.headBetaType (since := \"2022-07-15\")]\ndef headBetaMVarType (mvarId : MVarId) : MetaM Unit := do\n mvarId.headBetaType", "start": [ 94, 1 ], "end": [ 96, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.getNondepPropHyps", "code": "def _root_.Lean.MVarId.getNondepPropHyps (mvarId : MVarId) : MetaM (Array FVarId) :=\n let removeDeps (e : Expr) (candidates : FVarIdHashSet) : MetaM FVarIdHashSet := do\n let e ← instantiateMVars e\n let visit : StateRefT FVarIdHashSet MetaM FVarIdHashSet := do\n e.forEachWhere Expr.isFVar fun e => modify fun s => s.erase e.fvarId!\n get\n visit |>.run' candidates\n mvarId.withContext do\n let mut candidates : FVarIdHashSet := {}\n for localDecl in (← getLCtx) do\n unless localDecl.isImplementationDetail do\n candidates ← removeDeps localDecl.type candidates\n match localDecl.value? with\n | none => pure ()\n | some value => candidates ← removeDeps value candidates\n if (← isProp localDecl.type) && !localDecl.hasValue then\n candidates := candidates.insert localDecl.fvarId\n candidates ← removeDeps (← mvarId.getType) candidates\n if candidates.isEmpty then\n return #[]\n else\n let mut result := #[]\n for localDecl in (← getLCtx) do\n if candidates.contains localDecl.fvarId then\n result := result.push localDecl.fvarId\n return result", "start": [ 98, 1 ], "end": [ 124, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getNondepPropHyps", "code": "@[deprecated MVarId.getNondepPropHyps (since := \"2022-07-15\")]\ndef getNondepPropHyps (mvarId : MVarId) : MetaM (Array FVarId) :=\n mvarId.getNondepPropHyps", "start": [ 126, 1 ], "end": [ 128, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.saturate", "code": "partial def saturate (mvarId : MVarId) (x : MVarId β†’ MetaM (Option (List MVarId))) : MetaM (List MVarId) := do\n let (_, r) ← go mvarId |>.run #[]\n return r.toList\nwhere\n go (mvarId : MVarId) : StateRefT (Array MVarId) MetaM Unit :=\n withIncRecDepth do\n match (← x mvarId) with\n | none => modify fun s => s.push mvarId\n | some mvarIds => mvarIds.forM go", "start": [ 130, 1 ], "end": [ 138, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.exactlyOne", "code": "def exactlyOne (mvarIds : List MVarId) (msg : MessageData := \"unexpected number of goals\") : MetaM MVarId :=\n match mvarIds with\n | [mvarId] => return mvarId\n | _ => throwError msg", "start": [ 140, 1 ], "end": [ 143, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.ensureAtMostOne", "code": "def ensureAtMostOne (mvarIds : List MVarId) (msg : MessageData := \"unexpected number of goals\") : MetaM (Option MVarId) :=\n match mvarIds with\n | [] => return none\n | [mvarId] => return some mvarId\n | _ => throwError msg", "start": [ 145, 1 ], "end": [ 149, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getPropHyps", "code": "def getPropHyps : MetaM (Array FVarId) := do\n let mut result := #[]\n for localDecl in (← getLCtx) do\n unless localDecl.isImplementationDetail do\n if (← isProp localDecl.type) then\n result := result.push localDecl.fvarId\n return result", "start": [ 151, 1 ], "end": [ 158, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.inferInstance", "code": "def _root_.Lean.MVarId.inferInstance (mvarId : MVarId) : MetaM Unit := mvarId.withContext do\n mvarId.checkNotAssigned `infer_instance\n let synthVal ← synthInstance (← mvarId.getType)\n unless (← isDefEq (mkMVar mvarId) synthVal) do\n throwTacticEx `infer_instance mvarId \"`infer_instance` tactic failed to assign instance\"", "start": [ 160, 1 ], "end": [ 164, 93 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.TacticResultCNM", "code": "inductive TacticResultCNM where\n | closed\n | noChange\n | modified (mvarId : MVarId)", "start": [ 166, 1 ], "end": [ 169, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.isSubsingleton", "code": "def _root_.Lean.MVarId.isSubsingleton (g : MVarId) : MetaM Bool := do\n try\n discard <| synthInstance (← mkAppM ``Subsingleton #[← g.getType])\n return true\n catch _ =>\n return false", "start": [ 172, 1 ], "end": [ 178, 17 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Init/Data/Array/Mem.lean
[ ".lake/packages/lean4/src/lean/Init/Data/Nat/Linear.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/Basic.lean", ".lake/packages/lean4/src/lean/Init/Data/List/BasicAux.lean" ]
[ { "full_name": "Array.Mem", "code": "structure Mem (a : α) (as : Array α) : Prop where\n val : a ∈ as.data", "start": [ 13, 1 ], "end": [ 17, 20 ], "kind": "commanddeclaration" }, { "full_name": "Array.sizeOf_lt_of_mem", "code": "theorem sizeOf_lt_of_mem [SizeOf α] {as : Array α} (h : a ∈ as) : sizeOf a < sizeOf as", "start": [ 22, 1 ], "end": [ 24, 67 ], "kind": "commanddeclaration" }, { "full_name": "Array.sizeOf_get", "code": "@[simp] theorem sizeOf_get [SizeOf α] (as : Array α) (i : Fin as.size) : sizeOf (as.get i) < sizeOf as", "start": [ 26, 1 ], "end": [ 28, 58 ], "kind": "commanddeclaration" }, { "full_name": "Array.sizeOf_getElem", "code": "@[simp] theorem sizeOf_getElem [SizeOf α] (as : Array α) (i : Nat) (h : i < as.size) :\n sizeOf (as[i]'h) < sizeOf as", "start": [ 30, 1 ], "end": [ 31, 49 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Builtins.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/SubExpr.lean", ".lake/packages/lean4/src/lean/Lean/Meta/CoeAttr.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Parser.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/TopDownAnalyze.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Attributes.lean" ]
[ { "full_name": "Lean.PrettyPrinter.Delaborator.withTypeAscription", "code": "def withTypeAscription (d : Delab) (cond : Bool := true) : DelabM Term := do\n let stx ← d\n if cond then\n let stx ← annotateCurPos stx\n let typeStx ← withType delab\n `(($stx : $typeStx))\n else\n return stx", "start": [ 20, 1 ], "end": [ 30, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.maybeAddBlockImplicit", "code": "def maybeAddBlockImplicit (identLike : Syntax) : DelabM Syntax := do\n if ← getPPOption getPPAnalysisBlockImplicit then `(@$identLike) else pure identLike", "start": [ 32, 1 ], "end": [ 36, 86 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabFVar", "code": "@[builtin_delab fvar]\ndef delabFVar : Delab := do\n let Expr.fvar fvarId ← getExpr | unreachable!\n try\n let l ← fvarId.getDecl\n maybeAddBlockImplicit (mkIdent l.userName)\n catch _ =>\n maybeAddBlockImplicit <| mkIdent (fvarId.name.replacePrefix `_uniq `_fvar)", "start": [ 38, 1 ], "end": [ 46, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabBVar", "code": "@[builtin_delab bvar]\ndef delabBVar : Delab := do\n let Expr.bvar idx ← getExpr | unreachable!\n pure $ mkIdent $ Name.mkSimple $ \"#\" ++ toString idx", "start": [ 49, 1 ], "end": [ 52, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabMVar", "code": "@[builtin_delab mvar]\ndef delabMVar : Delab := do\n let Expr.mvar n ← getExpr | unreachable!\n withTypeAscription (cond := ← getPPOption getPPMVarsWithType) do\n if ← getPPOption getPPMVars then\n let mvarDecl ← n.getDecl\n let n :=\n match mvarDecl.userName with\n | .anonymous => n.name.replacePrefix `_uniq `m\n | n => n\n `(?$(mkIdent n))\n else\n `(?_)", "start": [ 54, 1 ], "end": [ 66, 12 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabSort", "code": "@[builtin_delab sort]\ndef delabSort : Delab := do\n let Expr.sort l ← getExpr | unreachable!\n match l with\n | Level.zero => `(Prop)\n | Level.succ .zero => `(Type)\n | _ =>\n let mvars ← getPPOption getPPMVars\n match l.dec with\n | some l' => `(Type $(Level.quote l' (prec := max_prec) (mvars := mvars)))\n | none => `(Sort $(Level.quote l (prec := max_prec) (mvars := mvars)))", "start": [ 68, 1 ], "end": [ 78, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabConst", "code": "def delabConst : Delab := do\n let Expr.const cβ‚€ ls ← getExpr | unreachable!\n let cβ‚€ := if (← getPPOption getPPPrivateNames) then cβ‚€ else (privateToUserName? cβ‚€).getD cβ‚€\n\n let mut c ← unresolveNameGlobal cβ‚€ (fullNames := ← getPPOption getPPFullNames)\n let stx ← if ls.isEmpty || !(← getPPOption getPPUniverses) then\n if (← getLCtx).usesUserName c then\n if c == cβ‚€ && !(← read).inPattern then\n c := `_root_ ++ c\n else\n c := cβ‚€\n pure <| mkIdent c\n else\n let mvars ← getPPOption getPPMVars\n `($(mkIdent c).{$[$(ls.toArray.map (Level.quote Β· (prec := 0) (mvars := mvars)))],*})\n\n let stx ← maybeAddBlockImplicit stx\n if (← getPPOption getPPTagAppFns) then\n annotateTermInfo stx\n else\n return stx", "start": [ 80, 1 ], "end": [ 108, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withMDataOptions", "code": "def withMDataOptions [Inhabited Ξ±] (x : DelabM Ξ±) : DelabM Ξ± := do\n match ← getExpr with\n | Expr.mdata m .. =>\n let mut posOpts := (← read).optionsPerPos\n let pos ← getPos\n for (k, v) in m do\n if (`pp).isPrefixOf k then\n let opts := posOpts.find? pos |>.getD {}\n posOpts := posOpts.insert pos (opts.insert k v)\n withReader ({ Β· with optionsPerPos := posOpts }) $ withMDataExpr x\n | _ => x", "start": [ 110, 1 ], "end": [ 120, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withMDatasOptions", "code": "partial def withMDatasOptions [Inhabited Ξ±] (x : DelabM Ξ±) : DelabM Ξ± := do\n if (← getExpr).isMData then withMDataOptions (withMDatasOptions x) else x", "start": [ 122, 1 ], "end": [ 123, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.ParamKind", "code": "structure ParamKind where\n \n name : Name\n \n bInfo : BinderInfo\n \n defVal : Option Expr := none\n \n isAutoParam : Bool := false\n deriving Inhabited", "start": [ 125, 1 ], "end": [ 137, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.ParamKind.isRegularExplicit", "code": "def ParamKind.isRegularExplicit (param : ParamKind) : Bool :=\n param.bInfo.isExplicit && !param.isAutoParam && param.defVal.isNone", "start": [ 139, 1 ], "end": [ 143, 70 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.getParamKinds", "code": "def getParamKinds (f : Expr) (args : Array Expr) : MetaM (Array ParamKind) := do\n try\n let mut result : Array ParamKind := Array.mkEmpty args.size\n let mut fnType ← inferType f\n let mut j := 0\n for i in [0:args.size] do\n unless fnType.isForall do\n fnType ← withTransparency .all <| whnf (fnType.instantiateRevRange j i args)\n j := i\n let .forallE n t b bi := fnType | failure\n let defVal := t.getOptParamDefault? |>.map (Β·.instantiateRevRange j i args)\n result := result.push { name := n, bInfo := bi, defVal, isAutoParam := t.isAutoParam }\n fnType := b\n fnType := fnType.instantiateRevRange j args.size args\n forallTelescopeReducing fnType fun xs _ => do\n xs.foldlM (init := result) fun result x => do\n let l ← x.fvarId!.getDecl\n pure <| result.push { name := l.userName, bInfo := l.binderInfo, defVal := l.type.getOptParamDefault?, isAutoParam := l.type.isAutoParam }\n catch _ => pure #[]", "start": [ 145, 1 ], "end": [ 180, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.shouldShowMotive", "code": "def shouldShowMotive (motive : Expr) (opts : Options) : MetaM Bool := do\n pure (getPPMotivesAll opts)\n <||> (pure (getPPMotivesPi opts) <&&> returnsPi motive)\n <||> (pure (getPPMotivesNonConst opts) <&&> isNonConstFun motive)", "start": [ 182, 1 ], "end": [ 185, 68 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.unexpandStructureInstance", "code": "def unexpandStructureInstance (stx : Syntax) : Delab := whenPPOption getPPStructureInstances do\n let env ← getEnv\n let e ← getExpr\n let some s ← isConstructorApp? e | failure\n guard <| isStructure env s.induct\n \n let fieldNames := getStructureFields env s.induct\n let mut fields := #[]\n guard $ fieldNames.size == stx[1].getNumArgs\n if hasPPUsingAnonymousConstructorAttribute env s.induct then\n return ← withTypeAscription (cond := (← withType <| getPPOption getPPStructureInstanceType)) do\n `(⟨$[$(stx[1].getArgs)],*⟩)\n let args := e.getAppArgs\n let fieldVals := args.extract s.numParams args.size\n for idx in [:fieldNames.size] do\n let fieldName := fieldNames[idx]!\n if (← getPPOption getPPStructureInstancesFlatten) && (Lean.isSubobjectField? env s.induct fieldName).isSome then\n match stx[1][idx] with\n | `({ $fields',* $[: $_]?}) =>\n fields := fields ++ fields'.getElems\n continue\n | _ => pure ()\n let fieldId := mkIdent fieldName\n let fieldPos ← nextExtraPos\n let fieldId := annotatePos fieldPos fieldId\n addFieldInfo fieldPos (s.induct ++ fieldName) fieldName fieldId fieldVals[idx]!\n let field ← `(structInstField|$fieldId:ident := $(stx[1][idx]))\n fields := fields.push field\n let tyStx ← withType do\n if (← getPPOption getPPStructureInstanceType) then delab >>= pure ∘ some else pure none\n `({ $fields,* $[: $tyStx]? })", "start": [ 187, 1 ], "end": [ 224, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.appFieldNotationCandidate?", "code": "def appFieldNotationCandidate? : DelabM (Option (Nat Γ— Name)) := do\n let e ← getExpr\n unless e.isApp do return none\n let some (field, idx) ← fieldNotationCandidate? e.getAppFn e.getAppArgs (← getPPOption getPPFieldNotationGeneralized)\n | return none\n unless idx < e.getAppNumArgs do return none\n \n let obj := e.getArg! idx\n if obj.isRawNatLit || obj.isAppOfArity ``OfNat.ofNat 3 || obj.isAppOfArity ``OfScientific.ofScientific 5 then\n return none\n return (idx, field)", "start": [ 226, 1 ], "end": [ 245, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withoutParentProjections", "code": "private partial def withoutParentProjections (explicit : Bool) (d : DelabM Ξ±) : DelabM Ξ± := do\n if ← try isParentProj explicit (← getExpr) catch _ => pure false then\n withAppArg <| withoutParentProjections explicit d\n else\n d", "start": [ 247, 1 ], "end": [ 258, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.stripParentProjections", "code": "private partial def stripParentProjections (s : Term) : DelabM Term :=\n match s with\n | `($x.$f:ident) => do\n if let some field ← try parentProj? false (← getExpr) catch _ => pure none then\n if f.getId == field then\n withAppArg <| stripParentProjections x\n else\n return s\n else\n return s\n | _ => return s", "start": [ 263, 1 ], "end": [ 274, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.needsExplicit", "code": "def needsExplicit (f : Expr) (numArgs : Nat) (paramKinds : Array ParamKind) : Bool :=\n if paramKinds.size == 0 && 0 < numArgs && f matches .const _ [] then\n false\n else\n paramKinds.size < numArgs\n || paramKinds[:numArgs].any (fun param => !param.bInfo.isExplicit)\n || (numArgs < paramKinds.size && paramKinds[numArgs]!.bInfo matches .implicit | .instImplicit)\n || paramKinds[numArgs:].any (fun param => param.bInfo.isExplicit && !param.isRegularExplicit)", "start": [ 276, 1 ], "end": [ 294, 98 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabAppExplicitCore", "code": "def delabAppExplicitCore (fieldNotation : Bool) (numArgs : Nat) (delabHead : (insertExplicit : Bool) β†’ Delab) (paramKinds : Array ParamKind) : Delab := do\n let insertExplicit := needsExplicit ((← getExpr).getBoundedAppFn numArgs) numArgs paramKinds\n let fieldNotation ← pure (fieldNotation && !insertExplicit) <&&> getPPOption getPPFieldNotation\n <&&> not <$> getPPOption getPPAnalysisNoDot\n <&&> withBoundedAppFn numArgs do pure (← getExpr).consumeMData.isConst <&&> not <$> withMDatasOptions (getPPOption getPPAnalysisBlockImplicit <|> getPPOption getPPUniverses)\n let field? ← if fieldNotation then appFieldNotationCandidate? else pure none\n let (fnStx, _, argStxs) ← withBoundedAppFnArgs numArgs\n (do return (← delabHead insertExplicit, paramKinds.toList, Array.mkEmpty numArgs))\n (fun ⟨fnStx, paramKinds, argStxs⟩ => do\n let isInstImplicit := paramKinds.head? |>.map (Β·.bInfo == .instImplicit) |>.getD false\n let argStx ← if some argStxs.size = field?.map Prod.fst then\n withoutParentProjections (explicit := true) delab\n else if ← getPPOption getPPAnalysisHole then `(_)\n else if isInstImplicit == true then\n withTypeAscription (cond := ← getPPOption getPPInstanceTypes) do\n if ← getPPOption getPPInstances then delab else `(_)\n else delab\n pure (fnStx, paramKinds.tailD [], argStxs.push argStx))\n if let some (idx, field) := field? then\n let obj := argStxs[idx]!\n let mut head : Term ← `($obj.$(mkIdent field))\n if idx == 0 then\n head ← withBoundedAppFn (numArgs - 1) <| annotateTermInfo head\n return Syntax.mkApp head (argStxs.eraseIdx idx)\n else\n return Syntax.mkApp fnStx argStxs", "start": [ 296, 1 ], "end": [ 330, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.AppImplicitArg", "code": "inductive AppImplicitArg\n \n | skip\n \n | regular (s : Term)\n \n | named (s : TSyntax ``Parser.Term.namedArgument)\n deriving Inhabited", "start": [ 332, 1 ], "end": [ 340, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.AppImplicitArg.canUnexpand", "code": "def AppImplicitArg.canUnexpand : AppImplicitArg β†’ Bool\n | .regular .. | .skip => true\n | .named .. => false", "start": [ 342, 1 ], "end": [ 345, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.AppImplicitArg.syntax?", "code": "def AppImplicitArg.syntax? : AppImplicitArg β†’ Option Syntax\n | .skip => none\n | .regular s => s\n | .named s => s", "start": [ 347, 1 ], "end": [ 351, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabAppImplicitCore", "code": "def delabAppImplicitCore (unexpand : Bool) (numArgs : Nat) (delabHead : Delab) (paramKinds : Array ParamKind) : Delab := do\n let unexpand ← pure unexpand\n <&&> withBoundedAppFn numArgs do pure (← getExpr).consumeMData.isConst <&&> not <$> withMDatasOptions (getPPOption getPPUniverses)\n let field? ←\n if ← pure unexpand <&&> getPPOption getPPFieldNotation <&&> not <$> getPPOption getPPAnalysisNoDot then\n appFieldNotationCandidate?\n else\n pure none\n let (fnStx, args) ←\n withBoundedAppFnArgs numArgs\n (do return ((← delabHead), Array.mkEmpty numArgs))\n (fun (fnStx, args) => do\n let idx := args.size\n let arg ← mkArg (numArgs - idx - 1) paramKinds[idx]!\n return (fnStx, args.push arg))\n\n if ← pure unexpand <&&> getPPOption getPPNotation then\n if let some stx ← (some <$> tryAppUnexpanders fnStx args) <|> pure none then\n return stx\n\n let stx := Syntax.mkApp fnStx (args.filterMap (Β·.syntax?))\n\n if ← pure (unexpand && args.all (Β·.canUnexpand)) <&&> getPPOption getPPStructureInstances then\n if let some stx ← (some <$> unexpandStructureInstance stx) <|> pure none then\n return stx\n\n if let some (fieldIdx, field) := field? then\n if fieldIdx < args.size then\n let obj? : Option Term ← do\n let arg := args[fieldIdx]!\n if let .regular s := arg then\n withNaryArg fieldIdx <| some <$> stripParentProjections s\n else\n pure none\n if let some obj := obj? then\n let isFirst := args[0:fieldIdx].all (Β· matches .skip)\n let args' := args.set! fieldIdx .skip\n let mut head : Term ← `($obj.$(mkIdent field))\n if isFirst then\n let objArity := args'.findIdx? (fun a => !(a matches .skip)) |>.getD args'.size\n head ← withBoundedAppFn (numArgs - objArity) <| annotateTermInfo <| head\n return Syntax.mkApp head (args'.filterMap (Β·.syntax?))\n\n return stx\nwhere\n mkNamedArg (name : Name) : DelabM AppImplicitArg :=\n return .named <| ← `(Parser.Term.namedArgument| ($(mkIdent name) := $(← delab)))\n \n mkArg (remainingArgs : Nat) (param : ParamKind) : DelabM AppImplicitArg := do\n let arg ← getExpr\n if ← getPPOption getPPAnalysisSkip then return .skip\n else if ← getPPOption getPPAnalysisHole then return .regular (← `(_))\n else if ← getPPOption getPPAnalysisNamedArg then\n mkNamedArg param.name\n else if param.defVal.isSome && remainingArgs == 0 && param.defVal.get! == arg then\n return .skip\n else if param.bInfo.isExplicit then\n return .regular (← delab)\n else if ← pure (param.name == `motive) <&&> shouldShowMotive arg (← getOptions) then\n mkNamedArg param.name\n else\n return .skip\n \n tryUnexpand (fs : List Unexpander) (stx : Syntax) : DelabM Syntax := do\n let ref ← getRef\n fs.firstM fun f =>\n match f stx |>.run ref |>.run () with\n | EStateM.Result.ok stx _ => return stx\n | _ => failure\n \n tryAppUnexpanders (fnStx : Term) (args : Array AppImplicitArg) : Delab := do\n let .const c _ := (← getExpr).getAppFn.consumeMData | unreachable!\n let fs := appUnexpanderAttribute.getValues (← getEnv) c\n if fs.isEmpty then failure\n let rec go (i : Nat) (implicitArgs : Nat) (argStxs : Array Syntax) : DelabM Term := do\n match i with\n | 0 =>\n let stx ← tryUnexpand fs fnStx\n return Syntax.mkApp (← annotateTermInfo stx) (args.filterMap (Β·.syntax?))\n | i' + 1 =>\n if args[i']!.syntax?.isSome then\n (do let stx ← tryUnexpand fs <| Syntax.mkApp fnStx argStxs\n let argStxs' := args.extract i args.size |>.filterMap (Β·.syntax?)\n return Syntax.mkApp (← annotateTermInfo stx) argStxs')\n <|> withBoundedAppFn (implicitArgs + 1) (go i' 0 argStxs.pop)\n else\n go i' (implicitArgs + 1) argStxs\n let maxUnexpand := args.findIdx? (!Β·.canUnexpand) |>.getD args.size\n withBoundedAppFn (args.size - maxUnexpand) <|\n go maxUnexpand 0 (args.extract 0 maxUnexpand |>.filterMap (Β·.syntax?))", "start": [ 353, 1 ], "end": [ 471, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.useAppExplicit", "code": "def useAppExplicit (numArgs : Nat) (paramKinds : Array ParamKind) : DelabM Bool := do\n if ← getPPOption getPPExplicit then return true\n\n if ← withBoundedAppFn numArgs <| withMDatasOptions <| getPPOption getPPAnalysisBlockImplicit then\n return true\n\n if paramKinds.size < numArgs then return true\n\n if numArgs < paramKinds.size then\n let nextParam := paramKinds[numArgs]!\n\n if nextParam.bInfo matches .implicit | .instImplicit then return true\n\n if paramKinds[numArgs:].any fun param => param.bInfo.isExplicit && !param.isRegularExplicit then return true\n\n return false", "start": [ 473, 1 ], "end": [ 499, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabAppCore", "code": "def delabAppCore (maxArgs : Nat) (delabHead : (insertExplicit : Bool) β†’ Delab) (unexpand : Bool) : Delab := do\n let tagAppFn ← getPPOption getPPTagAppFns\n let delabHead' (insertExplicit : Bool) : Delab := withOptionAtCurrPos `pp.tagAppFns tagAppFn (delabHead insertExplicit)\n let e ← getExpr\n let fn := e.getBoundedAppFn maxArgs\n let args := e.getBoundedAppArgs maxArgs\n let paramKinds ← getParamKinds fn args\n if (← useAppExplicit args.size paramKinds) then\n delabAppExplicitCore (fieldNotation := unexpand && !tagAppFn) args.size delabHead' paramKinds\n else\n delabAppImplicitCore (unexpand := unexpand) args.size (delabHead' false) paramKinds", "start": [ 501, 1 ], "end": [ 521, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabApp", "code": "@[builtin_delab app]\ndef delabApp : Delab := do\n let delabAppFn (insertExplicit : Bool) : Delab := do\n let stx ← if (← getExpr).consumeMData.isConst then withMDatasOptions delabConst else delab\n if insertExplicit && !stx.raw.isOfKind ``Lean.Parser.Term.explicit then `(@$stx) else pure stx\n delabAppCore (← getExpr).getAppNumArgs delabAppFn (unexpand := true)", "start": [ 523, 1 ], "end": [ 531, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.withOverApp", "code": "def withOverApp (arity : Nat) (x : Delab) : Delab := do\n let n := (← getExpr).getAppNumArgs\n guard <| n β‰₯ arity\n if n == arity then\n x\n else\n let delabHead (insertExplicit : Bool) : Delab := do\n guard <| !insertExplicit\n withAnnotateTermInfo x\n delabAppCore (n - arity) delabHead (unexpand := false)", "start": [ 533, 1 ], "end": [ 565, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.AppMatchState", "code": "structure AppMatchState where\n info : MatcherInfo\n \n matcherTy : SubExpr\n \n motive : Option (Term Γ— Expr) := none\n \n motiveNamed : Bool := false\n \n discrs : Array Term := #[]\n \n hNames? : Array (Option Name) := #[]\n \n alts : Array SubExpr := #[]\n \n varNames : Array (Array Name) := #[]\n \n rhss : Array Term := #[]", "start": [ 567, 1 ], "end": [ 589, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.skippingBinders", "code": "private partial def skippingBinders {Ξ±} (numParams : Nat) (hNames : Array Name) (x : Array Name β†’ DelabM Ξ±) : DelabM Ξ± := do\n loop 0 #[]\nwhere\n loop (i : Nat) (varNames : Array Name) : DelabM Ξ± := do\n let rec visitLambda : DelabM Ξ± := do\n let varName := (← getExpr).bindingName!.eraseMacroScopes\n if numParams - hNames.size ≀ i then\n let varName := hNames[i + hNames.size - numParams]!\n withBindingBody varName do\n loop (i + 1) (varNames.push varName)\n else if varNames.contains varName then\n let varName := (← getLCtx).getUnusedName varName\n withBindingBody varName do\n loop (i + 1) (varNames.push varName)\n else\n withBindingBodyUnusedName fun id => do\n loop (i + 1) (varNames.push id.getId)\n if i < numParams then\n let e ← getExpr\n if e.isLambda then\n visitLambda\n else\n let e ← forallTelescopeReducing (← inferType e) fun xs _ => do\n if xs.size == 1 && (← inferType xs[0]!).isConstOf ``Unit then\n mkLambdaFVars xs (mkApp e (mkConst ``Unit.unit))\n else\n mkLambdaFVars xs (mkAppN e xs)\n withTheReader SubExpr (fun ctx => { ctx with expr := e }) visitLambda\n else x varNames", "start": [ 591, 1 ], "end": [ 631, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabAppMatch", "code": "@[builtin_delab app]\npartial def delabAppMatch : Delab := whenPPOption getPPNotation <| whenPPOption getPPMatch do\n let Expr.const c us := (← getExpr).getAppFn | failure\n let some info ← getMatcherInfo? c | failure\n withOverApp info.arity do\n let st : AppMatchState ← withBoundedAppFnArgs (1 + info.numDiscrs + info.numAlts)\n (do\n let params := (← getExpr).getAppArgs\n let matcherTy : SubExpr :=\n { expr := ← instantiateForall (← instantiateTypeLevelParams (← getConstInfo c) us) params\n pos := (← getPos).pushType }\n guard <| ← isDefEq matcherTy.expr (← inferType (← getExpr))\n return { info, matcherTy })\n (fun st => do\n if st.motive.isNone then\n let lamMotive ← getExpr\n let piMotive ← lambdaTelescope lamMotive fun xs body => mkForallFVars xs body\n let piStx ← withTheReader SubExpr (fun cfg => { cfg with expr := piMotive }) delab\n let named ← getPPOption getPPAnalysisNamedArg\n return { st with motive := (piStx, lamMotive), motiveNamed := named }\n else if st.discrs.size < st.info.numDiscrs then\n return { st with discrs := st.discrs.push (← delab) }\n else if st.alts.size < st.info.numAlts then\n return { st with alts := st.alts.push (← readThe SubExpr) }\n else\n panic! \"impossible, number of arguments does not match arity\")\n\n let st ← withDummyBinders (st.info.discrInfos.map (Β·.hName?)) (← getExpr) fun hNames? => do\n let hNames := hNames?.filterMap id\n let mut st := {st with hNames? := hNames?}\n for i in [0:st.alts.size] do\n st ← withTheReader SubExpr (fun _ => st.alts[i]!) do\n skippingBinders st.info.altNumParams[i]! hNames fun varNames => do\n let rhs ← delab\n return { st with rhss := st.rhss.push rhs, varNames := st.varNames.push varNames }\n return st\n\n if st.rhss.isEmpty then\n `(nomatch $(st.discrs),*)\n else\n let pats ← withReader (fun ctx => { ctx with inPattern := true, subExpr := st.matcherTy }) do\n forallTelescopeReducing (← getExpr) fun afterParams _ => do\n let alts := Array.ofSubarray afterParams[1 + st.discrs.size:]\n alts.mapIdxM fun idx alt => do\n let altTy ← inferType alt\n withTheReader SubExpr (fun ctx =>\n { ctx with expr := altTy, pos := ctx.pos.pushNthBindingDomain (1 + st.discrs.size + idx) }) do\n usingNames st.varNames[idx]! <|\n withAppFnArgs (pure #[]) fun pats => return pats.push (← delab)\n let discrs ← (st.hNames?.zip st.discrs).mapM fun (hName?, discr) =>\n match hName? with\n | none => `(matchDiscr| $discr:term)\n | some hName => `(matchDiscr| $(mkIdent hName) : $discr)\n let (piStx, lamMotive) := st.motive.get!\n let opts ← getOptions\n if ← pure st.motiveNamed <||> shouldShowMotive lamMotive opts then\n `(match (motive := $piStx) $[$discrs:matchDiscr],* with $[| $pats,* => $st.rhss]*)\n else\n `(match $[$discrs:matchDiscr],* with $[| $pats,* => $st.rhss]*)\nwhere\n \n withDummyBinders {Ξ± : Type} (hNames? : Array (Option Name)) (body : Expr)\n (m : Array (Option Name) β†’ DelabM Ξ±) (acc : Array (Option Name) := #[]) : DelabM Ξ± := do\n let i := acc.size\n if i < hNames?.size then\n if let some name := hNames?[i]! then\n let n' ← getUnusedName name body\n withLocalDecl n' .default (.sort levelZero) (kind := .implDetail) fun _ =>\n withDummyBinders hNames? body m (acc.push n')\n else\n withDummyBinders hNames? body m (acc.push none)\n else\n m acc\n\n usingNames {Ξ±} (varNames : Array Name) (x : DelabM Ξ±) (i : Nat := 0) : DelabM Ξ± :=\n if i < varNames.size then\n withBindingBody varNames[i]! <| usingNames varNames x (i+1)\n else\n x", "start": [ 633, 1 ], "end": [ 741, 8 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabLetFun", "code": "@[builtin_delab app.letFun]\ndef delabLetFun : Delab := whenPPOption getPPNotation <| withOverApp 4 do\n let e ← getExpr\n guard <| e.getAppNumArgs == 4\n let Expr.lam n _ b _ := e.appArg! | failure\n let n ← getUnusedName n b\n let stxV ← withAppFn <| withAppArg delab\n let (stxN, stxB) ← withAppArg <| withBindingBody' n (mkAnnotatedIdent n) fun stxN => return (stxN, ← delab)\n if ← getPPOption getPPLetVarTypes <||> getPPOption getPPAnalysisLetVarType then\n let stxT ← SubExpr.withNaryArg 0 delab\n `(let_fun $stxN : $stxT := $stxV; $stxB)\n else\n `(let_fun $stxN := $stxV; $stxB)", "start": [ 743, 1 ], "end": [ 758, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabMData", "code": "@[builtin_delab mdata]\ndef delabMData : Delab := do\n if let some _ := inaccessible? (← getExpr) then\n let s ← withMDataExpr delab\n if (← read).inPattern then\n `(.($s)) else\n return s\n else if let some _ := isLHSGoal? (← getExpr) then\n withMDataExpr <| withAppFn <| withAppArg <| delab\n else\n withMDataOptions delab", "start": [ 760, 1 ], "end": [ 771, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.hasIdent", "code": "partial def hasIdent (id : Name) : Syntax β†’ Bool\n | Syntax.ident _ _ id' _ => id == id'\n | Syntax.node _ _ args => args.any (hasIdent id)\n | _ => false", "start": [ 773, 1 ], "end": [ 781, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.shouldGroupWithNext", "code": "private def shouldGroupWithNext : DelabM Bool := do\n let e ← getExpr\n let ppEType ← getPPOption (getPPBinderTypes e)\n let go (e' : Expr) := do\n let ppE'Type ← withBindingBody `_ $ getPPOption (getPPBinderTypes e)\n pure $ e.binderInfo == e'.binderInfo &&\n e.bindingDomain! == e'.bindingDomain! &&\n e'.binderInfo != BinderInfo.instImplicit &&\n ppEType == ppE'Type &&\n (e'.binderInfo != BinderInfo.default || ppE'Type)\n match e with\n | Expr.lam _ _ e'@(Expr.lam _ _ _ _) _ => go e'\n | Expr.forallE _ _ e'@(Expr.forallE _ _ _ _) _ => go e'\n | _ => pure false\nwhere\n getPPBinderTypes (e : Expr) :=\n if e.isForall then getPPPiBinderTypes else getPPFunBinderTypes", "start": [ 783, 1 ], "end": [ 807, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabBinders", "code": "private partial def delabBinders (delabGroup : Array Syntax β†’ Syntax β†’ Delab) : optParam (Array Syntax) #[] β†’ Delab\n | curNames => do\n if ← shouldGroupWithNext then\n withBindingBodyUnusedName fun stxN => delabBinders delabGroup (curNames.push stxN)\n else\n let (stx, stxN) ← withBindingBodyUnusedName fun stxN => return (← delab, stxN)\n delabGroup (curNames.push stxN) stx", "start": [ 809, 1 ], "end": [ 820, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabLam", "code": "@[builtin_delab lam]\ndef delabLam : Delab :=\n delabBinders fun curNames stxBody => do\n let e ← getExpr\n let stxT ← withBindingDomain delab\n let ppTypes ← getPPOption getPPFunBinderTypes\n let usedDownstream := curNames.any (fun n => hasIdent n.getId stxBody)\n\n let blockImplicitLambda := true\n \n\n if !blockImplicitLambda then\n pure stxBody\n else\n let defaultCase (_ : Unit) : Delab := do\n if ppTypes then\n let stxCurNames ←\n if curNames.size > 1 then\n `($(curNames.get! 0) $(curNames.eraseIdx 0)*)\n else\n pure $ curNames.get! 0;\n `(funBinder| ($stxCurNames : $stxT))\n else\n pure curNames.back let group ← match e.binderInfo, ppTypes with\n | BinderInfo.default, _ => defaultCase ()\n | BinderInfo.implicit, true => `(funBinder| {$curNames* : $stxT})\n | BinderInfo.implicit, false => `(funBinder| {$curNames*})\n | BinderInfo.strictImplicit, true => `(funBinder| ⦃$curNames* : $stxT⦄)\n | BinderInfo.strictImplicit, false => `(funBinder| ⦃$curNames*⦄)\n | BinderInfo.instImplicit, _ =>\n if usedDownstream then `(funBinder| [$curNames.back : $stxT]) else `(funBinder| [$stxT])\n let (binders, stxBody) :=\n match stxBody with\n | `(fun $binderGroups* => $stxBody) => (#[group] ++ binderGroups, stxBody)\n | _ => (#[group], stxBody)\n if ← getPPOption getPPUnicodeFun then\n `(fun $binders* ↦ $stxBody)\n else\n `(fun $binders* => $stxBody)", "start": [ 822, 1 ], "end": [ 876, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabForallBinders", "code": "private partial def delabForallBinders (delabGroup : Array Syntax β†’ Bool β†’ Syntax β†’ Delab) (curNames : Array Syntax := #[]) (curDep := false) : Delab := do\n let dep := !(← getExpr).isArrow\n if !curNames.isEmpty && dep != curDep then\n delabGroup curNames curDep (← delab)\n else\n let curDep := dep\n if ← shouldGroupWithNext then\n withBindingBodyUnusedName fun stxN => delabForallBinders delabGroup (curNames.push stxN) curDep\n else\n let (stx, stxN) ← withBindingBodyUnusedName fun stxN => return (← delab, stxN)\n delabGroup (curNames.push stxN) curDep stx", "start": [ 878, 1 ], "end": [ 896, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabForall", "code": "@[builtin_delab forallE]\ndef delabForall : Delab := do\n delabForallBinders fun curNames dependent stxBody => do\n let e ← getExpr\n let prop ← try isProp e catch _ => pure false\n let stxT ← withBindingDomain delab\n let group ← match e.binderInfo with\n | BinderInfo.implicit => `(bracketedBinderF|{$curNames* : $stxT})\n | BinderInfo.strictImplicit => `(bracketedBinderF|⦃$curNames* : $stxT⦄)\n | BinderInfo.instImplicit => `(bracketedBinderF|[$curNames.back : $stxT])\n | _ =>\n if dependent then\n if prop && !(← getPPOption getPPPiBinderTypes) then\n return ← `(βˆ€ $curNames:ident*, $stxBody)\n else\n `(bracketedBinderF|($curNames* : $stxT))\n else\n return ← curNames.foldrM (fun _ stxBody => `($stxT β†’ $stxBody)) stxBody\n if prop then\n match stxBody with\n | `(βˆ€ $groups*, $stxBody) => `(βˆ€ $group $groups*, $stxBody)\n | _ => `(βˆ€ $group, $stxBody)\n else\n `($group:bracketedBinder β†’ $stxBody)", "start": [ 898, 1 ], "end": [ 923, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabLetE", "code": "@[builtin_delab letE]\ndef delabLetE : Delab := do\n let Expr.letE n t v b _ ← getExpr | unreachable!\n let n ← getUnusedName n b\n let stxV ← descend v 1 delab\n let (stxN, stxB) ← withLetDecl n t v fun fvar => do\n let b := b.instantiate1 fvar\n return (← mkAnnotatedIdent n fvar, ← descend b 2 delab)\n if ← getPPOption getPPLetVarTypes <||> getPPOption getPPAnalysisLetVarType then\n let stxT ← descend t 0 delab\n `(let $stxN : $stxT := $stxV; $stxB)\n else `(let $stxN := $stxV; $stxB)", "start": [ 925, 1 ], "end": [ 936, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabChar", "code": "@[builtin_delab app.Char.ofNat]\ndef delabChar : Delab := do\n let e ← getExpr\n guard <| e.getAppNumArgs == 1\n let .lit (.natVal n) := e.appArg! | failure\n return quote (Char.ofNat n)", "start": [ 938, 1 ], "end": [ 943, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabLit", "code": "@[builtin_delab lit]\ndef delabLit : Delab := do\n let Expr.lit l ← getExpr | unreachable!\n match l with\n | Literal.natVal n =>\n if ← getPPOption getPPNatLit then\n `(nat_lit $(quote n))\n else\n return quote n\n | Literal.strVal s => return quote s", "start": [ 945, 1 ], "end": [ 954, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabOfNatCore", "code": "def delabOfNatCore (showType : Bool := false) : Delab := do\n let .app (.app (.app (.const ``OfNat.ofNat ..) _) (.lit (.natVal n))) _ ← getExpr | failure\n let stx ← annotateTermInfo <| quote n\n if showType then\n let ty ← withNaryArg 0 delab\n `(($stx : $ty))\n else\n return stx", "start": [ 956, 1 ], "end": [ 966, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabNegIntCore", "code": "def delabNegIntCore (showType : Bool := false) : Delab := do\n guard <| (← getExpr).isAppOfArity ``Neg.neg 3\n let n ← withAppArg delabOfNatCore\n let stx ← annotateTermInfo (← `(- $n))\n if showType then\n let ty ← withNaryArg 0 delab\n `(($stx : $ty))\n else\n return stx", "start": [ 968, 1 ], "end": [ 979, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabDivRatCore", "code": "def delabDivRatCore (showType : Bool := false) : Delab := do\n let e ← getExpr\n guard <| e.isAppOfArity ``HDiv.hDiv 6\n guard <| e.getArg! 0 == e.getArg! 1\n guard <| e.getArg! 0 == e.getArg! 2\n let p ← withAppFn <| withAppArg <| (delabOfNatCore <|> delabNegIntCore)\n let q ← withAppArg <| delabOfNatCore\n let stx ← annotateTermInfo (← `($p / $q))\n if showType then\n let ty ← withNaryArg 0 delab\n `(($stx : $ty))\n else\n return stx", "start": [ 981, 1 ], "end": [ 998, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabOfNat", "code": "@[builtin_delab app.OfNat.ofNat]\ndef delabOfNat : Delab := whenPPOption getPPCoercions <| withOverApp 3 do\n delabOfNatCore (showType := (← getPPOption getPPNumericTypes))", "start": [ 1000, 1 ], "end": [ 1006, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabNeg", "code": "@[builtin_delab app.Neg.neg]\ndef delabNeg : Delab := whenPPOption getPPCoercions do\n delabNegIntCore (showType := (← getPPOption getPPNumericTypes))", "start": [ 1008, 1 ], "end": [ 1014, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabHDiv", "code": "@[builtin_delab app.HDiv.hDiv]\ndef delabHDiv : Delab := whenPPOption getPPCoercions do\n delabDivRatCore (showType := (← getPPOption getPPNumericTypes))", "start": [ 1016, 1 ], "end": [ 1023, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabOfScientific", "code": "@[builtin_delab app.OfScientific.ofScientific]\ndef delabOfScientific : Delab := whenPPOption getPPCoercions <| withOverApp 5 do\n let expr ← getExpr\n guard <| expr.getAppNumArgs == 5\n let .lit (.natVal m) ← pure (expr.getArg! 2) | failure\n let .lit (.natVal e) ← pure (expr.getArg! 4) | failure\n let s ← match expr.getArg! 3 with\n | Expr.const ``Bool.true _ => pure true\n | Expr.const ``Bool.false _ => pure false\n | _ => failure\n let str := toString m\n if s && e == str.length then\n return Syntax.mkScientificLit (\"0.\" ++ str)\n else if s && e < str.length then\n let mStr := str.extract 0 ⟨str.length - e⟩\n let eStr := str.extract ⟨str.length - e⟩ ⟨str.length⟩\n return Syntax.mkScientificLit (mStr ++ \".\" ++ eStr)\n else\n return Syntax.mkScientificLit (str ++ \"e\" ++ (if s then \"-\" else \"\") ++ toString e)", "start": [ 1026, 1 ], "end": [ 1044, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabProj", "code": "@[builtin_delab proj]\ndef delabProj : Delab := do\n let Expr.proj _ idx _ ← getExpr | unreachable!\n let e ← withProj delab\n let idx := Syntax.mkLit fieldIdxKind (toString (idx + 1));\n `($(e).$idx:fieldIdx)", "start": [ 1046, 1 ], "end": [ 1059, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.coeDelaborator", "code": "@[builtin_delab app]\ndef coeDelaborator : Delab := whenPPOption getPPCoercions do\n let e ← getExpr\n let .const declName _ := e.getAppFn | failure\n let some info ← Meta.getCoeFnInfo? declName | failure\n let n := e.getAppNumArgs\n withOverApp info.numArgs do\n match info.type with\n | .coe => `(↑$(← withNaryArg info.coercee delab))\n | .coeFun =>\n if n = info.numArgs then\n `(⇑$(← withNaryArg info.coercee delab))\n else\n withNaryArg info.coercee delab\n | .coeSort => `(β†₯$(← withNaryArg info.coercee delab))", "start": [ 1061, 1 ], "end": [ 1080, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabDIte", "code": "@[builtin_delab app.dite]\ndef delabDIte : Delab := whenPPOption getPPNotation <| withOverApp 5 do\n guard $ (← getExpr).getAppNumArgs == 5\n let c ← withAppFn $ withAppFn $ withAppFn $ withAppArg delab\n let (t, h) ← withAppFn $ withAppArg $ delabBranch none\n let (e, _) ← withAppArg $ delabBranch h\n `(if $(mkIdent h):ident : $c then $t else $e)\nwhere\n delabBranch (h? : Option Name) : DelabM (Syntax Γ— Name) := do\n let e ← getExpr\n guard e.isLambda\n let h ← match h? with\n | some h => return (← withBindingBody h delab, h)\n | none => withBindingBodyUnusedName fun h => do\n return (← delab, h.getId)", "start": [ 1082, 1 ], "end": [ 1097, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabCond", "code": "@[builtin_delab app.cond]\ndef delabCond : Delab := whenPPOption getPPNotation <| withOverApp 4 do\n guard $ (← getExpr).getAppNumArgs == 4\n let c ← withAppFn $ withAppFn $ withAppArg delab\n let t ← withAppFn $ withAppArg delab\n let e ← withAppArg delab\n `(bif $c then $t else $e)", "start": [ 1099, 1 ], "end": [ 1105, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabNamedPattern", "code": "@[builtin_delab app.namedPattern]\ndef delabNamedPattern : Delab := do\n guard (← read).inPattern\n guard $ (← getExpr).getAppNumArgs == 4\n let x ← withAppFn $ withAppFn $ withAppArg delab\n let p ← withAppFn $ withAppArg delab\n let h ← withAppArg delab\n guard x.raw.isIdent\n `($x:ident@$h:ident:$p:term)", "start": [ 1107, 1 ], "end": [ 1117, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabSigmaCore", "code": "def delabSigmaCore (sigma : Bool) : Delab := whenPPOption getPPNotation do\n guard $ (← getExpr).getAppNumArgs == 2\n guard $ (← getExpr).appArg!.isLambda\n withAppArg do\n let Ξ± ← withBindingDomain delab\n let bodyExpr := (← getExpr).bindingBody!\n withBindingBodyUnusedName fun n => do\n let b ← delab\n if bodyExpr.hasLooseBVars then\n if sigma then `(($n:ident : $Ξ±) Γ— $b) else `(($n:ident : $Ξ±) Γ—' $b)\n else\n if sigma then `((_ : $Ξ±) Γ— $b) else `((_ : $Ξ±) Γ—' $b)", "start": [ 1120, 1 ], "end": [ 1131, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabSigma", "code": "@[builtin_delab app.Sigma]\ndef delabSigma : Delab := delabSigmaCore (sigma := true)", "start": [ 1133, 1 ], "end": [ 1134, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabPSigma", "code": "@[builtin_delab app.PSigma]\ndef delabPSigma : Delab := delabSigmaCore (sigma := false)", "start": [ 1136, 1 ], "end": [ 1137, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabDoElems", "code": "partial def delabDoElems : DelabM (List Syntax) := do\n let e ← getExpr\n if e.isAppOfArity ``Bind.bind 6 then\n let Ξ± := e.getAppArgs[2]!\n let ma ← withAppFn $ withAppArg delab\n withAppArg do\n match (← getExpr) with\n | Expr.lam _ _ body _ =>\n withBindingBodyUnusedName fun n => do\n if body.hasLooseBVars then\n prependAndRec `(doElem|let $n:term ← $ma:term)\n else if Ξ±.isConstOf ``Unit || Ξ±.isConstOf ``PUnit then\n prependAndRec `(doElem|$ma:term)\n else\n prependAndRec `(doElem|let _ ← $ma:term)\n | _ => failure\n else if e.isLet then\n let Expr.letE n t v b _ ← getExpr | unreachable!\n let n ← getUnusedName n b\n let stxT ← descend t 0 delab\n let stxV ← descend v 1 delab\n withLetDecl n t v fun fvar =>\n let b := b.instantiate1 fvar\n descend b 2 $\n prependAndRec `(doElem|let $(mkIdent n) : $stxT := $stxV)\n else if e.isLetFun then\n let stxT ← withNaryArg 0 delab\n let stxV ← withNaryArg 2 delab\n withAppArg do\n match (← getExpr) with\n | Expr.lam .. =>\n withBindingBodyUnusedName fun n => do\n prependAndRec `(doElem|have $n:term : $stxT := $stxV)\n | _ => failure\n else\n let stx ← delab\n return [← `(doElem|$stx:term)]\n where\n prependAndRec x : DelabM _ := List.cons <$> x <*> delabDoElems", "start": [ 1139, 1 ], "end": [ 1179, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabDo", "code": "@[builtin_delab app.Bind.bind]\ndef delabDo : Delab := whenPPOption getPPNotation do\n guard <| (← getExpr).isAppOfArity ``Bind.bind 6\n let elems ← delabDoElems\n let items ← elems.toArray.mapM (`(doSeqItem|$(Β·):doElem))\n `(do $items:doSeqItem*)", "start": [ 1181, 1 ], "end": [ 1186, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.reifyName", "code": "def reifyName : Expr β†’ DelabM Name\n | .const ``Lean.Name.anonymous .. => return Name.anonymous\n | .app (.app (.const ``Lean.Name.str ..) n) (.lit (.strVal s)) => return (← reifyName n).mkStr s\n | .app (.app (.const ``Lean.Name.num ..) n) (.lit (.natVal i)) => return (← reifyName n).mkNum i\n | _ => failure", "start": [ 1188, 1 ], "end": [ 1192, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabNameMkStr", "code": "@[builtin_delab app.Lean.Name.str]\ndef delabNameMkStr : Delab := whenPPOption getPPNotation do\n let n ← reifyName (← getExpr)\n return mkNode ``Lean.Parser.Term.quotedName #[Syntax.mkNameLit s!\"`{n}\"]", "start": [ 1194, 1 ], "end": [ 1198, 75 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabNameMkNum", "code": "@[builtin_delab app.Lean.Name.num]\ndef delabNameMkNum : Delab := delabNameMkStr", "start": [ 1200, 1 ], "end": [ 1201, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.declSigWithId", "code": "@[run_builtin_parser_attribute_hooks]\ndef declSigWithId := leading_parser termParser maxPrec >> declSig", "start": [ 1204, 1 ], "end": [ 1206, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.evalSyntaxConstantUnsafe", "code": "private unsafe def evalSyntaxConstantUnsafe (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax :=\n env.evalConstCheck Syntax opts ``Syntax constName", "start": [ 1208, 1 ], "end": [ 1209, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.evalSyntaxConstant", "code": "@[implemented_by evalSyntaxConstantUnsafe]\nprivate opaque evalSyntaxConstant (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax := throw \"\"", "start": [ 1211, 1 ], "end": [ 1212, 129 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.Delaborator.delabConstWithSignature", "code": "partial def delabConstWithSignature (universes : Bool := true) : Delab := do\n let e ← getExpr\n let idStx ← descend e 0 <|\n withOptions (pp.universes.set Β· universes |> (pp.fullNames.set Β· true)) <|\n delabConst\n descend (← inferType e) 1 <|\n delabParams {} idStx #[]\nwhere\n \n delabTy : DelabM Term := withOptions (pp.piBinderTypes.set Β· true) delab\n \n delabParams (bindingNames : NameSet) (idStx : Ident) (groups : TSyntaxArray ``bracketedBinder) := do\n let e ← getExpr\n if e.isForall && e.binderInfo.isInstImplicit && e.bindingName!.hasMacroScopes then\n let group ← withBindingDomain do `(bracketedBinderF|[$(← delabTy)])\n withBindingBody e.bindingName! <| delabParams bindingNames idStx (groups.push group)\n else if e.isForall && !e.bindingName!.hasMacroScopes && !bindingNames.contains e.bindingName! then\n delabParamsAux bindingNames idStx groups #[]\n else\n let type ← delabTy\n `(declSigWithId| $idStx:ident $groups* : $type)\n \n delabParamsAux (bindingNames : NameSet) (idStx : Ident) (groups : TSyntaxArray ``bracketedBinder) (curIds : Array Ident) := do\n let e@(.forallE n d e' i) ← getExpr | unreachable!\n let bindingNames := bindingNames.insert n\n let stxN := mkIdent n\n let curIds := curIds.push ⟨stxN⟩\n if shouldGroupWithNext bindingNames e e' then\n withBindingBody n <| delabParamsAux bindingNames idStx groups curIds\n else\n let group ← withBindingDomain do\n match i with\n | .implicit => `(bracketedBinderF|{$curIds* : $(← delabTy)})\n | .strictImplicit => `(bracketedBinderF|⦃$curIds* : $(← delabTy)⦄)\n | .instImplicit => `(bracketedBinderF|[$stxN : $(← delabTy)])\n | _ =>\n if d.isOptParam then\n `(bracketedBinderF|($curIds* : $(← withAppFn <| withAppArg delabTy) := $(← withAppArg delabTy)))\n else if let some (.const tacticDecl _) := d.getAutoParamTactic? then\n let tacticSyntax ← ofExcept <| evalSyntaxConstant (← getEnv) (← getOptions) tacticDecl\n `(bracketedBinderF|($curIds* : $(← withAppFn <| withAppArg delabTy) := by $tacticSyntax))\n else\n `(bracketedBinderF|($curIds* : $(← delabTy)))\n withBindingBody n <| delabParams bindingNames idStx (groups.push group)\n \n shouldGroupWithNext (bindingNames : NameSet) (e e' : Expr) : Bool :=\n e'.isForall &&\n !e'.bindingName!.hasMacroScopes &&\n !bindingNames.contains e'.bindingName! &&\n e.binderInfo == e'.binderInfo &&\n e.bindingDomain! == e'.bindingDomain! &&\n e'.binderInfo != BinderInfo.instImplicit", "start": [ 1214, 1 ], "end": [ 1293, 45 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/ReduceEval.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Offset.lean" ]
[ { "full_name": "Lean.Meta.ReduceEval", "code": "class ReduceEval (Ξ± : Type) where\n reduceEval : Expr β†’ MetaM Ξ±", "start": [ 13, 1 ], "end": [ 14, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.reduceEval", "code": "def reduceEval [ReduceEval Ξ±] (e : Expr) : MetaM Ξ± :=\n withAtLeastTransparency TransparencyMode.default $\n ReduceEval.reduceEval e", "start": [ 16, 1 ], "end": [ 18, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.throwFailedToEval", "code": "private def throwFailedToEval (e : Expr) : MetaM Ξ± :=\n throwError \"reduceEval: failed to evaluate argument{indentExpr e}\"", "start": [ 20, 1 ], "end": [ 21, 69 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.evalName", "code": "private partial def evalName (e : Expr) : MetaM Name := do\n let e ← whnf e\n let Expr.const c _ ← pure e.getAppFn | throwFailedToEval e\n let nargs := e.getAppNumArgs\n if c == ``Lean.Name.anonymous && nargs == 0 then pure Name.anonymous\n else if c == ``Lean.Name.str && nargs == 2 then do\n let n ← evalName $ e.getArg! 0\n let s ← reduceEval $ e.getArg! 1\n pure $ Name.mkStr n s\n else if c == ``Lean.Name.num && nargs == 2 then do\n let n ← evalName $ e.getArg! 0\n let u ← reduceEval $ e.getArg! 1\n pure $ Name.mkNum n u\n else\n throwFailedToEval e", "start": [ 43, 1 ], "end": [ 57, 24 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Clear.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Util.lean" ]
[ { "full_name": "Lean.MVarId.clear", "code": "def _root_.Lean.MVarId.clear (mvarId : MVarId) (fvarId : FVarId) : MetaM MVarId :=\n mvarId.withContext do\n mvarId.checkNotAssigned `clear\n let lctx ← getLCtx\n unless lctx.contains fvarId do\n throwTacticEx `clear mvarId m!\"unknown variable '{mkFVar fvarId}'\"\n let tag ← mvarId.getTag\n lctx.forM fun localDecl => do\n unless localDecl.fvarId == fvarId do\n if (← localDeclDependsOn localDecl fvarId) then\n throwTacticEx `clear mvarId m!\"variable '{localDecl.toExpr}' depends on '{mkFVar fvarId}'\"\n let mvarDecl ← mvarId.getDecl\n if (← exprDependsOn mvarDecl.type fvarId) then\n throwTacticEx `clear mvarId m!\"target depends on '{mkFVar fvarId}'\"\n let lctx := lctx.erase fvarId\n let localInsts ← getLocalInstances\n let localInsts := match localInsts.findIdx? fun localInst => localInst.fvar.fvarId! == fvarId with\n | none => localInsts\n | some idx => localInsts.eraseIdx idx\n let newMVar ← mkFreshExprMVarAt lctx localInsts mvarDecl.type MetavarKind.syntheticOpaque tag\n mvarId.assign newMVar\n pure newMVar.mvarId!", "start": [ 11, 1 ], "end": [ 35, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.clear", "code": "@[deprecated MVarId.clear (since := \"2022-07-15\")]\ndef clear (mvarId : MVarId) (fvarId : FVarId) : MetaM MVarId :=\n mvarId.clear fvarId", "start": [ 38, 1 ], "end": [ 40, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.tryClear", "code": "def _root_.Lean.MVarId.tryClear (mvarId : MVarId) (fvarId : FVarId) : MetaM MVarId :=\n mvarId.clear fvarId <|> pure mvarId", "start": [ 42, 1 ], "end": [ 47, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.tryClear", "code": "@[deprecated MVarId.tryClear (since := \"2022-07-15\")]\ndef tryClear (mvarId : MVarId) (fvarId : FVarId) : MetaM MVarId :=\n mvarId.tryClear fvarId", "start": [ 49, 1 ], "end": [ 51, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.tryClearMany", "code": "def _root_.Lean.MVarId.tryClearMany (mvarId : MVarId) (fvarIds : Array FVarId) : MetaM MVarId := do\n fvarIds.foldrM (init := mvarId) fun fvarId mvarId => mvarId.tryClear fvarId", "start": [ 53, 1 ], "end": [ 57, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.tryClearMany", "code": "@[deprecated MVarId.tryClearMany (since := \"2022-07-15\")]\ndef tryClearMany (mvarId : MVarId) (fvarIds : Array FVarId) : MetaM MVarId := do\n mvarId.tryClearMany fvarIds", "start": [ 59, 1 ], "end": [ 61, 30 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Init/Data/Array/DecidableEq.lean
[ ".lake/packages/lean4/src/lean/Init/Data/Array/Basic.lean", ".lake/packages/lean4/src/lean/Init/ByCases.lean" ]
[ { "full_name": "Array.eq_of_isEqvAux", "code": "theorem eq_of_isEqvAux [DecidableEq Ξ±] (a b : Array Ξ±) (hsz : a.size = b.size) (i : Nat) (hi : i ≀ a.size) (heqv : Array.isEqvAux a b hsz (fun x y => x = y) i) (j : Nat) (low : i ≀ j) (high : j < a.size) : a[j] = b[j]'(hsz β–Έ high)", "start": [ 12, 1 ], "end": [ 24, 43 ], "kind": "commanddeclaration" }, { "full_name": "Array.eq_of_isEqv", "code": "theorem eq_of_isEqv [DecidableEq Ξ±] (a b : Array Ξ±) : Array.isEqv a b (fun x y => x = y) β†’ a = b", "start": [ 27, 1 ], "end": [ 34, 31 ], "kind": "commanddeclaration" }, { "full_name": "Array.isEqvAux_self", "code": "theorem isEqvAux_self [DecidableEq Ξ±] (a : Array Ξ±) (i : Nat) : Array.isEqvAux a a rfl (fun x y => x = y) i = true", "start": [ 36, 1 ], "end": [ 42, 43 ], "kind": "commanddeclaration" }, { "full_name": "Array.isEqv_self", "code": "theorem isEqv_self [DecidableEq Ξ±] (a : Array Ξ±) : Array.isEqv a a (fun x y => x = y) = true", "start": [ 44, 1 ], "end": [ 45, 30 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Init/Data/Array/Lemmas.lean
[ ".lake/packages/lean4/src/lean/Init/TacticsExtra.lean", ".lake/packages/lean4/src/lean/Init/Data/Fin/Basic.lean", ".lake/packages/lean4/src/lean/Init/Data/Nat/MinMax.lean", ".lake/packages/lean4/src/lean/Init/Data/List/Lemmas.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/Mem.lean", ".lake/packages/lean4/src/lean/Init/Data/Nat/Lemmas.lean" ]
[ { "full_name": "Array.singleton_def", "code": "@[simp] theorem singleton_def (v : Ξ±) : singleton v = #[v]", "start": [ 24, 1 ], "end": [ 24, 66 ], "kind": "commanddeclaration" }, { "full_name": "Array.toArray_data", "code": "@[simp] theorem toArray_data : (a : Array Ξ±) β†’ a.data.toArray = a", "start": [ 26, 1 ], "end": [ 27, 33 ], "kind": "commanddeclaration" }, { "full_name": "Array.data_length", "code": "@[simp] theorem data_length {l : Array Ξ±} : l.data.length = l.size", "start": [ 29, 1 ], "end": [ 29, 74 ], "kind": "commanddeclaration" }, { "full_name": "Array.mkEmpty_eq", "code": "@[simp] theorem mkEmpty_eq (Ξ± n) : @mkEmpty Ξ± n = #[]", "start": [ 31, 1 ], "end": [ 31, 61 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_toArray", "code": "@[simp] theorem size_toArray (as : List Ξ±) : as.toArray.size = as.length", "start": [ 33, 1 ], "end": [ 33, 91 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_mk", "code": "@[simp] theorem size_mk (as : List Ξ±) : (Array.mk as).size = as.length", "start": [ 35, 1 ], "end": [ 35, 89 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_eq_data_getElem", "code": "theorem getElem_eq_data_getElem (a : Array Ξ±) (h : i < a.size) : a[i] = a.data[i]", "start": [ 37, 1 ], "end": [ 38, 49 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_eq_data_get", "code": "@[deprecated getElem_eq_data_getElem (since := \"2024-06-12\")]\ntheorem getElem_eq_data_get (a : Array Ξ±) (h : i < a.size) : a[i] = a.data.get ⟨i, h⟩", "start": [ 40, 1 ], "end": [ 42, 33 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldlM_eq_foldlM_data.aux", "code": "theorem foldlM_eq_foldlM_data.aux [Monad m]\n (f : Ξ² β†’ Ξ± β†’ m Ξ²) (arr : Array Ξ±) (i j) (H : arr.size ≀ i + j) (b) :\n foldlM.loop f arr arr.size (Nat.le_refl _) i j b = (arr.data.drop j).foldlM f b", "start": [ 44, 1 ], "end": [ 54, 57 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldlM_eq_foldlM_data", "code": "theorem foldlM_eq_foldlM_data [Monad m]\n (f : Ξ² β†’ Ξ± β†’ m Ξ²) (init : Ξ²) (arr : Array Ξ±) :\n arr.foldlM f init = arr.data.foldlM f init", "start": [ 56, 1 ], "end": [ 59, 43 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldl_eq_foldl_data", "code": "theorem foldl_eq_foldl_data (f : Ξ² β†’ Ξ± β†’ Ξ²) (init : Ξ²) (arr : Array Ξ±) :\n arr.foldl f init = arr.data.foldl f init", "start": [ 61, 1 ], "end": [ 63, 53 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldrM_eq_reverse_foldlM_data.aux", "code": "theorem foldrM_eq_reverse_foldlM_data.aux [Monad m]\n (f : Ξ± β†’ Ξ² β†’ m Ξ²) (arr : Array Ξ±) (init : Ξ²) (i h) :\n (arr.data.take i).reverse.foldlM (fun x y => f y x) init = foldrM.fold f arr 0 i h init", "start": [ 65, 1 ], "end": [ 71, 76 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldrM_eq_reverse_foldlM_data", "code": "theorem foldrM_eq_reverse_foldlM_data [Monad m] (f : Ξ± β†’ Ξ² β†’ m Ξ²) (init : Ξ²) (arr : Array Ξ±) :\n arr.foldrM f init = arr.data.reverse.foldlM (fun x y => f y x) init", "start": [ 73, 1 ], "end": [ 78, 74 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldrM_eq_foldrM_data", "code": "theorem foldrM_eq_foldrM_data [Monad m]\n (f : Ξ± β†’ Ξ² β†’ m Ξ²) (init : Ξ²) (arr : Array Ξ±) :\n arr.foldrM f init = arr.data.foldrM f init", "start": [ 80, 1 ], "end": [ 83, 58 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldr_eq_foldr_data", "code": "theorem foldr_eq_foldr_data (f : Ξ± β†’ Ξ² β†’ Ξ²) (init : Ξ²) (arr : Array Ξ±) :\n arr.foldr f init = arr.data.foldr f init", "start": [ 85, 1 ], "end": [ 87, 53 ], "kind": "commanddeclaration" }, { "full_name": "Array.push_data", "code": "@[simp] theorem push_data (arr : Array Ξ±) (a : Ξ±) : (arr.push a).data = arr.data ++ [a]", "start": [ 89, 1 ], "end": [ 90, 37 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldrM_push", "code": "theorem foldrM_push [Monad m] (f : Ξ± β†’ Ξ² β†’ m Ξ²) (init : Ξ²) (arr : Array Ξ±) (a : Ξ±) :\n (arr.push a).foldrM f init = f a init >>= arr.foldrM f", "start": [ 92, 1 ], "end": [ 94, 51 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldrM_push'", "code": "@[simp] theorem foldrM_push' [Monad m] (f : Ξ± β†’ Ξ² β†’ m Ξ²) (init : Ξ²) (arr : Array Ξ±) (a : Ξ±) :\n (arr.push a).foldrM f init (start := arr.size + 1) = f a init >>= arr.foldrM f", "start": [ 96, 1 ], "end": [ 98, 23 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldr_push", "code": "theorem foldr_push (f : Ξ± β†’ Ξ² β†’ Ξ²) (init : Ξ²) (arr : Array Ξ±) (a : Ξ±) :\n (arr.push a).foldr f init = arr.foldr f (f a init)", "start": [ 100, 1 ], "end": [ 101, 73 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldr_push'", "code": "@[simp] theorem foldr_push' (f : Ξ± β†’ Ξ² β†’ Ξ²) (init : Ξ²) (arr : Array Ξ±) (a : Ξ±) :\n (arr.push a).foldr f init (start := arr.size + 1) = arr.foldr f (f a init)", "start": [ 103, 1 ], "end": [ 104, 98 ], "kind": "commanddeclaration" }, { "full_name": "Array.toListAppend_eq", "code": "@[simp] theorem toListAppend_eq (arr : Array Ξ±) (l) : arr.toListAppend l = arr.data ++ l", "start": [ 106, 1 ], "end": [ 107, 43 ], "kind": "commanddeclaration" }, { "full_name": "Array.toList_eq", "code": "@[simp] theorem toList_eq (arr : Array Ξ±) : arr.toList = arr.data", "start": [ 109, 1 ], "end": [ 110, 37 ], "kind": "commanddeclaration" }, { "full_name": "Array.toListRev", "code": "@[inline] def toListRev (arr : Array Ξ±) : List Ξ± := arr.foldl (fun l t => t :: l) []", "start": [ 112, 1 ], "end": [ 113, 85 ], "kind": "commanddeclaration" }, { "full_name": "Array.toListRev_eq", "code": "@[simp] theorem toListRev_eq (arr : Array Ξ±) : arr.toListRev = arr.data.reverse", "start": [ 115, 1 ], "end": [ 116, 77 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_push_lt", "code": "theorem get_push_lt (a : Array Ξ±) (x : Ξ±) (i : Nat) (h : i < a.size) :\n have : i < (a.push x).size := by simp [*, Nat.lt_succ_of_le, Nat.le_of_lt]\n (a.push x)[i] = a[i]", "start": [ 118, 1 ], "end": [ 121, 96 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_push_eq", "code": "@[simp] theorem get_push_eq (a : Array Ξ±) (x : Ξ±) : (a.push x)[a.size] = x", "start": [ 123, 1 ], "end": [ 125, 85 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_push", "code": "theorem get_push (a : Array Ξ±) (x : Ξ±) (i : Nat) (h : i < (a.push x).size) :\n (a.push x)[i] = if h : i < a.size then a[i] else x", "start": [ 127, 1 ], "end": [ 132, 84 ], "kind": "commanddeclaration" }, { "full_name": "Array.mapM_eq_foldlM", "code": "theorem mapM_eq_foldlM [Monad m] [LawfulMonad m] (f : Ξ± β†’ m Ξ²) (arr : Array Ξ±) :\n arr.mapM f = arr.foldlM (fun bs a => bs.push <$> f a) #[]", "start": [ 134, 1 ], "end": [ 146, 45 ], "kind": "commanddeclaration" }, { "full_name": "Array.map_data", "code": "@[simp] theorem map_data (f : Ξ± β†’ Ξ²) (arr : Array Ξ±) : (arr.map f).data = arr.data.map f", "start": [ 148, 1 ], "end": [ 153, 11 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_map", "code": "@[simp] theorem size_map (f : Ξ± β†’ Ξ²) (arr : Array Ξ±) : (arr.map f).size = arr.size", "start": [ 155, 1 ], "end": [ 157, 7 ], "kind": "commanddeclaration" }, { "full_name": "Array.pop_data", "code": "@[simp] theorem pop_data (arr : Array Ξ±) : arr.pop.data = arr.data.dropLast", "start": [ 159, 1 ], "end": [ 159, 83 ], "kind": "commanddeclaration" }, { "full_name": "Array.append_eq_append", "code": "@[simp] theorem append_eq_append (arr arr' : Array Ξ±) : arr.append arr' = arr ++ arr'", "start": [ 161, 1 ], "end": [ 161, 93 ], "kind": "commanddeclaration" }, { "full_name": "Array.append_data", "code": "@[simp] theorem append_data (arr arr' : Array Ξ±) :\n (arr ++ arr').data = arr.data ++ arr'.data", "start": [ 163, 1 ], "end": [ 167, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.appendList_eq_append", "code": "@[simp] theorem appendList_eq_append\n (arr : Array Ξ±) (l : List Ξ±) : arr.appendList l = arr ++ l", "start": [ 169, 1 ], "end": [ 170, 70 ], "kind": "commanddeclaration" }, { "full_name": "Array.appendList_data", "code": "@[simp] theorem appendList_data (arr : Array Ξ±) (l : List Ξ±) :\n (arr ++ l).data = arr.data ++ l", "start": [ 172, 1 ], "end": [ 175, 44 ], "kind": "commanddeclaration" }, { "full_name": "Array.appendList_nil", "code": "@[simp] theorem appendList_nil (arr : Array Ξ±) : arr ++ ([] : List Ξ±) = arr", "start": [ 177, 1 ], "end": [ 177, 100 ], "kind": "commanddeclaration" }, { "full_name": "Array.appendList_cons", "code": "@[simp] theorem appendList_cons (arr : Array Ξ±) (a : Ξ±) (l : List Ξ±) :\n arr ++ (a :: l) = arr.push a ++ l", "start": [ 179, 1 ], "end": [ 180, 62 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldl_data_eq_bind", "code": "theorem foldl_data_eq_bind (l : List Ξ±) (acc : Array Ξ²)\n (F : Array Ξ² β†’ Ξ± β†’ Array Ξ²) (G : Ξ± β†’ List Ξ²)\n (H : βˆ€ acc a, (F acc a).data = acc.data ++ G a) :\n (l.foldl F acc).data = acc.data ++ l.bind G", "start": [ 182, 1 ], "end": [ 186, 55 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldl_data_eq_map", "code": "theorem foldl_data_eq_map (l : List Ξ±) (acc : Array Ξ²) (G : Ξ± β†’ Ξ²) :\n (l.foldl (fun acc a => acc.push (G a)) acc).data = acc.data ++ l.map G", "start": [ 188, 1 ], "end": [ 190, 44 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_uset", "code": "theorem size_uset (a : Array Ξ±) (v i h) : (uset a i v h).size = a.size", "start": [ 192, 1 ], "end": [ 192, 82 ], "kind": "commanddeclaration" }, { "full_name": "Array.anyM_eq_anyM_loop", "code": "theorem anyM_eq_anyM_loop [Monad m] (p : Ξ± β†’ m Bool) (as : Array Ξ±) (start stop) :\n anyM p as start stop = anyM.loop p as (min stop as.size) (Nat.min_le_right ..) start", "start": [ 194, 1 ], "end": [ 196, 47 ], "kind": "commanddeclaration" }, { "full_name": "Array.anyM_stop_le_start", "code": "theorem anyM_stop_le_start [Monad m] (p : Ξ± β†’ m Bool) (as : Array Ξ±) (start stop)\n (h : min stop as.size ≀ start) : anyM p as start stop = pure false", "start": [ 198, 1 ], "end": [ 200, 62 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_def", "code": "theorem mem_def (a : Ξ±) (as : Array Ξ±) : a ∈ as ↔ a ∈ as.data", "start": [ 202, 1 ], "end": [ 203, 35 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_eq_getElem", "code": "@[simp] theorem get_eq_getElem (a : Array Ξ±) (i : Fin _) : a.get i = a[i.1]", "start": [ 207, 1 ], "end": [ 207, 83 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_lt", "code": "theorem getElem?_lt\n (a : Array Ξ±) {i : Nat} (h : i < a.size) : a[i]? = some (a[i])", "start": [ 209, 1 ], "end": [ 210, 80 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_ge", "code": "theorem getElem?_ge\n (a : Array Ξ±) {i : Nat} (h : i β‰₯ a.size) : a[i]? = none", "start": [ 212, 1 ], "end": [ 213, 92 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_eq_getElem?", "code": "@[simp] theorem get?_eq_getElem? (a : Array Ξ±) (i : Nat) : a.get? i = a[i]?", "start": [ 215, 1 ], "end": [ 215, 83 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_len_le", "code": "theorem getElem?_len_le (a : Array Ξ±) {i : Nat} (h : a.size ≀ i) : a[i]? = none", "start": [ 217, 1 ], "end": [ 218, 24 ], "kind": "commanddeclaration" }, { "full_name": "Array.getD_get?", "code": "theorem getD_get? (a : Array Ξ±) (i : Nat) (d : Ξ±) :\n Option.getD a[i]? d = if p : i < a.size then a[i]'p else d", "start": [ 220, 1 ], "end": [ 226, 40 ], "kind": "commanddeclaration" }, { "full_name": "Array.getD_eq_get?", "code": "@[simp] theorem getD_eq_get? (a : Array Ξ±) (n d) : a.getD n d = (a[n]?).getD d", "start": [ 228, 1 ], "end": [ 229, 84 ], "kind": "commanddeclaration" }, { "full_name": "Array.get!_eq_getD", "code": "theorem get!_eq_getD [Inhabited Ξ±] (a : Array Ξ±) : a.get! n = a.getD n default", "start": [ 231, 1 ], "end": [ 231, 86 ], "kind": "commanddeclaration" }, { "full_name": "Array.get!_eq_getElem?", "code": "@[simp] theorem get!_eq_getElem? [Inhabited Ξ±] (a : Array Ξ±) (i : Nat) : a.get! i = (a.get? i).getD default", "start": [ 233, 1 ], "end": [ 234, 64 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_set_eq", "code": "@[simp] theorem getElem_set_eq (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) {j : Nat}\n (eq : i.val = j) (p : j < (a.set i v).size) :\n (a.set i v)[j]'p = v", "start": [ 238, 1 ], "end": [ 241, 43 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_set_ne", "code": "@[simp] theorem getElem_set_ne (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) {j : Nat} (pj : j < (a.set i v).size)\n (h : i.val β‰  j) : (a.set i v)[j]'pj = a[j]'(size_set a i v β–Έ pj)", "start": [ 243, 1 ], "end": [ 245, 66 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_set", "code": "theorem getElem_set (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) (j : Nat)\n (h : j < (a.set i v).size) :\n (a.set i v)[j]'h = if i = j then v else a[j]'(size_set a i v β–Έ h)", "start": [ 247, 1 ], "end": [ 250, 36 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_set_eq", "code": "@[simp] theorem getElem?_set_eq (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) :\n (a.set i v)[i.1]? = v", "start": [ 252, 1 ], "end": [ 253, 56 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_set_ne", "code": "@[simp] theorem getElem?_set_ne (a : Array Ξ±) (i : Fin a.size) {j : Nat} (v : Ξ±)\n (ne : i.val β‰  j) : (a.set i v)[j]? = a[j]?", "start": [ 255, 1 ], "end": [ 257, 87 ], "kind": "commanddeclaration" }, { "full_name": "Array.set!_is_setD", "code": "@[simp] theorem set!_is_setD : @set! = @setD", "start": [ 261, 1 ], "end": [ 261, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_setD", "code": "@[simp] theorem size_setD (a : Array Ξ±) (index : Nat) (val : Ξ±) :\n (Array.setD a index val).size = a.size", "start": [ 263, 1 ], "end": [ 268, 19 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_setD_eq", "code": "@[simp] theorem getElem_setD_eq (a : Array Ξ±) {i : Nat} (v : Ξ±) (h : _) :\n (setD a i v)[i]'h = v", "start": [ 270, 1 ], "end": [ 273, 56 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_setD_eq", "code": "@[simp]\ntheorem getElem?_setD_eq (a : Array Ξ±) {i : Nat} (p : i < a.size) (v : Ξ±) : (a.setD i v)[i]? = some v", "start": [ 275, 1 ], "end": [ 277, 24 ], "kind": "commanddeclaration" }, { "full_name": "Array.getD_get?_setD", "code": "@[simp] theorem getD_get?_setD (a : Array Ξ±) (i : Nat) (v d : Ξ±) :\n Option.getD (setD a i v)[i]? d = if i < a.size then v else d", "start": [ 279, 1 ], "end": [ 283, 49 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_ofFn_go", "code": "@[simp] theorem size_ofFn_go {n} (f : Fin n β†’ Ξ±) (i acc) :\n (ofFn.go f i acc).size = acc.size + (n - i)", "start": [ 287, 1 ], "end": [ 298, 21 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_ofFn", "code": "@[simp] theorem size_ofFn (f : Fin n β†’ Ξ±) : (ofFn f).size = n", "start": [ 300, 1 ], "end": [ 300, 80 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_ofFn_go", "code": "theorem getElem_ofFn_go (f : Fin n β†’ Ξ±) (i) {acc k}\n (hki : k < n) (hin : i ≀ n) (hi : i = acc.size)\n (hacc : βˆ€ j, βˆ€ hj : j < acc.size, acc[j] = f ⟨j, Nat.lt_of_lt_of_le hj (hi β–Έ hin)⟩) :\n haveI : acc.size + (n - acc.size) = n := Nat.add_sub_cancel' (hi β–Έ hin)\n (ofFn.go f i acc)[k]'(by simp [*]) = f ⟨k, hki⟩", "start": [ 302, 1 ], "end": [ 318, 21 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_ofFn", "code": "@[simp] theorem getElem_ofFn (f : Fin n β†’ Ξ±) (i : Nat) (h) :\n (ofFn f)[i] = f ⟨i, size_ofFn f β–Έ h⟩", "start": [ 320, 1 ], "end": [ 322, 50 ], "kind": "commanddeclaration" }, { "full_name": "Array.mkArray_data", "code": "@[simp] theorem mkArray_data (n : Nat) (v : Ξ±) : (mkArray n v).data = List.replicate n v", "start": [ 324, 1 ], "end": [ 326, 96 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_mkArray", "code": "@[simp] theorem getElem_mkArray (n : Nat) (v : Ξ±) (h : i < (mkArray n v).size) :\n (mkArray n v)[i] = v", "start": [ 328, 1 ], "end": [ 329, 68 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_data", "code": "theorem mem_data {a : Ξ±} {l : Array Ξ±} : a ∈ l.data ↔ a ∈ l", "start": [ 331, 1 ], "end": [ 333, 82 ], "kind": "commanddeclaration" }, { "full_name": "Array.not_mem_nil", "code": "theorem not_mem_nil (a : Ξ±) : Β¬ a ∈ #[]", "start": [ 335, 1 ], "end": [ 335, 49 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_mem", "code": "theorem getElem?_mem {l : Array Ξ±} {i : Fin l.size} : l[i] ∈ l", "start": [ 337, 1 ], "end": [ 341, 21 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_fin_eq_data_get", "code": "theorem getElem_fin_eq_data_get (a : Array Ξ±) (i : Fin _) : a[i] = a.data.get i", "start": [ 343, 1 ], "end": [ 343, 87 ], "kind": "commanddeclaration" }, { "full_name": "Array.ugetElem_eq_getElem", "code": "@[simp] theorem ugetElem_eq_getElem (a : Array Ξ±) {i : USize} (h : i.toNat < a.size) :\n a[i] = a[i.toNat]", "start": [ 345, 1 ], "end": [ 346, 27 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_eq_getElem", "code": "theorem getElem?_eq_getElem (a : Array Ξ±) (i : Nat) (h : i < a.size) : a[i]? = a[i]", "start": [ 348, 1 ], "end": [ 349, 18 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_len_le", "code": "theorem get?_len_le (a : Array Ξ±) (i : Nat) (h : a.size ≀ i) : a[i]? = none", "start": [ 351, 1 ], "end": [ 352, 25 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_mem_data", "code": "theorem getElem_mem_data (a : Array Ξ±) (h : i < a.size) : a[i] ∈ a.data", "start": [ 354, 1 ], "end": [ 355, 56 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem?_eq_data_get?", "code": "theorem getElem?_eq_data_get? (a : Array Ξ±) (i : Nat) : a[i]? = a.data.get? i", "start": [ 357, 1 ], "end": [ 358, 96 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_eq_data_get?", "code": "theorem get?_eq_data_get? (a : Array Ξ±) (i : Nat) : a.get? i = a.data.get? i", "start": [ 360, 1 ], "end": [ 361, 27 ], "kind": "commanddeclaration" }, { "full_name": "Array.get!_eq_get?", "code": "theorem get!_eq_get? [Inhabited Ξ±] (a : Array Ξ±) : a.get! n = (a.get? n).getD default", "start": [ 363, 1 ], "end": [ 364, 22 ], "kind": "commanddeclaration" }, { "full_name": "Array.back_eq_back?", "code": "@[simp] theorem back_eq_back? [Inhabited Ξ±] (a : Array Ξ±) : a.back = a.back?.getD default", "start": [ 366, 1 ], "end": [ 367, 21 ], "kind": "commanddeclaration" }, { "full_name": "Array.back?_push", "code": "@[simp] theorem back?_push (a : Array Ξ±) : (a.push x).back? = some x", "start": [ 369, 1 ], "end": [ 370, 38 ], "kind": "commanddeclaration" }, { "full_name": "Array.back_push", "code": "theorem back_push [Inhabited Ξ±] (a : Array Ξ±) : (a.push x).back = x", "start": [ 372, 1 ], "end": [ 372, 79 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_push_lt", "code": "theorem get?_push_lt (a : Array Ξ±) (x : Ξ±) (i : Nat) (h : i < a.size) :\n (a.push x)[i]? = some a[i]", "start": [ 374, 1 ], "end": [ 376, 33 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_push_eq", "code": "theorem get?_push_eq (a : Array Ξ±) (x : Ξ±) : (a.push x)[a.size]? = some x", "start": [ 378, 1 ], "end": [ 379, 33 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_push", "code": "theorem get?_push {a : Array Ξ±} : (a.push x)[i]? = if i = a.size then some x else a[i]?", "start": [ 381, 1 ], "end": [ 394, 22 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_size", "code": "@[simp] theorem get?_size {a : Array Ξ±} : a[a.size]? = none", "start": [ 396, 1 ], "end": [ 397, 54 ], "kind": "commanddeclaration" }, { "full_name": "Array.data_set", "code": "@[simp] theorem data_set (a : Array Ξ±) (i v) : (a.set i v).data = a.data.set i.1 v", "start": [ 399, 1 ], "end": [ 399, 90 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_set_eq", "code": "theorem get_set_eq (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) :\n (a.set i v)[i.1] = v", "start": [ 401, 1 ], "end": [ 403, 64 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_set_eq", "code": "theorem get?_set_eq (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) :\n (a.set i v)[i.1]? = v", "start": [ 405, 1 ], "end": [ 406, 57 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_set_ne", "code": "@[simp] theorem get?_set_ne (a : Array Ξ±) (i : Fin a.size) {j : Nat} (v : Ξ±)\n (h : i.1 β‰  j) : (a.set i v)[j]? = a[j]?", "start": [ 408, 1 ], "end": [ 410, 63 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_set", "code": "theorem get?_set (a : Array Ξ±) (i : Fin a.size) (j : Nat) (v : Ξ±) :\n (a.set i v)[j]? = if i.1 = j then some v else a[j]?", "start": [ 412, 1 ], "end": [ 414, 54 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_set", "code": "theorem get_set (a : Array Ξ±) (i : Fin a.size) (j : Nat) (hj : j < a.size) (v : Ξ±) :\n (a.set i v)[j]'(by simp [*]) = if i = j then v else a[j]", "start": [ 416, 1 ], "end": [ 418, 54 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_set_ne", "code": "@[simp] theorem get_set_ne (a : Array Ξ±) (i : Fin a.size) {j : Nat} (v : Ξ±) (hj : j < a.size)\n (h : i.1 β‰  j) : (a.set i v)[j]'(by simp [*]) = a[j]", "start": [ 420, 1 ], "end": [ 422, 66 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_setD", "code": "theorem getElem_setD (a : Array Ξ±) (i : Nat) (v : Ξ±) (h : i < (setD a i v).size) :\n (setD a i v)[i] = v", "start": [ 424, 1 ], "end": [ 427, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.set_set", "code": "theorem set_set (a : Array Ξ±) (i : Fin a.size) (v v' : Ξ±) :\n (a.set i v).set ⟨i, by simp [i.2]⟩ v' = a.set i v'", "start": [ 429, 1 ], "end": [ 430, 86 ], "kind": "commanddeclaration" }, { "full_name": "Array.fin_cast_val", "code": "private theorem fin_cast_val (e : n = n') (i : Fin n) : e β–Έ i = ⟨i.1, e β–Έ i.2⟩", "start": [ 432, 1 ], "end": [ 432, 98 ], "kind": "commanddeclaration" }, { "full_name": "Array.swap_def", "code": "theorem swap_def (a : Array Ξ±) (i j : Fin a.size) :\n a.swap i j = (a.set i (a.get j)).set ⟨j.1, by simp [j.2]⟩ (a.get i)", "start": [ 434, 1 ], "end": [ 436, 28 ], "kind": "commanddeclaration" }, { "full_name": "Array.data_swap", "code": "theorem data_swap (a : Array Ξ±) (i j : Fin a.size) :\n (a.swap i j).data = (a.data.set i (a.get j)).set j (a.get i)", "start": [ 438, 1 ], "end": [ 439, 87 ], "kind": "commanddeclaration" }, { "full_name": "Array.get?_swap", "code": "theorem get?_swap (a : Array Ξ±) (i j : Fin a.size) (k : Nat) : (a.swap i j)[k]? =\n if j = k then some a[i.1] else if i = k then some a[j.1] else a[k]?", "start": [ 441, 1 ], "end": [ 443, 55 ], "kind": "commanddeclaration" }, { "full_name": "Array.swapAt_def", "code": "@[simp] theorem swapAt_def (a : Array Ξ±) (i : Fin a.size) (v : Ξ±) :\n a.swapAt i v = (a[i.1], a.set i v)", "start": [ 445, 1 ], "end": [ 446, 46 ], "kind": "commanddeclaration" }, { "full_name": "Array.swapAt!_def", "code": "theorem swapAt!_def (a : Array Ξ±) (i : Nat) (v : Ξ±) (h : i < a.size) :\n a.swapAt! i v = (a[i], a.set ⟨i, h⟩ v)", "start": [ 449, 1 ], "end": [ 450, 67 ], "kind": "commanddeclaration" }, { "full_name": "Array.data_pop", "code": "@[simp] theorem data_pop (a : Array Ξ±) : a.pop.data = a.data.dropLast", "start": [ 452, 1 ], "end": [ 452, 87 ], "kind": "commanddeclaration" }, { "full_name": "Array.pop_empty", "code": "@[simp] theorem pop_empty : (#[] : Array Ξ±).pop = #[]", "start": [ 454, 1 ], "end": [ 454, 61 ], "kind": "commanddeclaration" }, { "full_name": "Array.pop_push", "code": "@[simp] theorem pop_push (a : Array Ξ±) : (a.push x).pop = a", "start": [ 456, 1 ], "end": [ 456, 77 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_pop", "code": "@[simp] theorem getElem_pop (a : Array Ξ±) (i : Nat) (hi : i < a.pop.size) :\n a.pop[i] = a[i]'(Nat.lt_of_lt_of_le (a.size_pop β–Έ hi) (Nat.sub_le _ _))", "start": [ 458, 1 ], "end": [ 460, 27 ], "kind": "commanddeclaration" }, { "full_name": "Array.eq_empty_of_size_eq_zero", "code": "theorem eq_empty_of_size_eq_zero {as : Array Ξ±} (h : as.size = 0) : as = #[]", "start": [ 462, 1 ], "end": [ 465, 26 ], "kind": "commanddeclaration" }, { "full_name": "Array.eq_push_pop_back_of_size_ne_zero", "code": "theorem eq_push_pop_back_of_size_ne_zero [Inhabited Ξ±] {as : Array Ξ±} (h : as.size β‰  0) :\n as = as.pop.push as.back", "start": [ 467, 1 ], "end": [ 477, 87 ], "kind": "commanddeclaration" }, { "full_name": "Array.eq_push_of_size_ne_zero", "code": "theorem eq_push_of_size_ne_zero {as : Array Ξ±} (h : as.size β‰  0) :\n βˆƒ (bs : Array Ξ±) (c : Ξ±), as = bs.push c", "start": [ 479, 1 ], "end": [ 482, 56 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_eq_length_data", "code": "theorem size_eq_length_data (as : Array Ξ±) : as.size = as.data.length", "start": [ 484, 1 ], "end": [ 484, 77 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_swap!", "code": "@[simp] theorem size_swap! (a : Array Ξ±) (i j) :\n (a.swap! i j).size = a.size", "start": [ 486, 1 ], "end": [ 487, 95 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_reverse", "code": "@[simp] theorem size_reverse (a : Array Ξ±) : a.reverse.size = a.size", "start": [ 489, 1 ], "end": [ 497, 43 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_range", "code": "@[simp] theorem size_range {n : Nat} : (range n).size = n", "start": [ 499, 1 ], "end": [ 506, 10 ], "kind": "commanddeclaration" }, { "full_name": "Array.reverse_data", "code": "@[simp] theorem reverse_data (a : Array Ξ±) : a.reverse.data = a.data.reverse", "start": [ 509, 1 ], "end": [ 548, 86 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldl_induction", "code": "theorem foldl_induction\n {as : Array Ξ±} (motive : Nat β†’ Ξ² β†’ Prop) {init : Ξ²} (h0 : motive 0 init) {f : Ξ² β†’ Ξ± β†’ Ξ²}\n (hf : βˆ€ i : Fin as.size, βˆ€ b, motive i.1 b β†’ motive (i.1 + 1) (f b as[i])) :\n motive as.size (as.foldl f init)", "start": [ 554, 1 ], "end": [ 566, 68 ], "kind": "commanddeclaration" }, { "full_name": "Array.foldr_induction", "code": "theorem foldr_induction\n {as : Array Ξ±} (motive : Nat β†’ Ξ² β†’ Prop) {init : Ξ²} (h0 : motive as.size init) {f : Ξ± β†’ Ξ² β†’ Ξ²}\n (hf : βˆ€ i : Fin as.size, βˆ€ b, motive (i.1 + 1) b β†’ motive i.1 (f as[i] b)) :\n motive 0 (as.foldr f init)", "start": [ 570, 1 ], "end": [ 583, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_map", "code": "@[simp] theorem mem_map {f : Ξ± β†’ Ξ²} {l : Array Ξ±} : b ∈ l.map f ↔ βˆƒ a, a ∈ l ∧ f a = b", "start": [ 587, 1 ], "end": [ 588, 46 ], "kind": "commanddeclaration" }, { "full_name": "Array.mapM_eq_mapM_data", "code": "theorem mapM_eq_mapM_data [Monad m] [LawfulMonad m] (f : Ξ± β†’ m Ξ²) (arr : Array Ξ±) :\n arr.mapM f = return mk (← arr.data.mapM f)", "start": [ 590, 1 ], "end": [ 596, 60 ], "kind": "commanddeclaration" }, { "full_name": "Array.mapM_map_eq_foldl", "code": "theorem mapM_map_eq_foldl (as : Array Ξ±) (f : Ξ± β†’ Ξ²) (i) :\n mapM.map (m := Id) f as i b = as.foldl (start := i) (fun r a => r.push (f a)) b", "start": [ 598, 1 ], "end": [ 612, 27 ], "kind": "commanddeclaration" }, { "full_name": "Array.map_eq_foldl", "code": "theorem map_eq_foldl (as : Array Ξ±) (f : Ξ± β†’ Ξ²) :\n as.map f = as.foldl (fun r a => r.push (f a)) #[]", "start": [ 614, 1 ], "end": [ 616, 26 ], "kind": "commanddeclaration" }, { "full_name": "Array.map_induction", "code": "theorem map_induction (as : Array Ξ±) (f : Ξ± β†’ Ξ²) (motive : Nat β†’ Prop) (h0 : motive 0)\n (p : Fin as.size β†’ Ξ² β†’ Prop) (hs : βˆ€ i, motive i.1 β†’ p i (f as[i]) ∧ motive (i+1)) :\n motive as.size ∧\n βˆƒ eq : (as.map f).size = as.size, βˆ€ i h, p ⟨i, h⟩ ((as.map f)[i])", "start": [ 618, 1 ], "end": [ 643, 25 ], "kind": "commanddeclaration" }, { "full_name": "Array.map_spec", "code": "theorem map_spec (as : Array Ξ±) (f : Ξ± β†’ Ξ²) (p : Fin as.size β†’ Ξ² β†’ Prop)\n (hs : βˆ€ i, p i (f as[i])) :\n βˆƒ eq : (as.map f).size = as.size, βˆ€ i h, p ⟨i, h⟩ ((as.map f)[i])", "start": [ 645, 1 ], "end": [ 648, 73 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_map", "code": "@[simp] theorem getElem_map (f : Ξ± β†’ Ξ²) (as : Array Ξ±) (i : Nat) (h) :\n ((as.map f)[i]) = f (as[i]'(size_map .. β–Έ h))", "start": [ 650, 1 ], "end": [ 656, 11 ], "kind": "commanddeclaration" }, { "full_name": "Array.mapIdx_induction", "code": "theorem mapIdx_induction (as : Array Ξ±) (f : Fin as.size β†’ Ξ± β†’ Ξ²)\n (motive : Nat β†’ Prop) (h0 : motive 0)\n (p : Fin as.size β†’ Ξ² β†’ Prop)\n (hs : βˆ€ i, motive i.1 β†’ p i (f i as[i]) ∧ motive (i + 1)) :\n motive as.size ∧ βˆƒ eq : (Array.mapIdx as f).size = as.size,\n βˆ€ i h, p ⟨i, h⟩ ((Array.mapIdx as f)[i])", "start": [ 661, 1 ], "end": [ 684, 48 ], "kind": "commanddeclaration" }, { "full_name": "Array.mapIdx_spec", "code": "theorem mapIdx_spec (as : Array Ξ±) (f : Fin as.size β†’ Ξ± β†’ Ξ²)\n (p : Fin as.size β†’ Ξ² β†’ Prop) (hs : βˆ€ i, p i (f i as[i])) :\n βˆƒ eq : (Array.mapIdx as f).size = as.size,\n βˆ€ i h, p ⟨i, h⟩ ((Array.mapIdx as f)[i])", "start": [ 686, 1 ], "end": [ 690, 81 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_mapIdx", "code": "@[simp] theorem size_mapIdx (a : Array Ξ±) (f : Fin a.size β†’ Ξ± β†’ Ξ²) : (a.mapIdx f).size = a.size", "start": [ 692, 1 ], "end": [ 693, 66 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_zipWithIndex", "code": "@[simp] theorem size_zipWithIndex (as : Array Ξ±) : as.zipWithIndex.size = as.size", "start": [ 695, 1 ], "end": [ 696, 24 ], "kind": "commanddeclaration" }, { "full_name": "Array.getElem_mapIdx", "code": "@[simp] theorem getElem_mapIdx (a : Array Ξ±) (f : Fin a.size β†’ Ξ± β†’ Ξ²) (i : Nat)\n (h : i < (mapIdx a f).size) :\n haveI : i < a.size := by simp_all\n (a.mapIdx f)[i] = f ⟨i, this⟩ a[i]", "start": [ 698, 1 ], "end": [ 702, 65 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_modify", "code": "@[simp] theorem size_modify (a : Array Ξ±) (i : Nat) (f : Ξ± β†’ Ξ±) : (a.modify i f).size = a.size", "start": [ 706, 1 ], "end": [ 708, 17 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_modify", "code": "theorem get_modify {arr : Array Ξ±} {x i} (h : i < arr.size) :\n (arr.modify x f).get ⟨i, by simp [h]⟩ =\n if x = i then f (arr.get ⟨i, h⟩) else arr.get ⟨i, h⟩", "start": [ 710, 1 ], "end": [ 715, 50 ], "kind": "commanddeclaration" }, { "full_name": "Array.filter_data", "code": "@[simp] theorem filter_data (p : Ξ± β†’ Bool) (l : Array Ξ±) :\n (l.filter p).data = l.data.filter p", "start": [ 719, 1 ], "end": [ 728, 31 ], "kind": "commanddeclaration" }, { "full_name": "Array.filter_filter", "code": "@[simp] theorem filter_filter (q) (l : Array Ξ±) :\n filter p (filter q l) = filter (fun a => p a ∧ q a) l", "start": [ 730, 1 ], "end": [ 733, 46 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_filter", "code": "@[simp] theorem mem_filter : x ∈ filter p as ↔ x ∈ as ∧ p x", "start": [ 735, 1 ], "end": [ 736, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_of_mem_filter", "code": "theorem mem_of_mem_filter {a : Ξ±} {l} (h : a ∈ filter p l) : a ∈ l", "start": [ 738, 1 ], "end": [ 739, 22 ], "kind": "commanddeclaration" }, { "full_name": "Array.filterMap_data", "code": "@[simp] theorem filterMap_data (f : Ξ± β†’ Option Ξ²) (l : Array Ξ±) :\n (l.filterMap f).data = l.data.filterMap f", "start": [ 743, 1 ], "end": [ 754, 23 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_filterMap", "code": "@[simp] theorem mem_filterMap (f : Ξ± β†’ Option Ξ²) (l : Array Ξ±) {b : Ξ²} :\n b ∈ filterMap f l ↔ βˆƒ a, a ∈ l ∧ f a = some b", "start": [ 756, 1 ], "end": [ 758, 58 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_empty", "code": "theorem size_empty : (#[] : Array Ξ±).size = 0", "start": [ 762, 1 ], "end": [ 762, 53 ], "kind": "commanddeclaration" }, { "full_name": "Array.empty_data", "code": "theorem empty_data : (#[] : Array Ξ±).data = []", "start": [ 764, 1 ], "end": [ 764, 54 ], "kind": "commanddeclaration" }, { "full_name": "Array.push_eq_append_singleton", "code": "theorem push_eq_append_singleton (as : Array Ξ±) (x) : as.push x = as ++ #[x]", "start": [ 768, 1 ], "end": [ 768, 84 ], "kind": "commanddeclaration" }, { "full_name": "Array.mem_append", "code": "@[simp] theorem mem_append {a : Ξ±} {s t : Array Ξ±} : a ∈ s ++ t ↔ a ∈ s ∨ a ∈ t", "start": [ 770, 1 ], "end": [ 771, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_append", "code": "theorem size_append (as bs : Array Ξ±) : (as ++ bs).size = as.size + bs.size", "start": [ 773, 1 ], "end": [ 774, 52 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_append_left", "code": "theorem get_append_left {as bs : Array Ξ±} {h : i < (as ++ bs).size} (hlt : i < as.size) :\n (as ++ bs)[i] = as[i]", "start": [ 776, 1 ], "end": [ 781, 41 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_append_right", "code": "theorem get_append_right {as bs : Array Ξ±} {h : i < (as ++ bs).size} (hle : as.size ≀ i)\n (hlt : i - as.size < bs.size := Nat.sub_lt_left_of_lt_add hle (size_append .. β–Έ h)) :\n (as ++ bs)[i] = bs[i - as.size]", "start": [ 783, 1 ], "end": [ 789, 41 ], "kind": "commanddeclaration" }, { "full_name": "Array.append_nil", "code": "@[simp] theorem append_nil (as : Array Ξ±) : as ++ #[] = as", "start": [ 791, 1 ], "end": [ 792, 67 ], "kind": "commanddeclaration" }, { "full_name": "Array.nil_append", "code": "@[simp] theorem nil_append (as : Array Ξ±) : #[] ++ as = as", "start": [ 794, 1 ], "end": [ 795, 67 ], "kind": "commanddeclaration" }, { "full_name": "Array.append_assoc", "code": "theorem append_assoc (as bs cs : Array Ξ±) : as ++ bs ++ cs = as ++ (bs ++ cs)", "start": [ 797, 1 ], "end": [ 798, 57 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_loop_zero", "code": "theorem extract_loop_zero (as bs : Array Ξ±) (start : Nat) : extract.loop as 0 start bs = bs", "start": [ 802, 1 ], "end": [ 803, 35 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_loop_succ", "code": "theorem extract_loop_succ (as bs : Array Ξ±) (size start : Nat) (h : start < as.size) :\n extract.loop as (size+1) start bs = extract.loop as size (start+1) (bs.push as[start])", "start": [ 805, 1 ], "end": [ 807, 36 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_loop_of_ge", "code": "theorem extract_loop_of_ge (as bs : Array Ξ±) (size start : Nat) (h : start β‰₯ as.size) :\n extract.loop as size start bs = bs", "start": [ 809, 1 ], "end": [ 811, 50 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_loop_eq_aux", "code": "theorem extract_loop_eq_aux (as bs : Array Ξ±) (size start : Nat) :\n extract.loop as size start bs = bs ++ extract.loop as size start #[]", "start": [ 813, 1 ], "end": [ 825, 22 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_loop_eq", "code": "theorem extract_loop_eq (as bs : Array Ξ±) (size start : Nat) (h : start + size ≀ as.size) :\n extract.loop as size start bs = bs ++ as.extract start (start + size)", "start": [ 827, 1 ], "end": [ 829, 87 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_extract_loop", "code": "theorem size_extract_loop (as bs : Array Ξ±) (size start : Nat) :\n (extract.loop as size start bs).size = bs.size + min size (as.size - start)", "start": [ 831, 1 ], "end": [ 841, 90 ], "kind": "commanddeclaration" }, { "full_name": "Array.size_extract", "code": "@[simp] theorem size_extract (as : Array Ξ±) (start stop : Nat) :\n (as.extract start stop).size = min stop as.size - start", "start": [ 843, 1 ], "end": [ 846, 33 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_extract_loop_lt_aux", "code": "theorem get_extract_loop_lt_aux (as bs : Array Ξ±) (size start : Nat) (hlt : i < bs.size) :\n i < (extract.loop as size start bs).size", "start": [ 848, 1 ], "end": [ 852, 28 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_extract_loop_lt", "code": "theorem get_extract_loop_lt (as bs : Array Ξ±) (size start : Nat) (hlt : i < bs.size)\n (h := get_extract_loop_lt_aux as bs size start hlt) :\n (extract.loop as size start bs)[i] = bs[i]", "start": [ 854, 1 ], "end": [ 859, 36 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_extract_loop_ge_aux", "code": "theorem get_extract_loop_ge_aux (as bs : Array Ξ±) (size start : Nat) (hge : i β‰₯ bs.size)\n (h : i < (extract.loop as size start bs).size) : start + i - bs.size < as.size", "start": [ 861, 1 ], "end": [ 870, 40 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_extract_loop_ge", "code": "theorem get_extract_loop_ge (as bs : Array Ξ±) (size start : Nat) (hge : i β‰₯ bs.size)\n (h : i < (extract.loop as size start bs).size)\n (h' := get_extract_loop_ge_aux as bs size start hge h) :\n (extract.loop as size start bs)[i] = as[start + i - bs.size]", "start": [ 872, 1 ], "end": [ 901, 73 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_extract_aux", "code": "theorem get_extract_aux {as : Array Ξ±} {start stop : Nat} (h : i < (as.extract start stop).size) :\n start + i < as.size", "start": [ 903, 1 ], "end": [ 906, 53 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_extract", "code": "@[simp] theorem get_extract {as : Array Ξ±} {start stop : Nat}\n (h : i < (as.extract start stop).size) :\n (as.extract start stop)[i] = as[start + i]'(get_extract_aux h)", "start": [ 908, 1 ], "end": [ 912, 94 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_all", "code": "@[simp] theorem extract_all (as : Array Ξ±) : as.extract 0 as.size = as", "start": [ 914, 1 ], "end": [ 917, 55 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_empty_of_stop_le_start", "code": "theorem extract_empty_of_stop_le_start (as : Array Ξ±) {start stop : Nat} (h : stop ≀ start) :\n as.extract start stop = #[]", "start": [ 919, 1 ], "end": [ 922, 23 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_empty_of_size_le_start", "code": "theorem extract_empty_of_size_le_start (as : Array Ξ±) {start stop : Nat} (h : as.size ≀ start) :\n as.extract start stop = #[]", "start": [ 924, 1 ], "end": [ 927, 23 ], "kind": "commanddeclaration" }, { "full_name": "Array.extract_empty", "code": "@[simp] theorem extract_empty (start stop : Nat) : (#[] : Array Ξ±).extract start stop = #[]", "start": [ 929, 1 ], "end": [ 930, 51 ], "kind": "commanddeclaration" }, { "full_name": "Array.anyM_loop_iff_exists", "code": "theorem anyM_loop_iff_exists (p : Ξ± β†’ Bool) (as : Array Ξ±) (start stop) (h : stop ≀ as.size) :\n anyM.loop (m := Id) p as stop h start = true ↔\n βˆƒ i : Fin as.size, start ≀ ↑i ∧ ↑i < stop ∧ p as[i] = true", "start": [ 935, 1 ], "end": [ 954, 28 ], "kind": "commanddeclaration" }, { "full_name": "Array.any_iff_exists", "code": "theorem any_iff_exists (p : Ξ± β†’ Bool) (as : Array Ξ±) (start stop) :\n any as p start stop ↔ βˆƒ i : Fin as.size, start ≀ i.1 ∧ i.1 < stop ∧ p as[i]", "start": [ 957, 1 ], "end": [ 967, 39 ], "kind": "commanddeclaration" }, { "full_name": "Array.any_eq_true", "code": "theorem any_eq_true (p : Ξ± β†’ Bool) (as : Array Ξ±) :\n any as p ↔ βˆƒ i : Fin as.size, p as[i]", "start": [ 969, 1 ], "end": [ 970, 80 ], "kind": "commanddeclaration" }, { "full_name": "Array.any_def", "code": "theorem any_def {p : Ξ± β†’ Bool} (as : Array Ξ±) : as.any p = as.data.any p", "start": [ 972, 1 ], "end": [ 974, 73 ], "kind": "commanddeclaration" }, { "full_name": "Array.all_eq_not_any_not", "code": "theorem all_eq_not_any_not (p : Ξ± β†’ Bool) (as : Array Ξ±) (start stop) :\n all as p start stop = !(any as (!p Β·) start stop)", "start": [ 978, 1 ], "end": [ 981, 6 ], "kind": "commanddeclaration" }, { "full_name": "Array.all_iff_forall", "code": "theorem all_iff_forall (p : Ξ± β†’ Bool) (as : Array Ξ±) (start stop) :\n all as p start stop ↔ βˆ€ i : Fin as.size, start ≀ i.1 ∧ i.1 < stop β†’ p as[i]", "start": [ 983, 1 ], "end": [ 990, 7 ], "kind": "commanddeclaration" }, { "full_name": "Array.all_eq_true", "code": "theorem all_eq_true (p : Ξ± β†’ Bool) (as : Array Ξ±) : all as p ↔ βˆ€ i : Fin as.size, p as[i]", "start": [ 992, 1 ], "end": [ 993, 34 ], "kind": "commanddeclaration" }, { "full_name": "Array.all_def", "code": "theorem all_def {p : Ξ± β†’ Bool} (as : Array Ξ±) : as.all p = as.data.all p", "start": [ 995, 1 ], "end": [ 1002, 66 ], "kind": "commanddeclaration" }, { "full_name": "Array.all_eq_true_iff_forall_mem", "code": "theorem all_eq_true_iff_forall_mem {l : Array Ξ±} : l.all p ↔ βˆ€ x, x ∈ l β†’ p x", "start": [ 1004, 1 ], "end": [ 1005, 49 ], "kind": "commanddeclaration" }, { "full_name": "Array.contains_def", "code": "theorem contains_def [DecidableEq Ξ±] {a : Ξ±} {as : Array Ξ±} : as.contains a ↔ a ∈ as", "start": [ 1009, 1 ], "end": [ 1010, 69 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_swap_right", "code": "@[simp] theorem get_swap_right (a : Array Ξ±) {i j : Fin a.size} : (a.swap i j)[j.val] = a[i]", "start": [ 1019, 1 ], "end": [ 1020, 81 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_swap_left", "code": "@[simp] theorem get_swap_left (a : Array Ξ±) {i j : Fin a.size} : (a.swap i j)[i.val] = a[j]", "start": [ 1022, 1 ], "end": [ 1030, 24 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_swap_of_ne", "code": "@[simp] theorem get_swap_of_ne (a : Array Ξ±) {i j : Fin a.size} (hp : p < a.size)\n (hi : p β‰  i) (hj : p β‰  j) : (a.swap i j)[p]'(a.size_swap .. |>.symm β–Έ hp) = a[p]", "start": [ 1032, 1 ], "end": [ 1042, 19 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_swap", "code": "theorem get_swap (a : Array Ξ±) (i j : Fin a.size) (k : Nat) (hk: k < a.size) :\n (a.swap i j)[k]'(by simp_all) = if k = i then a[j] else if k = j then a[i] else a[k]", "start": [ 1044, 1 ], "end": [ 1048, 23 ], "kind": "commanddeclaration" }, { "full_name": "Array.get_swap'", "code": "theorem get_swap' (a : Array Ξ±) (i j : Fin a.size) (k : Nat) (hk' : k < (a.swap i j).size) :\n (a.swap i j)[k] = if k = i then a[j] else if k = j then a[i] else a[k]'(by simp_all)", "start": [ 1050, 1 ], "end": [ 1052, 17 ], "kind": "commanddeclaration" }, { "full_name": "Array.swap_swap", "code": "@[simp] theorem swap_swap (a : Array Ξ±) {i j : Fin a.size} :\n (a.swap i j).swap ⟨i.1, (a.size_swap ..).symm β–Έi.2⟩ ⟨j.1, (a.size_swap ..).symm β–Έj.2⟩ = a", "start": [ 1054, 1 ], "end": [ 1062, 25 ], "kind": "commanddeclaration" }, { "full_name": "Array.swap_comm", "code": "theorem swap_comm (a : Array Ξ±) {i j : Fin a.size} : a.swap i j = a.swap j i", "start": [ 1064, 1 ], "end": [ 1071, 25 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Data/JsonRpc.lean
[ ".lake/packages/lean4/src/lean/Init/System/IO.lean", ".lake/packages/lean4/src/lean/Lean/Data/Json.lean", ".lake/packages/lean4/src/lean/Lean/Data/RBTree.lean" ]
[ { "full_name": "Lean.JsonRpc.RequestID", "code": "inductive RequestID where\n | str (s : String)\n | num (n : JsonNumber)\n | null\n deriving Inhabited, BEq, Ord", "start": [ 19, 1 ], "end": [ 25, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.ErrorCode", "code": "inductive ErrorCode where\n \n | parseError\n \n | invalidRequest\n \n | methodNotFound\n \n | invalidParams\n \n | internalError\n \n | serverNotInitialized\n | unknownErrorCode\n \n | contentModified\n \n | requestCancelled\n | rpcNeedsReconnect\n | workerExited\n | workerCrashed\n deriving Inhabited, BEq", "start": [ 35, 1 ], "end": [ 69, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.Message", "code": "inductive Message where\n \n | request (id : RequestID) (method : String) (params? : Option Structured)\n \n | notification (method : String) (params? : Option Structured)\n \n | response (id : RequestID) (result : Json)\n \n | responseError (id : RequestID) (code : ErrorCode) (message : String) (data? : Option Json)", "start": [ 100, 1 ], "end": [ 113, 95 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.Batch", "code": "def Batch := Array Message", "start": [ 115, 1 ], "end": [ 115, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.Request", "code": "structure Request (Ξ± : Type u) where\n id : RequestID\n method : String\n param : Ξ±\n deriving Inhabited, BEq", "start": [ 117, 1 ], "end": [ 128, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.Notification", "code": "structure Notification (Ξ± : Type u) where\n method : String\n param : Ξ±\n deriving Inhabited, BEq", "start": [ 133, 1 ], "end": [ 143, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.Response", "code": "structure Response (Ξ± : Type u) where\n id : RequestID\n result : Ξ±\n deriving Inhabited, BEq", "start": [ 148, 1 ], "end": [ 162, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.ResponseError", "code": "structure ResponseError (Ξ± : Type u) where\n id : RequestID\n code : ErrorCode\n \n message : String\n \n data? : Option Ξ± := none\n deriving Inhabited, BEq", "start": [ 167, 1 ], "end": [ 181, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.RequestID.lt", "code": "private def RequestID.lt : RequestID β†’ RequestID β†’ Bool\n | RequestID.str a, RequestID.str b => a < b\n | RequestID.num a, RequestID.num b => a < b\n | RequestID.null, RequestID.num _ => true\n | RequestID.null, RequestID.str _ => true\n | RequestID.num _, RequestID.str _ => true\n | _, _ => false", "start": [ 192, 1 ], "end": [ 198, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.JsonRpc.RequestID.ltProp", "code": "private def RequestID.ltProp : LT RequestID :=\n ⟨fun a b => RequestID.lt a b = true⟩", "start": [ 200, 1 ], "end": [ 201, 39 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.readMessage", "code": "def readMessage (h : FS.Stream) (nBytes : Nat) : IO Message := do\n let j ← h.readJson nBytes\n match fromJson? j with\n | Except.ok m => pure m\n | Except.error inner => throw $ userError s!\"JSON '{j.compress}' did not have the format of a JSON-RPC message.\\n{inner}\"", "start": [ 279, 3 ], "end": [ 283, 126 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.readRequestAs", "code": "def readRequestAs (h : FS.Stream) (nBytes : Nat) (expectedMethod : String) (Ξ±) [FromJson Ξ±] : IO (Request Ξ±) := do\n let m ← h.readMessage nBytes\n match m with\n | Message.request id method params? =>\n if method = expectedMethod then\n let j := toJson params?\n match fromJson? j with\n | Except.ok v => pure ⟨id, expectedMethod, v⟩\n | Except.error inner => throw $ userError s!\"Unexpected param '{j.compress}' for method '{expectedMethod}'\\n{inner}\"\n else\n throw $ userError s!\"Expected method '{expectedMethod}', got method '{method}'\"\n | _ => throw $ userError s!\"Expected JSON-RPC request, got: '{(toJson m).compress}'\"", "start": [ 285, 3 ], "end": [ 296, 89 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.readNotificationAs", "code": "def readNotificationAs (h : FS.Stream) (nBytes : Nat) (expectedMethod : String) (Ξ±) [FromJson Ξ±] : IO (Notification Ξ±) := do\n let m ← h.readMessage nBytes\n match m with\n | Message.notification method params? =>\n if method = expectedMethod then\n let j := toJson params?\n match fromJson? j with\n | Except.ok v => pure ⟨expectedMethod, v⟩\n | Except.error inner => throw $ userError s!\"Unexpected param '{j.compress}' for method '{expectedMethod}'\\n{inner}\"\n else\n throw $ userError s!\"Expected method '{expectedMethod}', got method '{method}'\"\n | _ => throw $ userError s!\"Expected JSON-RPC notification, got: '{(toJson m).compress}'\"", "start": [ 298, 3 ], "end": [ 309, 94 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.readResponseAs", "code": "def readResponseAs (h : FS.Stream) (nBytes : Nat) (expectedID : RequestID) (Ξ±) [FromJson Ξ±] : IO (Response Ξ±) := do\n let m ← h.readMessage nBytes\n match m with\n | Message.response id result =>\n if id == expectedID then\n match fromJson? result with\n | Except.ok v => pure ⟨expectedID, v⟩\n | Except.error inner => throw $ userError s!\"Unexpected result '{result.compress}'\\n{inner}\"\n else\n throw $ userError s!\"Expected id {expectedID}, got id {id}\"\n | _ => throw $ userError s!\"Expected JSON-RPC response, got: '{(toJson m).compress}'\"", "start": [ 311, 3 ], "end": [ 321, 90 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.writeMessage", "code": "def writeMessage (h : FS.Stream) (m : Message) : IO Unit :=\n h.writeJson (toJson m)", "start": [ 327, 3 ], "end": [ 328, 27 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.writeRequest", "code": "def writeRequest (h : FS.Stream) (r : Request Ξ±) : IO Unit :=\n h.writeMessage r", "start": [ 330, 3 ], "end": [ 331, 21 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.writeNotification", "code": "def writeNotification (h : FS.Stream) (n : Notification Ξ±) : IO Unit :=\n h.writeMessage n", "start": [ 333, 3 ], "end": [ 334, 21 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.writeResponse", "code": "def writeResponse (h : FS.Stream) (r : Response Ξ±) : IO Unit :=\n h.writeMessage r", "start": [ 336, 3 ], "end": [ 337, 21 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.writeResponseError", "code": "def writeResponseError (h : FS.Stream) (e : ResponseError Unit) : IO Unit :=\n h.writeMessage (Message.responseError e.id e.code e.message none)", "start": [ 339, 3 ], "end": [ 340, 70 ], "kind": "commanddeclaration" }, { "full_name": "IO.FS.Stream.writeResponseErrorWithData", "code": "def writeResponseErrorWithData (h : FS.Stream) (e : ResponseError Ξ±) : IO Unit :=\n h.writeMessage e", "start": [ 342, 3 ], "end": [ 343, 21 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/SubExpr.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Basic.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/TopDownAnalyze.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Builtins.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator/Options.lean" ]
[]
.lake/packages/lean4/src/lean/Lean/ParserCompiler.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/WHNF.lean", ".lake/packages/lean4/src/lean/Lean/ParserCompiler/Attribute.lean", ".lake/packages/lean4/src/lean/Lean/KeyedDeclsAttribute.lean", ".lake/packages/lean4/src/lean/Lean/Meta/ReduceEval.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Extension.lean" ]
[ { "full_name": "Lean.ParserCompiler.Context", "code": "structure Context (Ξ± : Type) where\n varName : Name\n categoryAttr : KeyedDeclsAttribute Ξ±\n combinatorAttr : CombinatorAttribute", "start": [ 20, 1 ], "end": [ 23, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.Context.tyName", "code": "def Context.tyName {Ξ±} (ctx : Context Ξ±) : Name := ctx.categoryAttr.defn.valueTypeName", "start": [ 25, 1 ], "end": [ 25, 87 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.replaceParserTy", "code": "def replaceParserTy {Ξ±} (ctx : Context Ξ±) (e : Expr) : Expr :=\n e.replace fun e =>\n let e := if e.isOptParam then e.appFn!.appArg! else e\n if e.isConstOf `Lean.Parser.Parser then mkConst ctx.tyName else none", "start": [ 27, 1 ], "end": [ 32, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.parserNodeKind?", "code": "partial def parserNodeKind? (e : Expr) : MetaM (Option Name) := do\n let reduceEval? e : MetaM (Option Name) := do\n try pure <| some (← reduceEval e) catch _ => pure none\n let e ← whnfCore e\n if e matches Expr.lam .. then\n lambdaLetTelescope e fun _ e => parserNodeKind? e\n else if e.isAppOfArity ``leadingNode 3 || e.isAppOfArity ``trailingNode 4 || e.isAppOfArity ``node 2 then\n reduceEval? (e.getArg! 0)\n else if e.isAppOfArity ``withAntiquot 2 then\n parserNodeKind? (e.getArg! 1)\n else forallTelescope (← inferType e.getAppFn) fun params _ => do\n let lctx ← getLCtx\n if let [(i, _)] := params.toList.enum.filter (lctx.getFVar! Β·.2 |>.type.isConstOf ``Parser) then\n parserNodeKind? (e.getArg! i)\n else\n return none", "start": [ 35, 1 ], "end": [ 52, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.compileParserExpr", "code": "partial def compileParserExpr (e : Expr) : MetaM Expr := do\n let e ← whnfCore e\n match e with\n | .lam .. => lambdaLetTelescope e fun xs b => compileParserExpr b >>= mkLambdaFVars xs\n | .fvar .. => return e\n | _ => do\n let fn := e.getAppFn\n let .const c .. := fn | throwError \"call of unknown parser at '{e}'\"\n let mkCall (p : Name) := do\n let ty ← inferType (mkConst p)\n forallTelescope ty fun params _ => do\n let mut p := mkConst p\n let args := e.getAppArgs\n for i in [:Nat.min params.size args.size] do\n let param := params[i]!\n let arg := args[i]!\n let paramTy ← inferType param\n let resultTy ← forallTelescope paramTy fun _ b => pure b\n let arg ← if resultTy.isConstOf ctx.tyName then compileParserExpr arg else pure arg\n p := mkApp p arg\n return p\n let env ← getEnv\n match ctx.combinatorAttr.getDeclFor? env c with\n | some p => mkCall p\n | none =>\n let c' := c ++ ctx.varName\n let cinfo ← getConstInfo c\n let resultTy ← forallTelescope cinfo.type fun _ b => pure b\n if resultTy.isConstOf ``Lean.Parser.TrailingParser || resultTy.isConstOf ``Lean.Parser.Parser then do\n let some value ← pure cinfo.value?\n | throwError \"don't know how to generate {ctx.varName} for non-definition '{e}'\"\n unless (env.getModuleIdxFor? c).isNone || force do\n throwError \"refusing to generate code for imported parser declaration '{c}'; use `@[run_parser_attribute_hooks]` on its definition instead.\"\n let value ← compileParserExpr <| replaceParserTy ctx value\n let ty ← forallTelescope cinfo.type fun params _ =>\n params.foldrM (init := mkConst ctx.tyName) fun param ty => do\n let paramTy ← replaceParserTy ctx <$> inferType param\n return mkForall `_ BinderInfo.default paramTy ty\n let decl := Declaration.defnDecl {\n name := c', levelParams := []\n type := ty, value := value, hints := ReducibilityHints.opaque, safety := DefinitionSafety.safe\n }\n let env ← getEnv\n let env ← match env.addAndCompile {} decl with\n | Except.ok env => pure env\n | Except.error kex => do throwError (← (kex.toMessageData {}).toString)\n setEnv <| ctx.combinatorAttr.setDeclFor env c c'\n if cinfo.type.isConst then\n if let some kind ← parserNodeKind? cinfo.value! then\n let attrName := if builtin then ctx.categoryAttr.defn.builtinName else ctx.categoryAttr.defn.name\n let stx := mkNode `Lean.Parser.Attr.simple #[mkIdent attrName, mkNullNode #[mkIdent kind]]\n Attribute.add c' attrName stx\n mkCall c'\n else\n let some e' ← unfoldDefinition? e\n | throwError \"don't know how to generate {ctx.varName} for non-parser combinator '{e}'\"\n compileParserExpr e'", "start": [ 58, 1 ], "end": [ 127, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.compileEmbeddedParsers", "code": "def compileEmbeddedParsers : ParserDescr β†’ MetaM Unit\n | ParserDescr.const _ => pure ()\n | ParserDescr.unary _ d => compileEmbeddedParsers d\n | ParserDescr.binary _ d₁ dβ‚‚ => compileEmbeddedParsers d₁ *> compileEmbeddedParsers dβ‚‚\n | ParserDescr.parser constName => discard <| compileParserExpr ctx (mkConst constName) (builtin := builtin) (force := false)\n | ParserDescr.node _ _ d => compileEmbeddedParsers d\n | ParserDescr.nodeWithAntiquot _ _ d => compileEmbeddedParsers d\n | ParserDescr.sepBy p _ psep _ => compileEmbeddedParsers p *> compileEmbeddedParsers psep\n | ParserDescr.sepBy1 p _ psep _ => compileEmbeddedParsers p *> compileEmbeddedParsers psep\n | ParserDescr.trailingNode _ _ _ d => compileEmbeddedParsers d\n | ParserDescr.symbol _ => pure ()\n | ParserDescr.nonReservedSymbol _ _ => pure ()\n | ParserDescr.cat _ _ => pure ()", "start": [ 131, 1 ], "end": [ 143, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.ParserCompiler.registerParserCompiler", "code": "unsafe def registerParserCompiler {Ξ±} (ctx : Context Ξ±) : IO Unit := do\n Parser.registerParserAttributeHook {\n postAdd := fun catName constName builtin => do\n let info ← getConstInfo constName\n if info.type.isConstOf ``Lean.ParserDescr || info.type.isConstOf ``Lean.TrailingParserDescr then\n let d ← evalConstCheck ParserDescr `Lean.ParserDescr constName <|>\n evalConstCheck TrailingParserDescr `Lean.TrailingParserDescr constName\n compileEmbeddedParsers ctx d (builtin := builtin) |>.run'\n else\n let force := catName.isAnonymous\n discard (compileParserExpr ctx (mkConst constName) (builtin := builtin) (force := force)).run'\n }", "start": [ 145, 1 ], "end": [ 158, 4 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/FVarSubst.lean
[ ".lake/packages/lean4/src/lean/Lean/LocalContext.lean", ".lake/packages/lean4/src/lean/Lean/Data/AssocList.lean", ".lake/packages/lean4/src/lean/Lean/Util/ReplaceExpr.lean", ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.Meta.FVarSubst", "code": "structure FVarSubst where\n map : AssocList FVarId Expr := {}\n deriving Inhabited", "start": [ 13, 1 ], "end": [ 21, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.empty", "code": "def empty : FVarSubst := {}", "start": [ 25, 1 ], "end": [ 25, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.isEmpty", "code": "def isEmpty (s : FVarSubst) : Bool :=\n s.map.isEmpty", "start": [ 27, 1 ], "end": [ 28, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.contains", "code": "def contains (s : FVarSubst) (fvarId : FVarId) : Bool :=\n s.map.contains fvarId", "start": [ 30, 1 ], "end": [ 31, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.insert", "code": "def insert (s : FVarSubst) (fvarId : FVarId) (v : Expr) : FVarSubst :=\n if s.contains fvarId then s\n else\n let map := s.map.mapVal fun e => e.replaceFVarId fvarId v;\n { map := map.insert fvarId v }", "start": [ 33, 1 ], "end": [ 38, 35 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.erase", "code": "def erase (s : FVarSubst) (fvarId : FVarId) : FVarSubst :=\n { map := s.map.erase fvarId }", "start": [ 40, 1 ], "end": [ 41, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.find?", "code": "def find? (s : FVarSubst) (fvarId : FVarId) : Option Expr :=\n s.map.find? fvarId", "start": [ 43, 1 ], "end": [ 44, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.get", "code": "def get (s : FVarSubst) (fvarId : FVarId) : Expr :=\n match s.map.find? fvarId with\n | none => mkFVar fvarId | some v => v", "start": [ 46, 1 ], "end": [ 49, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.apply", "code": "def apply (s : FVarSubst) (e : Expr) : Expr :=\n if s.map.isEmpty then e\n else if !e.hasFVar then e\n else e.replace fun e => match e with\n | Expr.fvar fvarId => match s.map.find? fvarId with\n | none => e\n | some v => v\n | _ => none", "start": [ 51, 1 ], "end": [ 59, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.domain", "code": "def domain (s : FVarSubst) : List FVarId :=\n s.map.foldl (init := []) fun r k _ => k :: r", "start": [ 61, 1 ], "end": [ 62, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.any", "code": "def any (p : FVarId β†’ Expr β†’ Bool) (s : FVarSubst) : Bool :=\n s.map.any p", "start": [ 64, 1 ], "end": [ 65, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.FVarSubst.append", "code": "def append (s t : FVarSubst) : FVarSubst :=\n s.1.foldl (fun s' k v => s'.insert k (t.apply v)) t", "start": [ 67, 1 ], "end": [ 72, 54 ], "kind": "commanddeclaration" }, { "full_name": "LocalDecl.applyFVarSubst", "code": "def LocalDecl.applyFVarSubst (s : Meta.FVarSubst) : LocalDecl β†’ LocalDecl\n | LocalDecl.cdecl i id n t bi k => LocalDecl.cdecl i id n (s.apply t) bi k\n | LocalDecl.ldecl i id n t v nd k => LocalDecl.ldecl i id n (s.apply t) (s.apply v) nd k", "start": [ 77, 1 ], "end": [ 79, 91 ], "kind": "commanddeclaration" }, { "full_name": "Expr.applyFVarSubst", "code": "abbrev Expr.applyFVarSubst (s : Meta.FVarSubst) (e : Expr) : Expr :=\n s.apply e", "start": [ 81, 1 ], "end": [ 82, 12 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Intro.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Util.lean" ]
[ { "full_name": "Lean.Meta.introNImp", "code": "@[inline] private partial def introNImp {Οƒ} (mvarId : MVarId) (n : Nat) (mkName : LocalContext β†’ Name β†’ Bool β†’ Οƒ β†’ MetaM (Name Γ— Οƒ)) (s : Οƒ)\n : MetaM (Array FVarId Γ— MVarId) := mvarId.withContext do\n mvarId.checkNotAssigned `introN\n let mvarType ← mvarId.getType\n let lctx ← getLCtx\n let rec @[specialize] loop (i : Nat) (lctx : LocalContext) (fvars : Array Expr) (j : Nat) (s : Οƒ) (type : Expr) : MetaM (Array Expr Γ— MVarId) := do\n match i, type with\n | 0, type =>\n let type := type.instantiateRevRange j fvars.size fvars\n withReader (fun ctx => { ctx with lctx := lctx }) do\n withNewLocalInstances fvars j do\n let tag ← mvarId.getTag\n let type := type.headBeta\n let newMVar ← mkFreshExprSyntheticOpaqueMVar type tag\n let newVal ← mkLambdaFVars fvars newMVar\n mvarId.assign newVal\n return (fvars, newMVar.mvarId!)\n | i+1, .letE n type val body _ =>\n let type := type.instantiateRevRange j fvars.size fvars\n let type := type.headBeta\n let val := val.instantiateRevRange j fvars.size fvars\n let fvarId ← mkFreshFVarId\n let (n, s) ← mkName lctx n true s\n let lctx := lctx.mkLetDecl fvarId n type val\n let fvar := mkFVar fvarId\n let fvars := fvars.push fvar\n loop i lctx fvars j s body\n | i+1, .forallE n type body c =>\n let type := type.instantiateRevRange j fvars.size fvars\n let type := type.headBeta\n let fvarId ← mkFreshFVarId\n let (n, s) ← mkName lctx n c.isExplicit s\n let lctx := lctx.mkLocalDecl fvarId n type c\n let fvar := mkFVar fvarId\n let fvars := fvars.push fvar\n loop i lctx fvars j s body\n | i+1, type =>\n if let some (n, type, val, body) := type.letFun? then\n let type := type.instantiateRevRange j fvars.size fvars\n let type := type.headBeta\n let val := val.instantiateRevRange j fvars.size fvars\n let fvarId ← mkFreshFVarId\n let (n, s) ← mkName lctx n true s\n let lctx := lctx.mkLetDecl fvarId n type val\n let fvar := mkFVar fvarId\n let fvars := fvars.push fvar\n loop i lctx fvars j s body\n else\n let type := type.instantiateRevRange j fvars.size fvars\n withReader (fun ctx => { ctx with lctx := lctx }) do\n withNewLocalInstances fvars j do\n \n let newType := (← instantiateMVars type).cleanupAnnotations\n if newType.isForall || newType.isLet || newType.isLetFun then\n loop (i+1) lctx fvars fvars.size s newType\n else\n let newType ← whnf newType\n if newType.isForall then\n loop (i+1) lctx fvars fvars.size s newType\n else\n throwTacticEx `introN mvarId \"insufficient number of binders\"\n let (fvars, mvarId) ← loop n lctx #[] 0 s mvarType\n return (fvars.map Expr.fvarId!, mvarId)", "start": [ 11, 1 ], "end": [ 78, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkFreshBinderNameForTacticCore", "code": "private def mkFreshBinderNameForTacticCore (lctx : LocalContext) (binderName : Name) (hygienic := true) : MetaM Name := do\n if hygienic then\n mkFreshUserName binderName\n else\n return lctx.getUnusedName binderName", "start": [ 86, 1 ], "end": [ 90, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkFreshBinderNameForTactic", "code": "def mkFreshBinderNameForTactic (binderName : Name) : MetaM Name := do\n mkFreshBinderNameForTacticCore (← getLCtx) binderName (tactic.hygienic.get (← getOptions))", "start": [ 92, 1 ], "end": [ 98, 93 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAuxNameImp", "code": "private def mkAuxNameImp (preserveBinderNames : Bool) (hygienic : Bool) (useNamesForExplicitOnly : Bool)\n (lctx : LocalContext) (binderName : Name) (isExplicit : Bool) : List Name β†’ MetaM (Name Γ— List Name)\n | [] => mkAuxNameWithoutGivenName []\n | n :: rest => do\n if useNamesForExplicitOnly && !isExplicit then\n mkAuxNameWithoutGivenName (n :: rest)\n else if n != Name.mkSimple \"_\" then\n return (n, rest)\n else\n mkAuxNameWithoutGivenName rest\nwhere\n mkAuxNameWithoutGivenName (rest : List Name) : MetaM (Name Γ— List Name) := do\n let binderName ← if binderName.isAnonymous then mkFreshUserName `a else pure binderName\n if preserveBinderNames then\n return (binderName, rest)\n else\n let binderName ← mkFreshBinderNameForTacticCore lctx binderName hygienic\n return (binderName, rest)", "start": [ 100, 1 ], "end": [ 119, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.introNCore", "code": "def introNCore (mvarId : MVarId) (n : Nat) (givenNames : List Name) (useNamesForExplicitOnly : Bool) (preserveBinderNames : Bool)\n : MetaM (Array FVarId Γ— MVarId) := do\n let hygienic := tactic.hygienic.get (← getOptions)\n if n == 0 then\n return (#[], mvarId)\n else\n introNImp mvarId n (mkAuxNameImp preserveBinderNames hygienic useNamesForExplicitOnly) givenNames", "start": [ 121, 1 ], "end": [ 127, 102 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.introN", "code": "abbrev _root_.Lean.MVarId.introN (mvarId : MVarId) (n : Nat) (givenNames : List Name := []) (useNamesForExplicitOnly := false) : MetaM (Array FVarId Γ— MVarId) :=\n introNCore mvarId n givenNames (useNamesForExplicitOnly := useNamesForExplicitOnly) (preserveBinderNames := false)", "start": [ 129, 1 ], "end": [ 133, 117 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.introN", "code": "@[deprecated MVarId.introN (since := \"2022-07-15\")]\nabbrev introN (mvarId : MVarId) (n : Nat) (givenNames : List Name := []) (useNamesForExplicitOnly := false) : MetaM (Array FVarId Γ— MVarId) :=\n mvarId.introN n givenNames useNamesForExplicitOnly", "start": [ 135, 1 ], "end": [ 137, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.introNP", "code": "abbrev _root_.Lean.MVarId.introNP (mvarId : MVarId) (n : Nat) : MetaM (Array FVarId Γ— MVarId) :=\n introNCore mvarId n [] (useNamesForExplicitOnly := false) (preserveBinderNames := true)", "start": [ 139, 1 ], "end": [ 144, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.introNP", "code": "@[deprecated MVarId.introNP (since := \"2022-07-15\")]\nabbrev introNP (mvarId : MVarId) (n : Nat) : MetaM (Array FVarId Γ— MVarId) :=\n mvarId.introNP n", "start": [ 146, 1 ], "end": [ 148, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.intro", "code": "def _root_.Lean.MVarId.intro (mvarId : MVarId) (name : Name) : MetaM (FVarId Γ— MVarId) := do\n let (fvarIds, mvarId) ← mvarId.introN 1 [name]\n return (fvarIds[0]!, mvarId)", "start": [ 150, 1 ], "end": [ 155, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.intro", "code": "@[deprecated MVarId.intro (since := \"2022-07-15\")]\ndef intro (mvarId : MVarId) (name : Name) : MetaM (FVarId Γ— MVarId) := do\n mvarId.intro name", "start": [ 157, 1 ], "end": [ 159, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.intro1Core", "code": "def intro1Core (mvarId : MVarId) (preserveBinderNames : Bool) : MetaM (FVarId Γ— MVarId) := do\n let (fvarIds, mvarId) ← introNCore mvarId 1 [] (useNamesForExplicitOnly := false) preserveBinderNames\n return (fvarIds[0]!, mvarId)", "start": [ 161, 1 ], "end": [ 163, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.intro1", "code": "abbrev _root_.Lean.MVarId.intro1 (mvarId : MVarId) : MetaM (FVarId Γ— MVarId) :=\n intro1Core mvarId false", "start": [ 165, 1 ], "end": [ 170, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.intro1", "code": "@[deprecated MVarId.intro1 (since := \"2022-07-15\")]\nabbrev intro1 (mvarId : MVarId) : MetaM (FVarId Γ— MVarId) :=\n mvarId.intro1", "start": [ 172, 1 ], "end": [ 174, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.intro1P", "code": "abbrev _root_.Lean.MVarId.intro1P (mvarId : MVarId) : MetaM (FVarId Γ— MVarId) :=\n intro1Core mvarId true", "start": [ 176, 1 ], "end": [ 181, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.intro1P", "code": "@[deprecated MVarId.intro1P (since := \"2022-07-15\")]\nabbrev intro1P (mvarId : MVarId) : MetaM (FVarId Γ— MVarId) :=\n mvarId.intro1P", "start": [ 183, 1 ], "end": [ 185, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getIntrosSize", "code": "private partial def getIntrosSize : Expr β†’ Nat\n | .forallE _ _ b _ => getIntrosSize b + 1\n | .letE _ _ _ b _ => getIntrosSize b + 1\n | .mdata _ b => getIntrosSize b\n | e =>\n if let some (_, _, _, b) := e.letFun? then\n getIntrosSize b + 1\n else\n 0", "start": [ 187, 1 ], "end": [ 195, 8 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.intros", "code": "def _root_.Lean.MVarId.intros (mvarId : MVarId) : MetaM (Array FVarId Γ— MVarId) := do\n let type ← mvarId.getType\n let type ← instantiateMVars type\n let n := getIntrosSize type\n if n == 0 then\n return (#[], mvarId)\n else\n mvarId.introN n", "start": [ 197, 1 ], "end": [ 207, 20 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.intros", "code": "@[deprecated MVarId.intros (since := \"2022-07-15\")]\ndef intros (mvarId : MVarId) : MetaM (Array FVarId Γ— MVarId) := do\n mvarId.intros", "start": [ 209, 1 ], "end": [ 211, 16 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/ForEachExpr.lean
[ ".lake/packages/lean4/src/lean/Lean/Util/MonadCache.lean", ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.ForEachExpr.visit", "code": "def visit (g : Expr β†’ m Bool) (e : Expr) : MonadCacheT Expr Unit m Unit :=\n checkCache e fun _ => do\n if (← g e) then\n match e with\n | Expr.forallE _ d b _ => do visit g d; visit g b\n | Expr.lam _ d b _ => do visit g d; visit g b\n | Expr.letE _ t v b _ => do visit g t; visit g v; visit g b\n | Expr.app f a => do visit g f; visit g a\n | Expr.mdata _ b => visit g b\n | Expr.proj _ _ b => visit g b\n | _ => pure ()", "start": [ 19, 1 ], "end": [ 29, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.forEach'", "code": "@[inline] def Expr.forEach' (e : Expr) (f : Expr β†’ m Bool) : m Unit :=\n (ForEachExpr.visit f e).run", "start": [ 33, 1 ], "end": [ 35, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.forEach", "code": "@[inline] def Expr.forEach (e : Expr) (f : Expr β†’ m Unit) : m Unit :=\n e.forEach' fun e => do f e; pure true", "start": [ 37, 1 ], "end": [ 38, 40 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Revert.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Clear.lean" ]
[ { "full_name": "Lean.MVarId.revert", "code": "def _root_.Lean.MVarId.revert (mvarId : MVarId) (fvarIds : Array FVarId) (preserveOrder : Bool := false)\n (clearAuxDeclsInsteadOfRevert := false) : MetaM (Array FVarId Γ— MVarId) := do\n if fvarIds.isEmpty then\n pure (#[], mvarId)\n else mvarId.withContext do\n mvarId.checkNotAssigned `revert\n unless clearAuxDeclsInsteadOfRevert do\n for fvarId in fvarIds do\n if (← fvarId.getDecl) |>.isAuxDecl then\n throwError \"failed to revert {mkFVar fvarId}, it is an auxiliary declaration created to represent recursive definitions\"\n let fvars := fvarIds.map mkFVar\n let toRevert ← collectForwardDeps fvars preserveOrder\n \n let mut mvarId := mvarId\n let mut toRevertNew := #[]\n for x in toRevert do\n if (← x.fvarId!.getDecl).isAuxDecl then\n mvarId ← mvarId.clear x.fvarId!\n else\n toRevertNew := toRevertNew.push x\n let tag ← mvarId.getTag\n mvarId.setKind .natural\n let (e, toRevert) ←\n try\n liftMkBindingM <| MetavarContext.revert toRevertNew mvarId preserveOrder\n finally\n mvarId.setKind .syntheticOpaque\n let mvar := e.getAppFn\n mvar.mvarId!.setTag tag\n return (toRevert.map Expr.fvarId!, mvar.mvarId!)", "start": [ 11, 1 ], "end": [ 47, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.revertAfter", "code": "def _root_.Lean.MVarId.revertAfter (mvarId : MVarId) (fvarId : FVarId) : MetaM (Array FVarId Γ— MVarId) :=\n mvarId.withContext do\n let localDecl ← fvarId.getDecl\n let fvarIds := (← getLCtx).foldl (init := #[]) (start := localDecl.index+1) fun fvarIds decl => fvarIds.push decl.fvarId\n mvarId.revert fvarIds (preserveOrder := true) (clearAuxDeclsInsteadOfRevert := true)", "start": [ 49, 1 ], "end": [ 54, 89 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.revert", "code": "@[deprecated MVarId.revert (since := \"2022-07-15\")]\ndef revert (mvarId : MVarId) (fvarIds : Array FVarId) (preserveOrder : Bool := false) : MetaM (Array FVarId Γ— MVarId) := do\n mvarId.revert fvarIds preserveOrder", "start": [ 56, 1 ], "end": [ 58, 38 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Init/Data/Array.lean
[ ".lake/packages/lean4/src/lean/Init/Data/Array/InsertionSort.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/BasicAux.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/Basic.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/BinSearch.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/QSort.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/Lemmas.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/Mem.lean", ".lake/packages/lean4/src/lean/Init/Data/Array/DecidableEq.lean" ]
[]
.lake/packages/lean4/src/lean/Lean/Data/Lsp/Basic.lean
[ ".lake/packages/lean4/src/lean/Lean/Data/Json.lean", ".lake/packages/lean4/src/lean/Lean/Data/JsonRpc.lean" ]
[ { "full_name": "Lean.Lsp.CancelParams", "code": "structure CancelParams where\n id : JsonRpc.RequestID\n deriving Inhabited, BEq, ToJson, FromJson", "start": [ 22, 1 ], "end": [ 24, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.DocumentUri", "code": "abbrev DocumentUri := String", "start": [ 26, 1 ], "end": [ 26, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.Position", "code": "structure Position where\n line : Nat\n character : Nat\n deriving Inhabited, BEq, Ord, Hashable, ToJson, FromJson", "start": [ 28, 1 ], "end": [ 35, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.Range", "code": "structure Range where\n start : Position\n Β«endΒ» : Position\n deriving Inhabited, BEq, Hashable, ToJson, FromJson, Ord", "start": [ 43, 1 ], "end": [ 46, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.Location", "code": "structure Location where\n uri : DocumentUri\n range : Range\n deriving Inhabited, BEq, ToJson, FromJson, Ord", "start": [ 51, 1 ], "end": [ 55, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.LocationLink", "code": "structure LocationLink where\n originSelectionRange? : Option Range\n targetUri : DocumentUri\n targetRange : Range\n targetSelectionRange : Range\n deriving ToJson, FromJson", "start": [ 57, 1 ], "end": [ 62, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.Command", "code": "structure Command where\n \n title : String\n \n command : String\n \n arguments? : Option (Array Json) := none\n deriving ToJson, FromJson", "start": [ 66, 1 ], "end": [ 80, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.SnippetString", "code": "structure SnippetString where\n value : String\n deriving ToJson, FromJson", "start": [ 82, 1 ], "end": [ 112, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextEdit", "code": "structure TextEdit where\n \n range : Range\n \n newText : String\n \n \n leanExtSnippet? : Option SnippetString := none\n \n annotationId? : Option String := none\n deriving ToJson, FromJson", "start": [ 114, 1 ], "end": [ 146, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextEditBatch", "code": "def TextEditBatch := Array TextEdit", "start": [ 148, 1 ], "end": [ 149, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextDocumentIdentifier", "code": "structure TextDocumentIdentifier where\n uri : DocumentUri\n deriving ToJson, FromJson", "start": [ 165, 1 ], "end": [ 167, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.VersionedTextDocumentIdentifier", "code": "structure VersionedTextDocumentIdentifier where\n uri : DocumentUri\n version? : Option Nat := none\n deriving ToJson, FromJson", "start": [ 169, 1 ], "end": [ 172, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextDocumentEdit", "code": "structure TextDocumentEdit where\n textDocument : VersionedTextDocumentIdentifier\n edits : TextEditBatch\n deriving ToJson, FromJson", "start": [ 174, 1 ], "end": [ 180, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.ChangeAnnotation", "code": "structure ChangeAnnotation where\n \n label : String\n \n needsConfirmation : Bool := false\n \n description? : Option String := none\n deriving ToJson, FromJson", "start": [ 182, 1 ], "end": [ 193, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.CreateFile.Options", "code": "structure CreateFile.Options where\n overwrite : Bool := false\n ignoreIfExists : Bool := false\n deriving ToJson, FromJson", "start": [ 195, 1 ], "end": [ 199, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.DeleteFile.Options", "code": "structure DeleteFile.Options where\n recursive : Bool := false\n ignoreIfNotExists := false\n deriving ToJson, FromJson", "start": [ 201, 1 ], "end": [ 205, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.CreateFile", "code": "structure CreateFile where\n uri : DocumentUri\n options? : Option CreateFile.Options := none\n annotationId? : Option String := none\n deriving ToJson, FromJson", "start": [ 207, 1 ], "end": [ 211, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.RenameFile", "code": "structure RenameFile where\n oldUri : DocumentUri\n newUri : DocumentUri\n options? : Option CreateFile.Options := none\n annotationId? : Option String := none\n deriving ToJson, FromJson", "start": [ 213, 1 ], "end": [ 218, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.DeleteFile", "code": "structure DeleteFile where\n uri : DocumentUri\n options? : Option DeleteFile.Options := none\n annotationId? : Option String := none\n deriving ToJson, FromJson", "start": [ 220, 1 ], "end": [ 224, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.DocumentChange", "code": "inductive DocumentChange where\n | create : CreateFile β†’ DocumentChange\n | rename : RenameFile β†’ DocumentChange\n | delete : DeleteFile β†’ DocumentChange\n | edit : TextDocumentEdit β†’ DocumentChange", "start": [ 226, 1 ], "end": [ 233, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkspaceEdit", "code": "structure WorkspaceEdit where\n \n changes? : Option (RBMap DocumentUri TextEditBatch compare) := none\n \n documentChanges? : Option (Array DocumentChange) := none\n \n changeAnnotations? : Option (RBMap String ChangeAnnotation compare) := none\n deriving ToJson, FromJson", "start": [ 252, 1 ], "end": [ 279, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkspaceEdit.ofTextDocumentEdit", "code": "def ofTextDocumentEdit (e : TextDocumentEdit) : WorkspaceEdit :=\n { documentChanges? := #[DocumentChange.edit e]}", "start": [ 301, 1 ], "end": [ 302, 50 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkspaceEdit.ofTextEdit", "code": "def ofTextEdit (doc : VersionedTextDocumentIdentifier) (te : TextEdit) : WorkspaceEdit :=\n ofTextDocumentEdit { textDocument := doc, edits := #[te]}", "start": [ 304, 1 ], "end": [ 305, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.ApplyWorkspaceEditParams", "code": "structure ApplyWorkspaceEditParams where\n \n label? : Option String := none\n \n edit : WorkspaceEdit\n deriving ToJson, FromJson", "start": [ 309, 1 ], "end": [ 319, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextDocumentItem", "code": "structure TextDocumentItem where\n \n uri : DocumentUri\n \n languageId : String\n \n version : Nat\n \n text : String\n deriving ToJson, FromJson", "start": [ 321, 1 ], "end": [ 334, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextDocumentPositionParams", "code": "structure TextDocumentPositionParams where\n textDocument : TextDocumentIdentifier\n position : Position\n deriving ToJson, FromJson", "start": [ 336, 1 ], "end": [ 339, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.DocumentFilter", "code": "structure DocumentFilter where\n language? : Option String := none\n scheme? : Option String := none\n pattern? : Option String := none\n deriving ToJson, FromJson", "start": [ 344, 1 ], "end": [ 348, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.DocumentSelector", "code": "def DocumentSelector := Array DocumentFilter", "start": [ 350, 1 ], "end": [ 350, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.StaticRegistrationOptions", "code": "structure StaticRegistrationOptions where\n id? : Option String := none\n deriving ToJson, FromJson", "start": [ 358, 1 ], "end": [ 360, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.TextDocumentRegistrationOptions", "code": "structure TextDocumentRegistrationOptions where\n documentSelector? : Option DocumentSelector := none\n deriving ToJson, FromJson", "start": [ 362, 1 ], "end": [ 364, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.MarkupKind", "code": "inductive MarkupKind where\n | plaintext | markdown", "start": [ 366, 1 ], "end": [ 367, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.MarkupContent", "code": "structure MarkupContent where\n kind : MarkupKind\n value : String\n deriving ToJson, FromJson", "start": [ 378, 1 ], "end": [ 381, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.ProgressToken", "code": "abbrev ProgressToken := String", "start": [ 383, 1 ], "end": [ 387, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.ProgressParams", "code": "structure ProgressParams (Ξ± : Type) where\n token : ProgressToken\n value : Ξ±\n deriving ToJson", "start": [ 389, 1 ], "end": [ 395, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkDoneProgressReport", "code": "structure WorkDoneProgressReport where\n kind := \"report\"\n \n message? : Option String := none\n \n cancellable := false\n \n percentage? : Option Nat := none\n deriving ToJson", "start": [ 397, 1 ], "end": [ 406, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkDoneProgressBegin", "code": "structure WorkDoneProgressBegin extends WorkDoneProgressReport where\n kind := \"begin\"\n title : String\n deriving ToJson", "start": [ 408, 1 ], "end": [ 412, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkDoneProgressEnd", "code": "structure WorkDoneProgressEnd where\n kind := \"end\"\n message? : Option String := none\n deriving ToJson", "start": [ 414, 1 ], "end": [ 418, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkDoneProgressParams", "code": "structure WorkDoneProgressParams where\n workDoneToken? : Option ProgressToken := none\n deriving ToJson, FromJson", "start": [ 420, 1 ], "end": [ 422, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.PartialResultParams", "code": "structure PartialResultParams where\n partialResultToken? : Option ProgressToken := none\n deriving ToJson, FromJson", "start": [ 424, 1 ], "end": [ 426, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Lsp.WorkDoneProgressOptions", "code": "structure WorkDoneProgressOptions where\n workDoneProgress := false\n deriving ToJson, FromJson", "start": [ 428, 1 ], "end": [ 431, 28 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/HeadIndex.lean
[ ".lake/packages/lean4/src/lean/Lean/Expr.lean" ]
[ { "full_name": "Lean.HeadIndex", "code": "inductive HeadIndex where\n | fvar (fvarId : FVarId)\n | mvar (mvarId : MVarId)\n | const (constName : Name)\n | proj (structName : Name) (idx : Nat)\n | lit (litVal : Literal)\n | sort\n | lam\n | forallE\n deriving Inhabited, BEq, Repr", "start": [ 11, 1 ], "end": [ 33, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.HeadIndex.hash", "code": "protected def HeadIndex.hash : HeadIndex β†’ UInt64\n | fvar fvarId => mixHash 11 <| hash fvarId\n | mvar mvarId => mixHash 13 <| hash mvarId\n | const constName => mixHash 17 <| hash constName\n | proj structName idx => mixHash 19 <| mixHash (hash structName) (hash idx)\n | lit litVal => mixHash 23 <| hash litVal\n | sort => 29\n | lam => 31\n | forallE => 37", "start": [ 35, 1 ], "end": [ 44, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.headNumArgs", "code": "def headNumArgs (e : Expr) : Nat :=\n go e 0\nwhere\n go : Expr β†’ Nat β†’ Nat\n | app f _, n => go f (n + 1)\n | letE _ _ _ b _, n => go b n\n | mdata _ e, n => go e n\n | _, n => n", "start": [ 50, 1 ], "end": [ 58, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.toHeadIndexQuick?", "code": "private def toHeadIndexQuick? : Expr β†’ Option HeadIndex\n | mvar mvarId => HeadIndex.mvar mvarId\n | fvar fvarId => HeadIndex.fvar fvarId\n | const constName _ => HeadIndex.const constName\n | proj structName idx _ => HeadIndex.proj structName idx\n | sort _ => HeadIndex.sort\n | lam .. => HeadIndex.lam\n | forallE .. => HeadIndex.forallE\n | lit v => HeadIndex.lit v\n | app f _ => toHeadIndexQuick? f\n | letE _ _ _ b _ => toHeadIndexQuick? b\n | mdata _ e => toHeadIndexQuick? e\n | _ => none", "start": [ 60, 1 ], "end": [ 80, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.toHeadIndexSlow", "code": "private partial def toHeadIndexSlow : Expr β†’ HeadIndex\n | mvar mvarId => HeadIndex.mvar mvarId\n | fvar fvarId => HeadIndex.fvar fvarId\n | const constName _ => HeadIndex.const constName\n | proj structName idx _ => HeadIndex.proj structName idx\n | sort _ => HeadIndex.sort\n | lam .. => HeadIndex.lam\n | forallE .. => HeadIndex.forallE\n | lit v => HeadIndex.lit v\n | app f _ => toHeadIndexSlow f\n | letE _ _ v b _ => toHeadIndexSlow (b.instantiate1 v)\n | mdata _ e => toHeadIndexSlow e\n | _ => panic! \"unexpected expression kind\"", "start": [ 82, 1 ], "end": [ 100, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.toHeadIndex", "code": "def toHeadIndex (e : Expr) : HeadIndex :=\n match toHeadIndexQuick? e with\n | some i => i\n | none => toHeadIndexSlow e", "start": [ 102, 1 ], "end": [ 108, 30 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/AuxLemma.lean
[ ".lake/packages/lean4/src/lean/Lean/AddDecl.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Meta.AuxLemmas", "code": "structure AuxLemmas where\n idx : Nat := 1\n lemmas : PHashMap Expr (Name Γ— List Name) := {}\n deriving Inhabited", "start": [ 12, 1 ], "end": [ 15, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkAuxLemma", "code": "def mkAuxLemma (levelParams : List Name) (type : Expr) (value : Expr) : MetaM Name := do\n let env ← getEnv\n let s := auxLemmasExt.getState env\n let mkNewAuxLemma := do\n let auxName := Name.mkNum (env.mainModule ++ `_auxLemma) s.idx\n addDecl <| Declaration.thmDecl {\n name := auxName\n levelParams, type, value\n }\n modifyEnv fun env => auxLemmasExt.modifyState env fun ⟨idx, lemmas⟩ => ⟨idx + 1, lemmas.insert type (auxName, levelParams)⟩\n return auxName\n match s.lemmas.find? type with\n | some (name, levelParams') => if levelParams == levelParams' then return name else mkNewAuxLemma\n | none => mkNewAuxLemma", "start": [ 19, 1 ], "end": [ 41, 26 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/DocString.lean
[ ".lake/packages/lean4/src/lean/Lean/DocString/Extension.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Tactic/Doc.lean" ]
[ { "full_name": "Lean.findDocString?", "code": "def findDocString? (env : Environment) (declName : Name) (includeBuiltin := true) : IO (Option String) := do\n let declName := alternativeOfTactic env declName |>.getD declName\n let exts := getTacticExtensionString env declName\n return (← findSimpleDocString? env declName (includeBuiltin := includeBuiltin)).map (Β· ++ exts)", "start": [ 19, 1 ], "end": [ 29, 98 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/PrettyPrinter.lean
[ ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Formatter.lean", ".lake/packages/lean4/src/lean/Lean/ParserCompiler.lean", ".lake/packages/lean4/src/lean/Lean/Parser/Module.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Parenthesizer.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter/Delaborator.lean" ]
[ { "full_name": "Lean.PPContext.runCoreM", "code": "def PPContext.runCoreM {Ξ± : Type} (ppCtx : PPContext) (x : CoreM Ξ±) : IO Ξ± :=\n Prod.fst <$> x.toIO { options := ppCtx.opts, currNamespace := ppCtx.currNamespace\n openDecls := ppCtx.openDecls\n fileName := \"<PrettyPrinter>\", fileMap := default\n diag := getDiag ppCtx.opts }\n { env := ppCtx.env, ngen := { namePrefix := `_pp_uniq } }", "start": [ 15, 1 ], "end": [ 20, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PPContext.runMetaM", "code": "def PPContext.runMetaM {Ξ± : Type} (ppCtx : PPContext) (x : MetaM Ξ±) : IO Ξ± :=\n ppCtx.runCoreM <| x.run' { lctx := ppCtx.lctx } { mctx := ppCtx.mctx }", "start": [ 22, 1 ], "end": [ 23, 73 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppCategory", "code": "def ppCategory (cat : Name) (stx : Syntax) : CoreM Format := do\n let opts ← getOptions\n let stx := (sanitizeSyntax stx).run' { options := opts }\n parenthesizeCategory cat stx >>= formatCategory cat", "start": [ 27, 1 ], "end": [ 30, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppTerm", "code": "def ppTerm (stx : Term) : CoreM Format := ppCategory `term stx", "start": [ 32, 1 ], "end": [ 32, 63 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppUsing", "code": "def ppUsing (e : Expr) (delab : Expr β†’ MetaM Term) : MetaM Format := do\n let lctx := (← getLCtx).sanitizeNames.run' { options := (← getOptions) }\n Meta.withLCtx lctx #[] do\n ppTerm (← delab e)", "start": [ 34, 1 ], "end": [ 37, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppExpr", "code": "def ppExpr (e : Expr) : MetaM Format := do\n ppUsing e delab", "start": [ 39, 1 ], "end": [ 40, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppExprWithInfos", "code": "def ppExprWithInfos (e : Expr) (optsPerPos : Delaborator.OptionsPerPos := {}) (delab := Delaborator.delab)\n : MetaM FormatWithInfos := do\n let lctx := (← getLCtx).sanitizeNames.run' { options := (← getOptions) }\n Meta.withLCtx lctx #[] do\n let (stx, infos) ← delabCore e optsPerPos delab\n let fmt ← ppTerm stx\n return ⟨fmt, infos⟩", "start": [ 42, 1 ], "end": [ 50, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppExprLegacy", "code": "@[export lean_pp_expr]\ndef ppExprLegacy (env : Environment) (mctx : MetavarContext) (lctx : LocalContext) (opts : Options) (e : Expr) : IO Format :=\n Prod.fst <$> ((withOptions (fun _ => opts) <| ppExpr e).run' { lctx := lctx } { mctx := mctx }).toIO\n { fileName := \"<PrettyPrinter>\", fileMap := default }\n { env := env }", "start": [ 52, 1 ], "end": [ 56, 19 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppTactic", "code": "def ppTactic (stx : TSyntax `tactic) : CoreM Format := ppCategory `tactic stx", "start": [ 58, 1 ], "end": [ 58, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppCommand", "code": "def ppCommand (stx : Syntax.Command) : CoreM Format := ppCategory `command stx", "start": [ 60, 1 ], "end": [ 60, 79 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppModule", "code": "def ppModule (stx : TSyntax ``Parser.Module.module) : CoreM Format := do\n parenthesize Lean.Parser.Module.module.parenthesizer stx >>= format Lean.Parser.Module.module.formatter", "start": [ 62, 1 ], "end": [ 63, 106 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.ppSignature", "code": "def ppSignature (c : Name) : MetaM FormatWithInfos := do\n let decl ← getConstInfo c\n let e := .const c (decl.levelParams.map mkLevelParam)\n let (stx, infos) ← delabCore e (delab := delabConstWithSignature)\n return βŸ¨β† ppTerm ⟨stx⟩, infos⟩", "start": [ 66, 1 ], "end": [ 71, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.noContext", "code": "private partial def noContext : MessageData β†’ MessageData\n | MessageData.withContext _ msg => noContext msg\n | MessageData.withNamingContext ctx msg => MessageData.withNamingContext ctx (noContext msg)\n | MessageData.nest n msg => MessageData.nest n (noContext msg)\n | MessageData.group msg => MessageData.group (noContext msg)\n | MessageData.compose msg₁ msgβ‚‚ => MessageData.compose (noContext msg₁) (noContext msgβ‚‚)\n | MessageData.tagged tag msg => MessageData.tagged tag (noContext msg)\n | MessageData.trace data header children =>\n MessageData.trace data (noContext header) (children.map noContext)\n | msg => msg", "start": [ 73, 1 ], "end": [ 82, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.withoutContext", "code": "private def withoutContext {m} [MonadExcept Exception m] (x : m Ξ±) : m Ξ± :=\n tryCatch x fun\n | Exception.error ref msg => throw <| Exception.error ref (noContext msg)\n | ex => throw ex", "start": [ 85, 1 ], "end": [ 88, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.PrettyPrinter.registerParserCompilers", "code": "@[builtin_init]\nunsafe def registerParserCompilers : IO Unit := do\n ParserCompiler.registerParserCompiler ⟨`parenthesizer, parenthesizerAttribute, combinatorParenthesizerAttribute⟩\n ParserCompiler.registerParserCompiler ⟨`formatter, formatterAttribute, combinatorFormatterAttribute⟩", "start": [ 101, 1 ], "end": [ 104, 103 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MessageData.ofFormatWithInfosM", "code": "def ofFormatWithInfosM (fmt : MetaM FormatWithInfos) : MessageData :=\n .lazy fun ctx => ctx.runMetaM <|\n withOptions (pp.tagAppFns.set Β· true) <|\n .ofFormatWithInfos <$> fmt", "start": [ 112, 1 ], "end": [ 120, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MessageData.ofLazyM", "code": "def ofLazyM (f : MetaM MessageData) (es : Array Expr := #[]) : MessageData :=\n .lazy\n (f := fun ppctxt => ppctxt.runMetaM f)\n (hasSyntheticSorry := fun mvarctxt => es.any (fun a =>\n instantiateMVarsCore mvarctxt a |>.1.hasSyntheticSorry\n ))", "start": [ 122, 1 ], "end": [ 132, 7 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MessageData.ofConst", "code": "def ofConst (e : Expr) : MessageData :=\n if e.isConst then\n .ofFormatWithInfosM (PrettyPrinter.ppExprWithInfos (delab := delabConst) e)\n else\n panic! \"not a constant\"", "start": [ 134, 1 ], "end": [ 142, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MessageData.signature", "code": "def signature (c : Name) : MessageData :=\n .ofFormatWithInfosM (PrettyPrinter.ppSignature c)", "start": [ 144, 1 ], "end": [ 146, 52 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Eqns.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Match/MatcherInfo.lean", ".lake/packages/lean4/src/lean/Lean/ReservedNameAction.lean", ".lake/packages/lean4/src/lean/Lean/AddDecl.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean" ]
[ { "full_name": "Lean.Meta.markAsRecursive", "code": "def markAsRecursive (declName : Name) : CoreM Unit :=\n modifyEnv (recExt.tag Β· declName)", "start": [ 21, 1 ], "end": [ 25, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isRecursiveDefinition", "code": "def isRecursiveDefinition (declName : Name) : CoreM Bool :=\n return recExt.isTagged (← getEnv) declName", "start": [ 27, 1 ], "end": [ 31, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.eqnThmSuffixBase", "code": "def eqnThmSuffixBase := \"eq\"", "start": [ 33, 1 ], "end": [ 33, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.eqnThmSuffixBasePrefix", "code": "def eqnThmSuffixBasePrefix := eqnThmSuffixBase ++ \"_\"", "start": [ 34, 1 ], "end": [ 34, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.eqn1ThmSuffix", "code": "def eqn1ThmSuffix := eqnThmSuffixBasePrefix ++ \"1\"", "start": [ 35, 1 ], "end": [ 35, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isEqnReservedNameSuffix", "code": "def isEqnReservedNameSuffix (s : String) : Bool :=\n eqnThmSuffixBasePrefix.isPrefixOf s && (s.drop 3).isNat", "start": [ 38, 1 ], "end": [ 40, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.unfoldThmSuffix", "code": "def unfoldThmSuffix := \"eq_def\"", "start": [ 42, 1 ], "end": [ 42, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isUnfoldReservedNameSuffix", "code": "def isUnfoldReservedNameSuffix (s : String) : Bool :=\n s == unfoldThmSuffix", "start": [ 44, 1 ], "end": [ 46, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.ensureEqnReservedNamesAvailable", "code": "def ensureEqnReservedNamesAvailable (declName : Name) : CoreM Unit := do\n ensureReservedNameAvailable declName unfoldThmSuffix\n ensureReservedNameAvailable declName eqn1ThmSuffix", "start": [ 48, 1 ], "end": [ 53, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.GetEqnsFn", "code": "def GetEqnsFn := Name β†’ MetaM (Option (Array Name))", "start": [ 71, 1 ], "end": [ 71, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.registerGetEqnsFn", "code": "def registerGetEqnsFn (f : GetEqnsFn) : IO Unit := do\n unless (← initializing) do\n throw (IO.userError \"failed to register equation getter, this kind of extension can only be registered during initialization\")\n getEqnsFnsRef.modify (f :: Β·)", "start": [ 75, 1 ], "end": [ 103, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.shouldGenerateEqnThms", "code": "private def shouldGenerateEqnThms (declName : Name) : MetaM Bool := do\n if let some (.defnInfo info) := (← getEnv).find? declName then\n return !(← isProp info.type)\n else\n return false", "start": [ 105, 1 ], "end": [ 110, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.EqnsExtState", "code": "structure EqnsExtState where\n map : PHashMap Name (Array Name) := {}\n mapInv : PHashMap Name Name := {} deriving Inhabited", "start": [ 112, 1 ], "end": [ 115, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSimpleEqThm", "code": "private def mkSimpleEqThm (declName : Name) (suffix := Name.mkSimple unfoldThmSuffix) : MetaM (Option Name) := do\n if let some (.defnInfo info) := (← getEnv).find? declName then\n lambdaTelescope (cleanupAnnotations := true) info.value fun xs body => do\n let lhs := mkAppN (mkConst info.name <| info.levelParams.map mkLevelParam) xs\n let type ← mkForallFVars xs (← mkEq lhs body)\n let value ← mkLambdaFVars xs (← mkEqRefl lhs)\n let name := declName ++ suffix\n addDecl <| Declaration.thmDecl {\n name, type, value\n levelParams := info.levelParams\n }\n return some name\n else\n return none", "start": [ 121, 1 ], "end": [ 137, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isEqnThm?", "code": "def isEqnThm? (thmName : Name) : CoreM (Option Name) := do\n return eqnsExt.getState (← getEnv) |>.mapInv.find? thmName", "start": [ 139, 1 ], "end": [ 143, 61 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.registerEqnThms", "code": "private def registerEqnThms (declName : Name) (eqThms : Array Name) : CoreM Unit := do\n modifyEnv fun env => eqnsExt.modifyState env fun s => { s with\n map := s.map.insert declName eqThms\n mapInv := eqThms.foldl (init := s.mapInv) fun mapInv eqThm => mapInv.insert eqThm declName\n }", "start": [ 145, 1 ], "end": [ 152, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.alreadyGenerated?", "code": "private partial def alreadyGenerated? (declName : Name) : MetaM (Option (Array Name)) := do\n let env ← getEnv\n let eq1 := Name.str declName eqn1ThmSuffix\n if env.contains eq1 then\n let rec loop (idx : Nat) (eqs : Array Name) : MetaM (Array Name) := do\n let nextEq := declName ++ (`eq).appendIndexAfter idx\n if env.contains nextEq then\n loop (idx+1) (eqs.push nextEq)\n else\n return eqs\n let eqs ← loop 2 #[eq1]\n registerEqnThms declName eqs\n return some eqs\n else\n return none", "start": [ 154, 1 ], "end": [ 171, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getEqnsFor?", "code": "def getEqnsFor? (declName : Name) (nonRec := false) : MetaM (Option (Array Name)) := withLCtx {} {} do\n if let some eqs := eqnsExt.getState (← getEnv) |>.map.find? declName then\n return some eqs\n else if let some eqs ← alreadyGenerated? declName then\n return some eqs\n else if (← shouldGenerateEqnThms declName) then\n for f in (← getEqnsFnsRef.get) do\n if let some r ← f declName then\n registerEqnThms declName r\n return some r\n if nonRec then\n let some eqThm ← mkSimpleEqThm declName (suffix := Name.mkSimple eqn1ThmSuffix) | return none\n let r := #[eqThm]\n registerEqnThms declName r\n return some r\n return none", "start": [ 173, 1 ], "end": [ 193, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.GetUnfoldEqnFn", "code": "def GetUnfoldEqnFn := Name β†’ MetaM (Option Name)", "start": [ 195, 1 ], "end": [ 195, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.registerGetUnfoldEqnFn", "code": "def registerGetUnfoldEqnFn (f : GetUnfoldEqnFn) : IO Unit := do\n unless (← initializing) do\n throw (IO.userError \"failed to register equation getter, this kind of extension can only be registered during initialization\")\n getUnfoldEqnFnsRef.modify (f :: Β·)", "start": [ 199, 1 ], "end": [ 227, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getUnfoldEqnFor?", "code": "def getUnfoldEqnFor? (declName : Name) (nonRec := false) : MetaM (Option Name) := withLCtx {} {} do\n let env ← getEnv\n let unfoldName := Name.str declName unfoldThmSuffix\n if env.contains unfoldName then\n return some unfoldName\n if (← shouldGenerateEqnThms declName) then\n for f in (← getUnfoldEqnFnsRef.get) do\n if let some r ← f declName then\n unless r == unfoldName do\n throwError \"invalid unfold theorem name `{r}` has been generated expected `{unfoldName}`\"\n return some r\n if nonRec then\n return (← mkSimpleEqThm declName)\n return none", "start": [ 229, 1 ], "end": [ 247, 15 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/MatchUtil.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Util/Recognizers.lean", ".lake/packages/lean4/src/lean/Lean/Meta/CtorRecognizer.lean" ]
[ { "full_name": "Lean.Meta.testHelper", "code": "@[inline] def testHelper (e : Expr) (p : Expr β†’ MetaM Bool) : MetaM Bool := do\n if (← p e) then\n return true\n else\n p (← whnf e)", "start": [ 13, 1 ], "end": [ 17, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchHelper?", "code": "@[inline] def matchHelper? (e : Expr) (p? : Expr β†’ MetaM (Option Ξ±)) : MetaM (Option Ξ±) := do\n match (← p? e) with\n | none => p? (← whnf e)\n | s => return s", "start": [ 19, 1 ], "end": [ 22, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchEq?", "code": "def matchEq? (e : Expr) : MetaM (Option (Expr Γ— Expr Γ— Expr)) :=\n matchHelper? e fun e => return Expr.eq? e", "start": [ 24, 1 ], "end": [ 26, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchHEq?", "code": "def matchHEq? (e : Expr) : MetaM (Option (Expr Γ— Expr Γ— Expr Γ— Expr)) :=\n matchHelper? e fun e => return Expr.heq? e", "start": [ 28, 1 ], "end": [ 29, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchEqHEq?", "code": "def matchEqHEq? (e : Expr) : MetaM (Option (Expr Γ— Expr Γ— Expr)) := do\n if let some r ← matchEq? e then\n return some r\n else if let some (Ξ±, lhs, Ξ², rhs) ← matchHEq? e then\n if (← isDefEq Ξ± Ξ²) then\n return some (Ξ±, lhs, rhs)\n return none\n else\n return none", "start": [ 31, 1 ], "end": [ 42, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchFalse", "code": "def matchFalse (e : Expr) : MetaM Bool := do\n testHelper e fun e => return e.isFalse", "start": [ 44, 1 ], "end": [ 45, 41 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchNot?", "code": "def matchNot? (e : Expr) : MetaM (Option Expr) :=\n matchHelper? e fun e => do\n if let some e := e.not? then\n return e\n else if let some (a, b) := e.arrow? then\n if (← matchFalse b) then return some a else return none\n else\n return none", "start": [ 47, 1 ], "end": [ 54, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchNe?", "code": "def matchNe? (e : Expr) : MetaM (Option (Expr Γ— Expr Γ— Expr)) :=\n matchHelper? e fun e => do\n if let some r := e.ne? then\n return r\n else if let some e ← matchNot? e then\n matchEq? e\n else\n return none", "start": [ 56, 1 ], "end": [ 63, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.matchConstructorApp?", "code": "def matchConstructorApp? (e : Expr) : MetaM (Option ConstructorVal) := do\n matchHelper? e isConstructorApp?", "start": [ 65, 1 ], "end": [ 66, 35 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Assert.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Revert.lean", ".lake/packages/lean4/src/lean/Lean/Util/ForEachExpr.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Intro.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/FVarSubst.lean" ]
[ { "full_name": "Lean.MVarId.assert", "code": "def _root_.Lean.MVarId.assert (mvarId : MVarId) (name : Name) (type : Expr) (val : Expr) : MetaM MVarId :=\n mvarId.withContext do\n mvarId.checkNotAssigned `assert\n let tag ← mvarId.getTag\n let target ← mvarId.getType\n let newType := Lean.mkForall name BinderInfo.default type target\n let newMVar ← mkFreshExprSyntheticOpaqueMVar newType tag\n mvarId.assign (mkApp newMVar val)\n return newMVar.mvarId!", "start": [ 14, 1 ], "end": [ 25, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.assert", "code": "@[deprecated MVarId.assert (since := \"2022-07-15\")]\ndef assert (mvarId : MVarId) (name : Name) (type : Expr) (val : Expr) : MetaM MVarId :=\n mvarId.assert name type val", "start": [ 27, 1 ], "end": [ 29, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.note", "code": "def _root_.Lean.MVarId.note (g : MVarId) (h : Name) (v : Expr) (t? : Option Expr := .none) :\n MetaM (FVarId Γ— MVarId) := do\n (← g.assert h (← match t? with | some t => pure t | none => inferType v) v).intro1P", "start": [ 31, 1 ], "end": [ 34, 86 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.define", "code": "def _root_.Lean.MVarId.define (mvarId : MVarId) (name : Name) (type : Expr) (val : Expr) : MetaM MVarId := do\n mvarId.withContext do\n mvarId.checkNotAssigned `define\n let tag ← mvarId.getTag\n let target ← mvarId.getType\n let newType := Lean.mkLet name type val target\n let newMVar ← mkFreshExprSyntheticOpaqueMVar newType tag\n mvarId.assign newMVar\n return newMVar.mvarId!", "start": [ 36, 1 ], "end": [ 47, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.define", "code": "@[deprecated MVarId.define (since := \"2022-07-15\")]\ndef define (mvarId : MVarId) (name : Name) (type : Expr) (val : Expr) : MetaM MVarId := do\n mvarId.define name type val", "start": [ 49, 1 ], "end": [ 51, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.assertExt", "code": "def _root_.Lean.MVarId.assertExt (mvarId : MVarId) (name : Name) (type : Expr) (val : Expr) (hName : Name := `h) : MetaM MVarId := do\n mvarId.withContext do\n mvarId.checkNotAssigned `assert\n let tag ← mvarId.getTag\n let target ← mvarId.getType\n let u ← getLevel type\n let hType := mkApp3 (mkConst `Eq [u]) type (mkBVar 0) val\n let newType := Lean.mkForall name BinderInfo.default type $ Lean.mkForall hName BinderInfo.default hType target\n let newMVar ← mkFreshExprSyntheticOpaqueMVar newType tag\n let rflPrf ← mkEqRefl val\n mvarId.assign (mkApp2 newMVar val rflPrf)\n return newMVar.mvarId!", "start": [ 53, 1 ], "end": [ 67, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.assertExt", "code": "@[deprecated MVarId.assertExt (since := \"2022-07-15\")]\ndef assertExt (mvarId : MVarId) (name : Name) (type : Expr) (val : Expr) (hName : Name := `h) : MetaM MVarId := do\n mvarId.assertExt name type val hName", "start": [ 69, 1 ], "end": [ 71, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.AssertAfterResult", "code": "structure AssertAfterResult where\n fvarId : FVarId\n mvarId : MVarId\n subst : FVarSubst", "start": [ 73, 1 ], "end": [ 76, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.assertAfter", "code": "def _root_.Lean.MVarId.assertAfter (mvarId : MVarId) (fvarId : FVarId) (userName : Name) (type : Expr) (val : Expr) : MetaM AssertAfterResult := do\n mvarId.checkNotAssigned `assertAfter\n let (fvarIds, mvarId) ← mvarId.revertAfter fvarId\n let mvarId ← mvarId.assert userName type val\n let (fvarIdNew, mvarId) ← mvarId.intro1P\n let (fvarIdsNew, mvarId) ← mvarId.introNP fvarIds.size\n let mut subst := {}\n for f in fvarIds, fNew in fvarIdsNew do\n subst := subst.insert f (mkFVar fNew)\n return { fvarId := fvarIdNew, mvarId, subst }", "start": [ 78, 1 ], "end": [ 91, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.assertAfter", "code": "@[deprecated MVarId.assertAfter (since := \"2022-07-15\")]\ndef assertAfter (mvarId : MVarId) (fvarId : FVarId) (userName : Name) (type : Expr) (val : Expr) : MetaM AssertAfterResult := do\n mvarId.assertAfter fvarId userName type val", "start": [ 93, 1 ], "end": [ 95, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Hypothesis", "code": "structure Hypothesis where\n userName : Name\n type : Expr\n value : Expr", "start": [ 97, 1 ], "end": [ 100, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.assertHypotheses", "code": "def _root_.Lean.MVarId.assertHypotheses (mvarId : MVarId) (hs : Array Hypothesis) : MetaM (Array FVarId Γ— MVarId) := do\n if hs.isEmpty then\n return (#[], mvarId)\n else mvarId.withContext do\n mvarId.checkNotAssigned `assertHypotheses\n let tag ← mvarId.getTag\n let target ← mvarId.getType\n let targetNew := hs.foldr (init := target) fun h targetNew =>\n mkForall h.userName BinderInfo.default h.type targetNew\n let mvarNew ← mkFreshExprSyntheticOpaqueMVar targetNew tag\n let val := hs.foldl (init := mvarNew) fun val h => mkApp val h.value\n mvarId.assign val\n mvarNew.mvarId!.introNP hs.size", "start": [ 102, 1 ], "end": [ 117, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.assertHypotheses", "code": "@[deprecated MVarId.assertHypotheses (since := \"2022-07-15\")]\ndef assertHypotheses (mvarId : MVarId) (hs : Array Hypothesis) : MetaM (Array FVarId Γ— MVarId) := do\n mvarId.assertHypotheses hs", "start": [ 119, 1 ], "end": [ 121, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.replace", "code": "def _root_.Lean.MVarId.replace (g : MVarId) (hyp : FVarId) (proof : Expr) (typeNew : Option Expr := none) :\n MetaM AssertAfterResult :=\n g.withContext do\n let typeNew ← match typeNew with\n | some t => pure t\n | none => inferType proof\n let ldecl ← hyp.getDecl\n let (_, ldecl') ← findMaxFVar typeNew |>.run ldecl\n let result ← g.assertAfter ldecl'.fvarId ldecl.userName typeNew proof\n (return { result with mvarId := ← result.mvarId.clear hyp }) <|> pure result\nwhere\n \n findMaxFVar (e : Expr) : StateRefT LocalDecl MetaM Unit :=\n e.forEach' fun e => do\n if e.isFVar then\n let ldecl' ← e.fvarId!.getDecl\n modify fun ldecl => if ldecl'.index > ldecl.index then ldecl' else ldecl\n return false\n else\n return e.hasFVar", "start": [ 124, 1 ], "end": [ 152, 25 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Util/OccursCheck.lean
[ ".lake/packages/lean4/src/lean/Lean/MetavarContext.lean" ]
[ { "full_name": "Lean.occursCheck", "code": "partial def occursCheck [Monad m] [MonadMCtx m] (mvarId : MVarId) (e : Expr) : m Bool := do\n if !e.hasExprMVar then\n return true\n else\n match (← visit e |>.run |>.run {}) with\n | (.ok .., _) => return true\n | (.error .., _) => return false\nwhere\n visitMVar (mvarId' : MVarId) : ExceptT Unit (StateT ExprSet m) Unit := do\n if mvarId == mvarId' then\n throw () else\n match (← getExprMVarAssignment? mvarId') with\n | some v => visit v\n | none =>\n match (← getDelayedMVarAssignment? mvarId') with\n | some d => visitMVar d.mvarIdPending\n | none => return ()\n\n visit (e : Expr) : ExceptT Unit (StateT ExprSet m) Unit := do\n if !e.hasExprMVar then\n return ()\n else if (← get).contains e then\n return ()\n else\n modify fun s => s.insert e\n match e with\n | Expr.proj _ _ s => visit s\n | Expr.forallE _ d b _ => visit d; visit b\n | Expr.lam _ d b _ => visit d; visit b\n | Expr.letE _ t v b _ => visit t; visit v; visit b\n | Expr.mdata _ b => visit b\n | Expr.app f a => visit f; visit a\n | Expr.mvar mvarId => visitMVar mvarId\n | _ => return ()", "start": [ 11, 1 ], "end": [ 48, 42 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Tactic/Basic.lean
[ ".lake/packages/lean4/src/lean/Lean/Elab/Term.lean" ]
[ { "full_name": "Lean.Elab.admitGoal", "code": "def admitGoal (mvarId : MVarId) : MetaM Unit :=\n mvarId.withContext do\n let mvarType ← inferType (mkMVar mvarId)\n mvarId.assign (← mkSorry mvarType (synthetic := true))", "start": [ 12, 1 ], "end": [ 16, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.goalsToMessageData", "code": "def goalsToMessageData (goals : List MVarId) : MessageData :=\n MessageData.joinSep (goals.map MessageData.ofGoal) m!\"\\n\\n\"", "start": [ 18, 1 ], "end": [ 19, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.reportUnsolvedGoals", "code": "def Term.reportUnsolvedGoals (goals : List MVarId) : MetaM Unit := do\n logError <| MessageData.tagged `Tactic.unsolvedGoals <| m!\"unsolved goals\\n{goalsToMessageData goals}\"\n goals.forM fun mvarId => admitGoal mvarId", "start": [ 21, 1 ], "end": [ 23, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.Context", "code": "structure Context where\n \n elaborator : Name\n \n recover : Bool := true", "start": [ 27, 1 ], "end": [ 35, 28 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticM", "code": "abbrev TacticM := ReaderT Context $ StateRefT State TermElabM", "start": [ 37, 1 ], "end": [ 37, 62 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.Tactic", "code": "abbrev Tactic := Syntax β†’ TacticM Unit", "start": [ 38, 1 ], "end": [ 38, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getGoals", "code": "def getGoals : TacticM (List MVarId) :=\n return (← get).goals", "start": [ 51, 1 ], "end": [ 52, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.setGoals", "code": "def setGoals (mvarIds : List MVarId) : TacticM Unit :=\n modify fun _ => { goals := mvarIds }", "start": [ 54, 1 ], "end": [ 55, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.pruneSolvedGoals", "code": "def pruneSolvedGoals : TacticM Unit := do\n let gs ← getGoals\n let gs ← gs.filterM fun g => not <$> g.isAssigned\n setGoals gs", "start": [ 57, 1 ], "end": [ 60, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getUnsolvedGoals", "code": "def getUnsolvedGoals : TacticM (List MVarId) := do\n pruneSolvedGoals\n getGoals", "start": [ 62, 1 ], "end": [ 64, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticM.runCore", "code": "@[inline] private def TacticM.runCore (x : TacticM Ξ±) (ctx : Context) (s : State) : TermElabM (Ξ± Γ— State) :=\n x ctx |>.run s", "start": [ 66, 1 ], "end": [ 67, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.TacticM.runCore'", "code": "@[inline] private def TacticM.runCore' (x : TacticM Ξ±) (ctx : Context) (s : State) : TermElabM Ξ± :=\n Prod.fst <$> x.runCore ctx s", "start": [ 69, 1 ], "end": [ 70, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.run", "code": "def run (mvarId : MVarId) (x : TacticM Unit) : TermElabM (List MVarId) :=\n mvarId.withContext do\n let pendingMVarsSaved := (← get).pendingMVars\n modify fun s => { s with pendingMVars := [] }\n let aux : TacticM (List MVarId) :=\n \n try\n x; getUnsolvedGoals\n catch ex =>\n if isAbortTacticException ex then\n getUnsolvedGoals\n else\n throw ex\n try\n aux.runCore' { elaborator := .anonymous } { goals := [mvarId] }\n finally\n modify fun s => { s with pendingMVars := pendingMVarsSaved }", "start": [ 72, 1 ], "end": [ 90, 66 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.saveState", "code": "protected def saveState : TacticM SavedState :=\n return { term := (← Term.saveState), tactic := (← get) }", "start": [ 92, 1 ], "end": [ 93, 59 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.SavedState.restore", "code": "def SavedState.restore (b : SavedState) (restoreInfo := false) : TacticM Unit := do\n b.term.restore restoreInfo\n set b.tactic", "start": [ 95, 1 ], "end": [ 97, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.withRestoreOrSaveFull", "code": "@[specialize, inherit_doc Core.withRestoreOrSaveFull]\ndef withRestoreOrSaveFull (reusableResult? : Option (Ξ± Γ— SavedState)) (act : TacticM Ξ±) :\n TacticM (Ξ± Γ— SavedState) := do\n if let some (_, state) := reusableResult? then\n set state.tactic\n let reusableResult? := reusableResult?.map (fun (val, state) => (val, state.term))\n let (a, term) ← controlAt TermElabM fun runInBase => do\n Term.withRestoreOrSaveFull reusableResult? <| runInBase act\n return (a, { term, tactic := (← get) })", "start": [ 99, 1 ], "end": [ 107, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getCurrMacroScope", "code": "protected def getCurrMacroScope : TacticM MacroScope := do pure (← readThe Core.Context).currMacroScope", "start": [ 109, 1 ], "end": [ 109, 104 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getMainModule", "code": "protected def getMainModule : TacticM Name := do pure (← getEnv).mainModule", "start": [ 110, 1 ], "end": [ 110, 86 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.mkTacticAttribute", "code": "unsafe def mkTacticAttribute : IO (KeyedDeclsAttribute Tactic) :=\n mkElabAttribute Tactic `builtin_tactic `tactic `Lean.Parser.Tactic `Lean.Elab.Tactic.Tactic \"tactic\" `Lean.Elab.Tactic.tacticElabAttribute", "start": [ 112, 1 ], "end": [ 113, 141 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.tacticElabAttribute", "code": "@[builtin_init mkTacticAttribute] opaque tacticElabAttribute : KeyedDeclsAttribute Tactic", "start": [ 115, 1 ], "end": [ 115, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.mkTacticInfo", "code": "def mkTacticInfo (mctxBefore : MetavarContext) (goalsBefore : List MVarId) (stx : Syntax) : TacticM Info :=\n return Info.ofTacticInfo {\n elaborator := (← read).elaborator\n mctxBefore := mctxBefore\n goalsBefore := goalsBefore\n stx := stx\n mctxAfter := (← getMCtx)\n goalsAfter := (← getUnsolvedGoals)\n }", "start": [ 117, 1 ], "end": [ 125, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.mkInitialTacticInfo", "code": "def mkInitialTacticInfo (stx : Syntax) : TacticM (TacticM Info) := do\n let mctxBefore ← getMCtx\n let goalsBefore ← getUnsolvedGoals\n return mkTacticInfo mctxBefore goalsBefore stx", "start": [ 127, 1 ], "end": [ 130, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.withTacticInfoContext", "code": "@[inline] def withTacticInfoContext (stx : Syntax) (x : TacticM Ξ±) : TacticM Ξ± := do\n withInfoContext x (← mkInitialTacticInfo stx)", "start": [ 132, 1 ], "end": [ 133, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.EvalTacticFailure", "code": "structure EvalTacticFailure where\n exception : Exception\n state : SavedState", "start": [ 142, 1 ], "end": [ 147, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.evalTactic", "code": "partial def evalTactic (stx : Syntax) : TacticM Unit := do\n profileitM Exception \"tactic execution\" (decl := stx.getKind) (← getOptions) <|\n withRef stx <| withIncRecDepth <| withFreshMacroScope <| match stx with\n | .node _ k _ =>\n if k == nullKind then\n Term.withoutTacticIncrementality true do\n stx.getArgs.forM evalTactic\n else withTraceNode `Elab.step (fun _ => return stx) (tag := stx.getKind.toString) do\n let evalFns := tacticElabAttribute.getEntries (← getEnv) stx.getKind\n let macros := macroAttribute.getEntries (← getEnv) stx.getKind\n if evalFns.isEmpty && macros.isEmpty then\n throwErrorAt stx \"tactic '{stx.getKind}' has not been implemented\"\n let s ← Tactic.saveState\n expandEval s macros evalFns #[]\n | .missing => pure ()\n | _ => throwError m!\"unexpected tactic{indentD stx}\"\nwhere\n throwExs (failures : Array EvalTacticFailure) : TacticM Unit := do\n if h : 0 < failures.size then\n let fail := failures[failures.size-1]\n fail.state.restore (restoreInfo := true)\n throw fail.exception else\n throwErrorAt stx \"unexpected syntax {indentD stx}\"\n\n @[inline] handleEx (s : SavedState) (failures : Array EvalTacticFailure) (ex : Exception) (k : Array EvalTacticFailure β†’ TacticM Unit) := do\n match ex with\n | .error .. =>\n trace[Elab.tactic.backtrack] ex.toMessageData\n let failures := failures.push ⟨ex, ← Tactic.saveState⟩\n s.restore (restoreInfo := true); k failures\n | .internal id _ =>\n if id == unsupportedSyntaxExceptionId then\n s.restore (restoreInfo := true); k failures\n else if id == abortTacticExceptionId then\n for msg in (← Core.getMessageLog).toList do\n trace[Elab.tactic.backtrack] msg.data\n let failures := failures.push ⟨ex, ← Tactic.saveState⟩\n s.restore (restoreInfo := true); k failures\n else\n throw ex expandEval (s : SavedState) (macros : List _) (evalFns : List _) (failures : Array EvalTacticFailure) : TacticM Unit :=\n match macros with\n | [] => eval s evalFns failures\n | m :: ms =>\n try\n withReader ({ Β· with elaborator := m.declName }) do\n withTacticInfoContext stx do\n let stx' ← adaptMacro m.value stx\n if evalFns.isEmpty && ms.isEmpty then if let some snap := (← readThe Term.Context).tacSnap? then\n let nextMacroScope := (← getThe Core.State).nextMacroScope\n let traceState ← getTraceState\n let old? := do\n let old ← snap.old?\n guard <| old.stx.isOfKind stx.getKind\n let state ← old.val.get.data.finished.get.state?\n guard <| state.term.meta.core.nextMacroScope == nextMacroScope\n guard <| state.term.meta.core.traceState.traces.size == 0\n guard <| traceState.traces.size == 0\n return old.val.get\n Language.withAlwaysResolvedPromise fun promise => do\n snap.new.resolve <| .mk {\n stx := stx'\n diagnostics := .empty\n finished := .pure { state? := (← Tactic.saveState) }\n } #[{ range? := stx'.getRange?, task := promise.result }]\n withTheReader Term.Context ({ Β· with tacSnap? := some {\n new := promise\n old? := do\n let old ← old?\n return ⟨old.data.stx, (← old.next.get? 0)⟩\n } }) do\n evalTactic stx'\n return\n evalTactic stx'\n catch ex => handleEx s failures ex (expandEval s ms evalFns)\n\n eval (s : SavedState) (evalFns : List _) (failures : Array EvalTacticFailure) : TacticM Unit := do\n match evalFns with\n | [] => throwExs failures\n | evalFn::evalFns => do\n try\n Term.withoutTacticIncrementality (!(← isIncrementalElab evalFn.declName)) do\n withReader ({ Β· with elaborator := evalFn.declName }) do\n withTacticInfoContext stx do\n evalFn.value stx\n catch ex => handleEx s failures ex (eval s evalFns)", "start": [ 149, 1 ], "end": [ 248, 60 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.throwNoGoalsToBeSolved", "code": "def throwNoGoalsToBeSolved : TacticM Ξ± :=\n throwError \"no goals to be solved\"", "start": [ 250, 1 ], "end": [ 251, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.done", "code": "def done : TacticM Unit := do\n let gs ← getUnsolvedGoals\n unless gs.isEmpty do\n Term.reportUnsolvedGoals gs\n throwAbortTactic", "start": [ 253, 1 ], "end": [ 257, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.focus", "code": "def focus (x : TacticM Ξ±) : TacticM Ξ± := do\n let mvarId :: mvarIds ← getUnsolvedGoals | throwNoGoalsToBeSolved\n setGoals [mvarId]\n let a ← x\n let mvarIds' ← getUnsolvedGoals\n setGoals (mvarIds' ++ mvarIds)\n pure a", "start": [ 259, 1 ], "end": [ 265, 9 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.focusAndDone", "code": "def focusAndDone (tactic : TacticM Ξ±) : TacticM Ξ± :=\n focus do\n let a ← tactic\n done\n pure a", "start": [ 267, 1 ], "end": [ 271, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.closeUsingOrAdmit", "code": "def closeUsingOrAdmit (tac : TacticM Unit) : TacticM Unit := do\n \n let mvarId :: mvarIds ← getUnsolvedGoals | throwNoGoalsToBeSolved\n tryCatchRuntimeEx\n (focusAndDone tac)\n fun ex => do\n if (← read).recover then\n logException ex\n admitGoal mvarId\n setGoals mvarIds\n else\n throw ex", "start": [ 273, 1 ], "end": [ 286, 17 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.tryCatch", "code": "@[inline] protected def tryCatch {Ξ±} (x : TacticM Ξ±) (h : Exception β†’ TacticM Ξ±) : TacticM Ξ± := do\n let b ← saveState\n try x catch ex => b.restore; h ex", "start": [ 292, 1 ], "end": [ 294, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.withoutRecover", "code": "def withoutRecover (x : TacticM Ξ±) : TacticM Ξ± :=\n withReader (fun ctx => { ctx with recover := false }) x", "start": [ 300, 1 ], "end": [ 302, 58 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.orElse", "code": "@[inline] protected def orElse (x : TacticM Ξ±) (y : Unit β†’ TacticM Ξ±) : TacticM Ξ± := do\n try withoutRecover x catch _ => y ()", "start": [ 304, 1 ], "end": [ 305, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.saveTacticInfoForToken", "code": "def saveTacticInfoForToken (stx : Syntax) : TacticM Unit := do\n unless stx.getPos?.isNone do\n withTacticInfoContext stx (pure ())", "start": [ 314, 1 ], "end": [ 321, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.withMacroExpansion", "code": "@[inline]\ndef withMacroExpansion (beforeStx afterStx : Syntax) (x : TacticM Ξ±) : TacticM Ξ± :=\n withMacroExpansionInfo beforeStx afterStx do\n withTheReader Term.Context (fun ctx => { ctx with macroStack := { before := beforeStx, after := afterStx } :: ctx.macroStack }) x", "start": [ 323, 1 ], "end": [ 327, 134 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.adaptExpander", "code": "def adaptExpander (exp : Syntax β†’ TacticM Syntax) : Tactic := fun stx => do\n let stx' ← exp stx\n withMacroExpansion stx stx' $ evalTactic stx'", "start": [ 329, 1 ], "end": [ 332, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.appendGoals", "code": "def appendGoals (mvarIds : List MVarId) : TacticM Unit :=\n modify fun s => { s with goals := s.goals ++ mvarIds }", "start": [ 334, 1 ], "end": [ 336, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.replaceMainGoal", "code": "def replaceMainGoal (mvarIds : List MVarId) : TacticM Unit := do\n let (_ :: mvarIds') ← getGoals | throwNoGoalsToBeSolved\n modify fun _ => { goals := mvarIds ++ mvarIds' }", "start": [ 338, 1 ], "end": [ 342, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getMainGoal", "code": "def getMainGoal : TacticM MVarId := do\n loop (← getGoals)\nwhere\n loop : List MVarId β†’ TacticM MVarId\n | [] => throwNoGoalsToBeSolved\n | mvarId :: mvarIds => do\n if (← mvarId.isAssigned) then\n loop mvarIds\n else\n setGoals (mvarId :: mvarIds)\n return mvarId", "start": [ 344, 1 ], "end": [ 355, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getMainDecl", "code": "def getMainDecl : TacticM MetavarDecl := do\n (← getMainGoal).getDecl", "start": [ 357, 1 ], "end": [ 359, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getMainTag", "code": "def getMainTag : TacticM Name :=\n return (← getMainDecl).userName", "start": [ 361, 1 ], "end": [ 363, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getMainTarget", "code": "def getMainTarget : TacticM Expr := do\n instantiateMVars (← getMainDecl).type", "start": [ 365, 1 ], "end": [ 367, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.withMainContext", "code": "def withMainContext (x : TacticM Ξ±) : TacticM Ξ± := do\n (← getMainGoal).withContext x", "start": [ 369, 1 ], "end": [ 371, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.evalTacticAt", "code": "def evalTacticAt (tac : Syntax) (mvarId : MVarId) : TacticM (List MVarId) := do\n let gs ← getGoals\n try\n setGoals [mvarId]\n evalTactic tac\n pruneSolvedGoals\n getGoals\n finally\n setGoals gs", "start": [ 373, 1 ], "end": [ 382, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.evalTacticAtRaw", "code": "def evalTacticAtRaw (tac : Syntax) (mvarId : MVarId) : TacticM (List MVarId) := do\n setGoals [mvarId]\n evalTactic tac\n getGoals", "start": [ 384, 1 ], "end": [ 391, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.ensureHasNoMVars", "code": "def ensureHasNoMVars (e : Expr) : TacticM Unit := do\n let e ← instantiateMVars e\n let pendingMVars ← getMVars e\n discard <| Term.logUnassignedUsingErrorInfos pendingMVars\n if e.hasExprMVar then\n throwError \"tactic failed, resulting expression contains metavariables{indentExpr e}\"", "start": [ 393, 1 ], "end": [ 398, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.closeMainGoal", "code": "def closeMainGoal (val : Expr) (checkUnassigned := true): TacticM Unit := do\n if checkUnassigned then\n ensureHasNoMVars val\n (← getMainGoal).assign val\n replaceMainGoal []", "start": [ 400, 1 ], "end": [ 405, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.liftMetaMAtMain", "code": "@[inline] def liftMetaMAtMain (x : MVarId β†’ MetaM Ξ±) : TacticM Ξ± := do\n withMainContext do x (← getMainGoal)", "start": [ 407, 1 ], "end": [ 408, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.liftMetaTacticAux", "code": "@[inline] def liftMetaTacticAux (tac : MVarId β†’ MetaM (Ξ± Γ— List MVarId)) : TacticM Ξ± := do\n withMainContext do\n let (a, mvarIds) ← tac (← getMainGoal)\n replaceMainGoal mvarIds\n pure a", "start": [ 410, 1 ], "end": [ 414, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.liftMetaTactic", "code": "@[inline] def liftMetaTactic (tactic : MVarId β†’ MetaM (List MVarId)) : TacticM Unit :=\n liftMetaTacticAux fun mvarId => do\n let gs ← tactic mvarId\n pure ((), gs)", "start": [ 416, 1 ], "end": [ 421, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.liftMetaTactic1", "code": "@[inline] def liftMetaTactic1 (tactic : MVarId β†’ MetaM (Option MVarId)) : TacticM Unit :=\n withMainContext do\n if let some mvarId ← tactic (← getMainGoal) then\n replaceMainGoal [mvarId]\n else\n replaceMainGoal []", "start": [ 423, 1 ], "end": [ 428, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.liftMetaFinishingTactic", "code": "@[inline] def liftMetaFinishingTactic (tac : MVarId β†’ MetaM Unit) : TacticM Unit :=\n liftMetaTactic fun g => do tac g; pure []", "start": [ 430, 1 ], "end": [ 432, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.tryTactic?", "code": "def tryTactic? (tactic : TacticM Ξ±) : TacticM (Option Ξ±) := do\n try\n pure (some (← tactic))\n catch _ =>\n pure none", "start": [ 434, 1 ], "end": [ 438, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.tryTactic", "code": "def tryTactic (tactic : TacticM Ξ±) : TacticM Bool := do\n try\n discard tactic\n pure true\n catch _ =>\n pure false", "start": [ 440, 1 ], "end": [ 445, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.tagUntaggedGoals", "code": "def tagUntaggedGoals (parentTag : Name) (newSuffix : Name) (newGoals : List MVarId) : TacticM Unit := do\n let mctx ← getMCtx\n let mut numAnonymous := 0\n for g in newGoals do\n if mctx.isAnonymousMVar g then\n numAnonymous := numAnonymous + 1\n modifyMCtx fun mctx => Id.run do\n let mut mctx := mctx\n let mut idx := 1\n for g in newGoals do\n if mctx.isAnonymousMVar g then\n if numAnonymous == 1 then\n mctx := mctx.setMVarUserName g parentTag\n else\n mctx := mctx.setMVarUserName g (parentTag ++ newSuffix.appendIndexAfter idx)\n idx := idx + 1\n pure mctx", "start": [ 446, 1 ], "end": [ 466, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.getNameOfIdent'", "code": "def getNameOfIdent' (id : Syntax) : Name :=\n if id.isIdent then id.getId else `_", "start": [ 469, 1 ], "end": [ 470, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Tactic.withCaseRef", "code": "def withCaseRef [Monad m] [MonadRef m] (arrow body : Syntax) (x : m Ξ±) : m Ξ± :=\n withRef (mkNullNode #[arrow, body]) x", "start": [ 472, 1 ], "end": [ 477, 40 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Elab/Quotation/Util.lean
[ ".lake/packages/lean4/src/lean/Lean/Elab/Term.lean" ]
[ { "full_name": "Lean.Elab.Term.Quotation.getAntiquotationIds", "code": "def getAntiquotationIds (stx : Syntax) : TermElabM (Array Ident) := do\n let mut ids := #[]\n for stx in stx.topDown (firstChoiceOnly := true) do\n if (isAntiquot stx || isTokenAntiquot stx) && !isEscapedAntiquot stx then\n let anti := getAntiquotTerm stx\n if anti.isIdent then ids := ids.push ⟨anti⟩\n else if anti.isOfKind ``Parser.Term.hole then pure ()\n else throwErrorAt stx \"complex antiquotation not allowed here\"\n return ids", "start": [ 17, 1 ], "end": [ 25, 13 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.Quotation.getPatternVars", "code": "partial def getPatternVars (stx : Syntax) : TermElabM (Array Syntax) :=\n if stx.isQuot then\n getAntiquotationIds stx\n else match stx with\n | `(_) => return #[]\n | `($id:ident) => return #[id]\n | `($id:ident@$e) => return (← getPatternVars e).push id\n | _ => throwErrorAt stx \"unsupported pattern in syntax match{indentD stx}\"", "start": [ 27, 1 ], "end": [ 35, 93 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.Quotation.getPatternsVars", "code": "def getPatternsVars (pats : Array Syntax) : TermElabM (Array Syntax) :=\n pats.foldlM (fun vars pat => do return vars ++ (← getPatternVars pat)) #[]", "start": [ 37, 1 ], "end": [ 38, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Elab.Term.Quotation.getAntiquotKindSpec?", "code": "def getAntiquotKindSpec? (antiquot : Syntax) : Option Syntax :=\n let name := antiquot[3][1]\n if name.isMissing then none else some name", "start": [ 40, 1 ], "end": [ 46, 45 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Data/Lsp/Utf16.lean
[ ".lake/packages/lean4/src/lean/Lean/Data/Lsp/Basic.lean", ".lake/packages/lean4/src/lean/Init/Data/Array.lean", ".lake/packages/lean4/src/lean/Lean/DeclarationRange.lean", ".lake/packages/lean4/src/lean/Lean/Data/Position.lean", ".lake/packages/lean4/src/lean/Init/Data/String.lean" ]
[ { "full_name": "Char.utf16Size", "code": "def utf16Size (c : Char) : UInt32 :=\n if c.val ≀ 0xFFFF then 1 else 2", "start": [ 19, 1 ], "end": [ 20, 34 ], "kind": "commanddeclaration" }, { "full_name": "String.csize16", "code": "private def csize16 (c : Char) : Nat :=\n c.utf16Size.toNat", "start": [ 26, 1 ], "end": [ 27, 20 ], "kind": "commanddeclaration" }, { "full_name": "String.utf16Length", "code": "def utf16Length (s : String) : Nat :=\n s.foldr (fun c acc => csize16 c + acc) 0", "start": [ 29, 1 ], "end": [ 30, 43 ], "kind": "commanddeclaration" }, { "full_name": "String.codepointPosToUtf16PosFromAux", "code": "private def codepointPosToUtf16PosFromAux (s : String) : Nat β†’ Pos β†’ Nat β†’ Nat\n | 0, _, utf16pos => utf16pos\n | cp+1, utf8pos, utf16pos => codepointPosToUtf16PosFromAux s cp (s.next utf8pos) (utf16pos + csize16 (s.get utf8pos))", "start": [ 32, 1 ], "end": [ 34, 120 ], "kind": "commanddeclaration" }, { "full_name": "String.codepointPosToUtf16PosFrom", "code": "def codepointPosToUtf16PosFrom (s : String) (n : Nat) (off : Pos) : Nat :=\n codepointPosToUtf16PosFromAux s n off 0", "start": [ 36, 1 ], "end": [ 40, 42 ], "kind": "commanddeclaration" }, { "full_name": "String.codepointPosToUtf16Pos", "code": "def codepointPosToUtf16Pos (s : String) (pos : Nat) : Nat :=\n codepointPosToUtf16PosFrom s pos 0", "start": [ 42, 1 ], "end": [ 43, 37 ], "kind": "commanddeclaration" }, { "full_name": "String.utf16PosToCodepointPosFromAux", "code": "private partial def utf16PosToCodepointPosFromAux (s : String) : Nat β†’ Pos β†’ Nat β†’ Nat\n | 0, _, cp => cp\n | utf16pos, utf8pos, cp => utf16PosToCodepointPosFromAux s (utf16pos - csize16 (s.get utf8pos)) (s.next utf8pos) (cp + 1)", "start": [ 45, 1 ], "end": [ 47, 124 ], "kind": "commanddeclaration" }, { "full_name": "String.utf16PosToCodepointPosFrom", "code": "def utf16PosToCodepointPosFrom (s : String) (utf16pos : Nat) (off : Pos) : Nat :=\n utf16PosToCodepointPosFromAux s utf16pos off 0", "start": [ 49, 1 ], "end": [ 52, 49 ], "kind": "commanddeclaration" }, { "full_name": "String.utf16PosToCodepointPos", "code": "def utf16PosToCodepointPos (s : String) (pos : Nat) : Nat :=\n utf16PosToCodepointPosFrom s pos 0", "start": [ 54, 1 ], "end": [ 55, 37 ], "kind": "commanddeclaration" }, { "full_name": "String.codepointPosToUtf8PosFrom", "code": "def codepointPosToUtf8PosFrom (s : String) : String.Pos β†’ Nat β†’ String.Pos\n | utf8pos, 0 => utf8pos\n | utf8pos, p+1 => codepointPosToUtf8PosFrom s (s.next utf8pos) p", "start": [ 57, 1 ], "end": [ 60, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FileMap.lineStartPos", "code": "private def lineStartPos (text : FileMap) (line : Nat) : String.Pos :=\n if h : line < text.positions.size then\n text.positions.get ⟨line, h⟩\n else if text.positions.isEmpty then\n 0\n else\n text.positions.back", "start": [ 67, 1 ], "end": [ 73, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FileMap.lspPosToUtf8Pos", "code": "def lspPosToUtf8Pos (text : FileMap) (pos : Lsp.Position) : String.Pos :=\n let lineStartPos := lineStartPos text pos.line\n let chr := text.source.utf16PosToCodepointPosFrom pos.character lineStartPos\n text.source.codepointPosToUtf8PosFrom lineStartPos chr", "start": [ 75, 1 ], "end": [ 80, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FileMap.leanPosToLspPos", "code": "def leanPosToLspPos (text : FileMap) : Lean.Position β†’ Lsp.Position\n | ⟨line, col⟩ =>\n ⟨line - 1, text.source.codepointPosToUtf16PosFrom col (lineStartPos text (line - 1))⟩", "start": [ 82, 1 ], "end": [ 84, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FileMap.utf8PosToLspPos", "code": "def utf8PosToLspPos (text : FileMap) (pos : String.Pos) : Lsp.Position :=\n text.leanPosToLspPos (text.toPosition pos)", "start": [ 86, 1 ], "end": [ 87, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.FileMap.utf8RangeToLspRange", "code": "def utf8RangeToLspRange (text : FileMap) (range : String.Range) : Lsp.Range :=\n { start := text.utf8PosToLspPos range.start, Β«endΒ» := text.utf8PosToLspPos range.stop }", "start": [ 89, 1 ], "end": [ 91, 90 ], "kind": "commanddeclaration" }, { "full_name": "Lean.DeclarationRange.toLspRange", "code": "def Lean.DeclarationRange.toLspRange (r : Lean.DeclarationRange) : Lsp.Range := {\n start := ⟨r.pos.line - 1, r.charUtf16⟩\n Β«endΒ» := ⟨r.endPos.line - 1, r.endCharUtf16⟩\n}", "start": [ 96, 1 ], "end": [ 104, 2 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Compiler/Specialize.lean
[ ".lake/packages/lean4/src/lean/Lean/Attributes.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean" ]
[ { "full_name": "Lean.Compiler.SpecializeAttributeKind", "code": "inductive SpecializeAttributeKind where\n | specialize | nospecialize\n deriving Inhabited, BEq", "start": [ 12, 1 ], "end": [ 14, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.elabSpecArgs", "code": "private def elabSpecArgs (declName : Name) (args : Array Syntax) : MetaM (Array Nat) := do\n if args.isEmpty then return #[]\n let info ← getConstInfo declName\n Meta.forallTelescopeReducing info.type fun xs _ => do\n let argNames ← xs.mapM fun x => x.fvarId!.getUserName\n let mut result := #[]\n for arg in args do\n if let some idx := arg.isNatLit? then\n if idx == 0 then throwErrorAt arg \"invalid specialization argument index, index must be greater than 0\"\n let idx := idx - 1\n if idx >= argNames.size then\n throwErrorAt arg \"invalid argument index, `{declName}` has #{argNames.size} arguments\"\n if result.contains idx then throwErrorAt arg \"invalid specialization argument index, `{argNames[idx]!}` has already been specified as a specialization candidate\"\n result := result.push idx\n else\n let argName := arg.getId\n if let some idx := argNames.getIdx? argName then\n if result.contains idx then throwErrorAt arg \"invalid specialization argument name `{argName}`, it has already been specified as a specialization candidate\"\n result := result.push idx\n else\n throwErrorAt arg \"invalid specialization argument name `{argName}`, `{declName}` does have an argument with this name\"\n return result.qsort (Β·<Β·)", "start": [ 19, 1 ], "end": [ 40, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.getSpecializationArgs?", "code": "def getSpecializationArgs? (env : Environment) (declName : Name) : Option (Array Nat) :=\n specializeAttr.getParam? env declName", "start": [ 51, 1 ], "end": [ 52, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.hasSpecializeAttribute", "code": "def hasSpecializeAttribute (env : Environment) (declName : Name) : Bool :=\n getSpecializationArgs? env declName |>.isSome", "start": [ 54, 1 ], "end": [ 55, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.hasNospecializeAttribute", "code": "def hasNospecializeAttribute (env : Environment) (declName : Name) : Bool :=\n nospecializeAttr.hasTag env declName", "start": [ 57, 1 ], "end": [ 58, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.hasSpecializeAttributeOld", "code": "@[export lean_has_specialize_attribute]\npartial def hasSpecializeAttributeOld (env : Environment) (n : Name) : Bool :=\n match specializeAttr.getParam? env n with\n | some _ => true\n | none => if n.isInternal then hasSpecializeAttributeOld env n.getPrefix else false", "start": [ 62, 1 ], "end": [ 66, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.hasNospecializeAttributeOld", "code": "@[export lean_has_nospecialize_attribute]\npartial def hasNospecializeAttributeOld (env : Environment) (n : Name) : Bool :=\n nospecializeAttr.hasTag env n ||\n (n.isInternal && hasNospecializeAttributeOld env n.getPrefix)", "start": [ 68, 1 ], "end": [ 71, 64 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.SpecArgKind", "code": "inductive SpecArgKind where\n | fixed\n | fixedNeutral | fixedHO | fixedInst | other\n deriving Inhabited", "start": [ 73, 1 ], "end": [ 79, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.SpecInfo", "code": "structure SpecInfo where\n mutualDecls : List Name\n argKinds : List SpecArgKind\n deriving Inhabited", "start": [ 81, 1 ], "end": [ 84, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.SpecState", "code": "structure SpecState where\n specInfo : SMap Name SpecInfo := {}\n cache : SMap Expr Name := {}\n deriving Inhabited", "start": [ 86, 1 ], "end": [ 89, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.SpecEntry", "code": "inductive SpecEntry where\n | info (name : Name) (info : SpecInfo)\n | cache (key : Expr) (fn : Name)\n deriving Inhabited", "start": [ 91, 1 ], "end": [ 94, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.SpecState.addEntry", "code": "def addEntry (s : SpecState) (e : SpecEntry) : SpecState :=\n match e with\n | SpecEntry.info name info => { s with specInfo := s.specInfo.insert name info }\n | SpecEntry.cache key fn => { s with cache := s.cache.insert key fn }", "start": [ 98, 1 ], "end": [ 101, 77 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.SpecState.switch", "code": "def switch : SpecState β†’ SpecState\n | ⟨m₁, mβ‚‚βŸ© => ⟨m₁.switch, mβ‚‚.switch⟩", "start": [ 103, 1 ], "end": [ 104, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.addSpecializationInfo", "code": "@[export lean_add_specialization_info]\ndef addSpecializationInfo (env : Environment) (fn : Name) (info : SpecInfo) : Environment :=\n specExtension.addEntry env (SpecEntry.info fn info)", "start": [ 114, 1 ], "end": [ 116, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.getSpecializationInfo", "code": "@[export lean_get_specialization_info]\ndef getSpecializationInfo (env : Environment) (fn : Name) : Option SpecInfo :=\n (specExtension.getState env).specInfo.find? fn", "start": [ 118, 1 ], "end": [ 120, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.cacheSpecialization", "code": "@[export lean_cache_specialization]\ndef cacheSpecialization (env : Environment) (e : Expr) (fn : Name) : Environment :=\n specExtension.addEntry env (SpecEntry.cache e fn)", "start": [ 122, 1 ], "end": [ 124, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.getCachedSpecialization", "code": "@[export lean_get_cached_specialization]\ndef getCachedSpecialization (env : Environment) (e : Expr) : Option Name :=\n (specExtension.getState env).cache.find? e", "start": [ 126, 1 ], "end": [ 128, 45 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Compiler/LCNF/Types.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/InferType.lean" ]
[ { "full_name": "Lean.Compiler.LCNF.erasedExpr", "code": "def erasedExpr := mkConst ``lcErased", "start": [ 15, 1 ], "end": [ 15, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Expr.isErased", "code": "def _root_.Lean.Expr.isErased (e : Expr) :=\n e.isAppOf ``lcErased", "start": [ 17, 1 ], "end": [ 18, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isPropFormerTypeQuick", "code": "def isPropFormerTypeQuick : Expr β†’ Bool\n | .forallE _ _ b _ => isPropFormerTypeQuick b\n | .sort .zero => true\n | _ => false", "start": [ 20, 1 ], "end": [ 23, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isPropFormerType", "code": "partial def isPropFormerType (type : Expr) : MetaM Bool := do\n match isPropFormerTypeQuick type with\n | true => return true\n | false => go type #[]\nwhere\n go (type : Expr) (xs : Array Expr) : MetaM Bool := do\n match type with\n | .sort .zero => return true\n | .forallE n d b c => Meta.withLocalDecl n c (d.instantiateRev xs) fun x => go b (xs.push x)\n | _ =>\n let type ← Meta.whnfD (type.instantiateRev xs)\n match type with\n | .sort .zero => return true\n | .forallE .. => go type #[]\n | _ => return false", "start": [ 25, 1 ], "end": [ 42, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isPropFormer", "code": "def isPropFormer (e : Expr) : MetaM Bool := do\n isPropFormerType (← Meta.inferType e)", "start": [ 44, 1 ], "end": [ 48, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.toLCNFType", "code": "partial def toLCNFType (type : Expr) : MetaM Expr := do\n if (← isProp type) then\n return erasedExpr\n let type ← whnfEta type\n match type with\n | .sort u => return .sort u\n | .const .. => visitApp type #[]\n | .lam n d b bi =>\n withLocalDecl n bi d fun x => do\n let d ← toLCNFType d\n let b ← toLCNFType (b.instantiate1 x)\n if b.isErased then\n return b\n else\n return Expr.lam n d (b.abstract #[x]) bi\n | .forallE .. => visitForall type #[]\n | .app .. => type.withApp visitApp\n | .fvar .. => visitApp type #[]\n | _ => return erasedExpr\nwhere\n whnfEta (type : Expr) : MetaM Expr := do\n let type ← whnf type\n let type' := type.eta\n if type' != type then\n whnfEta type'\n else\n return type\n\n visitForall (e : Expr) (xs : Array Expr) : MetaM Expr := do\n match e with\n | .forallE n d b bi =>\n let d := d.instantiateRev xs\n withLocalDecl n bi d fun x => do\n let d := (← toLCNFType d).abstract xs\n return .forallE n d (← visitForall b (xs.push x)) bi\n | _ =>\n let e ← toLCNFType (e.instantiateRev xs)\n return e.abstract xs\n\n visitApp (f : Expr) (args : Array Expr) := do\n let fNew ← match f with\n | .const declName us =>\n let .inductInfo _ ← getConstInfo declName | return erasedExpr\n pure <| .const declName us\n | .fvar .. => pure f\n | _ => return erasedExpr\n let mut result := fNew\n for arg in args do\n if (← isProp arg) then\n result := mkApp result erasedExpr\n else if (← isPropFormer arg) then\n result := mkApp result erasedExpr\n else if (← isTypeFormer arg) then\n result := mkApp result (← toLCNFType arg)\n else\n result := mkApp result erasedExpr\n return result", "start": [ 113, 1 ], "end": [ 172, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.joinTypes", "code": "partial def joinTypes (a b : Expr) : Expr :=\n joinTypes? a b |>.getD erasedExpr", "start": [ 176, 1 ], "end": [ 177, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.joinTypes?", "code": "partial def joinTypes? (a b : Expr) : Option Expr := do\n if a.isErased || b.isErased then\n return erasedExpr else if a == b then\n return a\n else\n let a' := a.headBeta\n let b' := b.headBeta\n if a != a' || b != b' then\n joinTypes? a' b'\n else\n match a, b with\n | .mdata _ a, b => joinTypes? a b\n | a, .mdata _ b => joinTypes? a b\n | .app f a, .app g b =>\n (do return .app (← joinTypes? f g) (← joinTypes? a b))\n <|>\n return erasedExpr\n | .forallE n d₁ b₁ _, .forallE _ dβ‚‚ bβ‚‚ _ =>\n (do return .forallE n (← joinTypes? d₁ dβ‚‚) (joinTypes b₁ bβ‚‚) .default)\n <|>\n return erasedExpr\n | .lam n d₁ b₁ _, .lam _ dβ‚‚ bβ‚‚ _ =>\n (do return .lam n (← joinTypes? d₁ dβ‚‚) (joinTypes b₁ bβ‚‚) .default)\n <|>\n return erasedExpr\n | _, _ => return erasedExpr", "start": [ 179, 1 ], "end": [ 205, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isTypeFormerType", "code": "partial def isTypeFormerType (type : Expr) : Bool :=\n match type.headBeta with\n | .sort .. => true\n | .forallE _ _ b _ => isTypeFormerType b\n | _ => false", "start": [ 209, 1 ], "end": [ 219, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.instantiateForall", "code": "def instantiateForall (type : Expr) (ps : Array Expr) : CoreM Expr :=\n go 0 type\nwhere\n go (i : Nat) (type : Expr) : CoreM Expr :=\n if h : i < ps.size then\n if let .forallE _ _ b _ := type.headBeta then\n go (i+1) (b.instantiate1 ps[i])\n else\n throwError \"invalid instantiateForall, too many parameters\"\n else\n return type\n termination_by ps.size - i", "start": [ 221, 1 ], "end": [ 238, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isPredicateType", "code": "partial def isPredicateType (type : Expr) : Bool :=\n match type.headBeta with\n | .sort .zero => true\n | .forallE _ _ b _ => isPredicateType b\n | _ => false", "start": [ 240, 1 ], "end": [ 248, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.maybeTypeFormerType", "code": "partial def maybeTypeFormerType (type : Expr) : Bool :=\n match type.headBeta with\n | .sort .. => true\n | .forallE _ _ b _ => maybeTypeFormerType b\n | _ => type.isErased", "start": [ 250, 1 ], "end": [ 260, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isClass?", "code": "def isClass? (type : Expr) : CoreM (Option Name) := do\n let .const declName _ := type.getAppFn | return none\n if isClass (← getEnv) declName then\n return declName\n else\n return none", "start": [ 262, 1 ], "end": [ 270, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isArrowClass?", "code": "partial def isArrowClass? (type : Expr) : CoreM (Option Name) := do\n match type.headBeta with\n | .forallE _ _ b _ => isArrowClass? b\n | _ => isClass? type", "start": [ 272, 1 ], "end": [ 279, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.getArrowArity", "code": "partial def getArrowArity (e : Expr) :=\n match e.headBeta with\n | .forallE _ _ b _ => getArrowArity b + 1\n | _ => 0", "start": [ 281, 1 ], "end": [ 284, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Compiler.LCNF.isInductiveWithNoCtors", "code": "def isInductiveWithNoCtors (type : Expr) : CoreM Bool := do\n let .const declName _ := type.getAppFn | return false\n let some (.inductInfo info) := (← getEnv).find? declName | return false\n return info.numCtors == 0", "start": [ 286, 1 ], "end": [ 290, 28 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/KExprMap.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/HeadIndex.lean" ]
[ { "full_name": "Lean.Meta.KExprMap", "code": "structure KExprMap (Ξ± : Type) where\n map : PHashMap HeadIndex (AssocList Expr Ξ±) := {}\n deriving Inhabited", "start": [ 12, 1 ], "end": [ 20, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.KExprMap.find?", "code": "def KExprMap.find? (m : KExprMap Ξ±) (e : Expr) : MetaM (Option Ξ±) := do\n match m.map.find? e.toHeadIndex with\n | none => return none\n | some ps =>\n for ⟨e', a⟩ in ps do\n if (← isDefEq e e') then\n return some a\n return none", "start": [ 22, 1 ], "end": [ 30, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.updateList", "code": "private def updateList (ps : AssocList Expr Ξ±) (e : Expr) (v : Ξ±) : MetaM (AssocList Expr Ξ±) := do\n match ps with\n | AssocList.nil => return AssocList.cons e v ps\n | AssocList.cons e' v' ps =>\n if (← isDefEq e e') then\n return AssocList.cons e v ps\n else\n return AssocList.cons e' v' (← updateList ps e v)", "start": [ 32, 1 ], "end": [ 39, 56 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.KExprMap.insert", "code": "def KExprMap.insert (m : KExprMap Ξ±) (e : Expr) (v : Ξ±) : MetaM (KExprMap Ξ±) :=\n let k := e.toHeadIndex\n match m.map.find? k with\n | none => return { map := m.map.insert k (AssocList.cons e v AssocList.nil) }\n | some ps => return { map := m.map.insert k (← updateList ps e v) }", "start": [ 41, 1 ], "end": [ 46, 70 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Simp/SimpCongrTheorems.lean
[ ".lake/packages/lean4/src/lean/Lean/Util/CollectMVars.lean", ".lake/packages/lean4/src/lean/Lean/ScopedEnvExtension.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Basic.lean", ".lake/packages/lean4/src/lean/Lean/Util/Recognizers.lean" ]
[ { "full_name": "Lean.Meta.SimpCongrTheorem", "code": "structure SimpCongrTheorem where\n theoremName : Name\n funName : Name\n hypothesesPos : Array Nat\n priority : Nat\nderiving Inhabited, Repr", "start": [ 14, 1 ], "end": [ 25, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpCongrTheorems", "code": "structure SimpCongrTheorems where\n lemmas : SMap Name (List SimpCongrTheorem) := {}\n deriving Inhabited, Repr", "start": [ 27, 1 ], "end": [ 29, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpCongrTheorems.get", "code": "def SimpCongrTheorems.get (d : SimpCongrTheorems) (declName : Name) : List SimpCongrTheorem :=\n match d.lemmas.find? declName with\n | none => []\n | some cs => cs", "start": [ 31, 1 ], "end": [ 34, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addSimpCongrTheoremEntry", "code": "def addSimpCongrTheoremEntry (d : SimpCongrTheorems) (e : SimpCongrTheorem) : SimpCongrTheorems :=\n { d with lemmas :=\n match d.lemmas.find? e.funName with\n | none => d.lemmas.insert e.funName [e]\n | some es => d.lemmas.insert e.funName <| insert es }\nwhere\n insert : List SimpCongrTheorem β†’ List SimpCongrTheorem\n | [] => [e]\n | e'::es => if e.priority β‰₯ e'.priority then e::e'::es else e' :: insert es", "start": [ 36, 1 ], "end": [ 44, 80 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSimpCongrTheorem", "code": "def mkSimpCongrTheorem (declName : Name) (prio : Nat) : MetaM SimpCongrTheorem := withReducible do\n let c ← mkConstWithLevelParams declName\n let (xs, bis, type) ← forallMetaTelescopeReducing (← inferType c)\n match type.eqOrIff? with\n | none => throwError \"invalid 'congr' theorem, equality expected{indentExpr type}\"\n | some (lhs, rhs) =>\n lhs.withApp fun lhsFn lhsArgs => rhs.withApp fun rhsFn rhsArgs => do\n unless lhsFn.isConst && rhsFn.isConst && lhsFn.constName! == rhsFn.constName! && lhsArgs.size == rhsArgs.size do\n throwError \"invalid 'congr' theorem, equality left/right-hand sides must be applications of the same function{indentExpr type}\"\n let mut foundMVars : MVarIdSet := {}\n for lhsArg in lhsArgs do\n for mvarId in (lhsArg.collectMVars {}).result do\n foundMVars := foundMVars.insert mvarId\n let mut i := 0\n let mut hypothesesPos := #[]\n for x in xs, bi in bis do\n if bi.isExplicit && !foundMVars.contains x.mvarId! then\n let rhsFn? ← forallTelescopeReducing (← inferType x) fun ys xType => do\n match xType.eqOrIff? with\n | none => pure none | some (xLhs, xRhs) =>\n let mut j := 0\n for y in ys do\n let yType ← inferType y\n unless onlyMVarsAt yType foundMVars do\n throwError \"invalid 'congr' theorem, argument #{j+1} of parameter #{i+1} contains unresolved parameter{indentExpr yType}\"\n j := j + 1\n unless onlyMVarsAt xLhs foundMVars do\n throwError \"invalid 'congr' theorem, parameter #{i+1} is not a valid hypothesis, the left-hand-side contains unresolved parameters{indentExpr xLhs}\"\n let xRhsFn := xRhs.getAppFn\n unless xRhsFn.isMVar do\n throwError \"invalid 'congr' theorem, parameter #{i+1} is not a valid hypothesis, the right-hand-side head is not a metavariable{indentExpr xRhs}\"\n unless !foundMVars.contains xRhsFn.mvarId! do\n throwError \"invalid 'congr' theorem, parameter #{i+1} is not a valid hypothesis, the right-hand-side head was already resolved{indentExpr xRhs}\"\n for arg in xRhs.getAppArgs do\n unless arg.isFVar do\n throwError \"invalid 'congr' theorem, parameter #{i+1} is not a valid hypothesis, the right-hand-side argument is not local variable{indentExpr xRhs}\"\n pure (some xRhsFn)\n match rhsFn? with\n | none => pure ()\n | some rhsFn =>\n foundMVars := foundMVars.insert x.mvarId! |>.insert rhsFn.mvarId!\n hypothesesPos := hypothesesPos.push i\n i := i + 1\n return {\n theoremName := declName\n funName := lhsFn.constName!\n hypothesesPos := hypothesesPos\n priority := prio\n }\nwhere\n \n onlyMVarsAt (t : Expr) (mvarSet : MVarIdSet) : Bool :=\n Option.isNone <| t.find? fun e => e.isMVar && !mvarSet.contains e.mvarId!", "start": [ 53, 1 ], "end": [ 106, 78 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addSimpCongrTheorem", "code": "def addSimpCongrTheorem (declName : Name) (attrKind : AttributeKind) (prio : Nat) : MetaM Unit := do\n let lemma ← mkSimpCongrTheorem declName prio\n congrExtension.add lemma attrKind", "start": [ 108, 1 ], "end": [ 110, 36 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getSimpCongrTheorems", "code": "def getSimpCongrTheorems : CoreM SimpCongrTheorems :=\n return congrExtension.getState (← getEnv)", "start": [ 121, 1 ], "end": [ 122, 44 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/CongrTheorems.lean
[ ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean", ".lake/packages/lean4/src/lean/Lean/Class.lean" ]
[ { "full_name": "Lean.Meta.CongrArgKind", "code": "inductive CongrArgKind where\n \n | fixed\n \n | fixedNoParam\n \n | eq\n \n | cast\n \n | heq\n \n | subsingletonInst\n deriving Inhabited, Repr", "start": [ 12, 1 ], "end": [ 35, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.CongrTheorem", "code": "structure CongrTheorem where\n type : Expr\n proof : Expr\n argKinds : Array CongrArgKind", "start": [ 37, 1 ], "end": [ 40, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addPrimeToFVarUserNames", "code": "private def addPrimeToFVarUserNames (ys : Array Expr) (lctx : LocalContext) : LocalContext := Id.run do\n let mut lctx := lctx\n for y in ys do\n let decl := lctx.getFVar! y\n lctx := lctx.setUserName decl.fvarId (decl.userName.appendAfter \"'\")\n return lctx", "start": [ 42, 1 ], "end": [ 47, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.setBinderInfosD", "code": "private def setBinderInfosD (ys : Array Expr) (lctx : LocalContext) : LocalContext := Id.run do\n let mut lctx := lctx\n for y in ys do\n let decl := lctx.getFVar! y\n lctx := lctx.setBinderInfo decl.fvarId BinderInfo.default\n return lctx", "start": [ 49, 1 ], "end": [ 54, 14 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHCongrWithArity", "code": "partial def mkHCongrWithArity (f : Expr) (numArgs : Nat) : MetaM CongrTheorem := do\n let fType ← inferType f\n forallBoundedTelescope fType numArgs (cleanupAnnotations := true) fun xs _ =>\n forallBoundedTelescope fType numArgs (cleanupAnnotations := true) fun ys _ => do\n if xs.size != numArgs then\n throwError \"failed to generate hcongr theorem, insufficient number of arguments\"\n else\n let lctx := addPrimeToFVarUserNames ys (← getLCtx) |> setBinderInfosD ys |> setBinderInfosD xs\n withLCtx lctx (← getLocalInstances) do\n withNewEqs xs ys fun eqs argKinds => do\n let mut hs := #[]\n for x in xs, y in ys, eq in eqs do\n hs := hs.push x |>.push y |>.push eq\n let lhs := mkAppN f xs\n let rhs := mkAppN f ys\n let congrType ← mkForallFVars hs (← mkHEq lhs rhs)\n return {\n type := congrType\n proof := (← mkProof congrType)\n argKinds\n }\nwhere\n withNewEqs {Ξ±} (xs ys : Array Expr) (k : Array Expr β†’ Array CongrArgKind β†’ MetaM Ξ±) : MetaM Ξ± :=\n let rec loop (i : Nat) (eqs : Array Expr) (kinds : Array CongrArgKind) := do\n if i < xs.size then\n let x := xs[i]!\n let y := ys[i]!\n let xType := (← inferType x).cleanupAnnotations\n let yType := (← inferType y).cleanupAnnotations\n if xType == yType then\n withLocalDeclD ((`e).appendIndexAfter (i+1)) (← mkEq x y) fun h =>\n loop (i+1) (eqs.push h) (kinds.push CongrArgKind.eq)\n else\n withLocalDeclD ((`e).appendIndexAfter (i+1)) (← mkHEq x y) fun h =>\n loop (i+1) (eqs.push h) (kinds.push CongrArgKind.heq)\n else\n k eqs kinds\n loop 0 #[] #[]\n\n mkProof (type : Expr) : MetaM Expr := do\n if let some (_, lhs, _) := type.eq? then\n mkEqRefl lhs\n else if let some (_, lhs, _, _) := type.heq? then\n mkHEqRefl lhs\n else\n forallBoundedTelescope type (some 1) (cleanupAnnotations := true) fun a type =>\n let a := a[0]!\n forallBoundedTelescope type (some 1) (cleanupAnnotations := true) fun b motive =>\n let b := b[0]!\n let type := type.bindingBody!.instantiate1 a\n withLocalDeclD motive.bindingName! motive.bindingDomain! fun eqPr => do\n let type := type.bindingBody!\n let motive := motive.bindingBody!\n let minor ← mkProof type\n let mut major := eqPr\n if (← whnf (← inferType eqPr)).isHEq then\n major ← mkEqOfHEq major\n let motive ← mkLambdaFVars #[b] motive\n mkLambdaFVars #[a, b, eqPr] (← mkEqNDRec motive minor major)", "start": [ 56, 1 ], "end": [ 114, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkHCongr", "code": "def mkHCongr (f : Expr) : MetaM CongrTheorem := do\n mkHCongrWithArity f (← getFunInfo f).getArity", "start": [ 116, 1 ], "end": [ 117, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.fixKindsForDependencies", "code": "private def fixKindsForDependencies (info : FunInfo) (kinds : Array CongrArgKind) : Array CongrArgKind := Id.run do\n let mut kinds := kinds\n for i in [:info.paramInfo.size] do\n for j in [i+1:info.paramInfo.size] do\n if info.paramInfo[j]!.backDeps.contains i then\n if kinds[j]! matches CongrArgKind.eq || kinds[j]! matches CongrArgKind.fixed then\n kinds := kinds.set! i CongrArgKind.fixed\n break\n return kinds", "start": [ 119, 1 ], "end": [ 131, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkCast", "code": "private partial def mkCast (e : Expr) (type : Expr) (deps : Array Nat) (eqs : Array (Option Expr)) : MetaM Expr := do\n let rec go (i : Nat) (type : Expr) : MetaM Expr := do\n if i < deps.size then\n match eqs[deps[i]!]! with\n | none => go (i+1) type\n | some major =>\n let some (_, lhs, rhs) := (← inferType major).eq? | unreachable!\n if (← dependsOn type major.fvarId!) then\n let motive ← mkLambdaFVars #[rhs, major] type\n let typeNew := type.replaceFVar rhs lhs |>.replaceFVar major (← mkEqRefl lhs)\n let minor ← go (i+1) typeNew\n mkEqRec motive minor major\n else\n let motive ← mkLambdaFVars #[rhs] type\n let typeNew := type.replaceFVar rhs lhs\n let minor ← go (i+1) typeNew\n mkEqNDRec motive minor major\n else\n return e\n go 0 type", "start": [ 133, 1 ], "end": [ 156, 12 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.hasCastLike", "code": "private def hasCastLike (kinds : Array CongrArgKind) : Bool :=\n kinds.any fun kind => kind matches CongrArgKind.cast || kind matches CongrArgKind.subsingletonInst", "start": [ 158, 1 ], "end": [ 159, 101 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.withNext", "code": "private def withNext (type : Expr) (k : Expr β†’ Expr β†’ MetaM Ξ±) : MetaM Ξ± := do\n forallBoundedTelescope type (some 1) (cleanupAnnotations := true) fun xs type => k xs[0]! type", "start": [ 161, 1 ], "end": [ 162, 97 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.shouldUseSubsingletonInst", "code": "private def shouldUseSubsingletonInst (info : FunInfo) (kinds : Array CongrArgKind) (i : Nat) : Bool := Id.run do\n if info.paramInfo[i]!.isDecInst then\n for j in info.paramInfo[i]!.backDeps do\n if kinds[j]! matches CongrArgKind.eq then\n return true\n return false", "start": [ 164, 1 ], "end": [ 172, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getClassSubobjectMask?", "code": "private def getClassSubobjectMask? (f : Expr) : MetaM (Option (Array Bool)) := do\n let .const declName _ := f | return none\n let .ctorInfo val ← getConstInfo declName | return none\n unless isClass (← getEnv) val.induct do return none\n forallTelescopeReducing val.type (cleanupAnnotations := true) fun xs _ => do\n let env ← getEnv\n let mut mask := #[]\n for i in [:xs.size] do\n if i < val.numParams then\n mask := mask.push false\n else\n let localDecl ← xs[i]!.fvarId!.getDecl\n mask := mask.push (isSubobjectField? env val.induct localDecl.userName).isSome\n return some mask", "start": [ 174, 1 ], "end": [ 194, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getCongrSimpKinds", "code": "def getCongrSimpKinds (f : Expr) (info : FunInfo) : MetaM (Array CongrArgKind) := do\n \n let mut result := #[]\n let mask? ← getClassSubobjectMask? f\n for i in [:info.paramInfo.size] do\n if info.resultDeps.contains i then\n result := result.push .fixed\n else if info.paramInfo[i]!.isProp then\n result := result.push .cast\n else if info.paramInfo[i]!.isInstImplicit then\n if let some mask := mask? then\n if h : i < mask.size then\n if mask[i] then\n result := result.push .eq\n continue\n if shouldUseSubsingletonInst info result i then\n result := result.push .subsingletonInst\n else\n result := result.push .fixed\n else\n result := result.push .eq\n return fixKindsForDependencies info result", "start": [ 196, 1 ], "end": [ 232, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkCongrSimpCore?", "code": "partial def mkCongrSimpCore? (f : Expr) (info : FunInfo) (kinds : Array CongrArgKind) (subsingletonInstImplicitRhs : Bool := true) : MetaM (Option CongrTheorem) := do\n if let some result ← mk? f info kinds then\n return some result\n else if hasCastLike kinds then\n let kinds := kinds.map fun kind =>\n if kind matches CongrArgKind.cast || kind matches CongrArgKind.subsingletonInst then CongrArgKind.fixed else kind\n mk? f info kinds\n else\n return none\nwhere\n \n mk? (f : Expr) (info : FunInfo) (kinds : Array CongrArgKind) : MetaM (Option CongrTheorem) := do\n try\n let fType ← inferType f\n forallBoundedTelescope fType kinds.size (cleanupAnnotations := true) fun lhss _ => do\n if lhss.size != kinds.size then return none\n let rec go (i : Nat) (rhss : Array Expr) (eqs : Array (Option Expr)) (hyps : Array Expr) : MetaM CongrTheorem := do\n if i == kinds.size then\n let lhs := mkAppN f lhss\n let rhs := mkAppN f rhss\n let type ← mkForallFVars hyps (← mkEq lhs rhs)\n let proof ← mkProof type kinds\n return { type, proof, argKinds := kinds }\n else\n let hyps := hyps.push lhss[i]!\n match kinds[i]! with\n | .heq | .fixedNoParam => unreachable!\n | .eq =>\n let localDecl ← lhss[i]!.fvarId!.getDecl\n withLocalDecl localDecl.userName localDecl.binderInfo localDecl.type fun rhs => do\n withLocalDeclD (localDecl.userName.appendBefore \"e_\") (← mkEq lhss[i]! rhs) fun eq => do\n go (i+1) (rhss.push rhs) (eqs.push eq) (hyps.push rhs |>.push eq)\n | .fixed => go (i+1) (rhss.push lhss[i]!) (eqs.push none) hyps\n | .cast =>\n let rhsType := (← inferType lhss[i]!).replaceFVars (lhss[:rhss.size]) rhss\n let rhs ← mkCast lhss[i]! rhsType info.paramInfo[i]!.backDeps eqs\n go (i+1) (rhss.push rhs) (eqs.push none) hyps\n | .subsingletonInst =>\n withNewBinderInfos #[(lhss[i]!.fvarId!, .implicit)] do\n let rhsType := (← inferType lhss[i]!).replaceFVars (lhss[:rhss.size]) rhss\n let rhsBi := if subsingletonInstImplicitRhs then .instImplicit else .implicit\n withLocalDecl (← lhss[i]!.fvarId!.getDecl).userName rhsBi rhsType fun rhs =>\n go (i+1) (rhss.push rhs) (eqs.push none) (hyps.push rhs)\n return some (← go 0 #[] #[] #[])\n catch _ =>\n return none\n\n mkProof (type : Expr) (kinds : Array CongrArgKind) : MetaM Expr := do\n let rec go (i : Nat) (type : Expr) : MetaM Expr := do\n if i == kinds.size then\n let some (_, lhs, _) := type.eq? | unreachable!\n mkEqRefl lhs\n else\n withNext type fun lhs type => do\n match kinds[i]! with\n | .heq | .fixedNoParam => unreachable!\n | .fixed => mkLambdaFVars #[lhs] (← go (i+1) type)\n | .cast => mkLambdaFVars #[lhs] (← go (i+1) type)\n | .eq =>\n let typeSub := type.bindingBody!.bindingBody!.instantiate #[(← mkEqRefl lhs), lhs]\n withNext type fun rhs type =>\n withNext type fun heq type => do\n let motive ← mkLambdaFVars #[rhs, heq] type\n let proofSub ← go (i+1) typeSub\n mkLambdaFVars #[lhs, rhs, heq] (← mkEqRec motive proofSub heq)\n | .subsingletonInst =>\n let typeSub := type.bindingBody!.instantiate #[lhs]\n withNext type fun rhs type => do\n let motive ← mkLambdaFVars #[rhs] type\n let proofSub ← go (i+1) typeSub\n let heq ← mkAppM ``Subsingleton.elim #[lhs, rhs]\n mkLambdaFVars #[lhs, rhs] (← mkEqNDRec motive proofSub heq)\n go 0 type", "start": [ 234, 1 ], "end": [ 317, 15 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkCongrSimp?", "code": "def mkCongrSimp? (f : Expr) (subsingletonInstImplicitRhs : Bool := true) : MetaM (Option CongrTheorem) := do\n let f := (← instantiateMVars f).cleanupAnnotations\n let info ← getFunInfo f\n mkCongrSimpCore? f info (← getCongrSimpKinds f info) (subsingletonInstImplicitRhs := subsingletonInstImplicitRhs)", "start": [ 319, 1 ], "end": [ 330, 116 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Simp/SimpTheorems.lean
[ ".lake/packages/lean4/src/lean/Lean/Util/Recognizers.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Eqns.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean", ".lake/packages/lean4/src/lean/Lean/PrettyPrinter.lean", ".lake/packages/lean4/src/lean/Lean/ScopedEnvExtension.lean", ".lake/packages/lean4/src/lean/Lean/Meta/DiscrTree.lean", ".lake/packages/lean4/src/lean/Lean/DocString.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/AuxLemma.lean" ]
[ { "full_name": "Lean.Meta.Origin", "code": "inductive Origin where\n \n | decl (declName : Name) (post := true) (inv := false)\n \n | fvar (fvarId : FVarId)\n \n | stx (id : Name) (ref : Syntax)\n \n | other (name : Name)\n deriving Inhabited, Repr", "start": [ 17, 1 ], "end": [ 43, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Origin.key", "code": "def Origin.key : Origin β†’ Name\n | .decl declName _ _ => declName\n | .fvar fvarId => fvarId.name\n | .stx id _ => id\n | .other name => name", "start": [ 45, 1 ], "end": [ 50, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.Origin.lt", "code": "def Origin.lt : Origin β†’ Origin β†’ Bool\n | .decl declName₁ _ inv₁, .decl declNameβ‚‚ _ invβ‚‚ =>\n Name.lt declName₁ declNameβ‚‚ || (declName₁ == declNameβ‚‚ && !inv₁ && invβ‚‚)\n | .decl .., _ => false\n | _, .decl .. => true\n | a, b => Name.lt a.key b.key", "start": [ 67, 1 ], "end": [ 72, 32 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremKey", "code": "abbrev SimpTheoremKey := DiscrTree.Key", "start": [ 91, 1 ], "end": [ 91, 39 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorem", "code": "structure SimpTheorem where\n keys : Array SimpTheoremKey := #[]\n \n levelParams : Array Name := #[]\n proof : Expr\n priority : Nat := eval_prio default\n post : Bool := true\n \n perm : Bool := false\n \n origin : Origin\n \n rfl : Bool\n deriving Inhabited", "start": [ 93, 1 ], "end": [ 122, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isRflProofCore", "code": "partial def isRflProofCore (type : Expr) (proof : Expr) : CoreM Bool := do\n match type with\n | .forallE _ _ type _ =>\n if let .lam _ _ proof _ := proof then\n isRflProofCore type proof\n else\n return false\n | _ =>\n if type.isAppOfArity ``Eq 3 then\n if proof.isAppOfArity ``Eq.refl 2 || proof.isAppOfArity ``rfl 2 then\n return true\n else if proof.isAppOfArity ``Eq.symm 4 then\n isRflProofCore type proof.appArg! else if proof.getAppFn.isConst then\n isRflTheorem proof.getAppFn.constName!\n else\n return false\n else\n return false", "start": [ 125, 3 ], "end": [ 146, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isRflTheorem", "code": "partial def isRflTheorem (declName : Name) : CoreM Bool := do\n let .thmInfo info ← getConstInfo declName | return false\n isRflProofCore info.type info.value", "start": [ 148, 3 ], "end": [ 150, 40 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isRflProof", "code": "def isRflProof (proof : Expr) : MetaM Bool := do\n if let .const declName .. := proof then\n isRflTheorem declName\n else\n isRflProofCore (← inferType proof) proof", "start": [ 153, 1 ], "end": [ 157, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.ppOrigin", "code": "def ppOrigin [Monad m] [MonadEnv m] [MonadError m] : Origin β†’ m MessageData\n | .decl n post inv => do\n let r := MessageData.ofConst (← mkConstWithLevelParams n)\n match post, inv with\n | true, true => return m!\"← {r}\"\n | true, false => return r\n | false, true => return m!\"↓ ← {r}\"\n | false, false => return m!\"↓ {r}\"\n | .fvar n => return mkFVar n\n | .stx _ ref => return ref\n | .other n => return n", "start": [ 166, 1 ], "end": [ 176, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.ppSimpTheorem", "code": "def ppSimpTheorem [Monad m] [MonadEnv m] [MonadError m] (s : SimpTheorem) : m MessageData := do\n let perm := if s.perm then \":perm\" else \"\"\n let name ← ppOrigin s.origin\n let prio := m!\":{s.priority}\"\n return name ++ prio ++ perm", "start": [ 178, 1 ], "end": [ 182, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremTree", "code": "abbrev SimpTheoremTree := DiscrTree SimpTheorem", "start": [ 187, 1 ], "end": [ 187, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems", "code": "structure SimpTheorems where\n pre : SimpTheoremTree := DiscrTree.empty\n post : SimpTheoremTree := DiscrTree.empty\n lemmaNames : PHashSet Origin := {}\n \n toUnfold : PHashSet Name := {}\n erased : PHashSet Origin := {}\n toUnfoldThms : PHashMap Name (Array Name) := {}\n deriving Inhabited", "start": [ 189, 1 ], "end": [ 200, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.simpDtConfig", "code": "def simpDtConfig : WhnfCoreConfig := { iota := false, proj := .no, zetaDelta := false }", "start": [ 202, 1 ], "end": [ 203, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.eraseCore", "code": "partial def SimpTheorems.eraseCore (d : SimpTheorems) (thmId : Origin) : SimpTheorems :=\n let d := { d with erased := d.erased.insert thmId, lemmaNames := d.lemmaNames.erase thmId }\n if let .decl declName .. := thmId then\n let d := { d with toUnfold := d.toUnfold.erase declName }\n if let some thms := d.toUnfoldThms.find? declName then\n let dummy := true\n thms.foldl (init := d) (eraseCore Β· <| .decl Β· dummy (inv := false))\n else\n d\n else\n d", "start": [ 205, 1 ], "end": [ 215, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.eraseIfExists", "code": "private def eraseIfExists (d : SimpTheorems) (thmId : Origin) : SimpTheorems :=\n if d.lemmaNames.contains thmId then\n d.eraseCore thmId\n else\n d", "start": [ 217, 1 ], "end": [ 221, 6 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.eraseFwdIfBwd", "code": "private def eraseFwdIfBwd (d : SimpTheorems) (e : SimpTheorem) : SimpTheorems :=\n match e.origin with\n | .decl declName post true => eraseIfExists d (.decl declName post false)\n | _ => d", "start": [ 223, 1 ], "end": [ 230, 11 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addSimpTheoremEntry", "code": "def addSimpTheoremEntry (d : SimpTheorems) (e : SimpTheorem) : SimpTheorems :=\n let d := eraseFwdIfBwd d e\n if e.post then\n { d with post := d.post.insertCore e.keys e, lemmaNames := updateLemmaNames d.lemmaNames }\n else\n { d with pre := d.pre.insertCore e.keys e, lemmaNames := updateLemmaNames d.lemmaNames }\nwhere\n updateLemmaNames (s : PHashSet Origin) : PHashSet Origin :=\n s.insert e.origin", "start": [ 232, 1 ], "end": [ 240, 22 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.addDeclToUnfoldCore", "code": "def SimpTheorems.addDeclToUnfoldCore (d : SimpTheorems) (declName : Name) : SimpTheorems :=\n { d with toUnfold := d.toUnfold.insert declName }", "start": [ 242, 1 ], "end": [ 243, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.addLetDeclToUnfold", "code": "def SimpTheorems.addLetDeclToUnfold (d : SimpTheorems) (fvarId : FVarId) : SimpTheorems :=\n { d with toUnfold := d.toUnfold.insert fvarId.name }", "start": [ 245, 1 ], "end": [ 247, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.isDeclToUnfold", "code": "def SimpTheorems.isDeclToUnfold (d : SimpTheorems) (declName : Name) : Bool :=\n d.toUnfold.contains declName", "start": [ 249, 1 ], "end": [ 251, 31 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.isLetDeclToUnfold", "code": "def SimpTheorems.isLetDeclToUnfold (d : SimpTheorems) (fvarId : FVarId) : Bool :=\n d.toUnfold.contains fvarId.name", "start": [ 253, 1 ], "end": [ 254, 34 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.isLemma", "code": "def SimpTheorems.isLemma (d : SimpTheorems) (thmId : Origin) : Bool :=\n d.lemmaNames.contains thmId", "start": [ 256, 1 ], "end": [ 257, 30 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.registerDeclToUnfoldThms", "code": "def SimpTheorems.registerDeclToUnfoldThms (d : SimpTheorems) (declName : Name) (eqThms : Array Name) : SimpTheorems :=\n { d with toUnfoldThms := d.toUnfoldThms.insert declName eqThms }", "start": [ 259, 1 ], "end": [ 261, 67 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.erase", "code": "def SimpTheorems.erase [Monad m] [MonadLog m] [AddMessageContext m] [MonadOptions m]\n (d : SimpTheorems) (thmId : Origin) : m SimpTheorems := do\n unless d.isLemma thmId ||\n match thmId with\n | .decl declName .. => d.isDeclToUnfold declName || d.toUnfoldThms.contains declName\n | _ => false\n do\n logWarning m!\"'{thmId.key}' does not have [simp] attribute\"\n return d.eraseCore thmId", "start": [ 263, 1 ], "end": [ 271, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.isPerm", "code": "private partial def isPerm : Expr β†’ Expr β†’ MetaM Bool\n | .app f₁ a₁, .app fβ‚‚ aβ‚‚ => isPerm f₁ fβ‚‚ <&&> isPerm a₁ aβ‚‚\n | .mdata _ s, t => isPerm s t\n | s, .mdata _ t => isPerm s t\n | s@(.mvar ..), t@(.mvar ..) => isDefEq s t\n | .forallE n₁ d₁ b₁ _, .forallE _ dβ‚‚ bβ‚‚ _ =>\n isPerm d₁ dβ‚‚ <&&> withLocalDeclD n₁ d₁ fun x => isPerm (b₁.instantiate1 x) (bβ‚‚.instantiate1 x)\n | .lam n₁ d₁ b₁ _, .lam _ dβ‚‚ bβ‚‚ _ =>\n isPerm d₁ dβ‚‚ <&&> withLocalDeclD n₁ d₁ fun x => isPerm (b₁.instantiate1 x) (bβ‚‚.instantiate1 x)\n | .letE n₁ t₁ v₁ b₁ _, .letE _ tβ‚‚ vβ‚‚ bβ‚‚ _ =>\n isPerm t₁ tβ‚‚ <&&> isPerm v₁ vβ‚‚ <&&> withLetDecl n₁ t₁ v₁ fun x => isPerm (b₁.instantiate1 x) (bβ‚‚.instantiate1 x)\n | .proj _ i₁ b₁, .proj _ iβ‚‚ bβ‚‚ => pure (i₁ == iβ‚‚) <&&> isPerm b₁ bβ‚‚\n | s, t => return s == t", "start": [ 273, 1 ], "end": [ 285, 26 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.checkBadRewrite", "code": "private def checkBadRewrite (lhs rhs : Expr) : MetaM Unit := do\n let lhs ← DiscrTree.reduceDT lhs (root := true) simpDtConfig\n if lhs == rhs && lhs.isFVar then\n throwError \"invalid `simp` theorem, equation is equivalent to{indentExpr (← mkEq lhs rhs)}\"", "start": [ 287, 1 ], "end": [ 290, 96 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.shouldPreprocess", "code": "private partial def shouldPreprocess (type : Expr) : MetaM Bool :=\n forallTelescopeReducing type fun _ result => do\n if let some (_, lhs, rhs) := result.eq? then\n checkBadRewrite lhs rhs\n return false\n else\n return true", "start": [ 292, 1 ], "end": [ 298, 18 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.preprocess", "code": "private partial def preprocess (e type : Expr) (inv : Bool) (isGlobal : Bool) : MetaM (List (Expr Γ— Expr)) :=\n go e type\nwhere\n go (e type : Expr) : MetaM (List (Expr Γ— Expr)) := do\n let type ← whnf type\n if type.isForall then\n forallTelescopeReducing type fun xs type => do\n let e := mkAppN e xs\n let ps ← go e type\n ps.mapM fun (e, type) =>\n return (← mkLambdaFVars xs e, ← mkForallFVars xs type)\n else if let some (_, lhs, rhs) := type.eq? then\n if isGlobal then\n checkBadRewrite lhs rhs\n if inv then\n let type ← mkEq rhs lhs\n let e ← mkEqSymm e\n return [(e, type)]\n else\n return [(e, type)]\n else if let some (lhs, rhs) := type.iff? then\n if isGlobal then\n checkBadRewrite lhs rhs\n if inv then\n let type ← mkEq rhs lhs\n let e ← mkEqSymm (← mkPropExt e)\n return [(e, type)]\n else\n let type ← mkEq lhs rhs\n let e ← mkPropExt e\n return [(e, type)]\n else if let some (_, lhs, rhs) := type.ne? then\n if inv then\n throwError \"invalid '←' modifier in rewrite rule to 'False'\"\n if rhs.isConstOf ``Bool.true then\n return [(← mkAppM ``Bool.of_not_eq_true #[e], ← mkEq lhs (mkConst ``Bool.false))]\n else if rhs.isConstOf ``Bool.false then\n return [(← mkAppM ``Bool.of_not_eq_false #[e], ← mkEq lhs (mkConst ``Bool.true))]\n let type ← mkEq (← mkEq lhs rhs) (mkConst ``False)\n let e ← mkEqFalse e\n return [(e, type)]\n else if let some p := type.not? then\n if inv then\n throwError \"invalid '←' modifier in rewrite rule to 'False'\"\n if let some (_, lhs, rhs) := p.eq? then\n if rhs.isConstOf ``Bool.true then\n return [(← mkAppM ``Bool.of_not_eq_true #[e], ← mkEq lhs (mkConst ``Bool.false))]\n else if rhs.isConstOf ``Bool.false then\n return [(← mkAppM ``Bool.of_not_eq_false #[e], ← mkEq lhs (mkConst ``Bool.true))]\n let type ← mkEq p (mkConst ``False)\n let e ← mkEqFalse e\n return [(e, type)]\n else if let some (type₁, typeβ‚‚) := type.and? then\n let e₁ := mkProj ``And 0 e\n let eβ‚‚ := mkProj ``And 1 e\n return (← go e₁ type₁) ++ (← go eβ‚‚ typeβ‚‚)\n else\n if inv then\n throwError \"invalid '←' modifier in rewrite rule to 'True'\"\n let type ← mkEq type (mkConst ``True)\n let e ← mkEqTrue e\n return [(e, type)]", "start": [ 300, 1 ], "end": [ 361, 23 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.checkTypeIsProp", "code": "private def checkTypeIsProp (type : Expr) : MetaM Unit :=\n unless (← isProp type) do\n throwError \"invalid 'simp', proposition expected{indentExpr type}\"", "start": [ 363, 1 ], "end": [ 365, 71 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSimpTheoremCore", "code": "private def mkSimpTheoremCore (origin : Origin) (e : Expr) (levelParams : Array Name) (proof : Expr) (post : Bool) (prio : Nat) (noIndexAtArgs : Bool) : MetaM SimpTheorem := do\n assert! origin != .fvar ⟨.anonymous⟩\n let type ← instantiateMVars (← inferType e)\n withNewMCtxDepth do\n let (_, _, type) ← withReducible <| forallMetaTelescopeReducing type\n let type ← whnfR type\n let (keys, perm) ←\n match type.eq? with\n | some (_, lhs, rhs) => pure (← DiscrTree.mkPath lhs simpDtConfig noIndexAtArgs, ← isPerm lhs rhs)\n | none => throwError \"unexpected kind of 'simp' theorem{indentExpr type}\"\n return { origin, keys, perm, post, levelParams, proof, priority := prio, rfl := (← isRflProof proof) }", "start": [ 367, 1 ], "end": [ 377, 107 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSimpTheoremsFromConst", "code": "private def mkSimpTheoremsFromConst (declName : Name) (post : Bool) (inv : Bool) (prio : Nat) : MetaM (Array SimpTheorem) := do\n let cinfo ← getConstInfo declName\n let us := cinfo.levelParams.map mkLevelParam\n let origin := .decl declName post inv\n let val := mkConst declName us\n withReducible do\n let type ← inferType val\n checkTypeIsProp type\n if inv || (← shouldPreprocess type) then\n let mut r := #[]\n for (val, type) in (← preprocess val type inv (isGlobal := true)) do\n let auxName ← mkAuxLemma cinfo.levelParams type val\n r := r.push <| (← mkSimpTheoremCore origin (mkConst auxName us) #[] (mkConst auxName) post prio (noIndexAtArgs := false))\n return r\n else\n return #[← mkSimpTheoremCore origin (mkConst declName us) #[] (mkConst declName) post prio (noIndexAtArgs := false)]", "start": [ 379, 1 ], "end": [ 394, 123 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpEntry", "code": "inductive SimpEntry where\n | thm : SimpTheorem β†’ SimpEntry\n | toUnfold : Name β†’ SimpEntry\n | toUnfoldThms : Name β†’ Array Name β†’ SimpEntry\n deriving Inhabited", "start": [ 396, 1 ], "end": [ 400, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpExtension", "code": "abbrev SimpExtension := SimpleScopedEnvExtension SimpEntry SimpTheorems", "start": [ 402, 1 ], "end": [ 402, 72 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpExtension.getTheorems", "code": "def SimpExtension.getTheorems (ext : SimpExtension) : CoreM SimpTheorems :=\n return ext.getState (← getEnv)", "start": [ 404, 1 ], "end": [ 405, 33 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.addSimpTheorem", "code": "def addSimpTheorem (ext : SimpExtension) (declName : Name) (post : Bool) (inv : Bool) (attrKind : AttributeKind) (prio : Nat) : MetaM Unit := do\n let simpThms ← mkSimpTheoremsFromConst declName post inv prio\n for simpThm in simpThms do\n ext.add (SimpEntry.thm simpThm) attrKind", "start": [ 407, 1 ], "end": [ 410, 45 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSimpExt", "code": "def mkSimpExt (name : Name := by exact decl_name%) : IO SimpExtension :=\n registerSimpleScopedEnvExtension {\n name := name\n initial := {}\n addEntry := fun d e =>\n match e with\n | .thm e => addSimpTheoremEntry d e\n | .toUnfold n => d.addDeclToUnfoldCore n\n | .toUnfoldThms n thms => d.registerDeclToUnfoldThms n thms\n }", "start": [ 412, 1 ], "end": [ 421, 4 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpExtensionMap", "code": "abbrev SimpExtensionMap := HashMap Name SimpExtension", "start": [ 423, 1 ], "end": [ 423, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.getSimpExtension?", "code": "def getSimpExtension? (attrName : Name) : IO (Option SimpExtension) :=\n return (← simpExtensionMapRef.get).find? attrName", "start": [ 427, 1 ], "end": [ 428, 52 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.addConst", "code": "def SimpTheorems.addConst (s : SimpTheorems) (declName : Name) (post := true) (inv := false) (prio : Nat := eval_prio default) : MetaM SimpTheorems := do\n let s := { s with erased := s.erased.erase (.decl declName post inv) }\n let simpThms ← mkSimpTheoremsFromConst declName post inv prio\n return simpThms.foldl addSimpTheoremEntry s", "start": [ 430, 1 ], "end": [ 434, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorem.getValue", "code": "def SimpTheorem.getValue (simpThm : SimpTheorem) : MetaM Expr := do\n if simpThm.proof.isConst && simpThm.levelParams.isEmpty then\n let info ← getConstInfo simpThm.proof.constName!\n if info.levelParams.isEmpty then\n return simpThm.proof\n else\n return simpThm.proof.updateConst! (← info.levelParams.mapM fun _ => mkFreshLevelMVar)\n else\n let us ← simpThm.levelParams.mapM fun _ => mkFreshLevelMVar\n return simpThm.proof.instantiateLevelParamsArray simpThm.levelParams us", "start": [ 436, 1 ], "end": [ 445, 76 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.preprocessProof", "code": "private def preprocessProof (val : Expr) (inv : Bool) : MetaM (Array Expr) := do\n let type ← inferType val\n checkTypeIsProp type\n let ps ← preprocess val type inv (isGlobal := false)\n return ps.toArray.map fun (val, _) => val", "start": [ 447, 1 ], "end": [ 451, 44 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.mkSimpTheorems", "code": "def mkSimpTheorems (id : Origin) (levelParams : Array Name) (proof : Expr) (post := true) (inv := false) (prio : Nat := eval_prio default) : MetaM (Array SimpTheorem) :=\n withReducible do\n (← preprocessProof proof inv).mapM fun val => mkSimpTheoremCore id val levelParams val post prio (noIndexAtArgs := true)", "start": [ 453, 1 ], "end": [ 456, 125 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.add", "code": "def SimpTheorems.add (s : SimpTheorems) (id : Origin) (levelParams : Array Name) (proof : Expr) (inv := false) (post := true) (prio : Nat := eval_prio default) : MetaM SimpTheorems := do\n if proof.isConst then\n s.addConst proof.constName! post inv prio\n else\n let simpThms ← mkSimpTheorems id levelParams proof post inv prio\n return simpThms.foldl addSimpTheoremEntry s", "start": [ 458, 1 ], "end": [ 464, 48 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheorems.addDeclToUnfold", "code": "def SimpTheorems.addDeclToUnfold (d : SimpTheorems) (declName : Name) : MetaM SimpTheorems := do\n if let some eqns ← getEqnsFor? declName then\n let mut d := d\n for h : i in [:eqns.size] do\n let eqn := eqns[i]\n \n let prio := if eqns.size > 100 then\n if i + 1 = eqns.size then 0 else 1\n else\n 100 - i\n d ← SimpTheorems.addConst d eqn (prio := prio)\n \n if hasSmartUnfoldingDecl (← getEnv) declName || !(← isRecursiveDefinition declName) then\n d := d.addDeclToUnfoldCore declName\n return d\n else\n return d.addDeclToUnfoldCore declName", "start": [ 466, 1 ], "end": [ 505, 42 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremsArray", "code": "abbrev SimpTheoremsArray := Array SimpTheorems", "start": [ 507, 1 ], "end": [ 507, 47 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremsArray.addTheorem", "code": "def SimpTheoremsArray.addTheorem (thmsArray : SimpTheoremsArray) (id : Origin) (h : Expr) : MetaM SimpTheoremsArray :=\n if thmsArray.isEmpty then\n let thms : SimpTheorems := {}\n return #[ (← thms.add id #[] h) ]\n else\n thmsArray.modifyM 0 fun thms => thms.add id #[] h", "start": [ 509, 1 ], "end": [ 514, 54 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremsArray.eraseTheorem", "code": "def SimpTheoremsArray.eraseTheorem (thmsArray : SimpTheoremsArray) (thmId : Origin) : SimpTheoremsArray :=\n thmsArray.map fun thms => thms.eraseCore thmId", "start": [ 516, 1 ], "end": [ 517, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremsArray.isErased", "code": "def SimpTheoremsArray.isErased (thmsArray : SimpTheoremsArray) (thmId : Origin) : Bool :=\n thmsArray.any fun thms => thms.erased.contains thmId", "start": [ 519, 1 ], "end": [ 520, 55 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremsArray.isDeclToUnfold", "code": "def SimpTheoremsArray.isDeclToUnfold (thmsArray : SimpTheoremsArray) (declName : Name) : Bool :=\n thmsArray.any fun thms => thms.isDeclToUnfold declName", "start": [ 522, 1 ], "end": [ 523, 57 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.SimpTheoremsArray.isLetDeclToUnfold", "code": "def SimpTheoremsArray.isLetDeclToUnfold (thmsArray : SimpTheoremsArray) (fvarId : FVarId) : Bool :=\n thmsArray.any fun thms => thms.isLetDeclToUnfold fvarId", "start": [ 525, 1 ], "end": [ 526, 58 ], "kind": "commanddeclaration" } ]
.lake/packages/lean4/src/lean/Lean/Meta/Tactic/Replace.lean
[ ".lake/packages/lean4/src/lean/Lean/Util/ForEachExpr.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Intro.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Assert.lean", ".lake/packages/lean4/src/lean/Lean/Elab/InfoTree/Main.lean", ".lake/packages/lean4/src/lean/Lean/Meta/AppBuilder.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Revert.lean", ".lake/packages/lean4/src/lean/Lean/Meta/MatchUtil.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Clear.lean", ".lake/packages/lean4/src/lean/Lean/Meta/Tactic/Util.lean" ]
[ { "full_name": "Lean.MVarId.replaceTargetEq", "code": "def _root_.Lean.MVarId.replaceTargetEq (mvarId : MVarId) (targetNew : Expr) (eqProof : Expr) : MetaM MVarId :=\n mvarId.withContext do\n mvarId.checkNotAssigned `replaceTarget\n let tag ← mvarId.getTag\n let mvarNew ← mkFreshExprSyntheticOpaqueMVar targetNew tag\n let target ← mvarId.getType\n let u ← getLevel target\n let eq ← mkEq target targetNew\n let newProof ← mkExpectedTypeHint eqProof eq\n let val := mkAppN (Lean.mkConst `Eq.mpr [u]) #[target, targetNew, newProof, mvarNew]\n mvarId.assign val\n return mvarNew.mvarId!", "start": [ 19, 1 ], "end": [ 33, 27 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.replaceTargetEq", "code": "@[deprecated MVarId.replaceTargetEq (since := \"2022-07-15\")]\ndef replaceTargetEq (mvarId : MVarId) (targetNew : Expr) (eqProof : Expr) : MetaM MVarId :=\n mvarId.replaceTargetEq targetNew eqProof", "start": [ 35, 1 ], "end": [ 37, 43 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.replaceTargetDefEq", "code": "def _root_.Lean.MVarId.replaceTargetDefEq (mvarId : MVarId) (targetNew : Expr) : MetaM MVarId :=\n mvarId.withContext do\n mvarId.checkNotAssigned `change\n let target ← mvarId.getType\n if target == targetNew then\n return mvarId\n else\n let tag ← mvarId.getTag\n let mvarNew ← mkFreshExprSyntheticOpaqueMVar targetNew tag\n let newVal ← mkExpectedTypeHint mvarNew target\n mvarId.assign newVal\n return mvarNew.mvarId!", "start": [ 39, 1 ], "end": [ 57, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.replaceTargetDefEq", "code": "@[deprecated MVarId.replaceTargetDefEq (since := \"2022-07-15\")]\ndef replaceTargetDefEq (mvarId : MVarId) (targetNew : Expr) : MetaM MVarId :=\n mvarId.replaceTargetDefEq targetNew", "start": [ 59, 1 ], "end": [ 61, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.replaceLocalDeclCore", "code": "private def replaceLocalDeclCore (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) (eqProof : Expr) : MetaM AssertAfterResult :=\n mvarId.withContext do\n let localDecl ← fvarId.getDecl\n let typeNewPr ← mkEqMP eqProof (mkFVar fvarId)\n \n let (_, localDecl') ← findMaxFVar (← instantiateMVars typeNew) |>.run localDecl\n let result ← mvarId.assertAfter localDecl'.fvarId localDecl.userName typeNew typeNewPr\n (do let mvarIdNew ← result.mvarId.clear fvarId\n pure { result with mvarId := mvarIdNew })\n <|> pure result\nwhere\n findMaxFVar (e : Expr) : StateRefT LocalDecl MetaM Unit :=\n e.forEach' fun e => do\n if e.isFVar then\n let localDecl' ← e.fvarId!.getDecl\n modify fun localDecl => if localDecl'.index > localDecl.index then localDecl' else localDecl\n return false\n else\n return e.hasFVar", "start": [ 63, 1 ], "end": [ 85, 25 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.replaceLocalDecl", "code": "abbrev _root_.Lean.MVarId.replaceLocalDecl (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) (eqProof : Expr) : MetaM AssertAfterResult :=\n replaceLocalDeclCore mvarId fvarId typeNew eqProof", "start": [ 87, 1 ], "end": [ 103, 53 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.replaceLocalDecl", "code": "@[deprecated MVarId.replaceLocalDecl (since := \"2022-07-15\")]\nabbrev replaceLocalDecl (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) (eqProof : Expr) : MetaM AssertAfterResult :=\n mvarId.replaceLocalDecl fvarId typeNew eqProof", "start": [ 105, 1 ], "end": [ 107, 49 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.replaceLocalDeclDefEq", "code": "def _root_.Lean.MVarId.replaceLocalDeclDefEq (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) : MetaM MVarId := do\n mvarId.withContext do\n if typeNew == (← fvarId.getType) then\n return mvarId\n else\n let mvarDecl ← mvarId.getDecl\n let lctxNew := (← getLCtx).modifyLocalDecl fvarId (Β·.setType typeNew)\n let mvarNew ← mkFreshExprMVarAt lctxNew (← getLocalInstances) mvarDecl.type mvarDecl.kind mvarDecl.userName\n mvarId.assign mvarNew\n return mvarNew.mvarId!", "start": [ 109, 1 ], "end": [ 122, 29 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.replaceLocalDeclDefEq", "code": "@[deprecated MVarId.replaceLocalDeclDefEq (since := \"2022-07-15\")]\ndef replaceLocalDeclDefEq (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) : MetaM MVarId := do\n mvarId.replaceLocalDeclDefEq fvarId typeNew", "start": [ 124, 1 ], "end": [ 126, 46 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.change", "code": "def _root_.Lean.MVarId.change (mvarId : MVarId) (targetNew : Expr) (checkDefEq := true) : MetaM MVarId := mvarId.withContext do\n let target ← mvarId.getType\n if checkDefEq then\n unless (← isDefEq target targetNew) do\n throwTacticEx `change mvarId m!\"given type{indentExpr targetNew}\\nis not definitionally equal to{indentExpr target}\"\n mvarId.replaceTargetDefEq targetNew", "start": [ 128, 1 ], "end": [ 138, 38 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.change", "code": "@[deprecated MVarId.change (since := \"2022-07-15\")]\ndef change (mvarId : MVarId) (targetNew : Expr) (checkDefEq := true) : MetaM MVarId := mvarId.withContext do\n mvarId.change targetNew checkDefEq", "start": [ 140, 1 ], "end": [ 142, 37 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.withReverted", "code": "def _root_.Lean.MVarId.withReverted (mvarId : MVarId) (fvarIds : Array FVarId)\n (k : MVarId β†’ Array FVarId β†’ MetaM (Ξ± Γ— Array (Option FVarId) Γ— MVarId))\n (clearAuxDeclsInsteadOfRevert := false) : MetaM (Ξ± Γ— MVarId) := do\n let (xs, mvarId) ← mvarId.revert fvarIds true clearAuxDeclsInsteadOfRevert\n let (r, xs', mvarId) ← k mvarId xs\n let (ys, mvarId) ← mvarId.introNP xs'.size\n mvarId.withContext do\n for x? in xs', y in ys do\n if let some x := x? then\n Elab.pushInfoLeaf (.ofFVarAliasInfo { id := y, baseId := x, userName := ← y.getUserName })\n return (r, mvarId)", "start": [ 144, 1 ], "end": [ 184, 21 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.changeLocalDecl", "code": "def _root_.Lean.MVarId.changeLocalDecl (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr)\n (checkDefEq := true) : MetaM MVarId := do\n mvarId.checkNotAssigned `changeLocalDecl\n let (_, mvarId) ← mvarId.withReverted #[fvarId] fun mvarId fvars => mvarId.withContext do\n let check (typeOld : Expr) : MetaM Unit := do\n if checkDefEq then\n unless ← isDefEq typeNew typeOld do\n throwTacticEx `changeLocalDecl mvarId\n m!\"given type{indentExpr typeNew}\\nis not definitionally equal to{indentExpr typeOld}\"\n let finalize (targetNew : Expr) := do\n return ((), fvars.map .some, ← mvarId.replaceTargetDefEq targetNew)\n match ← mvarId.getType with\n | .forallE n d b bi => do check d; finalize (.forallE n typeNew b bi)\n | .letE n t v b ndep => do check t; finalize (.letE n typeNew v b ndep)\n | _ => throwTacticEx `changeLocalDecl mvarId \"unexpected auxiliary target\"\n return mvarId", "start": [ 186, 1 ], "end": [ 211, 16 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.changeLocalDecl", "code": "@[deprecated MVarId.changeLocalDecl]\ndef changeLocalDecl (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) (checkDefEq := true) : MetaM MVarId := do\n mvarId.changeLocalDecl fvarId typeNew checkDefEq", "start": [ 213, 1 ], "end": [ 215, 51 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.modifyTarget", "code": "def _root_.Lean.MVarId.modifyTarget (mvarId : MVarId) (f : Expr β†’ MetaM Expr) : MetaM MVarId := do\n mvarId.withContext do\n mvarId.checkNotAssigned `modifyTarget\n mvarId.change (← f (← mvarId.getType)) (checkDefEq := false)", "start": [ 217, 1 ], "end": [ 223, 65 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.modifyTarget", "code": "@[deprecated modifyTarget (since := \"2022-07-15\")]\ndef modifyTarget (mvarId : MVarId) (f : Expr β†’ MetaM Expr) : MetaM MVarId := do\n mvarId.modifyTarget f", "start": [ 225, 1 ], "end": [ 227, 24 ], "kind": "commanddeclaration" }, { "full_name": "Lean.MVarId.modifyTargetEqLHS", "code": "def _root_.Lean.MVarId.modifyTargetEqLHS (mvarId : MVarId) (f : Expr β†’ MetaM Expr) : MetaM MVarId := do\n mvarId.modifyTarget fun target => do\n if let some (_, lhs, rhs) ← matchEq? target then\n mkEq (← f lhs) rhs\n else\n throwTacticEx `modifyTargetEqLHS mvarId m!\"equality expected{indentExpr target}\"", "start": [ 229, 1 ], "end": [ 238, 88 ], "kind": "commanddeclaration" }, { "full_name": "Lean.Meta.modifyTargetEqLHS", "code": "@[deprecated MVarId.modifyTargetEqLHS (since := \"2022-07-15\")]\ndef modifyTargetEqLHS (mvarId : MVarId) (f : Expr β†’ MetaM Expr) : MetaM MVarId := do\n mvarId.modifyTargetEqLHS f", "start": [ 240, 1 ], "end": [ 242, 29 ], "kind": "commanddeclaration" } ]