Proof Assistant Projects
Collection
Digesting proof assistant libraries for AI ingestion. • 103 items • Updated • 3
fact stringlengths 14 3.08k | statement stringlengths 8 1.28k | proof stringlengths 0 2.59k | type stringclasses 12
values | kind stringclasses 6
values | symbolic_name stringlengths 0 23 | library stringclasses 3
values | filename stringclasses 26
values | imports listlengths 0 2 | deps listlengths 0 15 | docstring stringclasses 24
values | line_start int64 4 655 | line_end int64 4 669 | has_proof bool 2
classes | source_url stringclasses 1
value | commit stringclasses 1
value | content_level stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
elab_rules : term <= expectedType | `(assertInstancesCommuteImpl $cont) => do
match ← findRedundantLocalInstQuoted? with
| some ⟨fvar, _, _, lhs, rhs⟩ =>
let n ← mkFreshUserName ((← fvar.getUserName).eraseMacroScopes.appendAfter "_eq")
let cmd := q(withNewMCtxDepth do withDefault do assertDefEqQ $lhs $rhs)
... | elab_rules : term <= expectedType | `(assertInstancesCommuteImpl $cont) => do
match ← findRedundantLocalInstQuoted? with
| some ⟨fvar, _, _, lhs, rhs⟩ =>
let n ← mkFreshUserName ((← fvar.getUserName).eraseMacroScopes.appendAfter "_eq")
let cmd | q(withNewMCtxDepth do withDefault do assertDefEqQ $lhs $rhs)
elabTerm (← `($(← exprToSyntax cmd) >>=
fun __defeqres =>
have $(mkIdent n) := __defeqres.1
assertInstancesCommuteImpl $cont))
expectedType
| none => elabTerm cont expectedType | elab_rules | other | Root | Qq/AssertInstancesCommute.lean | [] | [
"assertDefEqQ",
"n"
] | null | 46 | 56 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
elab_rules : term <= expectedType | `(assumeInstancesCommute' $cont) => do
match ← findRedundantLocalInstQuoted? with
| some ⟨fvar, _, _, lhs, rhs⟩ =>
let n ← mkFreshUserName ((← fvar.getUserName).eraseMacroScopes.appendAfter "_eq")
let ty := q(QuotedDefEq $lhs $rhs)
elabTerm (← `(
have $(mkIden... | elab_rules : term <= expectedType | `(assumeInstancesCommute' $cont) => do
match ← findRedundantLocalInstQuoted? with
| some ⟨fvar, _, _, lhs, rhs⟩ =>
let n ← mkFreshUserName ((← fvar.getUserName).eraseMacroScopes.appendAfter "_eq")
let ty | q(QuotedDefEq $lhs $rhs)
elabTerm (← `(
have $(mkIdent n) : $(← exprToSyntax ty) := ⟨⟩
assumeInstancesCommute' $cont))
expectedType
| none => elabTerm cont expectedType | elab_rules | other | Root | Qq/AssertInstancesCommute.lean | [] | [
"QuotedDefEq",
"n"
] | null | 58 | 67 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
macro_rules
| `(assert! assertInstancesCommuteDummy; $cont) =>
`(assertInstancesCommuteImpl $cont) | macro_rules
| `(assert! assertInstancesCommuteDummy; $cont) =>
`(assertInstancesCommuteImpl $cont) | macro_rules | definition | Root | Qq/AssertInstancesCommute.lean | [] | [] | null | 70 | 72 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
macro_rules
| `(assert! assumeInstancesCommuteDummy; $cont) =>
`(assumeInstancesCommute' $cont) | macro_rules
| `(assert! assumeInstancesCommuteDummy; $cont) =>
`(assumeInstancesCommute' $cont) | macro_rules | definition | Root | Qq/AssertInstancesCommute.lean | [] | [] | null | 75 | 77 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
scoped macro "assertInstancesCommute" : doElem =>
`(doElem| assert! assertInstancesCommuteDummy) | scoped macro "assertInstancesCommute" : doElem =>
`(doElem| assert! assertInstancesCommuteDummy) | macro | definition | Root | Qq/AssertInstancesCommute.lean | [] | [] | null | 82 | 83 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
scoped macro "assumeInstancesCommute" : doElem =>
`(doElem| assert! assumeInstancesCommuteDummy) | scoped macro "assumeInstancesCommute" : doElem =>
`(doElem| assert! assumeInstancesCommuteDummy) | macro | definition | Root | Qq/AssertInstancesCommute.lean | [] | [] | null | 85 | 86 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
scoped
elab "by_elabq" e:doSeq : term <= expectedType => do
let lctx ← getLCtx
let levelNames := (← Term.getLevelNames).reverse -- these are backwards!
let (quotedCtx, assignments, quotedGoal) ← liftMetaM <| StateT.run'
(s := { mayPostpone := false }) do
let (quotedCtx, assignments) ← Impl.quoteLCtx l... | scoped
elab "by_elabq" e:doSeq : term <= expectedType => do
let lctx ← getLCtx
let levelNames | (← Term.getLevelNames).reverse -- these are backwards!
let (quotedCtx, assignments, quotedGoal) ← liftMetaM <| StateT.run'
(s := { mayPostpone := false }) do
let (quotedCtx, assignments) ← Impl.quoteLCtx lctx levelNames
let expectedType ← instantiateMVars expectedType
let quotedGoal : Q(Type) ←
... | elab | other | e | Root | Qq/Commands.lean | [] | [
"Quoted",
"t"
] | `by_elabq` is the Qq analogue to `by_elab` which allows executing arbitrary `TermElabM` code in
place of a term. In contrast to `by_elab`, the local context can be directly accessed as quoted
expressions and the return type is Q-annotated.
Example:
```
def f (x : Prop) [Decidable x] : Int :=
by_elabq
Lean.logInfo... | 44 | 85 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
elab_rules : tactic
| `(tactic| run_tacq $[$gi:ident =>]? $seq:doSeq) => do
let goal ← try
getMainGoal
catch _ =>
throwError "no open goal, run_tacq requires main goal"
goal.withContext do
let lctx ← getLCtx
let levelNames := (← Term.getLevelNames).reverse -- these are backwards!
let target ← ... | elab_rules : tactic
| `(tactic| run_tacq $[$gi:ident =>]? $seq:doSeq) => do
let goal ← try
getMainGoal
catch _ =>
throwError "no open goal, run_tacq requires main goal"
goal.withContext do
let lctx ← getLCtx
let levelNames | (← Term.getLevelNames).reverse -- these are backwards!
let target ← instantiateMVars (← goal.getType)
let (quotedCtx, assignments, goalInfo?) ← liftMetaM <| StateT.run'
(s := { mayPostpone := false }) do
let (quotedCtx, assignments) ← Impl.quoteLCtx lctx levelNames
match gi with
| no... | elab_rules | other | Root | Qq/Commands.lean | [] | [
"Quoted"
] | null | 88 | 119 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
inductive MVarSynth
| term (quotedType : Expr) (unquotedMVar : MVarId) --> Quoted.unsafeMk _ _
| type (unquotedMVar : MVarId) --> Quoted _
| level (unquotedMVar : LMVarId) --> Level
meta structure UnquoteState where
/--
Quoted mvars in the outside lctx (of type `Level`, `Quoted _`, or `Type`).
The outside ... | inductive MVarSynth
| term (quotedType : Expr) (unquotedMVar : MVarId) --> Quoted.unsafeMk _ _
| type (unquotedMVar : MVarId) --> Quoted _
| level (unquotedMVar : LMVarId) --> Level
meta structure UnquoteState where
/--
Quoted mvars in the outside lctx (of type `Level`, `Quoted _`, or `Type`).
The outside ... | inductive | inductive | MVarSynth | Root | Qq/Macro.lean | [] | [
"Quoted",
"Quoted.unsafeMk",
"m"
] | null | 27 | 59 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
abbrev UnquoteM := StateT UnquoteState MetaM | abbrev UnquoteM | StateT UnquoteState MetaM | abbrev | definition | UnquoteM | Root | Qq/Macro.lean | [] | [] | null | 61 | 61 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
abbrev QuoteM := ReaderT UnquoteState MetaM
meta instance : MonadLift QuoteM UnquoteM where
monadLift k := do k (← get)
meta def determineLocalInstances (lctx : LocalContext) : MetaM LocalInstances := do
let mut localInsts : LocalInstances := {}
for ldecl in lctx do
match (← isClass? ldecl.type) with
... | abbrev QuoteM | ReaderT UnquoteState MetaM
meta instance : MonadLift QuoteM UnquoteM where
monadLift k := do k (← get)
meta def determineLocalInstances (lctx : LocalContext) : MetaM LocalInstances := do
let mut localInsts : LocalInstances := {}
for ldecl in lctx do
match (← isClass? ldecl.type) with
| some c => local... | abbrev | definition | QuoteM | Root | Qq/Macro.lean | [] | [
"UnquoteM",
"k",
"m"
] | null | 63 | 78 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
scoped elab "ql(" l:level ")" : term => do
let ((), s) ← unquoteLevelLCtx.run {mayPostpone := false}
let l ← s.withLevelNames do
let l ← elabLevel l
let refdLevels := (CollectLevelParams.collect (← instantiateLevelMVars l) {}).params
return (l, refdLevels)
quoteLevel l s
/-- `a =QL b` says that the l... | scoped elab "ql(" l:level ")" : term => do
let ((), s) ← unquoteLevelLCtx.run {mayPostpone := false}
let l ← s.withLevelNames do
let l ← elabLevel l
let refdLevels | (CollectLevelParams.collect (← instantiateLevelMVars l) {}).params
return (l, refdLevels)
quoteLevel l s
/-- `a =QL b` says that the levels `a` and `b` are definitionally equal. -/ | elab | other | l | Root | Qq/Macro.lean | [] | [] | `ql(u)` quotes the universe level `u`. | 520 | 528 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
macro_rules | `($a:level =QL $b) => `(QuotedLevelDefEq ql($a) ql($b))
meta def Impl.macro (t : Syntax) (expectedType : Expr) : TermElabM Expr := do
let mainMVar ← mkFreshExprMVar expectedType
let s ← (unquoteMVar mainMVar *> get).run' { mayPostpone := (← read).mayPostpone }
have lastId := match s.mvars with
... | macro_rules | `($a:level =QL $b) => `(QuotedLevelDefEq ql($a) ql($b))
meta def Impl.macro (t : Syntax) (expectedType : Expr) : TermElabM Expr | do
let mainMVar ← mkFreshExprMVar expectedType
let s ← (unquoteMVar mainMVar *> get).run' { mayPostpone := (← read).mayPostpone }
have lastId := match s.mvars with
| (_, .term _ lastMVar) :: _ | (_, .type lastMVar) :: _ => lastMVar
| _ => unreachable!
let lastDecl ← lastId.getDecl
withRef t do s.wit... | macro_rules | definition | Root | Qq/Macro.lean | [] | [
"QuotedLevelDefEq",
"t"
] | null | 530 | 571 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
macro_rules | `(q($t : $ty)) => `(q(($t : $ty))) | macro_rules | `(q($t : $ty)) => `(q(($t : $ty))) | macro_rules | definition | Root | Qq/Macro.lean | [] | [
"t"
] | null | 574 | 574 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
elab_rules : term <= expectedType
| `(q($t)) => do
let expectedType ← instantiateMVars expectedType
if expectedType.hasExprMVar then tryPostpone
if ← lctxHasMVar then tryPostpone
ensureHasType expectedType $ ← commitIfDidNotPostpone do
let mut expectedType ← withReducible <| Impl.whnf expectedTy... | elab_rules : term <= expectedType
| `(q($t)) => do
let expectedType ← instantiateMVars expectedType
if expectedType.hasExprMVar then tryPostpone
if ← lctxHasMVar then tryPostpone
ensureHasType expectedType $ ← commitIfDidNotPostpone do
let mut expectedType ← withReducible <| Impl.whnf expectedTy... | .app (.const ``Expr.sort []) u
let t ← mkFreshExprMVar (mkApp (.const ``Quoted []) u')
expectedType := .app (.const ``Quoted []) t
Impl.macro t expectedType
/-- `Q(α)` is the type of Lean expressions having type `α`. -/ | elab_rules | other | Root | Qq/Macro.lean | [] | [
"Quoted",
"t"
] | null | 576 | 590 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
macro_rules | `(Q($t : $ty)) => `(Q(($t : $ty))) | macro_rules | `(Q($t : $ty)) => `(Q(($t : $ty))) | macro_rules | definition | Root | Qq/Macro.lean | [] | [
"t"
] | null | 593 | 593 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
elab_rules : term <= expectedType
| `(Q($t)) => do
let expectedType ← instantiateMVars expectedType
unless ← isDefEq expectedType q(Type) do
throwError "Q(.) has type Type, expected type is{indentExpr expectedType}"
commitIfDidNotPostpone do Impl.macro t expectedType
/-- `a =Q b` says that `a` and ... | elab_rules : term <= expectedType
| `(Q($t)) => do
let expectedType ← instantiateMVars expectedType
unless ← isDefEq expectedType q(Type) do
throwError "Q(.) has type Type, expected type is{indentExpr expectedType}"
commitIfDidNotPostpone do Impl.macro t expectedType
/-- `a =Q b` says that `a` and ... | elab_rules | other | Root | Qq/Macro.lean | [] | [
"t"
] | null | 595 | 602 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
macro_rules
| `(Q($t0)) => do
let (t, lifts) ← floatExprAntiquot 0 t0 #[]
if lifts.isEmpty && t == t0 then Macro.throwUnsupported
let mut t ← `(Q($t))
for (a, ty, lift) in lifts do
t ← `(let $a:ident : $ty := $lift; $t)
pure t
| `(q($t0)) => do
let (t, lifts) ← floatExprAntiquot 0 t0 #... | macro_rules
| `(Q($t0)) => do
let (t, lifts) ← floatExprAntiquot 0 t0 #[]
if lifts.isEmpty && t == t0 then Macro.throwUnsupported
let mut t ← `(Q($t))
for (a, ty, lift) in lifts do
t ← `(let $a:ident : $ty := $lift; $t)
pure t
| `(q($t0)) => do
let (t, lifts) ← floatExprAntiquot 0 t0 #... | macro_rules | definition | Root | Qq/Macro.lean | [] | [
"floatExprAntiquot",
"t"
] | null | 655 | 669 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
def mkInstantiateMVars (decls : List PatVarDecl) : List PatVarDecl → MetaM Q(MetaM $(mkIsDefEqType decls))
| [] => return q(return $(mkIsDefEqResult true decls))
-- https://github.com/leanprover/lean4/issues/501
| { ty := none, fvarId := fvarId, userName := userName } :: rest => do
let decl : PatVarDecl := { ... | def mkInstantiateMVars (decls : List PatVarDecl) : List PatVarDecl → MetaM Q(MetaM $(mkIsDefEqType decls))
| [] => return q(return $(mkIsDefEqResult true decls))
-- https://github.com/leanprover/lean4/issues/501
| { ty := none, fvarId := fvarId, userName := userName } :: rest => do
let decl : PatVarDecl | { ty := none, fvarId := fvarId, userName := userName }
let instMVars : Q(Level → MetaM $(mkIsDefEqType decls)) ←
mkLambdaQ _ decl.fvar q($(← mkInstantiateMVars decls rest))
return q(Bind.bind (instantiateLevelMVars $(decl.fvar)) $instMVars)
| { ty := some ty, fvarId := fvarId, userName := userName } :: ... | def | definition | mkInstantiateMVars | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"mkIsDefEqResult",
"mkIsDefEqType",
"mkLambdaQ"
] | null | 68 | 80 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkIsDefEqCore (decls : List PatVarDecl) (pat discr : Q(Expr)) :
List PatVarDecl → MetaM Q(MetaM $(mkIsDefEqType decls))
| { ty := none, fvarId := fvarId, userName := userName } :: rest =>
let decl : PatVarDecl := { ty := none, fvarId := fvarId, userName := userName }
return q(Bind.bind mkFreshLevelMVa... | def mkIsDefEqCore (decls : List PatVarDecl) (pat discr : Q(Expr)) :
List PatVarDecl → MetaM Q(MetaM $(mkIsDefEqType decls))
| { ty := none, fvarId := fvarId, userName := userName } :: rest =>
let decl : PatVarDecl | { ty := none, fvarId := fvarId, userName := userName }
return q(Bind.bind mkFreshLevelMVar $(← mkLambdaQ `x decl.fvar (← mkIsDefEqCore decls pat discr rest)))
| { ty := some ty, fvarId := fvarId, userName := userName } :: rest =>
let decl : PatVarDecl := { ty := some ty, fvarId := fvarId, userName := userName... | def | definition | mkIsDefEqCore | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"mkInstantiateMVars",
"mkIsDefEqResult",
"mkIsDefEqType",
"mkLambdaQ",
"pat"
] | null | 82 | 94 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkIsDefEq (decls : List PatVarDecl) (pat discr : Q(Expr)) : MetaM Q(MetaM $(mkIsDefEqType decls)) := do
return q(withNewMCtxDepth $(← mkIsDefEqCore decls pat discr decls)) | def mkIsDefEq (decls : List PatVarDecl) (pat discr : Q(Expr)) : MetaM Q(MetaM $(mkIsDefEqType decls)) | do
return q(withNewMCtxDepth $(← mkIsDefEqCore decls pat discr decls)) | def | definition | mkIsDefEq | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"mkIsDefEqCore",
"mkIsDefEqType",
"pat"
] | null | 96 | 97 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def withLetHave [Monad m] [MonadControlT MetaM m] [MonadLiftT MetaM m] [MonadLCtx m]
(fvarId : FVarId) (userName : Name) (val : (Quoted α)) (k : (Quoted α) → m (Quoted β)) : m (Quoted β) := do
withExistingLocalDecls [LocalDecl.cdecl default fvarId userName α .default .default] do
return Quoted.unsafeMk $ ← mk... | def withLetHave [Monad m] [MonadControlT MetaM m] [MonadLiftT MetaM m] [MonadLCtx m]
(fvarId : FVarId) (userName : Name) (val : (Quoted α)) (k : (Quoted α) → m (Quoted β)) : m (Quoted β) | do
withExistingLocalDecls [LocalDecl.cdecl default fvarId userName α .default .default] do
return Quoted.unsafeMk $ ← mkLet' userName (.fvar fvarId) α val (← k (.fvar fvarId)) | def | definition | withLetHave | Root | Qq/Match.lean | [] | [
"Quoted",
"Quoted.unsafeMk",
"k",
"m",
"mkLet'"
] | null | 99 | 102 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkQqLets {γ : Q(Type)} : (decls : List PatVarDecl) → Q($(mkIsDefEqType decls)) →
TermElabM Q($γ) → TermElabM Q($γ)
| { ty := none, fvarId := fvarId, userName := userName } :: decls, acc, cb =>
withLetHave fvarId userName (α := q(Level)) q($acc.1) fun _ => mkQqLets decls q($acc.2) cb
| { ty := some ty, f... | def mkQqLets {γ : Q(Type)} : (decls : List PatVarDecl) → Q($(mkIsDefEqType decls)) →
TermElabM Q($γ) → TermElabM Q($γ)
| { ty := none, fvarId := fvarId, userName := userName } :: decls, acc, cb =>
withLetHave fvarId userName (α := q(Level)) q($acc.1) fun _ => mkQqLets decls q($acc.2) cb
| { ty := some ty, f... | def | definition | mkQqLets | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"Quoted",
"mkIsDefEqType",
"withLetHave"
] | null | 104 | 112 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
def replaceTempExprsByQVars : List PatVarDecl → Expr → Expr
| [], e => e
| { ty := some _, fvarId, .. } :: decls, e =>
((replaceTempExprsByQVars decls e).abstract #[.fvar fvarId]).instantiate #[.fvar fvarId]
| { ty := none, .. } :: decls, e =>
replaceTempExprsByQVars decls e | def replaceTempExprsByQVars : List PatVarDecl → Expr → Expr
| [], e => e
| { ty := some _, fvarId, .. } :: decls, e =>
((replaceTempExprsByQVars decls e).abstract #[.fvar fvarId]).instantiate #[.fvar fvarId]
| { ty := none, .. } :: decls, e =>
replaceTempExprsByQVars decls e | def | definition | replaceTempExprsByQVars | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"e"
] | null | 113 | 118 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
def makeMatchCode {γ : Q(Type)} {m : Q(Type → Type v)} (_instLift : Q(MonadLiftT MetaM $m)) (_instBind : Q(Bind $m))
(decls : List PatVarDecl) (uTy : Q(Level)) (ty : Q(Quoted (.sort $uTy)))
(pat discr : Q(Quoted $ty)) (alt : Q($m $γ)) (expectedType : Expr)
(k : Expr → TermElabM Q($m $γ)) : TermElabM Q($m $γ... | def makeMatchCode {γ : Q(Type)} {m : Q(Type → Type v)} (_instLift : Q(MonadLiftT MetaM $m)) (_instBind : Q(Bind $m))
(decls : List PatVarDecl) (uTy : Q(Level)) (ty : Q(Quoted (.sort $uTy)))
(pat discr : Q(Quoted $ty)) (alt : Q($m $γ)) (expectedType : Expr)
(k : Expr → TermElabM Q($m $γ)) : TermElabM Q($m $γ... | do
let nextDecls : List PatVarDecl :=
decls.map fun decl => { decl with ty := decl.ty.map fun e => replaceTempExprsByQVars decls e }
let next ← withLocalDecl (← mkFreshBinderName) default (mkIsDefEqType decls) (kind := .implDetail) fun fv => do
let fv : Q($(mkIsDefEqType decls)) := fv
-- note: cannot in... | def | definition | makeMatchCode | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"Quoted",
"Quoted.unsafeMk",
"QuotedDefEq",
"e",
"k",
"m",
"mkIsDefEq",
"mkIsDefEqResultVal",
"mkIsDefEqType",
"mkLambda'",
"mkQqLets",
"pat",
"replaceTempExprsByQVars",
"withLocalDeclDQ"
] | null | 120 | 146 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def unquoteForMatch (et : Expr) : UnquoteM (LocalContext × LocalInstances × Expr) := do
unquoteLCtx
let newET ← unquoteExpr et
let newLCtx := (← get).unquoted
return (newLCtx, ← determineLocalInstances newLCtx, newET) | def unquoteForMatch (et : Expr) : UnquoteM (LocalContext × LocalInstances × Expr) | do
unquoteLCtx
let newET ← unquoteExpr et
let newLCtx := (← get).unquoted
return (newLCtx, ← determineLocalInstances newLCtx, newET) | def | definition | unquoteForMatch | Root | Qq/Match.lean | [] | [
"UnquoteM"
] | null | 148 | 152 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkNAryFunctionType : Nat → MetaM Expr
| 0 => mkFreshTypeMVar
| n+1 => do withLocalDeclD `x (← mkFreshTypeMVar) fun x => do
mkForallFVars #[x] (← mkNAryFunctionType n) | def mkNAryFunctionType : Nat → MetaM Expr
| 0 => mkFreshTypeMVar
| n+1 => do withLocalDeclD `x (← mkFreshTypeMVar) fun x => do
mkForallFVars #[x] (← mkNAryFunctionType n) | def | definition | mkNAryFunctionType | Root | Qq/Match.lean | [] | [
"n"
] | null | 154 | 157 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
structure PatternVar where
name : Name
/-- Pattern variables can be functions; if so, this is their arity. -/
arity : Nat
mvar : Expr
stx : Term | structure PatternVar where
name : Name
/-- Pattern variables can be functions; if so, this is their arity. -/
arity : Nat
mvar : Expr
stx : Term | structure | structure | PatternVar | Root | Qq/Match.lean | [] | [] | null | 159 | 164 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
partial def getPatVars (pat : Term) : StateT (Array PatternVar) TermElabM Term := do
match pat with
| `($fn $args*) => if isPatVar fn then return ← mkMVar fn args
| _ => if isPatVar pat then return ← mkMVar pat #[]
match pat with
| ⟨.node info kind args⟩ => return ⟨.node info kind (← args.mapM (getPatVa... | partial def getPatVars (pat : Term) : StateT (Array PatternVar) TermElabM Term | do
match pat with
| `($fn $args*) => if isPatVar fn then return ← mkMVar fn args
| _ => if isPatVar pat then return ← mkMVar pat #[]
match pat with
| ⟨.node info kind args⟩ => return ⟨.node info kind (← args.mapM (getPatVars ⟨·⟩))⟩
| pat => return pat
where
isPatVar (fn : Syntax) : Bool :=
... | def | definition | getPatVars | Root | Qq/Match.lean | [] | [
"PatternVar",
"m",
"mkNAryFunctionType",
"pat",
"push"
] | null | 166 | 188 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def elabPat (pat : Term) (lctx : LocalContext) (localInsts : LocalInstances) (ty : Expr)
(levelNames : List Name) : TermElabM (Expr × Array LocalDecl × Array Name) :=
withLCtx lctx localInsts do
withLevelNames levelNames do
let (pat, patVars) ← getPatVars pat #[]
let pat ← Lean.Elab.Term.e... | def elabPat (pat : Term) (lctx : LocalContext) (localInsts : LocalInstances) (ty : Expr)
(levelNames : List Name) : TermElabM (Expr × Array LocalDecl × Array Name) | withLCtx lctx localInsts do
withLevelNames levelNames do
let (pat, patVars) ← getPatVars pat #[]
let pat ← Lean.Elab.Term.elabTerm pat ty
let pat ← ensureHasType ty pat
synthesizeSyntheticMVars (postpone := .no)
let pat ← instantiateMVars pat
let mctx ← g... | def | definition | elabPat | Root | Qq/Match.lean | [] | [
"getPatVars",
"pat",
"sortLocalDecls"
] | null | 189 | 225 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
scoped elab "_qq_match" pat:term " ← " e:term " | " alt:term " in " body:term : term <= expectedType => do
let emr ← extractBind expectedType
let alt ← elabTermEnsuringType alt expectedType
let argLvlExpr ← mkFreshExprMVarQ q(Level)
let argTyExpr ← mkFreshExprMVarQ q(Quoted (.sort $argLvlExpr))
let e' ← elab... | scoped elab "_qq_match" pat:term " ← " e:term " | " alt:term " in " body:term : term <= expectedType => do
let emr ← extractBind expectedType
let alt ← elabTermEnsuringType alt expectedType
let argLvlExpr ← mkFreshExprMVarQ q(Level)
let argTyExpr ← mkFreshExprMVarQ q(Quoted (.sort $argLvlExpr))
let e' ← elab... | s
let mut oldPatVarDecls : List PatVarDecl := []
for newLevel in newLevels do
let fvarId := FVarId.mk (← mkFreshId)
oldPatVarDecls := oldPatVarDecls ++ [{ ty := none, fvarId := fvarId, userName := newLevel }]
s := { s with levelBackSubst := s.levelBackSubst.insert (.param newLevel) (.fvar fvarId) }
f... | elab | other | pat | Root | Qq/Match.lean | [] | [
"PatVarDecl",
"Quoted",
"Quoted.unsafeMk",
"e",
"elabPat",
"elabTermEnsuringTypeQ",
"extractBind",
"instantiateMVarsQ",
"m",
"makeMatchCode",
"mkFreshExprMVarQ",
"synthInstanceQ",
"unquoteForMatch"
] | null | 227 | 258 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
macro_rules
| `(assert! (_qq_match $pat := $e | $alt); $x) =>
`(_qq_match $pat ← $e | (do $alt:doSeqIndent) in $x) | macro_rules
| `(assert! (_qq_match $pat := $e | $alt); $x) =>
`(_qq_match $pat ← $e | (do $alt:doSeqIndent) in $x) | macro_rules | definition | Root | Qq/Match.lean | [] | [
"e",
"pat"
] | null | 261 | 263 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
partial def isIrrefutablePattern : Term → Bool
| `(($stx)) => isIrrefutablePattern stx
| `(⟨$args,*⟩) => args.getElems.all isIrrefutablePattern
| `(($a, $b)) => isIrrefutablePattern a && isIrrefutablePattern b
| `(_) => true
| `(true) => false | `(false) => false -- TODO properly
| stx => stx.1.isIdent | partial def isIrrefutablePattern : Term → Bool
| `(($stx)) => isIrrefutablePattern stx
| `(⟨$args,*⟩) => args.getElems.all isIrrefutablePattern
| `(($a, $b)) => isIrrefutablePattern a && isIrrefutablePattern b
| `(_) => true
| `(true) => false | `(false) => false -- TODO properly
| stx => stx.1.isIdent | def | definition | isIrrefutablePattern | Root | Qq/Match.lean | [] | [] | null | 265 | 271 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
scoped elab "_comefrom" n:ident "do" b:doSeq " in " body:term : term <= expectedType => do
let _ ← extractBind expectedType
let ty ← exprToSyntax expectedType
elabTerm (← `(have $n:ident : $ty := (do $b:doSeq); $body)) expectedType | scoped elab "_comefrom" n:ident "do" b:doSeq " in " body:term : term <= expectedType => do
let _ ← extractBind expectedType
let ty ← exprToSyntax expectedType
elabTerm (← `(have $n:ident : $ty := (do $b:doSeq); $body)) expectedType | elab | other | n | Root | Qq/Match.lean | [] | [
"extractBind"
] | null | 273 | 276 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
macro_rules | `(assert! (_comefrom $n do $b); $body) => `(_comefrom $n do $b in $body)
-- The point of this macro as SG sees it is to get the do block result type to push it into `$b` | macro_rules | `(assert! (_comefrom $n do $b); $body) => `(_comefrom $n do $b in $body)
-- The point of this macro as SG sees it is to get the do block result type to push it into `$b` | macro_rules | definition | Root | Qq/Match.lean | [] | [
"n",
"push"
] | null | 279 | 281 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
scoped macro "comefrom" n:ident "do" b:doSeq : doElem =>
`(doElem| assert! (_comefrom $n do $b)) | scoped macro "comefrom" n:ident "do" b:doSeq : doElem =>
`(doElem| assert! (_comefrom $n do $b)) | macro | definition | n | Root | Qq/Match.lean | [] | [] | null | 282 | 283 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
partial def Impl.hasQMatch : Syntax → Bool
| `(~q($_)) => true
| stx => stx.getArgs.any hasQMatch | partial def Impl.hasQMatch : Syntax → Bool
| `(~q($_)) => true
| stx => stx.getArgs.any hasQMatch | def | definition | Impl.hasQMatch | Root | Qq/Match.lean | [] | [] | null | 326 | 328 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
partial def Impl.floatQMatch (alt : TSyntax ``doSeqIndent) : Term → StateT (List (TSyntax ``doSeqItem)) MacroM Term
| `(~q($term)) =>
withFreshMacroScope do
let auxDoElem ← `(doSeqItem| let ~q($term) := x | $alt)
modify fun s => s ++ [auxDoElem]
`(x)
| stx => do match stx with
| ⟨.node i k... | partial def Impl.floatQMatch (alt : TSyntax ``doSeqIndent) : Term → StateT (List (TSyntax ``doSeqItem)) MacroM Term
| `(~q($term)) =>
withFreshMacroScope do
let auxDoElem ← `(doSeqItem| let ~q($term) := x | $alt)
modify fun s => s ++ [auxDoElem]
`(x)
| stx => do match stx with
| ⟨.node i k... | def | definition | Impl.floatQMatch | Root | Qq/Match.lean | [] | [
"k"
] | null | 330 | 338 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
private def push (i : TSyntax ``doSeqItem) : StateT (Array (TSyntax ``doSeqItem)) MacroM Unit :=
modify fun s => s.push i | private def push (i : TSyntax ``doSeqItem) : StateT (Array (TSyntax ``doSeqItem)) MacroM Unit | modify fun s => s.push i | def | definition | push | Root | Qq/Match.lean | [] | [] | null | 340 | 341 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
partial def unpackParensIdent : Syntax → Option Syntax
| `(($stx)) => unpackParensIdent stx
| stx => if stx.isIdent then some stx else none | partial def unpackParensIdent : Syntax → Option Syntax
| `(($stx)) => unpackParensIdent stx
| stx => if stx.isIdent then some stx else none | def | definition | unpackParensIdent | Root | Qq/Match.lean | [] | [] | null | 343 | 345 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
private partial def floatLevelAntiquot (stx : Syntax.Level) : StateT (Array (TSyntax ``doSeqItem)) MacroM Syntax.Level :=
if stx.1.isAntiquot && !stx.1.isEscapedAntiquot then
if !stx.1.getAntiquotTerm.isIdent then
withFreshMacroScope do
push <| ← `(doSeqItem| let u : Level := $(⟨stx.1.getAntiquotTer... | private partial def floatLevelAntiquot (stx : Syntax.Level) : StateT (Array (TSyntax ``doSeqItem)) MacroM Syntax.Level | if stx.1.isAntiquot && !stx.1.isEscapedAntiquot then
if !stx.1.getAntiquotTerm.isIdent then
withFreshMacroScope do
push <| ← `(doSeqItem| let u : Level := $(⟨stx.1.getAntiquotTerm⟩))
`(level| u)
else
pure stx
else
match stx with
| ⟨.node i k args⟩ => return ⟨Syntax.node i k... | def | definition | floatLevelAntiquot | Root | Qq/Match.lean | [] | [
"k",
"push"
] | null | 347 | 358 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
private partial def floatExprAntiquot (depth : Nat) : Term → StateT (Array (TSyntax ``doSeqItem)) MacroM Term
| `(Q($x)) => do `(Q($(← floatExprAntiquot (depth + 1) x)))
| `(q($x)) => do `(q($(← floatExprAntiquot (depth + 1) x)))
| `(Type $term) => do `(Type $(← floatLevelAntiquot term))
| `(Sort $term) => do `... | private partial def floatExprAntiquot (depth : Nat) : Term → StateT (Array (TSyntax ``doSeqItem)) MacroM Term
| `(Q($x)) => do `(Q($(← floatExprAntiquot (depth + 1) x)))
| `(q($x)) => do `(q($(← floatExprAntiquot (depth + 1) x)))
| `(Type $term) => do `(Type $(← floatLevelAntiquot term))
| `(Sort $term) => do `... | ⟨stx.1.getAntiquotTerm⟩
if term.1.isIdent then
return stx
else if depth > 0 then
return ⟨.mkAntiquotNode stx.1.antiquotKind?.get!.1 (← floatExprAntiquot (depth - 1) term)⟩
else
match unpackParensIdent stx.1.getAntiquotTerm with
| some id =>
if id.getId.isA... | def | definition | floatExprAntiquot | Root | Qq/Match.lean | [] | [
"Quoted",
"floatLevelAntiquot",
"k",
"push",
"unpackParensIdent"
] | null | 360 | 384 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
macro_rules
| `(doElem| let $pat:term := $_) => do
if !hasQMatch pat then Macro.throwUnsupported
Macro.throwError "let-bindings with ~q(.) require an explicit alternative"
| `(doElem| let $pat:term := $rhs:term | $alt $(body?)?) => do
if !hasQMatch pat then Macro.throwUnsupported
match pat with
... | macro_rules
| `(doElem| let $pat:term := $_) => do
if !hasQMatch pat then Macro.throwUnsupported
Macro.throwError "let-bindings with ~q(.) require an explicit alternative"
| `(doElem| let $pat:term := $rhs:term | $alt $(body?)?) => do
if !hasQMatch pat then Macro.throwUnsupported
match pat with
... | lifts.push t
if let some body := body? then
items := items.push (← `(doSeqItem| do $body:doSeqIndent))
`(doElem| do $items:doSeqItem*)
| _ =>
let (pat', auxs) ← floatQMatch (← `(doSeqIndent| __alt)) pat []
-- Build the nested body from inside out, so that every `doLetEls... | macro_rules | definition | Root | Qq/Match.lean | [] | [
"floatExprAntiquot",
"isIrrefutablePattern",
"pat",
"t"
] | null | 386 | 450 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
partial def Lean.Syntax.stripPos : Syntax → Syntax
| atom _ a => atom .none a
| ident _ r v p => ident .none r v p
| node _ kind args => node .none kind (args.map stripPos)
| missing => missing | partial def Lean.Syntax.stripPos : Syntax → Syntax
| atom _ a => atom .none a
| ident _ r v p => ident .none r v p
| node _ kind args => node .none kind (args.map stripPos)
| missing => missing | def | definition | Lean.Syntax.stripPos | Root | Qq/MatchImpl.lean | [] | [] | null | 8 | 12 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
structure PatVarDecl where
ty : Option Q(Expr)
fvarId : FVarId
userName : Name | structure PatVarDecl where
ty : Option Q(Expr)
fvarId : FVarId
userName : Name | structure | structure | PatVarDecl | Root | Qq/MatchImpl.lean | [] | [] | null | 21 | 24 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
@[expose] def PatVarDecl.fvarTy : PatVarDecl → Q(Type)
| { ty := none, .. } => q(Level)
| { ty := some _, .. } => q(Expr) | @[expose] def PatVarDecl.fvarTy : PatVarDecl → Q(Type)
| { ty := none, .. } => q(Level)
| { ty := some _, .. } => q(Expr) | def | definition | PatVarDecl.fvarTy | Root | Qq/MatchImpl.lean | [] | [
"PatVarDecl"
] | null | 26 | 28 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
def PatVarDecl.fvar (decl : PatVarDecl) : Q($((decl.fvarTy))) :=
Expr.fvar decl.fvarId | def PatVarDecl.fvar (decl : PatVarDecl) : Q($((decl.fvarTy))) | Expr.fvar decl.fvarId | def | definition | PatVarDecl.fvar | Root | Qq/MatchImpl.lean | [] | [
"PatVarDecl"
] | null | 30 | 31 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[expose] def mkIsDefEqType : List PatVarDecl → Q(Type)
| [] => q(Bool)
| decl :: decls => q($(decl.fvarTy) × $(mkIsDefEqType decls)) | @[expose] def mkIsDefEqType : List PatVarDecl → Q(Type)
| [] => q(Bool)
| decl :: decls => q($(decl.fvarTy) × $(mkIsDefEqType decls)) | def | definition | mkIsDefEqType | Root | Qq/MatchImpl.lean | [] | [
"PatVarDecl"
] | null | 33 | 35 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
@[expose] def mkIsDefEqResult (val : Bool) : (decls : List PatVarDecl) → Q($(mkIsDefEqType decls))
| [] => show Q(Bool) from q($val)
| decl :: decls => q(($(decl.fvar), $(mkIsDefEqResult val decls))) | @[expose] def mkIsDefEqResult (val : Bool) : (decls : List PatVarDecl) → Q($(mkIsDefEqType decls))
| [] => show Q(Bool) from q($val)
| decl :: decls => q(($(decl.fvar), $(mkIsDefEqResult val decls))) | def | definition | mkIsDefEqResult | Root | Qq/MatchImpl.lean | [] | [
"PatVarDecl",
"mkIsDefEqType"
] | null | 37 | 39 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
@[expose] def mkIsDefEqResultVal : (decls : List PatVarDecl) → Q($(mkIsDefEqType decls)) → Q(Bool)
| [], val => q($val)
| _ :: decls, val => mkIsDefEqResultVal decls q($val.2) | @[expose] def mkIsDefEqResultVal : (decls : List PatVarDecl) → Q($(mkIsDefEqType decls)) → Q(Bool)
| [], val => q($val)
| _ :: decls, val => mkIsDefEqResultVal decls q($val.2) | def | definition | mkIsDefEqResultVal | Root | Qq/MatchImpl.lean | [] | [
"PatVarDecl",
"mkIsDefEqType"
] | null | 41 | 43 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
def mkLambda' (n : Name) (fvar : Expr) (ty : Expr) (body : Expr) : MetaM Expr :=
return mkLambda n BinderInfo.default ty (← body.abstractM #[fvar]) | def mkLambda' (n : Name) (fvar : Expr) (ty : Expr) (body : Expr) : MetaM Expr | return mkLambda n BinderInfo.default ty (← body.abstractM #[fvar]) | def | definition | mkLambda' | Root | Qq/MatchImpl.lean | [] | [
"n"
] | null | 45 | 46 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkLet' (n : Name) (fvar : Expr) (ty : Expr) (val : Expr) (body : Expr) : MetaM Expr :=
return mkLet n ty val (← body.abstractM #[fvar]) | def mkLet' (n : Name) (fvar : Expr) (ty : Expr) (val : Expr) (body : Expr) : MetaM Expr | return mkLet n ty val (← body.abstractM #[fvar]) | def | definition | mkLet' | Root | Qq/MatchImpl.lean | [] | [
"n"
] | null | 48 | 49 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkLambdaQ (n : Name) (fvar : Quoted α) (body : Quoted β) : MetaM (Quoted (.forallE n α β .default)) :=
return mkLambda n BinderInfo.default α (← body.abstractM #[fvar]) | def mkLambdaQ (n : Name) (fvar : Quoted α) (body : Quoted β) : MetaM (Quoted (.forallE n α β .default)) | return mkLambda n BinderInfo.default α (← body.abstractM #[fvar]) | def | definition | mkLambdaQ | Root | Qq/MatchImpl.lean | [] | [
"Quoted",
"n"
] | null | 51 | 52 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def mkFreshExprMVarQ (ty : Q(Sort u)) (kind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Q($ty) := do
mkFreshExprMVar (some ty) kind userName | def mkFreshExprMVarQ (ty : Q(Sort u)) (kind := MetavarKind.natural) (userName := Name.anonymous) : MetaM Q($ty) | do
mkFreshExprMVar (some ty) kind userName | def | definition | mkFreshExprMVarQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [] | null | 20 | 21 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def withLocalDeclDQ [Monad n] [MonadControlT MetaM n] (name : Name) (β : Q(Sort u)) (k : Q($β) → n α) : n α :=
withLocalDeclD name β k | def withLocalDeclDQ [Monad n] [MonadControlT MetaM n] (name : Name) (β : Q(Sort u)) (k : Q($β) → n α) : n α | withLocalDeclD name β k | def | definition | withLocalDeclDQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"k",
"n"
] | null | 23 | 24 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def withLocalDeclQ [Monad n] [MonadControlT MetaM n] (name : Name) (bi : BinderInfo) (β : Q(Sort u)) (k : Q($β) → n α) : n α :=
withLocalDecl name bi β k | def withLocalDeclQ [Monad n] [MonadControlT MetaM n] (name : Name) (bi : BinderInfo) (β : Q(Sort u)) (k : Q($β) → n α) : n α | withLocalDecl name bi β k | def | definition | withLocalDeclQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"k",
"n"
] | null | 26 | 27 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def synthInstanceQ? (α : Q(Sort u)) : MetaM (Option Q($α)) := do
synthInstance? α | def synthInstanceQ? (α : Q(Sort u)) : MetaM (Option Q($α)) | do
synthInstance? α | def | definition | synthInstanceQ? | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [] | null | 29 | 30 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def trySynthInstanceQ (α : Q(Sort u)) : MetaM (LOption Q($α)) := do
trySynthInstance α | def trySynthInstanceQ (α : Q(Sort u)) : MetaM (LOption Q($α)) | do
trySynthInstance α | def | definition | trySynthInstanceQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [] | null | 32 | 33 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def synthInstanceQ (α : Q(Sort u)) : MetaM Q($α) := do
synthInstance α | def synthInstanceQ (α : Q(Sort u)) : MetaM Q($α) | do
synthInstance α | def | definition | synthInstanceQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [] | null | 35 | 36 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def instantiateMVarsQ {α : Q(Sort u)} (e : Q($α)) : MetaM Q($α) := do
instantiateMVars e | def instantiateMVarsQ {α : Q(Sort u)} (e : Q($α)) : MetaM Q($α) | do
instantiateMVars e | def | definition | instantiateMVarsQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"e"
] | null | 38 | 39 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def elabTermEnsuringTypeQ (stx : Syntax) (expectedType : Q(Sort u))
(catchExPostpone := true) (implicitLambda := true) (errorMsgHeader? : Option String := none) :
TermElabM Q($expectedType) := do
elabTermEnsuringType stx (some expectedType) catchExPostpone implicitLambda errorMsgHeader?
/--
A `Qq`-ified vers... | def elabTermEnsuringTypeQ (stx : Syntax) (expectedType : Q(Sort u))
(catchExPostpone := true) (implicitLambda := true) (errorMsgHeader? : Option String := none) :
TermElabM Q($expectedType) | do
elabTermEnsuringType stx (some expectedType) catchExPostpone implicitLambda errorMsgHeader?
/--
A `Qq`-ified version of `Lean.Meta.inferType`
Instead of writing `let α ← inferType e`, this allows writing `let ⟨u, α, e⟩ ← inferTypeQ e`,
which results in a context of
```
e✝ : Expr
u : Level
α : Q(Type u)
e : Q($α)... | def | definition | elabTermEnsuringTypeQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"e",
"inferTypeQ"
] | null | 41 | 61 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def inferTypeQ (e : Expr) : MetaM ((u : Level) × (α : Q(Sort $u)) × Q($α)) := do
let α ← inferType e
let .sort u ← whnf (← inferType α) | throwError "not a type{indentExpr α}"
pure ⟨u, α, e⟩
/-- If `e` is a `ty`, then view it as a term of `Q($ty)`. -/ | def inferTypeQ (e : Expr) : MetaM ((u : Level) × (α : Q(Sort $u)) × Q($α)) | do
let α ← inferType e
let .sort u ← whnf (← inferType α) | throwError "not a type{indentExpr α}"
pure ⟨u, α, e⟩
/-- If `e` is a `ty`, then view it as a term of `Q($ty)`. -/ | def | definition | inferTypeQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"e"
] | A `Qq`-ified version of `Lean.Meta.inferType`
Instead of writing `let α ← inferType e`, this allows writing `let ⟨u, α, e⟩ ← inferTypeQ e`,
which results in a context of
```
e✝ : Expr
u : Level
α : Q(Type u)
e : Q($α)
```
Here, the new `e` is defeq to the old one, but now has `Qq`-ascribed type information.
This is f... | 62 | 67 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def checkTypeQ (e : Expr) (ty : Q(Sort $u)) : MetaM (Option Q($ty)) := do
if ← isDefEq (← inferType e) ty then
return some e
else
return none
/-- The result of `Qq.isDefEqQ`; `MaybeDefEq a b` is an optional version of `$a =Q $b`. -/ | def checkTypeQ (e : Expr) (ty : Q(Sort $u)) : MetaM (Option Q($ty)) | do
if ← isDefEq (← inferType e) ty then
return some e
else
return none
/-- The result of `Qq.isDefEqQ`; `MaybeDefEq a b` is an optional version of `$a =Q $b`. -/ | def | definition | checkTypeQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"MaybeDefEq",
"e"
] | If `e` is a `ty`, then view it as a term of `Q($ty)`. | 68 | 74 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
inductive MaybeDefEq {α : Q(Sort $u)} (a b : Q($α)) where
| defEq : QuotedDefEq a b → MaybeDefEq a b
| notDefEq : MaybeDefEq a b | inductive MaybeDefEq {α : Q(Sort $u)} (a b : Q($α)) where
| defEq : QuotedDefEq a b → MaybeDefEq a b
| notDefEq : MaybeDefEq a b | inductive | inductive | MaybeDefEq | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"QuotedDefEq"
] | The result of `Qq.isDefEqQ`; `MaybeDefEq a b` is an optional version of `$a =Q $b`. | 75 | 77 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : Repr (MaybeDefEq a b) where
reprPrec := fun
| .defEq _, prec => Repr.addAppParen "defEq _" prec
| .notDefEq, _ => "notDefEq"
/-- A version of `Lean.Meta.isDefEq` which returns a strongly-typed witness rather than a bool. -/ | instance : Repr (MaybeDefEq a b) where
reprPrec := fun
| .defEq _, prec => Repr.addAppParen "defEq _" prec
| .notDefEq, _ => "notDefEq"
/-- A version of `Lean.Meta.isDefEq` which returns a strongly-typed witness rather than a bool. -/ | instance | instance | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"MaybeDefEq"
] | null | 79 | 84 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
def isDefEqQ {α : Q(Sort $u)} (a b : Q($α)) : MetaM (MaybeDefEq a b) := do
if ← isDefEq a b then
return .defEq ⟨⟩
else
return .notDefEq
/-- Like `Qq.isDefEqQ`, but throws an error if not defeq. -/ | def isDefEqQ {α : Q(Sort $u)} (a b : Q($α)) : MetaM (MaybeDefEq a b) | do
if ← isDefEq a b then
return .defEq ⟨⟩
else
return .notDefEq
/-- Like `Qq.isDefEqQ`, but throws an error if not defeq. -/ | def | definition | isDefEqQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"MaybeDefEq"
] | A version of `Lean.Meta.isDefEq` which returns a strongly-typed witness rather than a bool. | 85 | 91 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def assertDefEqQ {α : Q(Sort $u)} (a b : Q($α)) : MetaM (PLift (QuotedDefEq a b)) := do
match ← isDefEqQ a b with
| .defEq witness => return ⟨witness⟩
| .notDefEq => throwError "{a} is not definitionally equal to{indentExpr b}"
/-- The result of `Qq.isLevelDefEqQ`; `MaybeLevelDefEq u v` is an optional version of... | def assertDefEqQ {α : Q(Sort $u)} (a b : Q($α)) : MetaM (PLift (QuotedDefEq a b)) | do
match ← isDefEqQ a b with
| .defEq witness => return ⟨witness⟩
| .notDefEq => throwError "{a} is not definitionally equal to{indentExpr b}"
/-- The result of `Qq.isLevelDefEqQ`; `MaybeLevelDefEq u v` is an optional version of `$u =QL $v`. -/ | def | definition | assertDefEqQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"MaybeLevelDefEq",
"QuotedDefEq",
"isDefEqQ"
] | Like `Qq.isDefEqQ`, but throws an error if not defeq. | 92 | 97 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
inductive MaybeLevelDefEq (u v : Level) where
| defEq : QuotedLevelDefEq u v → MaybeLevelDefEq u v
| notDefEq : MaybeLevelDefEq u v | inductive MaybeLevelDefEq (u v : Level) where
| defEq : QuotedLevelDefEq u v → MaybeLevelDefEq u v
| notDefEq : MaybeLevelDefEq u v | inductive | inductive | MaybeLevelDefEq | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"QuotedLevelDefEq"
] | The result of `Qq.isLevelDefEqQ`; `MaybeLevelDefEq u v` is an optional version of `$u =QL $v`. | 98 | 100 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : Repr (MaybeLevelDefEq u v) where
reprPrec := fun
| .defEq _, prec => Repr.addAppParen "defEq _" prec
| .notDefEq, _ => "notDefEq"
/-- A version of `Lean.Meta.isLevelDefEq` which returns a strongly-typed witness rather than a bool. -/ | instance : Repr (MaybeLevelDefEq u v) where
reprPrec := fun
| .defEq _, prec => Repr.addAppParen "defEq _" prec
| .notDefEq, _ => "notDefEq"
/-- A version of `Lean.Meta.isLevelDefEq` which returns a strongly-typed witness rather than a bool. -/ | instance | instance | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"MaybeLevelDefEq"
] | null | 102 | 107 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
def isLevelDefEqQ (u v : Level) : MetaM (MaybeLevelDefEq u v) := do
if ← isLevelDefEq u v then
return .defEq ⟨⟩
else
return .notDefEq
/-- Like `Qq.isLevelDefEqQ`, but throws an error if not defeq. -/ | def isLevelDefEqQ (u v : Level) : MetaM (MaybeLevelDefEq u v) | do
if ← isLevelDefEq u v then
return .defEq ⟨⟩
else
return .notDefEq
/-- Like `Qq.isLevelDefEqQ`, but throws an error if not defeq. -/ | def | definition | isLevelDefEqQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"MaybeLevelDefEq"
] | A version of `Lean.Meta.isLevelDefEq` which returns a strongly-typed witness rather than a bool. | 108 | 114 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def assertLevelDefEqQ (u v : Level) : MetaM (PLift (QuotedLevelDefEq u v)) := do
match ← isLevelDefEqQ u v with
| .defEq witness => return ⟨witness⟩
| .notDefEq => throwError "{u} and {v} are not definitionally equal" | def assertLevelDefEqQ (u v : Level) : MetaM (PLift (QuotedLevelDefEq u v)) | do
match ← isLevelDefEqQ u v with
| .defEq witness => return ⟨witness⟩
| .notDefEq => throwError "{u} and {v} are not definitionally equal" | def | definition | assertLevelDefEqQ | Root | Qq/MetaM.lean | [
"Lean.Meta.SynthInstance",
"Lean.Elab.Term.TermElabM"
] | [
"QuotedLevelDefEq",
"isLevelDefEqQ"
] | Like `Qq.isLevelDefEqQ`, but throws an error if not defeq. | 115 | 118 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[expose] def ResultQ (_e : Q($α)) : Type := Lean.Meta.Simp.Result
/-- A copy of `Meta.Simp.Result.mk` with explicit types. -/ | @[expose] def ResultQ (_e : Q($α)) : Type | Lean.Meta.Simp.Result
/-- A copy of `Meta.Simp.Result.mk` with explicit types. -/ | def | definition | ResultQ | Root | Qq/Simp.lean | [] | [] | A copy of `Meta.Simp.Result` with explicit types. | 32 | 34 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[inline] def ResultQ.mk {e : Q($α)}
(expr : Q($α))
(proof? : Option Q($e = $expr))
(cache : Bool := true) : ResultQ e :=
{expr, proof?, cache}
/-- A copy of `Meta.Simp.Step` with explicit types. -/ | @[inline] def ResultQ.mk {e : Q($α)}
(expr : Q($α))
(proof? : Option Q($e = $expr))
(cache : Bool := true) : ResultQ e | {expr, proof?, cache}
/-- A copy of `Meta.Simp.Step` with explicit types. -/ | def | definition | ResultQ.mk | Root | Qq/Simp.lean | [] | [
"ResultQ",
"e"
] | A copy of `Meta.Simp.Result.mk` with explicit types. | 35 | 41 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[expose] def StepQ (_e : Q($α)) : Type := Step | @[expose] def StepQ (_e : Q($α)) : Type | Step | def | definition | StepQ | Root | Qq/Simp.lean | [] | [] | A copy of `Meta.Simp.Step` with explicit types. | 42 | 42 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[inherit_doc Step.done, inline]
def StepQ.done {e : Q($α)} (r : ResultQ e) : StepQ e := Step.done r | @[inherit_doc Step.done, inline]
def StepQ.done {e : Q($α)} (r : ResultQ e) : StepQ e | Step.done r | def | definition | StepQ.done | Root | Qq/Simp.lean | [] | [
"ResultQ",
"StepQ",
"e"
] | null | 44 | 45 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[inherit_doc Step.visit, inline]
def StepQ.visit {e : Q($α)} (r : ResultQ e) : StepQ e := Step.visit r | @[inherit_doc Step.visit, inline]
def StepQ.visit {e : Q($α)} (r : ResultQ e) : StepQ e | Step.visit r | def | definition | StepQ.visit | Root | Qq/Simp.lean | [] | [
"ResultQ",
"StepQ",
"e"
] | null | 46 | 47 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[inherit_doc Step.continue, inline]
def StepQ.continue {e : Q($α)} (r : Option (ResultQ e) := none) : StepQ e := Step.continue r
/-- A copy of `Lean.Meta.Simproc` with explicit types.
See `Simproc.ofQ` to construct terms of this type. -/ | @[inherit_doc Step.continue, inline]
def StepQ.continue {e : Q($α)} (r : Option (ResultQ e) := none) : StepQ e | Step.continue r
/-- A copy of `Lean.Meta.Simproc` with explicit types.
See `Simproc.ofQ` to construct terms of this type. -/ | def | definition | StepQ.continue | Root | Qq/Simp.lean | [] | [
"ResultQ",
"Simproc.ofQ",
"StepQ",
"e"
] | null | 48 | 53 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
abbrev SimprocQ : Type := ∀ (u : Level) (α : Q(Sort u)) (e : Q($α)), Meta.SimpM (StepQ e)
/-- Build a simproc with Qq-enabled typechecking of inputs and outputs.
This calls `inferTypeQ` on the expression and passes the arguments to `proc`. -/ | abbrev SimprocQ : Type | ∀ (u : Level) (α : Q(Sort u)) (e : Q($α)), Meta.SimpM (StepQ e)
/-- Build a simproc with Qq-enabled typechecking of inputs and outputs.
This calls `inferTypeQ` on the expression and passes the arguments to `proc`. -/ | abbrev | definition | SimprocQ | Root | Qq/Simp.lean | [] | [
"StepQ",
"e",
"inferTypeQ"
] | A copy of `Lean.Meta.Simproc` with explicit types.
See `Simproc.ofQ` to construct terms of this type. | 54 | 58 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[inline] def Simproc.ofQ (proc : SimprocQ) : Simproc := fun e => do
let ⟨u, α, e⟩ ← inferTypeQ e
proc u α e | @[inline] def Simproc.ofQ (proc : SimprocQ) : Simproc | fun e => do
let ⟨u, α, e⟩ ← inferTypeQ e
proc u α e | def | definition | Simproc.ofQ | Root | Qq/Simp.lean | [] | [
"SimprocQ",
"e",
"inferTypeQ"
] | Build a simproc with Qq-enabled typechecking of inputs and outputs.
This calls `inferTypeQ` on the expression and passes the arguments to `proc`. | 59 | 61 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
structure Context where
localDecls : NameMap LocalDecl := {} | structure Context where
localDecls : NameMap LocalDecl := {} | structure | structure | Context | Root | Qq/SortLocalDecls.lean | [] | [] | null | 18 | 19 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
structure State where
visited : NameSet := {}
result : Array LocalDecl := #[] | structure State where
visited : NameSet := {}
result : Array LocalDecl := #[] | structure | structure | State | Root | Qq/SortLocalDecls.lean | [] | [] | null | 21 | 23 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
abbrev M := ReaderT Context $ StateRefT State MetaM | abbrev M | ReaderT Context $ StateRefT State MetaM | abbrev | definition | M | Root | Qq/SortLocalDecls.lean | [] | [
"Context",
"State"
] | null | 25 | 25 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
partial def visitExpr (e : Expr) : M Unit := do
match e with
| .proj _ _ e => visitExpr e
| .forallE _ d b _ => visitExpr d; visitExpr b
| .lam _ d b _ => visitExpr d; visitExpr b
| .letE _ t v b _ => visitExpr t; visitExpr v; visitExpr b
| .app f a => visitExpr f; visitExpr a
... | partial def visitExpr (e : Expr) : M Unit | do
match e with
| .proj _ _ e => visitExpr e
| .forallE _ d b _ => visitExpr d; visitExpr b
| .lam _ d b _ => visitExpr d; visitExpr b
| .letE _ t v b _ => visitExpr t; visitExpr v; visitExpr b
| .app f a => visitExpr f; visitExpr a
| .mdata _ b => visitExpr b
| .mvar _... | def | definition | visitExpr | Root | Qq/SortLocalDecls.lean | [] | [
"M",
"e",
"t",
"visitLocalDecl"
] | null | 28 | 38 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
partial def visitLocalDecl (localDecl : LocalDecl) : M Unit := do
unless (← get).visited.contains localDecl.fvarId.name do
modify fun s => { s with visited := s.visited.insert localDecl.fvarId.name }
visitExpr localDecl.type
if let some val := localDecl.value? then
visitExpr val
modi... | partial def visitLocalDecl (localDecl : LocalDecl) : M Unit | do
unless (← get).visited.contains localDecl.fvarId.name do
modify fun s => { s with visited := s.visited.insert localDecl.fvarId.name }
visitExpr localDecl.type
if let some val := localDecl.value? then
visitExpr val
modify fun s => { s with result := s.result.push localDecl } | def | definition | visitLocalDecl | Root | Qq/SortLocalDecls.lean | [] | [
"M",
"visitExpr"
] | null | 40 | 46 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
def sortLocalDecls (localDecls : Array LocalDecl) : MetaM (Array LocalDecl) :=
let aux : M (Array LocalDecl) := do localDecls.forM visitLocalDecl; return (← get).result
aux.run { localDecls := localDecls.foldl (init := {}) fun s d => s.insert d.fvarId.name d } |>.run' {} | def sortLocalDecls (localDecls : Array LocalDecl) : MetaM (Array LocalDecl) | let aux : M (Array LocalDecl) := do localDecls.forM visitLocalDecl; return (← get).result
aux.run { localDecls := localDecls.foldl (init := {}) fun s d => s.insert d.fvarId.name d } |>.run' {} | def | definition | sortLocalDecls | Root | Qq/SortLocalDecls.lean | [] | [
"M",
"visitLocalDecl"
] | null | 52 | 54 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[expose] def Quoted (α : Expr) := Expr
/--
Creates a quoted expression. Requires that `e` has type `α`.
You should usually write this using the notation `q($e)`.
-/ | @[expose] def Quoted (α : Expr) | Expr
/--
Creates a quoted expression. Requires that `e` has type `α`.
You should usually write this using the notation `q($e)`.
-/ | def | definition | Quoted | Root | Qq/Typ.lean | [] | [
"e"
] | `Quoted α` is the type of Lean expressions having type `α`.
You should usually write this using the notation `Q($α)`. | 17 | 23 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
@[expose] protected def Quoted.unsafeMk (e : Expr) : Quoted α := e | @[expose] protected def Quoted.unsafeMk (e : Expr) : Quoted α | e | def | definition | Quoted.unsafeMk | Root | Qq/Typ.lean | [] | [
"Quoted",
"e"
] | Creates a quoted expression. Requires that `e` has type `α`.
You should usually write this using the notation `q($e)`. | 24 | 24 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
instance : BEq (Quoted α) := inferInstanceAs (BEq Expr) | instance : BEq (Quoted α) | inferInstanceAs (BEq Expr) | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 26 | 26 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : Hashable (Quoted α) := inferInstanceAs (Hashable Expr) | instance : Hashable (Quoted α) | inferInstanceAs (Hashable Expr) | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 27 | 27 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : Inhabited (Quoted α) := inferInstanceAs (Inhabited Expr) | instance : Inhabited (Quoted α) | inferInstanceAs (Inhabited Expr) | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 28 | 28 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : ToString (Quoted α) := inferInstanceAs (ToString Expr) | instance : ToString (Quoted α) | inferInstanceAs (ToString Expr) | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 29 | 29 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : Repr (Quoted α) := inferInstanceAs (Repr Expr) | instance : Repr (Quoted α) | inferInstanceAs (Repr Expr) | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 30 | 30 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
instance : CoeOut (Quoted α) Expr where coe e := e | instance : CoeOut (Quoted α) Expr where coe e := e | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted",
"e"
] | null | 32 | 32 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
instance : CoeOut (Quoted α) MessageData where coe := .ofExpr | instance : CoeOut (Quoted α) MessageData where coe := .ofExpr | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 33 | 33 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
instance : ToMessageData (Quoted α) where toMessageData := .ofExpr
/-- Gets the type of a quoted expression. -/ | instance : ToMessageData (Quoted α) where toMessageData := .ofExpr
/-- Gets the type of a quoted expression. -/ | instance | instance | Root | Qq/Typ.lean | [] | [
"Quoted"
] | null | 34 | 36 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | ||
protected abbrev Quoted.ty (t : Quoted α) : Expr := α
/--
`QuotedDefEq lhs rhs` says that the expressions `lhs` and `rhs` are definitionally equal.
You should usually write this using the notation `$lhs =Q $rhs`.
-/ | protected abbrev Quoted.ty (t : Quoted α) : Expr | α
/--
`QuotedDefEq lhs rhs` says that the expressions `lhs` and `rhs` are definitionally equal.
You should usually write this using the notation `$lhs =Q $rhs`.
-/ | abbrev | definition | Quoted.ty | Root | Qq/Typ.lean | [] | [
"Quoted",
"QuotedDefEq",
"t"
] | Gets the type of a quoted expression. | 37 | 43 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
structure QuotedDefEq {α : Quoted (.sort u)} (lhs rhs : Quoted α) : Prop where
/-- For a safer constructor, see `Qq.assertDefEqQ`. -/
unsafeIntro ::
/--
`QuotedLevelDefEq u v` says that the levels `u` and `v` are definitionally equal.
You should usually write this using the notation `$u =QL $v`.
-/ | structure QuotedDefEq {α : Quoted (.sort u)} (lhs rhs : Quoted α) : Prop where
/-- For a safer constructor, see `Qq.assertDefEqQ`. -/
unsafeIntro ::
/--
`QuotedLevelDefEq u v` says that the levels `u` and `v` are definitionally equal.
You should usually write this using the notation `$u =QL $v`.
-/ | structure | structure | QuotedDefEq | Root | Qq/Typ.lean | [] | [
"Quoted",
"QuotedLevelDefEq"
] | `QuotedDefEq lhs rhs` says that the expressions `lhs` and `rhs` are definitionally equal.
You should usually write this using the notation `$lhs =Q $rhs`. | 44 | 52 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
structure QuotedLevelDefEq (u v : Level) : Prop where
/-- For a safer constructor, see `Qq.assertLevelDefEqQ`. -/
unsafeIntro :: | structure QuotedLevelDefEq (u v : Level) : Prop where
/-- For a safer constructor, see `Qq.assertLevelDefEqQ`. -/
unsafeIntro :: | structure | structure | QuotedLevelDefEq | Root | Qq/Typ.lean | [] | [] | `QuotedLevelDefEq u v` says that the levels `u` and `v` are definitionally equal.
You should usually write this using the notation `$u =QL $v`. | 53 | 55 | false | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof | |
protected def Quoted.check (e : Quoted α) : MetaM Unit := do
let α' ← inferType e
unless ← isDefEq α α' do
throwError "type mismatch{indentExpr e}\n{← mkHasTypeButIsExpectedMsg α' α}" | protected def Quoted.check (e : Quoted α) : MetaM Unit | do
let α' ← inferType e
unless ← isDefEq α α' do
throwError "type mismatch{indentExpr e}\n{← mkHasTypeButIsExpectedMsg α' α}" | def | definition | Quoted.check | Root | Qq/Typ.lean | [] | [
"Quoted",
"e",
"n"
] | Check that a term `e : Q(α)` really has type `α`. | 59 | 62 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
protected def QuotedDefEq.check (e : @QuotedDefEq u α lhs rhs) : MetaM Unit := do
α.check
lhs.check
rhs.check
unless ← isDefEq lhs rhs do
throwError "{lhs} and {rhs} are not defeq" | protected def QuotedDefEq.check (e : @QuotedDefEq u α lhs rhs) : MetaM Unit | do
α.check
lhs.check
rhs.check
unless ← isDefEq lhs rhs do
throwError "{lhs} and {rhs} are not defeq" | def | definition | QuotedDefEq.check | Root | Qq/Typ.lean | [] | [
"QuotedDefEq",
"e"
] | Check that the claim `$lhs =Q $rhs` is actually true; that the two terms are defeq. | 66 | 71 | true | https://github.com/leanprover-community/quote4 | 8d33324ee877e9735d2829bc6f1f439e60cf98b1 | statement+proof |
Qq provides type-safe expression quotations for constructing object-level expressions in meta-level Lean 4 code.
8d33324ee877e9735d2829bc6f1f439e60cf98b1| Column | Type | Description |
|---|---|---|
| fact | string | Verbatim declaration: statement followed by proof where present |
| statement | string | Verbatim statement (keyword through the closing period) |
| proof | string | Verbatim proof block (Proof. ... Qed./Defined.), empty if none |
| type | string | Raw declaration keyword |
| kind | string | Normalized kind |
| symbolic_name | string | Declaration identifier |
| library | string | Sub-library |
| filename | string | Repository-relative source path |
| imports | list[string] | File-level Require/Import modules |
| deps | list[string] | Intra-corpus identifiers referenced |
| docstring | string | Preceding documentation comment, null if absent |
| line_start | int | First source line |
| line_end | int | Last source line |
| has_proof | bool | Whether a proof block was captured |
| source_url | string | Upstream repository |
| commit | string | Upstream commit extracted |
| content_level | string | statement+proof |
| Type | Count |
|---|---|
| def | 93 |
| instance | 27 |
| macro_rules | 9 |
| example | 8 |
| elab | 7 |
| abbrev | 7 |
| structure | 6 |
| elab_rules | 5 |
| macro | 5 |
| inductive | 3 |
| opaque | 2 |
| class | 1 |
example (a b : Nat) (_h : a = b) : True := by
run_tacq
let p : Q(Prop) := q($a = $b)
trace_state
let t ← Meta.inferType _h
trivial
Statement and proof are available both joined (fact) and split (statement, proof) for
proof-term modeling, autoformalization, retrieval, and dependency analysis via deps.
@misc{lean4_qq_dataset,
title = {Lean4-Qq},
author = {Norton, Charles},
year = {2026},
note = {Extracted from https://github.com/leanprover-community/quote4, commit 8d33324ee877},
url = {https://huggingface.co/datasets/phanerozoic/Lean4-Qq}
}