chore: unused variables
This commit is contained in:
parent
a18c78e617
commit
041827bed5
136 changed files with 348 additions and 427 deletions
|
|
@ -63,7 +63,7 @@ noncomputable def inhabited_of_nonempty {α : Sort u} (h : Nonempty α) : Inhabi
|
|||
⟨choice h⟩
|
||||
|
||||
noncomputable def inhabited_of_exists {α : Sort u} {p : α → Prop} (h : ∃ x, p x) : Inhabited α :=
|
||||
inhabited_of_nonempty (Exists.elim h (fun w hw => ⟨w⟩))
|
||||
inhabited_of_nonempty (Exists.elim h (fun w _ => ⟨w⟩))
|
||||
|
||||
/- all propositions are Decidable -/
|
||||
noncomputable scoped instance (priority := low) propDecidable (a : Prop) : Decidable a :=
|
||||
|
|
@ -87,7 +87,7 @@ noncomputable def strongIndefiniteDescription {α : Sort u} (p : α → Prop) (h
|
|||
(fun (hp : ∃ x : α, p x) =>
|
||||
show {x : α // (∃ y : α, p y) → p x} from
|
||||
let xp := indefiniteDescription _ hp;
|
||||
⟨xp.val, fun h' => xp.property⟩)
|
||||
⟨xp.val, fun _ => xp.property⟩)
|
||||
(fun hp => ⟨choice h, fun h => absurd h hp⟩)
|
||||
|
||||
/-- the Hilbert epsilon Function -/
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ instance [Monad m] : MonadLift m (ExceptCpsT σ m) where
|
|||
monadLift := ExceptCpsT.lift
|
||||
|
||||
instance [Inhabited ε] : Inhabited (ExceptCpsT ε m α) where
|
||||
default := fun _ k₁ k₂ => k₂ default
|
||||
default := fun _ _ k₂ => k₂ default
|
||||
|
||||
@[simp] theorem run_pure [Monad m] : run (pure x : ExceptCpsT ε m α) = pure (Except.ok x) := rfl
|
||||
|
||||
|
|
|
|||
|
|
@ -407,6 +407,7 @@ variable {p q : Prop}
|
|||
theorem em (p : Prop) [Decidable p] : p ∨ ¬p :=
|
||||
byCases Or.inl Or.inr
|
||||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
theorem byContradiction [dec : Decidable p] (h : ¬p → False) : p :=
|
||||
byCases id (fun np => False.elim (h np))
|
||||
|
||||
|
|
|
|||
|
|
@ -606,7 +606,7 @@ theorem extLit {n : Nat}
|
|||
(a b : Array α)
|
||||
(hsz₁ : a.size = n) (hsz₂ : b.size = n)
|
||||
(h : (i : Nat) → (hi : i < n) → a.getLit i hsz₁ hi = b.getLit i hsz₂ hi) : a = b :=
|
||||
Array.ext a b (hsz₁.trans hsz₂.symm) fun i hi₁ hi₂ => h i (hsz₁ ▸ hi₁)
|
||||
Array.ext a b (hsz₁.trans hsz₂.symm) fun i hi₁ _ => h i (hsz₁ ▸ hi₁)
|
||||
|
||||
end Array
|
||||
|
||||
|
|
|
|||
|
|
@ -214,8 +214,8 @@ private structure State where
|
|||
instance : MonadPrettyFormat (StateM State) where
|
||||
-- We avoid a structure instance update, and write these functions using pattern matching because of issue #316
|
||||
pushOutput s := modify fun ⟨out, col⟩ => ⟨out ++ s, col + s.length⟩
|
||||
pushNewline indent := modify fun ⟨out, col⟩ => ⟨out ++ "\n".pushn ' ' indent, indent⟩
|
||||
currColumn := return (←get).column
|
||||
pushNewline indent := modify fun ⟨out, _⟩ => ⟨out ++ "\n".pushn ' ' indent, indent⟩
|
||||
currColumn := return (← get).column
|
||||
startTag _ := return ()
|
||||
endTags _ := return ()
|
||||
|
||||
|
|
|
|||
|
|
@ -399,8 +399,8 @@ instance [LT α] : LT (List α) := ⟨List.lt⟩
|
|||
|
||||
instance hasDecidableLt [LT α] [h : DecidableRel (α:=α) (·<·)] : (l₁ l₂ : List α) → Decidable (l₁ < l₂)
|
||||
| [], [] => isFalse (fun h => nomatch h)
|
||||
| [], _::bs => isTrue (List.lt.nil _ _)
|
||||
| _::as, [] => isFalse (fun h => nomatch h)
|
||||
| [], _::_ => isTrue (List.lt.nil _ _)
|
||||
| _::_, [] => isFalse (fun h => nomatch h)
|
||||
| a::as, b::bs =>
|
||||
match h a b with
|
||||
| isTrue h₁ => isTrue (List.lt.head _ _ h₁)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Stream (stream : Type u) (value : outParam (Type v)) : Type (max u v) wher
|
|||
next? : stream → Option (value × stream)
|
||||
|
||||
protected partial def Stream.forIn [Stream ρ α] [Monad m] (s : ρ) (b : β) (f : α → β → m (ForInStep β)) : m β := do
|
||||
let inst : Inhabited (m β) := ⟨pure b⟩
|
||||
let _ : Inhabited (m β) := ⟨pure b⟩
|
||||
let rec visit (s : ρ) (b : β) : m β := do
|
||||
match Stream.next? s with
|
||||
| some (a, s) => match (← f a b) with
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ theorem Iterator.sizeOf_next_lt_of_hasNext (i : String.Iterator) (h : i.hasNext)
|
|||
cases i; rename_i s pos; simp [Iterator.next, Iterator.sizeOf_eq]; simp [Iterator.hasNext] at h
|
||||
have := String.lt_next s pos
|
||||
apply Nat.sub.elim (motive := fun k => k < _) (utf8ByteSize s) (String.next s pos).1
|
||||
. intro hle k he
|
||||
. intro _ k he
|
||||
simp [he]; rw [Nat.add_comm, Nat.add_sub_assoc (Nat.le_of_lt this)]
|
||||
have := Nat.zero_lt_sub_of_lt this
|
||||
simp_all_arith
|
||||
|
|
|
|||
|
|
@ -300,8 +300,8 @@ def setTailInfo (stx : Syntax) (info : SourceInfo) : Syntax :=
|
|||
|
||||
def unsetTrailing (stx : Syntax) : Syntax :=
|
||||
match stx.getTailInfo with
|
||||
| SourceInfo.original lead pos trail endPos => stx.setTailInfo (SourceInfo.original lead pos "".toSubstring endPos)
|
||||
| _ => stx
|
||||
| SourceInfo.original lead pos _ endPos => stx.setTailInfo (SourceInfo.original lead pos "".toSubstring endPos)
|
||||
| _ => stx
|
||||
|
||||
@[specialize] private partial def updateFirst {α} [Inhabited α] (a : Array α) (f : α → Option α) (i : Nat) : Option (Array α) :=
|
||||
if h : i < a.size then
|
||||
|
|
@ -337,8 +337,8 @@ partial def getHead? : Syntax → Option Syntax
|
|||
| stx@(atom info ..) => info.getPos?.map fun _ => stx
|
||||
| stx@(ident info ..) => info.getPos?.map fun _ => stx
|
||||
| node SourceInfo.none _ args => args.findSome? getHead?
|
||||
| stx@(node info _ _) => stx
|
||||
| _ => none
|
||||
| stx@(node ..) => stx
|
||||
| _ => none
|
||||
|
||||
def copyHeadTailInfoFrom (target source : Syntax) : Syntax :=
|
||||
target.setHeadInfo source.getHeadInfo |>.setTailInfo source.getTailInfo
|
||||
|
|
@ -921,6 +921,7 @@ instance (sep) : CoeTail (SepArray sep) (Array Syntax) where
|
|||
|
||||
end Lean.Syntax.SepArray
|
||||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
/--
|
||||
Gadget for automatic parameter support. This is similar to the `optParam` gadget, but it uses
|
||||
the given tactic.
|
||||
|
|
@ -975,7 +976,6 @@ def expandInterpolatedStrChunks (chunks : Array Syntax) (mkAppend : Syntax → S
|
|||
return result
|
||||
|
||||
def expandInterpolatedStr (interpStr : Syntax) (type : Syntax) (toTypeFn : Syntax) : MacroM Syntax := do
|
||||
let ref := interpStr
|
||||
let r ← expandInterpolatedStrChunks interpStr.getArgs (fun a b => `($a ++ $b)) (fun a => `($toTypeFn $a))
|
||||
`(($r : $type))
|
||||
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ inductive Loop where
|
|||
| mk
|
||||
|
||||
@[inline]
|
||||
partial def Loop.forIn {β : Type u} {m : Type u → Type v} [Monad m] (loop : Loop) (init : β) (f : Unit → β → m (ForInStep β)) : m β :=
|
||||
partial def Loop.forIn {β : Type u} {m : Type u → Type v} [Monad m] (_ : Loop) (init : β) (f : Unit → β → m (ForInStep β)) : m β :=
|
||||
let rec @[specialize] loop (b : β) : m β := do
|
||||
match ← f () b with
|
||||
| ForInStep.done b => pure b
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ theorem decide_eq_true : [s : Decidable p] → p → Eq (decide p) true
|
|||
| isTrue _, _ => rfl
|
||||
| isFalse h₁, h₂ => absurd h₂ h₁
|
||||
|
||||
theorem decide_eq_false : [s : Decidable p] → Not p → Eq (decide p) false
|
||||
theorem decide_eq_false : [Decidable p] → Not p → Eq (decide p) false
|
||||
| isTrue h₁, h₂ => absurd h₁ h₂
|
||||
| isFalse _, _ => rfl
|
||||
|
||||
|
|
|
|||
|
|
@ -665,6 +665,7 @@ universe u
|
|||
|
||||
namespace Lean
|
||||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
/-- Typeclass used for presenting the output of an `#eval` command. -/
|
||||
class Eval (α : Type u) where
|
||||
-- We default `hideUnit` to `true`, but set it to `false` in the direct call from `#eval`
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Prim
|
|||
|
||||
/- Auxiliary definition for showing that `ST σ α` is inhabited when we have a `Ref σ α` -/
|
||||
private noncomputable def inhabitedFromRef {σ α} (r : Ref σ α) : ST σ α :=
|
||||
let inh : Inhabited α := Classical.inhabited_of_nonempty r.h
|
||||
let _ : Inhabited α := Classical.inhabited_of_nonempty r.h
|
||||
pure default
|
||||
|
||||
@[extern "lean_st_mk_ref"]
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ structure ParametricAttribute (α : Type) where
|
|||
|
||||
structure ParametricAttributeImpl (α : Type) extends AttributeImplCore where
|
||||
getParam : Name → Syntax → AttrM α
|
||||
afterSet : Name → α → AttrM Unit := fun env _ _ => pure ()
|
||||
afterSet : Name → α → AttrM Unit := fun _ _ _ => pure ()
|
||||
afterImport : Array (Array (Name × α)) → ImportM Unit := fun _ => pure ()
|
||||
|
||||
def registerParametricAttribute {α : Type} [Inhabited α] (impl : ParametricAttributeImpl α) : IO (ParametricAttribute α) := do
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ partial def visitFnBody (fnid : FunId) : FnBody → StateM ParamMap Unit
|
|||
| FnBody.case _ _ _ alts => alts.forM fun alt => visitFnBody fnid alt.body
|
||||
| e => do
|
||||
unless e.isTerminal do
|
||||
let (instr, b) := e.split
|
||||
let (_, b) := e.split
|
||||
visitFnBody fnid b
|
||||
|
||||
def visitDecls (env : Environment) (decls : Array Decl) : StateM ParamMap Unit :=
|
||||
|
|
@ -176,7 +176,6 @@ def isOwned (x : VarId) : M Bool := do
|
|||
|
||||
/- Updates `map[k]` using the current set of `owned` variables. -/
|
||||
def updateParamMap (k : ParamMap.Key) : M Unit := do
|
||||
let currFn ← getCurrFn
|
||||
let s ← get
|
||||
match s.paramMap.find? k with
|
||||
| some ps => do
|
||||
|
|
@ -252,7 +251,7 @@ def collectExpr (z : VarId) : Expr → M Unit
|
|||
ownVar z *> ownArgsUsingParams xs ps
|
||||
| Expr.ap x ys => ownVar z *> ownVar x *> ownArgs ys
|
||||
| Expr.pap _ xs => ownVar z *> ownArgs xs
|
||||
| other => pure ()
|
||||
| _ => pure ()
|
||||
|
||||
def preserveTailCall (x : VarId) (v : Expr) (b : FnBody) : M Unit := do
|
||||
let ctx ← read
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ def checkJP (j : JoinPointId) : M Unit := do
|
|||
def checkArg (a : Arg) : M Unit :=
|
||||
match a with
|
||||
| Arg.var x => checkVar x
|
||||
| other => pure ()
|
||||
| _ => pure ()
|
||||
|
||||
def checkArgs (as : Array Arg) : M Unit :=
|
||||
as.forM checkArg
|
||||
|
|
@ -147,14 +147,12 @@ def checkExpr (ty : IRType) : Expr → M Unit
|
|||
|
||||
partial def checkFnBody : FnBody → M Unit
|
||||
| FnBody.vdecl x t v b => do
|
||||
checkExpr t v;
|
||||
markVar x;
|
||||
let ctx ← read
|
||||
checkExpr t v
|
||||
markVar x
|
||||
withReader (fun ctx => { ctx with localCtx := ctx.localCtx.addLocal x t v }) (checkFnBody b)
|
||||
| FnBody.jdecl j ys v b => do
|
||||
markJP j;
|
||||
withParams ys (checkFnBody v);
|
||||
let ctx ← read
|
||||
markJP j
|
||||
withParams ys (checkFnBody v)
|
||||
withReader (fun ctx => { ctx with localCtx := ctx.localCtx.addJP j ys v }) (checkFnBody b)
|
||||
| FnBody.set x _ y b => checkVar x *> checkArg y *> checkFnBody b
|
||||
| FnBody.uset x _ y b => checkVar x *> checkVar y *> checkFnBody b
|
||||
|
|
@ -178,8 +176,8 @@ end Checker
|
|||
def checkDecl (decls : Array Decl) (decl : Decl) : CompilerM Unit := do
|
||||
let env ← getEnv
|
||||
match (Checker.checkDecl decl { env := env, decls := decls }).run' {} with
|
||||
| Except.error msg => throw s!"IR check failed at '{decl.name}', error: {msg}"
|
||||
| other => pure ()
|
||||
| .error msg => throw s!"IR check failed at '{decl.name}', error: {msg}"
|
||||
| _ => pure ()
|
||||
|
||||
def checkDecls (decls : Array Decl) : CompilerM Unit :=
|
||||
decls.forM (checkDecl decls)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ private def logMessageIfAux {α : Type} [ToFormat α] (optName : Name) (a : α)
|
|||
@[inline] def logMessageIf {α : Type} [ToFormat α] (cls : Name) (a : α) : CompilerM Unit :=
|
||||
logMessageIfAux (tracePrefixOptionName ++ cls) a
|
||||
|
||||
@[inline] def logMessage {α : Type} [ToFormat α] (cls : Name) (a : α) : CompilerM Unit :=
|
||||
@[inline] def logMessage {α : Type} [ToFormat α] (a : α) : CompilerM Unit :=
|
||||
logMessageIfAux tracePrefixOptionName a
|
||||
|
||||
@[inline] def modifyEnv (f : Environment → Environment) : CompilerM Unit :=
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ instance : BEq Value := ⟨Value.beq⟩
|
|||
|
||||
partial def addChoice (merge : Value → Value → Value) : List Value → Value → List Value
|
||||
| [], v => [v]
|
||||
| v₁@(ctor i₁ vs₁) :: cs, v₂@(ctor i₂ vs₂) =>
|
||||
| v₁@(ctor i₁ _) :: cs, v₂@(ctor i₂ _) =>
|
||||
if i₁ == i₂ then merge v₁ v₂ :: cs
|
||||
else v₁ :: addChoice merge cs v₂
|
||||
| _, _ => panic! "invalid addChoice"
|
||||
|
|
@ -226,8 +226,6 @@ def updateJPParamsAssignment (ys : Array Param) (xs : Array Arg) : M Bool := do
|
|||
|
||||
private partial def resetNestedJPParams : FnBody → M Unit
|
||||
| FnBody.jdecl _ ys _ k => do
|
||||
let ctx ← read
|
||||
let currFnIdx := ctx.currFnIdx
|
||||
ys.forM resetParamAssignment
|
||||
/- Remark we don't need to reset the parameters of joint-points
|
||||
nested in `b` since they will be reset if this JP is used. -/
|
||||
|
|
|
|||
|
|
@ -118,7 +118,6 @@ def emitFnDecl (decl : Decl) (isExternal : Bool) : M Unit := do
|
|||
emitFnDeclAux decl cppBaseName isExternal
|
||||
|
||||
def emitExternDeclAux (decl : Decl) (cNameStr : String) : M Unit := do
|
||||
let cName := Name.mkSimple cNameStr
|
||||
let env ← getEnv
|
||||
let extC := isExternC env decl.name
|
||||
emitFnDeclAux decl cNameStr extC
|
||||
|
|
@ -641,7 +640,7 @@ end
|
|||
|
||||
def emitDeclAux (d : Decl) : M Unit := do
|
||||
let env ← getEnv
|
||||
let (vMap, jpMap) := mkVarJPMaps d
|
||||
let (_, jpMap) := mkVarJPMaps d
|
||||
withReader (fun ctx => { ctx with jpMap := jpMap }) do
|
||||
unless hasInitAttr env d.name do
|
||||
match d with
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ partial def eraseProjIncForAux (y : VarId) (bs : Array FnBody) (mask : Mask) (ke
|
|||
let keep := if n == 1 then keep else keep.push (FnBody.inc z (n-1) c p FnBody.nil)
|
||||
eraseProjIncForAux y bs mask keep
|
||||
else done ()
|
||||
| other => done ()
|
||||
| other => done ()
|
||||
| _ => done ()
|
||||
| _ => done ()
|
||||
|
||||
/- Try to erase `inc` instructions on projections of `y` occurring in the tail of `bs`.
|
||||
Return the updated `bs` and a bit mask specifying which `inc`s have been removed. -/
|
||||
|
|
@ -235,7 +235,6 @@ def mkFastPath (x y : VarId) (mask : Mask) (b : FnBody) : M FnBody := do
|
|||
-- Expand `bs; x := reset[n] y; b`
|
||||
partial def expand (mainFn : FnBody → Array FnBody → M FnBody)
|
||||
(bs : Array FnBody) (x : VarId) (n : Nat) (y : VarId) (b : FnBody) : M FnBody := do
|
||||
let bOld := FnBody.vdecl x IRType.object (Expr.reset n y) b
|
||||
let (bs, mask) := eraseProjIncFor n y bs
|
||||
/- Remark: we may be duplicting variable/JP indices. That is, `bSlow` and `bFast` may
|
||||
have duplicate indices. We run `normalizeIds` to fix the ids after we have expand them. -/
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ partial def formatFnBody (fnBody : FnBody) (indent : Nat := 2) : Format :=
|
|||
| FnBody.dec x n _ _ b => "dec" ++ (if n != 1 then Format.sbracket (format n) else "") ++ " " ++ format x ++ ";" ++ Format.line ++ loop b
|
||||
| FnBody.del x b => "del " ++ format x ++ ";" ++ Format.line ++ loop b
|
||||
| FnBody.mdata d b => "mdata " ++ format d ++ ";" ++ Format.line ++ loop b
|
||||
| FnBody.case tid x xType cs => "case " ++ format x ++ " : " ++ format xType ++ " of" ++ cs.foldl (fun r c => r ++ Format.line ++ formatAlt loop indent c) Format.nil
|
||||
| FnBody.case _ x xType cs => "case " ++ format x ++ " : " ++ format xType ++ " of" ++ cs.foldl (fun r c => r ++ Format.line ++ formatAlt loop indent c) Format.nil
|
||||
| FnBody.jmp j ys => "jmp " ++ format j ++ formatArray ys
|
||||
| FnBody.ret x => "ret " ++ format x
|
||||
| FnBody.unreachable => "⊥"
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace FreeIndices
|
|||
abbrev Collector := IndexSet → IndexSet → IndexSet
|
||||
|
||||
@[inline] private def skip : Collector :=
|
||||
fun bv fv => fv
|
||||
fun _ fv => fv
|
||||
|
||||
@[inline] private def collectIndex (x : Index) : Collector :=
|
||||
fun bv fv => if bv.contains x then fv else fv.insert x
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ partial def normFnBody : FnBody → N FnBody
|
|||
|
||||
def normDecl (d : Decl) : N Decl :=
|
||||
match d with
|
||||
| Decl.fdecl (xs := xs) (body := b) .. => withParams xs fun xs => return d.updateBody! (← normFnBody b)
|
||||
| Decl.fdecl (xs := xs) (body := b) .. => withParams xs fun _ => return d.updateBody! (← normFnBody b)
|
||||
| other => pure other
|
||||
|
||||
end NormalizeIds
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ partial def visitFnBody : FnBody → Context → (FnBody × LiveVarSet)
|
|||
let bLiveVars := collectLiveVars b ctx.jpLiveVarMap
|
||||
(b, bLiveVars)
|
||||
| FnBody.unreachable, _ => (FnBody.unreachable, {})
|
||||
| other, ctx => (other, {}) -- unreachable if well-formed
|
||||
| other, _ => (other, {}) -- unreachable if well-formed
|
||||
|
||||
partial def visitDecl (env : Environment) (decls : Array Decl) (d : Decl) : Decl :=
|
||||
match d with
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ partial def visitFndBody (b : FnBody) : ExceptT Name M Unit := do
|
|||
| FnBody.case _ _ _ alts => alts.forM fun alt => visitFndBody alt.body
|
||||
| _ =>
|
||||
unless b.isTerminal do
|
||||
let (instr, b) := b.split
|
||||
let (_, b) := b.split
|
||||
visitFndBody b
|
||||
|
||||
def visitDecl (d : Decl) : M Unit := do
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ builtin_initialize specializeAttrs : EnumAttributes SpecializeAttributeKind ←
|
|||
In the new equation compiler we should pass all attributes and allow it to apply them to auxiliary definitions.
|
||||
In the current implementation, we workaround this issue by using functions such as `hasSpecializeAttrAux`.
|
||||
-/
|
||||
(fun declName _ => pure ())
|
||||
(fun _ _ => pure ())
|
||||
AttributeApplicationTime.beforeElaboration
|
||||
|
||||
private partial def hasSpecializeAttrAux (env : Environment) (kind : SpecializeAttributeKind) (n : Name) : Bool :=
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ partial def matchPrefix (s : String) (t : Trie α) (i : String.Pos) : String.Pos
|
|||
loop t i (i, none)
|
||||
|
||||
private partial def toStringAux {α : Type} : Trie α → List Format
|
||||
| Trie.Node val map => map.fold (fun Fs c t =>
|
||||
| Trie.Node _ map => map.fold (fun Fs c t =>
|
||||
format (repr c) :: (Format.group $ Format.nest 2 $ flip Format.joinSep Format.line $ toStringAux t) :: Fs) []
|
||||
|
||||
instance {α : Type} : ToString (Trie α) :=
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ private def elabAndAddNewArg (argName : Name) (arg : Arg) : M Unit := do
|
|||
|
||||
/- Return true if the given type contains `OptParam` or `AutoParams` -/
|
||||
private def hasOptAutoParams (type : Expr) : M Bool := do
|
||||
forallTelescopeReducing type fun xs type =>
|
||||
forallTelescopeReducing type fun xs _ =>
|
||||
xs.anyM fun x => do
|
||||
let xType ← inferType x
|
||||
return xType.getOptParamDefault?.isSome || xType.getAutoParamTactic?.isSome
|
||||
|
|
@ -882,7 +882,7 @@ private partial def elabAppFn (f : Syntax) (lvals : List LVal) (namedArgs : Arra
|
|||
| `($(e).$field:ident) => elabFieldName e field
|
||||
| `($e |>.$field:ident) => elabFieldName e field
|
||||
| `($e[%$bracket $idx]) => elabAppFn e (LVal.getOp bracket idx :: lvals) namedArgs args expectedType? explicit ellipsis overloaded acc
|
||||
| `($id:ident@$_:term) =>
|
||||
| `($_:ident@$_:term) =>
|
||||
throwError "unexpected occurrence of named pattern"
|
||||
| `($id:ident) => do
|
||||
elabAppFnId id [] lvals namedArgs args expectedType? explicit ellipsis overloaded acc
|
||||
|
|
@ -891,7 +891,7 @@ private partial def elabAppFn (f : Syntax) (lvals : List LVal) (namedArgs : Arra
|
|||
elabAppFnId id us lvals namedArgs args expectedType? explicit ellipsis overloaded acc
|
||||
| `(@$id:ident) =>
|
||||
elabAppFn id lvals namedArgs args expectedType? (explicit := true) ellipsis overloaded acc
|
||||
| `(@$id:ident.{$us,*}) =>
|
||||
| `(@$_:ident.{$_us,*}) =>
|
||||
elabAppFn (f.getArg 1) lvals namedArgs args expectedType? (explicit := true) ellipsis overloaded acc
|
||||
| `(@$_) => throwUnsupportedSyntax -- invalid occurrence of `@`
|
||||
| `(_) => throwError "placeholders '_' cannot be used where a function is expected"
|
||||
|
|
@ -1022,11 +1022,11 @@ private def elabAtom : TermElab := fun stx expectedType? => do
|
|||
`@e` for any term `e` also disables the insertion of implicit lambdas at this position. -/
|
||||
@[builtinTermElab explicit] def elabExplicit : TermElab := fun stx expectedType? =>
|
||||
match stx with
|
||||
| `(@$id:ident) => elabAtom stx expectedType? -- Recall that `elabApp` also has support for `@`
|
||||
| `(@$id:ident.{$us,*}) => elabAtom stx expectedType?
|
||||
| `(@($t)) => elabTerm t expectedType? (implicitLambda := false) -- `@` is being used just to disable implicit lambdas
|
||||
| `(@$t) => elabTerm t expectedType? (implicitLambda := false) -- `@` is being used just to disable implicit lambdas
|
||||
| _ => throwUnsupportedSyntax
|
||||
| `(@$_:ident) => elabAtom stx expectedType? -- Recall that `elabApp` also has support for `@`
|
||||
| `(@$_:ident.{$_us,*}) => elabAtom stx expectedType?
|
||||
| `(@($t)) => elabTerm t expectedType? (implicitLambda := false) -- `@` is being used just to disable implicit lambdas
|
||||
| `(@$t) => elabTerm t expectedType? (implicitLambda := false) -- `@` is being used just to disable implicit lambdas
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTermElab choice] def elabChoice : TermElab := elabAtom
|
||||
@[builtinTermElab proj] def elabProj : TermElab := elabAtom
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ def addNamedArg (namedArgs : Array NamedArg) (namedArg : NamedArg) : MetaM (Arra
|
|||
throwError "argument '{namedArg.name}' was already set"
|
||||
return namedArgs.push namedArg
|
||||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
partial def expandArgs (args : Array Syntax) (pattern := false) : MetaM (Array NamedArg × Array Arg × Bool) := do
|
||||
let (args, ellipsis) :=
|
||||
if args.isEmpty then
|
||||
|
|
@ -51,6 +52,7 @@ partial def expandArgs (args : Array Syntax) (pattern := false) : MetaM (Array N
|
|||
return (namedArgs, args.push $ Arg.stx stx)
|
||||
return (namedArgs, args, ellipsis)
|
||||
|
||||
set_option linter.unusedVariables.funArgs false in
|
||||
def expandApp (stx : Syntax) (pattern := false) : MetaM (Syntax × Array NamedArg × Array Arg × Bool) := do
|
||||
let (namedArgs, args, ellipsis) ← expandArgs stx[1].getArgs
|
||||
return (stx[0], namedArgs, args, ellipsis)
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ partial def quoteAutoTactic : Syntax → TermElabM Syntax
|
|||
let quotedArg ← quoteAutoTactic arg
|
||||
quotedArgs ← `(Array.push $quotedArgs $quotedArg)
|
||||
`(Syntax.node SourceInfo.none $(quote k) $quotedArgs)
|
||||
| Syntax.atom info val => `(mkAtom $(quote val))
|
||||
| Syntax.missing => throwError "invalid auto tactic, tactic is missing"
|
||||
| Syntax.atom _ val => `(mkAtom $(quote val))
|
||||
| Syntax.missing => throwError "invalid auto tactic, tactic is missing"
|
||||
|
||||
def declareTacticSyntax (tactic : Syntax) : TermElabM Name :=
|
||||
withFreshMacroScope do
|
||||
|
|
@ -552,7 +552,7 @@ def expandMatchAltsWhereDecls (matchAltsWhereDecls : Syntax) : MacroM Syntax :=
|
|||
open Lean.Elab.Term.Quotation in
|
||||
@[builtinQuotPrecheck Lean.Parser.Term.fun] def precheckFun : Precheck
|
||||
| `(fun $binders* => $body) => do
|
||||
let (binders, body, expandedPattern) ← liftMacroM <| expandFunBinders binders body
|
||||
let (binders, body, _) ← liftMacroM <| expandFunBinders binders body
|
||||
let mut ids := #[]
|
||||
for b in binders do
|
||||
for v in ← matchBinder b do
|
||||
|
|
@ -567,7 +567,7 @@ open Lean.Elab.Term.Quotation in
|
|||
-- We can assume all `match` binders have been iteratively expanded by the above macro here, though
|
||||
-- we still need to call `expandFunBinders` once to obtain `binders` in a normal form
|
||||
-- expected by `elabFunBinder`.
|
||||
let (binders, body, expandedPattern) ← liftMacroM <| expandFunBinders binders body
|
||||
let (binders, body, _) ← liftMacroM <| expandFunBinders binders body
|
||||
elabFunBinders binders expectedType? fun xs expectedType? => do
|
||||
/- We ensure the expectedType here since it will force coercions to be applied if needed.
|
||||
If we just use `elabTerm`, then we will need to a coercion `Coe (α → β) (α → δ)` whenever there is a coercion `Coe β δ`,
|
||||
|
|
@ -653,7 +653,6 @@ def expandLetEqnsDecl (letDecl : Syntax) : MacroM Syntax := do
|
|||
return mkNode `Lean.Parser.Term.letIdDecl #[letDecl[0], letDecl[1], letDecl[2], mkAtomFrom ref " := ", val]
|
||||
|
||||
def elabLetDeclCore (stx : Syntax) (expectedType? : Option Expr) (useLetExpr : Bool) (elabBodyFirst : Bool) (usedLetOnly : Bool) : TermElabM Expr := do
|
||||
let ref := stx
|
||||
let letDecl := stx[1][0]
|
||||
let body := stx[3]
|
||||
if letDecl.getKind == ``Lean.Parser.Term.letIdDecl then
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ def getMatchAltsNumPatterns (matchAlts : Syntax) : Nat :=
|
|||
-/
|
||||
def expandMatchAlt (matchAlt : Syntax) : Array Syntax :=
|
||||
let patss := matchAlt[1]
|
||||
let rhs := matchAlt[3]
|
||||
if patss.getArgs.size ≤ 1 then
|
||||
#[matchAlt]
|
||||
else
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ private partial def elabChoiceAux (cmds : Array Syntax) (i : Nat) : CommandElabM
|
|||
let cmd := cmds.get ⟨i, h⟩;
|
||||
catchInternalId unsupportedSyntaxExceptionId
|
||||
(elabCommand cmd)
|
||||
(fun ex => elabChoiceAux cmds (i+1))
|
||||
(fun _ => elabChoiceAux cmds (i+1))
|
||||
else
|
||||
throwUnsupportedSyntax
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ private partial def elabChoiceAux (cmds : Array Syntax) (i : Nat) : CommandElabM
|
|||
@[builtinCommandElab «universe»] def elabUniverse : CommandElab := fun n => do
|
||||
n[1].forArgsM addUnivLevel
|
||||
|
||||
@[builtinCommandElab «init_quot»] def elabInitQuot : CommandElab := fun stx => do
|
||||
@[builtinCommandElab «init_quot»] def elabInitQuot : CommandElab := fun _ => do
|
||||
match (← getEnv).addDecl Declaration.quotDecl with
|
||||
| Except.ok env => setEnv env
|
||||
| Except.error ex => throwError (ex.toMessageData (← getOptions))
|
||||
|
|
@ -124,7 +124,6 @@ private partial def elabChoiceAux (cmds : Array Syntax) (i : Nat) : CommandElabM
|
|||
let ns ← resolveNamespace id
|
||||
let currNamespace ← getCurrNamespace
|
||||
if ns == currNamespace then throwError "invalid 'export', self export"
|
||||
let env ← getEnv
|
||||
let ids := stx[3].getArgs
|
||||
let aliases ← ids.foldlM (init := []) fun (aliases : List (Name × Name)) (idStx : Syntax) => do
|
||||
let id := idStx.getId
|
||||
|
|
@ -307,7 +306,6 @@ private def mkRunEval (e : Expr) : MetaM Expr := do
|
|||
unsafe def elabEvalUnsafe : CommandElab
|
||||
| `(#eval%$tk $term) => do
|
||||
let n := `_eval
|
||||
let ctx ← read
|
||||
let addAndCompile (value : Expr) : TermElabM Unit := do
|
||||
let (value, _) ← Term.levelMVarToParam (← instantiateMVars value)
|
||||
let type ← inferType value
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ are turned into a new anonymous constructor application. For example,
|
|||
let expectedType ← whnf expectedType
|
||||
matchConstInduct expectedType.getAppFn
|
||||
(fun _ => throwError "invalid constructor ⟨...⟩, expected type must be an inductive type {indentExpr expectedType}")
|
||||
(fun ival us => do
|
||||
(fun ival _ => do
|
||||
match ival.ctors with
|
||||
| [ctor] =>
|
||||
let cinfo ← getConstInfoCtor ctor
|
||||
|
|
@ -141,7 +141,7 @@ then aborted. -/
|
|||
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
|
||||
|
||||
/-- A shorthand for `panic! "unreachable code has been reached"`. -/
|
||||
@[builtinMacro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun stx =>
|
||||
@[builtinMacro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun _ =>
|
||||
`(panic! "unreachable code has been reached")
|
||||
|
||||
/-- `assert! cond` panics if `cond` evaluates to `false`. -/
|
||||
|
|
@ -269,7 +269,7 @@ where
|
|||
else
|
||||
throw <| Macro.Exception.error stx "unexpected parentheses notation"
|
||||
|
||||
@[builtinTermElab paren] def elabParen : TermElab := fun stx expectedType? => do
|
||||
@[builtinTermElab paren] def elabParen : TermElab := fun stx _ => do
|
||||
match stx with
|
||||
| `(($e : $type)) =>
|
||||
let type ← withSynthesize (mayPostpone := true) <| elabType type
|
||||
|
|
@ -362,7 +362,6 @@ See the Chapter "Quantifiers and Equality" in the manual "Theorem Proving in Lea
|
|||
let h ← elabTerm hStx none
|
||||
let hType ← inferType h
|
||||
let hTypeAbst ← kabstract hType lhs
|
||||
let hTypeNew := hTypeAbst.instantiate1 rhs
|
||||
let motive ← mkMotive lhs hTypeAbst
|
||||
unless (← isTypeCorrect motive) do
|
||||
throwError "invalid `▸` notation, failed to compute motive for the substitution"
|
||||
|
|
|
|||
|
|
@ -146,7 +146,6 @@ private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr :=
|
|||
let mvar ← mkFreshExprMVar type MetavarKind.syntheticOpaque
|
||||
let mvarId := mvar.mvarId!
|
||||
let ref ← getRef
|
||||
let declName? ← getDeclName?
|
||||
registerSyntheticMVar ref mvarId <| SyntheticMVarKind.tactic tacticCode (← saveContext)
|
||||
return mvar
|
||||
|
||||
|
|
@ -159,7 +158,7 @@ private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr :=
|
|||
@[builtinTermElab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
|
||||
elabTerm stx[1] (mkNoImplicitLambdaAnnotation <$> expectedType?)
|
||||
|
||||
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun stx _ =>
|
||||
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun _ _ =>
|
||||
throwError "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
|
||||
|
||||
@[builtinTermElab str] def elabStrLit : TermElab := fun stx _ => do
|
||||
|
|
@ -185,7 +184,7 @@ private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr :=
|
|||
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
|
||||
return r
|
||||
|
||||
@[builtinTermElab rawNatLit] def elabRawNatLit : TermElab := fun stx expectedType? => do
|
||||
@[builtinTermElab rawNatLit] def elabRawNatLit : TermElab := fun stx _ => do
|
||||
match stx[1].isNatLit? with
|
||||
| some val => return mkRawNatLit val
|
||||
| none => throwIllFormedSyntax
|
||||
|
|
@ -250,7 +249,7 @@ private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
|
|||
else
|
||||
return e
|
||||
|
||||
@[builtinTermElab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx expectedType? =>
|
||||
@[builtinTermElab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx _ =>
|
||||
match stx[2].isStrLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some msg => do
|
||||
|
|
|
|||
|
|
@ -343,10 +343,10 @@ private def mkMetaContext : Meta.Context := {
|
|||
}
|
||||
|
||||
def getBracketedBinderIds : Syntax → Array Name
|
||||
| `(bracketedBinder|($ids* $[: $ty?]? $(annot?)?)) => ids.map Syntax.getId
|
||||
| `(bracketedBinder|($ids* $[: $ty?]? $(_annot?)?)) => ids.map Syntax.getId
|
||||
| `(bracketedBinder|{$ids* $[: $ty?]?}) => ids.map Syntax.getId
|
||||
| `(bracketedBinder|[$id : $ty]) => #[id.getId]
|
||||
| `(bracketedBinder|[$ty]) => #[Name.anonymous]
|
||||
| `(bracketedBinder|[$id : $_]) => #[id.getId]
|
||||
| `(bracketedBinder|[$_]) => #[Name.anonymous]
|
||||
| _ => #[]
|
||||
|
||||
private def mkTermContext (ctx : Context) (s : State) (declName? : Option Name) : Term.Context := Id.run do
|
||||
|
|
@ -377,7 +377,7 @@ def liftTermElabM {α} (declName? : Option Name) (x : TermElabM α) : CommandEla
|
|||
let x : MetaM _ := (observing x).run (mkTermContext ctx s declName?) (mkTermState scope s)
|
||||
let x : CoreM _ := x.run mkMetaContext {}
|
||||
let x : EIO _ _ := x.run (mkCoreContext ctx s heartbeats) { env := s.env, ngen := s.ngen, nextMacroScope := s.nextMacroScope }
|
||||
let (((ea, termS), metaS), coreS) ← liftEIO x
|
||||
let (((ea, termS), _), coreS) ← liftEIO x
|
||||
modify fun s => { s with
|
||||
env := coreS.env
|
||||
nextMacroScope := coreS.nextMacroScope
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ private def ensureValidNamespace (name : Name) : MacroM Unit := do
|
|||
|
||||
/- Auxiliary function for `expandDeclNamespace?` -/
|
||||
private def expandDeclIdNamespace? (declId : Syntax) : MacroM (Option (Name × Syntax)) := do
|
||||
let (id, optUnivDeclStx) := expandDeclIdCore declId
|
||||
let (id, _) := expandDeclIdCore declId
|
||||
let scpView := extractMacroScopes id
|
||||
match scpView.name with
|
||||
| Name.str Name.anonymous _ _ => return none
|
||||
|
|
@ -73,7 +73,7 @@ def elabAxiom (modifiers : Modifiers) (stx : Syntax) : CommandElabM Unit := do
|
|||
let declId := stx[1]
|
||||
let (binders, typeStx) := expandDeclSig stx[2]
|
||||
let scopeLevelNames ← getLevelNames
|
||||
let ⟨name, declName, allUserLevelNames⟩ ← expandDeclId declId modifiers
|
||||
let ⟨_, declName, allUserLevelNames⟩ ← expandDeclId declId modifiers
|
||||
addDeclarationRanges declName stx
|
||||
runTermElabM declName fun vars => Term.withLevelNames allUserLevelNames $ Term.elabBinders binders.getArgs fun xs => do
|
||||
Term.applyAttributesAt declName modifiers.attrs AttributeApplicationTime.beforeElaboration
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ def mkInstanceName (binders : Array Syntax) (type : Syntax) : CommandElabM Name
|
|||
ref.get
|
||||
set savedState
|
||||
liftMacroM <| mkUnusedBaseName <| Name.mkSimple ("inst" ++ result)
|
||||
catch ex =>
|
||||
catch _ =>
|
||||
set savedState
|
||||
mkFreshInstanceName
|
||||
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ namespace Lean.Elab.Deriving.BEq
|
|||
open Lean.Parser.Term
|
||||
open Meta
|
||||
|
||||
def mkBEqHeader (ctx : Context) (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader ctx `BEq 2 indVal
|
||||
def mkBEqHeader (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader `BEq 2 indVal
|
||||
|
||||
def mkMatch (ctx : Context) (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
def mkMatch (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts
|
||||
`(match $[$discrs],* with $alts:matchAlt*)
|
||||
|
|
@ -71,8 +71,8 @@ where
|
|||
def mkAuxFunction (ctx : Context) (i : Nat) : TermElabM Syntax := do
|
||||
let auxFunName := ctx.auxFunNames[i]
|
||||
let indVal := ctx.typeInfos[i]
|
||||
let header ← mkBEqHeader ctx indVal
|
||||
let mut body ← mkMatch ctx header indVal auxFunName
|
||||
let header ← mkBEqHeader indVal
|
||||
let mut body ← mkMatch header indVal auxFunName
|
||||
if ctx.usePartial then
|
||||
let letDecls ← mkLocalInstanceLetDecls ctx `BEq header.argNames
|
||||
body ← mkLet letDecls body
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ namespace Lean.Elab.Deriving.DecEq
|
|||
open Lean.Parser.Term
|
||||
open Meta
|
||||
|
||||
def mkDecEqHeader (ctx : Context) (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader ctx `DecidableEq 2 indVal
|
||||
def mkDecEqHeader (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader `DecidableEq 2 indVal
|
||||
|
||||
def mkMatch (ctx : Context) (header : Header) (indVal : InductiveVal) (auxFunName : Name) (argNames : Array Name) : TermElabM Syntax := do
|
||||
def mkMatch (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts
|
||||
`(match $[$discrs],* with $alts:matchAlt*)
|
||||
|
|
@ -86,8 +86,8 @@ where
|
|||
def mkAuxFunction (ctx : Context) : TermElabM Syntax := do
|
||||
let auxFunName := ctx.auxFunNames[0]
|
||||
let indVal :=ctx.typeInfos[0]
|
||||
let header ← mkDecEqHeader ctx indVal
|
||||
let mut body ← mkMatch ctx header indVal auxFunName header.argNames
|
||||
let header ← mkDecEqHeader indVal
|
||||
let mut body ← mkMatch header indVal auxFunName
|
||||
let binders := header.binders
|
||||
let type ← `(Decidable ($(mkIdent header.targetNames[0]) = $(mkIdent header.targetNames[1])))
|
||||
`(private def $(mkIdent auxFunName):ident $binders:explicitBinder* : $type:term := $body:term)
|
||||
|
|
@ -163,7 +163,6 @@ def mkDecEqEnum (declName : Name) : CommandElabM Unit := do
|
|||
liftTermElabM none <| mkEnumOfNatThm declName
|
||||
let ofNatIdent := mkIdent (Name.mkStr declName "ofNat")
|
||||
let auxThmIdent := mkIdent (Name.mkStr declName "ofNat_toCtorIdx")
|
||||
let indVal ← getConstInfoInduct declName
|
||||
let cmd ← `(
|
||||
instance : DecidableEq $(mkIdent declName) :=
|
||||
fun x y =>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ def mkToJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
|
|||
if isStructure (← getEnv) declNames[0] then
|
||||
let cmds ← liftTermElabM none <| do
|
||||
let ctx ← mkContext "toJson" declNames[0]
|
||||
let header ← mkHeader ctx ``ToJson 1 ctx.typeInfos[0]
|
||||
let header ← mkHeader ``ToJson 1 ctx.typeInfos[0]
|
||||
let fields := getStructureFieldsFlattened (← getEnv) declNames[0] (includeSubobjectFields := false)
|
||||
let fields : Array Syntax ← fields.mapM fun field => do
|
||||
let (isOptField, nm) := mkJsonField field
|
||||
|
|
@ -45,7 +45,7 @@ def mkToJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
|
|||
let mkToJson (id : Syntax) (type : Expr) : TermElabM Syntax := do
|
||||
if type.isAppOf indVal.name then `($toJsonFuncId:ident $id:ident)
|
||||
else ``(toJson $id:ident)
|
||||
let header ← mkHeader ctx ``ToJson 1 ctx.typeInfos[0]
|
||||
let header ← mkHeader ``ToJson 1 ctx.typeInfos[0]
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts indVal fun ctor args userNames => do
|
||||
match args, userNames with
|
||||
|
|
@ -76,7 +76,7 @@ where
|
|||
(rhs : ConstructorVal → Array (Syntax × Expr) → (Option $ Array Name) → TermElabM Syntax) : TermElabM (Array Syntax) := do
|
||||
indVal.ctors.toArray.mapM fun ctor => do
|
||||
let ctorInfo ← getConstInfoCtor ctor
|
||||
forallTelescopeReducing ctorInfo.type fun xs type => do
|
||||
forallTelescopeReducing ctorInfo.type fun xs _ => do
|
||||
let mut patterns := #[]
|
||||
-- add `_` pattern for indices
|
||||
for _ in [:indVal.numIndices] do
|
||||
|
|
@ -105,7 +105,7 @@ def mkFromJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
|
|||
if isStructure (← getEnv) declNames[0] then
|
||||
let cmds ← liftTermElabM none <| do
|
||||
let ctx ← mkContext "fromJson" declNames[0]
|
||||
let header ← mkHeader ctx ``FromJson 0 ctx.typeInfos[0]
|
||||
let header ← mkHeader ``FromJson 0 ctx.typeInfos[0]
|
||||
let fields := getStructureFieldsFlattened (← getEnv) declNames[0] (includeSubobjectFields := false)
|
||||
let jsonFields := fields.map (Prod.snd ∘ mkJsonField)
|
||||
let fields := fields.map mkIdent
|
||||
|
|
@ -120,9 +120,8 @@ def mkFromJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
|
|||
let indVal ← getConstInfoInduct declNames[0]
|
||||
let cmds ← liftTermElabM none <| do
|
||||
let ctx ← mkContext "fromJson" declNames[0]
|
||||
let header ← mkHeader ctx ``FromJson 0 ctx.typeInfos[0]
|
||||
let header ← mkHeader ``FromJson 0 ctx.typeInfos[0]
|
||||
let fromJsonFuncId := mkIdent ctx.auxFunNames[0]
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts indVal fromJsonFuncId
|
||||
let mut auxCmd ← alts.foldrM (fun xs x => `(Except.orElseLazy $xs (fun _ => $x))) (← `(Except.error "no inductive constructor matched"))
|
||||
if ctx.usePartial then
|
||||
|
|
@ -150,7 +149,7 @@ where
|
|||
let alts ←
|
||||
indVal.ctors.toArray.mapM fun ctor => do
|
||||
let ctorInfo ← getConstInfoCtor ctor
|
||||
forallTelescopeReducing ctorInfo.type fun xs type => do
|
||||
forallTelescopeReducing ctorInfo.type fun xs _ => do
|
||||
let mut binders := #[]
|
||||
let mut userNames := #[]
|
||||
for i in [:ctorInfo.numFields] do
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ open Command
|
|||
open Lean.Parser.Term
|
||||
open Meta
|
||||
|
||||
def mkHashableHeader (ctx : Context) (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader ctx `Hashable 1 indVal
|
||||
def mkHashableHeader (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader `Hashable 1 indVal
|
||||
|
||||
def mkMatch (ctx : Context) (header : Header) (indVal : InductiveVal) (auxFuncIdx : Nat) : TermElabM Syntax := do
|
||||
def mkMatch (ctx : Context) (header : Header) (indVal : InductiveVal) : TermElabM Syntax := do
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts
|
||||
`(match $[$discrs],* with $alts:matchAlt*)
|
||||
|
|
@ -27,8 +27,7 @@ where
|
|||
let allIndVals := indVal.all.toArray
|
||||
for ctorName in indVal.ctors do
|
||||
let ctorInfo ← getConstInfoCtor ctorName
|
||||
let alt ← forallTelescopeReducing ctorInfo.type fun xs type => do
|
||||
let type ← Core.betaReduce type -- we 'beta-reduce' to eliminate "artificial" dependencies
|
||||
let alt ← forallTelescopeReducing ctorInfo.type fun xs _ => do
|
||||
let mut patterns := #[]
|
||||
-- add `_` pattern for indices
|
||||
for _ in [:indVal.numIndices] do
|
||||
|
|
@ -58,8 +57,8 @@ where
|
|||
def mkAuxFunction (ctx : Context) (i : Nat) : TermElabM Syntax := do
|
||||
let auxFunName := ctx.auxFunNames[i]
|
||||
let indVal := ctx.typeInfos[i]
|
||||
let header ← mkHashableHeader ctx indVal
|
||||
let body ← mkMatch ctx header indVal i
|
||||
let header ← mkHashableHeader indVal
|
||||
let body ← mkMatch ctx header indVal
|
||||
let binders := header.binders
|
||||
if ctx.usePartial then
|
||||
-- TODO(Dany): Get rid of this code branch altogether once we have well-founded recursion
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ namespace Lean.Elab.Deriving.Ord
|
|||
open Lean.Parser.Term
|
||||
open Meta
|
||||
|
||||
def mkOrdHeader (ctx : Context) (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader ctx `Ord 2 indVal
|
||||
def mkOrdHeader (indVal : InductiveVal) : TermElabM Header := do
|
||||
mkHeader `Ord 2 indVal
|
||||
|
||||
def mkMatch (ctx : Context) (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
def mkMatch (header : Header) (indVal : InductiveVal) : TermElabM Syntax := do
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts
|
||||
`(match $[$discrs],* with $alts:matchAlt*)
|
||||
|
|
@ -67,8 +67,8 @@ where
|
|||
def mkAuxFunction (ctx : Context) (i : Nat) : TermElabM Syntax := do
|
||||
let auxFunName := ctx.auxFunNames[i]
|
||||
let indVal := ctx.typeInfos[i]
|
||||
let header ← mkOrdHeader ctx indVal
|
||||
let mut body ← mkMatch ctx header indVal auxFunName
|
||||
let header ← mkOrdHeader indVal
|
||||
let mut body ← mkMatch header indVal
|
||||
if ctx.usePartial || indVal.isRec then
|
||||
let letDecls ← mkLocalInstanceLetDecls ctx `Ord header.argNames
|
||||
body ← mkLet letDecls body
|
||||
|
|
|
|||
|
|
@ -13,14 +13,13 @@ open Lean.Parser.Term
|
|||
open Meta
|
||||
open Std
|
||||
|
||||
def mkReprHeader (ctx : Context) (indVal : InductiveVal) : TermElabM Header := do
|
||||
let prec ← `(prec)
|
||||
let header ← mkHeader ctx `Repr 1 indVal
|
||||
def mkReprHeader (indVal : InductiveVal) : TermElabM Header := do
|
||||
let header ← mkHeader `Repr 1 indVal
|
||||
return { header with
|
||||
binders := header.binders.push (← `(explicitBinderF| (prec : Nat)))
|
||||
}
|
||||
|
||||
def mkBodyForStruct (ctx : Context) (header : Header) (indVal : InductiveVal) : TermElabM Syntax := do
|
||||
def mkBodyForStruct (header : Header) (indVal : InductiveVal) : TermElabM Syntax := do
|
||||
let ctorVal ← getConstInfoCtor indVal.ctors.head!
|
||||
let fieldNames := getStructureFields (← getEnv) indVal.name
|
||||
let numParams := indVal.numParams
|
||||
|
|
@ -44,7 +43,7 @@ def mkBodyForStruct (ctx : Context) (header : Header) (indVal : InductiveVal) :
|
|||
fields ← `($fields ++ $fieldNameLit ++ " := " ++ repr ($target.$(mkIdent fieldName):ident))
|
||||
`(Format.bracket "{ " $fields:term " }")
|
||||
|
||||
def mkBodyForInduct (ctx : Context) (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
def mkBodyForInduct (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
let discrs ← mkDiscrs header indVal
|
||||
let alts ← mkAlts
|
||||
`(match $[$discrs],* with $alts:matchAlt*)
|
||||
|
|
@ -53,7 +52,7 @@ where
|
|||
let mut alts := #[]
|
||||
for ctorName in indVal.ctors do
|
||||
let ctorInfo ← getConstInfoCtor ctorName
|
||||
let alt ← forallTelescopeReducing ctorInfo.type fun xs type => do
|
||||
let alt ← forallTelescopeReducing ctorInfo.type fun xs _ => do
|
||||
let mut patterns := #[]
|
||||
-- add `_` pattern for indices
|
||||
for _ in [:indVal.numIndices] do
|
||||
|
|
@ -79,17 +78,17 @@ where
|
|||
alts := alts.push alt
|
||||
return alts
|
||||
|
||||
def mkBody (ctx : Context) (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
def mkBody (header : Header) (indVal : InductiveVal) (auxFunName : Name) : TermElabM Syntax := do
|
||||
if isStructure (← getEnv) indVal.name then
|
||||
mkBodyForStruct ctx header indVal
|
||||
mkBodyForStruct header indVal
|
||||
else
|
||||
mkBodyForInduct ctx header indVal auxFunName
|
||||
mkBodyForInduct header indVal auxFunName
|
||||
|
||||
def mkAuxFunction (ctx : Context) (i : Nat) : TermElabM Syntax := do
|
||||
let auxFunName := ctx.auxFunNames[i]
|
||||
let indVal := ctx.typeInfos[i]
|
||||
let header ← mkReprHeader ctx indVal
|
||||
let mut body ← mkBody ctx header indVal auxFunName
|
||||
let header ← mkReprHeader indVal
|
||||
let mut body ← mkBody header indVal auxFunName
|
||||
if ctx.usePartial then
|
||||
let letDecls ← mkLocalInstanceLetDecls ctx `Repr header.argNames
|
||||
body ← mkLet letDecls body
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ structure Header where
|
|||
targetNames : Array Name
|
||||
targetType : Syntax
|
||||
|
||||
def mkHeader (ctx : Context) (className : Name) (arity : Nat) (indVal : InductiveVal) : TermElabM Header := do
|
||||
def mkHeader (className : Name) (arity : Nat) (indVal : InductiveVal) : TermElabM Header := do
|
||||
let argNames ← mkInductArgNames indVal
|
||||
let binders ← mkImplicitBinders argNames
|
||||
let targetType ← mkInductiveApp indVal argNames
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ partial def pullExitPointsAux : VarSet → Code → StateRefT (Array JPDecl) Ter
|
|||
| rs, Code.seq e k => return Code.seq e (← pullExitPointsAux rs k)
|
||||
| rs, Code.ite ref x? o c t e => return Code.ite ref x? o c (← pullExitPointsAux (eraseOptVar rs x?) t) (← pullExitPointsAux (eraseOptVar rs x?) e)
|
||||
| rs, Code.«match» ref g ds t alts => return Code.«match» ref g ds t (← alts.mapM fun alt => do pure { alt with rhs := (← pullExitPointsAux (eraseVars rs alt.vars) alt.rhs) })
|
||||
| rs, c@(Code.jmp _ _ _) => return c
|
||||
| _, c@(Code.jmp _ _ _) => return c
|
||||
| rs, Code.«break» ref => mkSimpleJmp ref rs (Code.«break» ref)
|
||||
| rs, Code.«continue» ref => mkSimpleJmp ref rs (Code.«continue» ref)
|
||||
| rs, Code.«return» ref val => mkJmp ref rs val (fun y => return Code.«return» ref y)
|
||||
|
|
@ -940,7 +940,6 @@ def declToTerm (decl : Syntax) (k : Syntax) : M Syntax := withRef decl <| withFr
|
|||
return mkNode ``Lean.Parser.Term.letrec #[letRecToken, letRecDecls, mkNullNode, k]
|
||||
else if kind == ``Lean.Parser.Term.doLetArrow then
|
||||
let arg := decl[2]
|
||||
let ref := arg
|
||||
if arg.getKind == ``Lean.Parser.Term.doIdDecl then
|
||||
let id := arg[0]
|
||||
let type := expandOptType id arg[1]
|
||||
|
|
@ -1266,7 +1265,6 @@ mutual
|
|||
```
|
||||
-/
|
||||
partial def doLetArrowToCode (doLetArrow : Syntax) (doElems : List Syntax) : M CodeBlock := do
|
||||
let ref := doLetArrow
|
||||
let decl := doLetArrow[2]
|
||||
if decl.getKind == ``Lean.Parser.Term.doIdDecl then
|
||||
let y := decl[0]
|
||||
|
|
@ -1318,7 +1316,6 @@ mutual
|
|||
```
|
||||
-/
|
||||
partial def doReassignArrowToCode (doReassignArrow : Syntax) (doElems : List Syntax) : M CodeBlock := do
|
||||
let ref := doReassignArrow
|
||||
let decl := doReassignArrow[0]
|
||||
if decl.getKind == ``Lean.Parser.Term.doIdDecl then
|
||||
let doElem := decl[3]
|
||||
|
|
@ -1357,7 +1354,6 @@ mutual
|
|||
"unless " >> termParser >> "do " >> doSeq
|
||||
``` -/
|
||||
partial def doUnlessToCode (doUnless : Syntax) (doElems : List Syntax) : M CodeBlock := withRef doUnless do
|
||||
let ref := doUnless
|
||||
let cond := doUnless[1]
|
||||
let doSeq := doUnless[3]
|
||||
let body ← doSeqToCode (getDoSeqElems doSeq)
|
||||
|
|
@ -1481,7 +1477,6 @@ mutual
|
|||
```
|
||||
-/
|
||||
partial def doTryToCode (doTry : Syntax) (doElems: List Syntax) : M CodeBlock := do
|
||||
let ref := doTry
|
||||
let tryCode ← doSeqToCode (getDoSeqElems doTry[1])
|
||||
let optFinally := doTry[3]
|
||||
let catches ← doTry[2].getArgs.mapM fun catchStx => do
|
||||
|
|
@ -1547,7 +1542,6 @@ mutual
|
|||
doSeqToCode (liftedDoElems ++ [doElem] ++ doElems)
|
||||
else
|
||||
let ref := doElem
|
||||
let concatWithRest (c : CodeBlock) : M CodeBlock := concatWith c doElems
|
||||
let k := doElem.getKind
|
||||
if k == ``Lean.Parser.Term.doLet then
|
||||
let vars ← getDoLetVars doElem
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ def expandElab : Macro
|
|||
elab$[:$prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $args:macroArg* :
|
||||
$cat $[<= $expectedType?]? => $rhs) => do
|
||||
let prio ← evalOptPrio prio?
|
||||
let catName := cat.getId
|
||||
let (stxParts, patArgs) := (← args.mapM expandMacroArg).unzip
|
||||
-- name
|
||||
let name ← match name? with
|
||||
|
|
|
|||
|
|
@ -36,11 +36,10 @@ private def throwForInFailure (forInInstance : Expr) : TermElabM Expr :=
|
|||
let forInInstance ←
|
||||
try
|
||||
mkAppM ``ForIn #[m, colType, elemType]
|
||||
catch
|
||||
ex => tryPostpone; throwError "failed to construct 'ForIn' instance for collection{indentExpr colType}\nand monad{indentExpr m}"
|
||||
catch _ =>
|
||||
tryPostpone; throwError "failed to construct 'ForIn' instance for collection{indentExpr colType}\nand monad{indentExpr m}"
|
||||
match (← trySynthInstance forInInstance) with
|
||||
| LOption.some _ =>
|
||||
let ref ← getRef
|
||||
let forInFn ← mkConst ``forIn
|
||||
elabAppArgs forInFn #[] #[Arg.stx col, Arg.stx init, Arg.stx body] expectedType? (explicit := false) (ellipsis := false)
|
||||
| LOption.undef => tryPostpone; throwForInFailure forInInstance
|
||||
|
|
@ -61,11 +60,10 @@ private def throwForInFailure (forInInstance : Expr) : TermElabM Expr :=
|
|||
try
|
||||
let memType ← mkFreshExprMVar (← mkAppM ``Membership #[elemType, colType])
|
||||
mkAppM ``ForIn' #[m, colType, elemType, memType]
|
||||
catch
|
||||
ex => tryPostpone; throwError "failed to construct `ForIn'` instance for collection{indentExpr colType}\nand monad{indentExpr m}"
|
||||
catch _ =>
|
||||
tryPostpone; throwError "failed to construct `ForIn'` instance for collection{indentExpr colType}\nand monad{indentExpr m}"
|
||||
match (← trySynthInstance forInInstance) with
|
||||
| LOption.some _ =>
|
||||
let ref ← getRef
|
||||
let forInFn ← mkConst ``forIn'
|
||||
elabAppArgs forInFn #[] #[Arg.expr colFVar, Arg.stx init, Arg.stx body] expectedType? (explicit := false) (ellipsis := false)
|
||||
| LOption.undef => tryPostpone; throwForInFailure forInInstance
|
||||
|
|
@ -327,7 +325,6 @@ def elabBinRelCore (noProp : Bool) (stx : Syntax) (expectedType? : Option Expr)
|
|||
let lhs ← toBoolIfNecessary lhs
|
||||
let rhs ← toBoolIfNecessary rhs
|
||||
let lhsType ← inferType lhs
|
||||
let rhsType ← inferType rhs
|
||||
let rhs ← ensureHasType lhsType rhs
|
||||
elabAppArgs f #[] #[Arg.expr lhs, Arg.expr rhs] expectedType? (explicit := false) (ellipsis := false)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ def processCommand : FrontendM Bool := do
|
|||
let pstate ← getParserState
|
||||
let scope := cmdState.scopes.head!
|
||||
let pmctx := { env := cmdState.env, options := scope.opts, currNamespace := scope.currNamespace, openDecls := scope.openDecls }
|
||||
let pos := ictx.fileMap.toPosition pstate.pos
|
||||
match profileit "parsing" scope.opts fun _ => Parser.parseCommand ictx pmctx pstate cmdState.messages with
|
||||
| (cmd, ps, messages) =>
|
||||
modify fun s => { s with commands := s.commands.push cmd }
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ def parseImports (input : String) (fileName : Option String := none) : IO (List
|
|||
|
||||
@[export lean_print_imports]
|
||||
def printImports (input : String) (fileName : Option String) : IO Unit := do
|
||||
let (deps, pos, log) ← parseImports input fileName
|
||||
let (deps, _, _) ← parseImports input fileName
|
||||
for dep in deps do
|
||||
let fname ← findOLean dep.module
|
||||
IO.println fname
|
||||
|
|
|
|||
|
|
@ -448,7 +448,7 @@ def withMacroExpansionInfo [MonadFinally m] [Monad m] [MonadInfoTree m] [MonadLC
|
|||
@[inline] def withInfoHole [MonadFinally m] [Monad m] [MonadInfoTree m] (mvarId : MVarId) (x : m α) : m α := do
|
||||
if (← getInfoState).enabled then
|
||||
let treesSaved ← getResetInfoTrees
|
||||
Prod.fst <$> MonadFinally.tryFinally' x fun a? => modifyInfoState fun s =>
|
||||
Prod.fst <$> MonadFinally.tryFinally' x fun _ => modifyInfoState fun s =>
|
||||
if s.trees.size > 0 then
|
||||
{ s with trees := treesSaved, assignment := s.assignment.insert mvarId s.trees[s.trees.size - 1] }
|
||||
else
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ def expandMacroArg (stx : Syntax) : MacroM (Syntax × Syntax) := do
|
|||
let pat ← match stx with
|
||||
| `(stx| $s:str) => pure <| mkNode `token_antiquot #[← strLitToPattern s, mkAtom "%", mkAtom "$", id]
|
||||
| `(stx| &$s:str) => pure <| mkNode `token_antiquot #[← strLitToPattern s, mkAtom "%", mkAtom "$", id]
|
||||
| `(stx| optional($stx)) => pure <| mkSplicePat `optional id "?"
|
||||
| `(stx| many($stx)) => pure <| mkSplicePat `many id "*"
|
||||
| `(stx| many1($stx)) => pure <| mkSplicePat `many id "*"
|
||||
| `(stx| sepBy($stx, $sep:str $[, $stxsep]? $[, allowTrailingSep]?)) =>
|
||||
| `(stx| optional($_)) => pure <| mkSplicePat `optional id "?"
|
||||
| `(stx| many($_)) => pure <| mkSplicePat `many id "*"
|
||||
| `(stx| many1($_)) => pure <| mkSplicePat `many id "*"
|
||||
| `(stx| sepBy($_, $sep:str $[, $stxsep]? $[, allowTrailingSep]?)) =>
|
||||
pure <| mkSplicePat `sepBy id ((isStrLit? sep).get! ++ "*")
|
||||
| `(stx| sepBy1($stx, $sep:str $[, $stxsep]? $[, allowTrailingSep]?)) =>
|
||||
| `(stx| sepBy1($_, $sep:str $[, $stxsep]? $[, allowTrailingSep]?)) =>
|
||||
pure <| mkSplicePat `sepBy id ((isStrLit? sep).get! ++ "*")
|
||||
| _ => match id? with
|
||||
-- if there is a binding, we assume the user knows what they are doing
|
||||
|
|
|
|||
|
|
@ -83,18 +83,17 @@ structure ElabMatchTypeAndDiscrsResult where
|
|||
|
||||
private partial def elabMatchTypeAndDiscrs (discrStxs : Array Syntax) (matchOptMotive : Syntax) (matchAltViews : Array MatchAltView) (expectedType : Expr)
|
||||
: TermElabM ElabMatchTypeAndDiscrsResult := do
|
||||
let numDiscrs := discrStxs.size
|
||||
if matchOptMotive.isNone then
|
||||
elabDiscrs 0 #[]
|
||||
else
|
||||
-- motive := leading_parser atomic ("(" >> nonReservedSymbol "motive" >> " := ") >> termParser >> ")"
|
||||
let matchTypeStx := matchOptMotive[0][3]
|
||||
let matchType ← elabType matchTypeStx
|
||||
let (discrs, isDep) ← elabDiscrsWitMatchType matchType expectedType
|
||||
let (discrs, isDep) ← elabDiscrsWitMatchType matchType
|
||||
return { discrs := discrs, matchType := matchType, isDep := isDep, alts := matchAltViews }
|
||||
where
|
||||
/- Easy case: elaborate discriminant when the match-type has been explicitly provided by the user. -/
|
||||
elabDiscrsWitMatchType (matchType : Expr) (expectedType : Expr) : TermElabM (Array Discr × Bool) := do
|
||||
elabDiscrsWitMatchType (matchType : Expr) : TermElabM (Array Discr × Bool) := do
|
||||
let mut discrs := #[]
|
||||
let mut i := 0
|
||||
let mut matchType := matchType
|
||||
|
|
@ -150,13 +149,13 @@ def expandMacrosInPatterns (matchAlts : Array MatchAltView) : MacroM (Array Matc
|
|||
pure { matchAlt with patterns := patterns }
|
||||
|
||||
private def getMatchGeneralizing? : Syntax → Option Bool
|
||||
| `(match (generalizing := true) $[$motive]? $discrs,* with $alts:matchAlt*) => some true
|
||||
| `(match (generalizing := false) $[$motive]? $discrs,* with $alts:matchAlt*) => some false
|
||||
| `(match (generalizing := true) $[$motive]? $_discrs,* with $_alts:matchAlt*) => some true
|
||||
| `(match (generalizing := false) $[$motive]? $_discrs,* with $_alts:matchAlt*) => some false
|
||||
| _ => none
|
||||
|
||||
/- Given `stx` a match-expression, return its alternatives. -/
|
||||
private def getMatchAlts : Syntax → Array MatchAltView
|
||||
| `(match $[$gen]? $[$motive]? $discrs,* with $alts:matchAlt*) =>
|
||||
| `(match $[$gen]? $[$motive]? $_discrs,* with $alts:matchAlt*) =>
|
||||
alts.filterMap fun alt => match alt with
|
||||
| `(matchAltExpr| | $patterns,* => $rhs) => some {
|
||||
ref := alt,
|
||||
|
|
@ -427,7 +426,7 @@ where
|
|||
let map : ST.Ref σ (ExprMap Expr) ← ST.mkRef {}
|
||||
e.forEach fun e => do
|
||||
match patternWithRef? e with
|
||||
| some (ref, b) => map.modify (·.insert b e)
|
||||
| some (_, b) => map.modify (·.insert b e)
|
||||
| none => return ()
|
||||
map.get
|
||||
|
||||
|
|
@ -511,7 +510,7 @@ partial def normalize (e : Expr) : M Expr := do
|
|||
else
|
||||
matchConstCtor e.getAppFn
|
||||
(fun _ => return mkInaccessible (← eraseInaccessibleAnnotations (← instantiateMVars e)))
|
||||
(fun v us => do
|
||||
(fun v _ => do
|
||||
let args := e.getAppArgs
|
||||
unless args.size == v.numParams + v.numFields do
|
||||
throwInvalidPattern e
|
||||
|
|
@ -652,8 +651,8 @@ where
|
|||
/- The `Bool` context is true iff we are inside of an "inaccessible" pattern. -/
|
||||
go (p : Expr) : ReaderT Bool TermElabM Expr := do
|
||||
match p with
|
||||
| .forallE n d b bi => withLocalDecl n b.binderInfo (← go d) fun x => do mkForallFVars #[x] (← go (b.instantiate1 x))
|
||||
| .lam n d b bi => withLocalDecl n b.binderInfo (← go d) fun x => do mkLambdaFVars #[x] (← go (b.instantiate1 x))
|
||||
| .forallE n d b _ => withLocalDecl n b.binderInfo (← go d) fun x => do mkForallFVars #[x] (← go (b.instantiate1 x))
|
||||
| .lam n d b _ => withLocalDecl n b.binderInfo (← go d) fun x => do mkLambdaFVars #[x] (← go (b.instantiate1 x))
|
||||
| .letE n t v b .. => withLetDecl n (← go t) (← go v) fun x => do mkLetFVars #[x] (← go (b.instantiate1 x))
|
||||
| .app f a _ => return mkApp (← go f) (← go a)
|
||||
| .proj _ _ b _ => return p.updateProj! (← go b)
|
||||
|
|
@ -924,7 +923,7 @@ where
|
|||
let matchType ←
|
||||
try
|
||||
updateMatchType indices matchType
|
||||
catch ex =>
|
||||
catch _ =>
|
||||
throwEx first
|
||||
let ref ← getRef
|
||||
trace[Elab.match] "new indices to add as discriminants: {indices}"
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ private partial def withFunLocalDecls {α} (headers : Array DefViewElabHeader) (
|
|||
private def expandWhereStructInst : Macro
|
||||
| `(Parser.Command.whereStructInst|where $[$decls:letDecl$[;]?]*) => do
|
||||
let letIdDecls ← decls.mapM fun stx => match stx with
|
||||
| `(letDecl|$decl:letPatDecl) => Macro.throwErrorAt stx "patterns are not allowed here"
|
||||
| `(letDecl|$_decl:letPatDecl) => Macro.throwErrorAt stx "patterns are not allowed here"
|
||||
| `(letDecl|$decl:letEqnsDecl) => expandLetEqnsDecl decl
|
||||
| `(letDecl|$decl:letIdDecl) => pure decl
|
||||
| _ => Macro.throwUnsupported
|
||||
|
|
@ -708,7 +708,7 @@ def processDefDeriving (className : Name) (declName : Name) : TermElabM Bool :=
|
|||
}
|
||||
addInstance instName AttributeKind.global (eval_prio default)
|
||||
return true
|
||||
catch ex =>
|
||||
catch _ =>
|
||||
return false
|
||||
|
||||
/-- Remove auxiliary match discriminant let-declarations. -/
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ def expandNotationItemIntoPattern (stx : Syntax) : MacroM Syntax :=
|
|||
/-- Try to derive a `SimpleDelab` from a notation.
|
||||
The notation must be of the form `notation ... => c var_1 ... var_n`
|
||||
where `c` is a declaration in the current scope and the `var_i` are a permutation of the LHS vars. -/
|
||||
def mkSimpleDelab (attrKind : Syntax) (vars : Array Syntax) (pat qrhs : Syntax) : OptionT MacroM Syntax := do
|
||||
def mkSimpleDelab (attrKind : Syntax) (pat qrhs : Syntax) : OptionT MacroM Syntax := do
|
||||
match qrhs with
|
||||
| `($c:ident $args*) =>
|
||||
let [(c, [])] ← Macro.resolveGlobalName c.getId | failure
|
||||
|
|
@ -95,7 +95,7 @@ private def expandNotationAux (ref : Syntax)
|
|||
if isLocalAttrKind attrKind then
|
||||
-- Make sure the quotation pre-checker takes section variables into account for local notation.
|
||||
macroDecl ← `(section set_option quotPrecheck.allowSectionVars true $macroDecl end)
|
||||
match (← mkSimpleDelab attrKind vars pat qrhs |>.run) with
|
||||
match (← mkSimpleDelab attrKind pat qrhs |>.run) with
|
||||
| some delabDecl => return mkNullNode #[stxDecl, macroDecl, delabDecl]
|
||||
| none => return mkNullNode #[stxDecl, macroDecl]
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ private def elabOpenHiding (n : Syntax) : M (m:=m) Unit := do
|
|||
let ns ← resolveNamespace n[0].getId
|
||||
let mut ids : List Name := []
|
||||
for idStx in n[2].getArgs do
|
||||
let declName ← resolveId ns idStx
|
||||
let _ ← resolveId ns idStx
|
||||
let id := idStx.getId
|
||||
ids := id::ids
|
||||
addOpenDecl (OpenDecl.simple ns ids)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ def expandRHS? (mvarId : MVarId) : MetaM (Option MVarId) := do
|
|||
|
||||
def funext? (mvarId : MVarId) : MetaM (Option MVarId) := do
|
||||
let target ← getMVarType' mvarId
|
||||
let some (_, lhs, rhs) := target.eq? | return none
|
||||
let some (_, _, rhs) := target.eq? | return none
|
||||
unless rhs.isLambda do return none
|
||||
commitWhenSome? do
|
||||
let [mvarId] ← apply mvarId (← mkConstWithFreshMVarLevels ``funext) | return none
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ private def mkInhabitant? (type : Expr) (useOfNonempty : Bool) : MetaM (Option E
|
|||
return some (← mkOfNonempty type)
|
||||
else
|
||||
return some (← mkDefault type)
|
||||
catch ex =>
|
||||
catch _ =>
|
||||
return none
|
||||
|
||||
private def findAssumption? (xs : Array Expr) (type : Expr) : MetaM (Option Expr) := do
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ private partial def toBelow (below : Expr) (numIndParams : Nat) (recArg : Expr)
|
|||
def refinedArgType (matcherApp : MatcherApp) (arg : Expr) : MetaM Bool := do
|
||||
let argType ← inferType arg
|
||||
(Array.zip matcherApp.alts matcherApp.altNumParams).anyM fun (alt, numParams) =>
|
||||
lambdaTelescope alt fun xs altBody => do
|
||||
lambdaTelescope alt fun xs _ => do
|
||||
if xs.size >= numParams then
|
||||
let refinedArg := xs[numParams - 1]
|
||||
return !(← isDefEq (← inferType refinedArg) argType)
|
||||
|
|
@ -114,7 +114,7 @@ private partial def replaceRecApps (recFnName : Name) (recArgInfo : RecArgInfo)
|
|||
withLetDecl n (← loop below type) (← loop below val) fun x => do
|
||||
mkLetFVars #[x] (← loop below (body.instantiate1 x)) (usedLetOnly := false)
|
||||
| Expr.mdata d b _ =>
|
||||
if let some stx := getRecAppSyntax? e then
|
||||
if let some _ := getRecAppSyntax? e then
|
||||
loop below b
|
||||
else
|
||||
return mkMData d (← loop below b)
|
||||
|
|
|
|||
|
|
@ -90,7 +90,6 @@ def mkIndPredBRecOn (recFnName : Name) (recArgInfo : RecArgInfo) (value : Expr)
|
|||
let FType ← instantiateForall FType recArgInfo.indIndices
|
||||
instantiateForall FType #[major]
|
||||
forallBoundedTelescope FType (some 1) fun below _ => do
|
||||
let main ← mkFreshExprSyntheticOpaqueMVar FType
|
||||
let below := below[0]
|
||||
let valueNew ← replaceIndPredRecApps recFnName recArgInfo motive value
|
||||
let Farg ← mkLambdaFVars (recArgInfo.indIndices ++ #[major, below] ++ otherArgs) valueNew
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ structure EqnInfo extends EqnInfoCore where
|
|||
|
||||
private partial def deltaLHSUntilFix (mvarId : MVarId) : MetaM MVarId := withMVarContext mvarId do
|
||||
let target ← getMVarType' mvarId
|
||||
let some (_, lhs, rhs) := target.eq? | throwTacticEx `deltaLHSUntilFix mvarId "equality expected"
|
||||
let some (_, lhs, _) := target.eq? | throwTacticEx `deltaLHSUntilFix mvarId "equality expected"
|
||||
if lhs.isAppOf ``WellFounded.fix then
|
||||
return mvarId
|
||||
else
|
||||
|
|
@ -143,7 +143,7 @@ private def tryToFoldLHS? (info : EqnInfo) (us : List Level) (fixedPrefix : Arra
|
|||
-/
|
||||
private def getFixedPrefix (declName : Name) (info : EqnInfo) (mvarId : MVarId) : MetaM (List Level × Array Expr) := withMVarContext mvarId do
|
||||
let target ← getMVarType' mvarId
|
||||
let some (_, lhs, rhs) := target.eq? | unreachable!
|
||||
let some (_, lhs, _) := target.eq? | unreachable!
|
||||
let lhsArgs := lhs.getAppArgs
|
||||
if lhsArgs.size < info.fixedPrefixSize || !lhs.getAppFn matches .const .. then
|
||||
throwError "failed to generate equational theorem for '{declName}', unexpected number of arguments in the equation left-hand-side\n{mvarId}"
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ partial def packDomain (fixedPrefix : Nat) (preDefs : Array PreDefinition) : Met
|
|||
let mut arities := #[]
|
||||
let mut modified := false
|
||||
for preDef in preDefs do
|
||||
let (preDefNew, arity, modifiedCurr) ← lambdaTelescope preDef.value fun xs body => do
|
||||
let (preDefNew, arity, modifiedCurr) ← lambdaTelescope preDef.value fun xs _ => do
|
||||
if xs.size == fixedPrefix then
|
||||
throwError "well-founded recursion cannot be used, '{preDef.declName}' does not take any (non-fixed) arguments"
|
||||
let arity := xs.size
|
||||
|
|
@ -93,7 +93,6 @@ partial def packDomain (fixedPrefix : Nat) (preDefs : Array PreDefinition) : Met
|
|||
for i in [:preDefs.size] do
|
||||
let preDef := preDefs[i]
|
||||
let preDefNew := preDefsNew[i]
|
||||
let arity := arities[i]
|
||||
let valueNew ← lambdaTelescope preDef.value fun xs body => do
|
||||
let ys : Array Expr := xs[:fixedPrefix]
|
||||
let xs : Array Expr := xs[fixedPrefix:]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ private partial def unpackMutual (preDefs : Array PreDefinition) (mvarId : MVarI
|
|||
go 0 mvarId fvarId #[]
|
||||
|
||||
private partial def unpackUnary (preDef : PreDefinition) (prefixSize : Nat) (mvarId : MVarId) (fvarId : FVarId) (element : TerminationByElement) : TermElabM MVarId := do
|
||||
let varNames ← lambdaTelescope preDef.value fun xs body => do
|
||||
let varNames ← lambdaTelescope preDef.value fun xs _ => do
|
||||
let mut varNames ← xs.mapM fun x => return (← getLocalDecl x.fvarId!).userName
|
||||
if element.vars.size > varNames.size then
|
||||
throwErrorAt element.vars[varNames.size] "too many variable names"
|
||||
|
|
|
|||
|
|
@ -108,7 +108,6 @@ private def expandTerminationByNonCore (hint : Syntax) (cliques : Array (Array N
|
|||
let mut elseElemStx? := none
|
||||
for elementStx in elementStxs do
|
||||
let declStx := elementStx[0]
|
||||
let vars := elementStx[1].getArgs
|
||||
if declStx.isIdent then
|
||||
let declSuffix := declStx.getId
|
||||
if alreadyFound.contains declSuffix then
|
||||
|
|
|
|||
|
|
@ -50,10 +50,10 @@ private def printDefLike (kind : String) (id : Name) (levelParams : List Name) (
|
|||
private def printAxiomLike (kind : String) (id : Name) (levelParams : List Name) (type : Expr) (isUnsafe := false) : CommandElabM Unit := do
|
||||
logInfo (← mkHeader' kind id levelParams type isUnsafe)
|
||||
|
||||
private def printQuot (kind : QuotKind) (id : Name) (levelParams : List Name) (type : Expr) : CommandElabM Unit := do
|
||||
private def printQuot (id : Name) (levelParams : List Name) (type : Expr) : CommandElabM Unit := do
|
||||
printAxiomLike "Quotient primitive" id levelParams type
|
||||
|
||||
private def printInduct (id : Name) (levelParams : List Name) (numParams : Nat) (numIndices : Nat) (type : Expr)
|
||||
private def printInduct (id : Name) (levelParams : List Name) (numParams : Nat) (type : Expr)
|
||||
(ctors : List Name) (isUnsafe : Bool) : CommandElabM Unit := do
|
||||
let mut m ← mkHeader' "inductive" id levelParams type isUnsafe
|
||||
m := m ++ Format.line ++ "number of parameters: " ++ toString numParams
|
||||
|
|
@ -69,11 +69,11 @@ private def printIdCore (id : Name) : CommandElabM Unit := do
|
|||
| ConstantInfo.defnInfo { levelParams := us, type := t, value := v, safety := s, .. } => printDefLike "def" id us t v s
|
||||
| ConstantInfo.thmInfo { levelParams := us, type := t, value := v, .. } => printDefLike "theorem" id us t v
|
||||
| ConstantInfo.opaqueInfo { levelParams := us, type := t, isUnsafe := u, .. } => printAxiomLike "constant" id us t u
|
||||
| ConstantInfo.quotInfo { kind := kind, levelParams := us, type := t, .. } => printQuot kind id us t
|
||||
| ConstantInfo.quotInfo { levelParams := us, type := t, .. } => printQuot id us t
|
||||
| ConstantInfo.ctorInfo { levelParams := us, type := t, isUnsafe := u, .. } => printAxiomLike "constructor" id us t u
|
||||
| ConstantInfo.recInfo { levelParams := us, type := t, isUnsafe := u, .. } => printAxiomLike "recursor" id us t u
|
||||
| ConstantInfo.inductInfo { levelParams := us, numParams := numParams, numIndices := numIndices, type := t, ctors := ctors, isUnsafe := u, .. } =>
|
||||
printInduct id us numParams numIndices t ctors u
|
||||
| ConstantInfo.inductInfo { levelParams := us, numParams, type := t, ctors, isUnsafe := u, .. } =>
|
||||
printInduct id us numParams t ctors u
|
||||
| none => throwUnknownId id
|
||||
|
||||
private def printId (id : Syntax) : CommandElabM Unit := do
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ private partial def floatOutAntiquotTerms : Syntax → StateT (Syntax → TermEl
|
|||
if !e.isIdent || !e.getId.isAtomic then
|
||||
return ← withFreshMacroScope do
|
||||
let a ← `(a)
|
||||
modify (fun cont stx => (`(let $a:ident := $e; $stx) : TermElabM _))
|
||||
modify (fun _ stx => (`(let $a:ident := $e; $stx) : TermElabM _))
|
||||
pure <| stx.setArg 2 a
|
||||
return Syntax.node i k (← args.mapM floatOutAntiquotTerms)
|
||||
| stx => pure stx
|
||||
|
|
@ -260,7 +260,7 @@ private partial def getHeadInfo (alt : Alt) : TermElabM HeadInfo :=
|
|||
let pat := alt.fst.head!
|
||||
let unconditionally (rhsFn) := pure {
|
||||
check := unconditional,
|
||||
doMatch := fun yes no => yes [],
|
||||
doMatch := fun yes _ => yes [],
|
||||
onMatch := fun taken => covered (adaptRhs rhsFn ∘ noOpMatchAdaptPats taken) (match taken with | unconditional => true | _ => false)
|
||||
}
|
||||
-- quotation pattern
|
||||
|
|
@ -438,7 +438,7 @@ private partial def getHeadInfo (alt : Alt) : TermElabM HeadInfo :=
|
|||
private def deduplicate (floatedLetDecls : Array Syntax) : Alt → TermElabM (Array Syntax × Alt)
|
||||
-- NOTE: new macro scope so that introduced bindings do not collide
|
||||
| (pats, rhs) => do
|
||||
if let `($_:ident $[ $args:ident]*) := rhs then
|
||||
if let `($_:ident $[ $_:ident]*) := rhs then
|
||||
-- looks simple enough/created by this function, skip
|
||||
return (floatedLetDecls, (pats, rhs))
|
||||
withFreshMacroScope do
|
||||
|
|
@ -460,7 +460,6 @@ private partial def compileStxMatch (discrs : List Syntax) (alts : List Alt) : T
|
|||
pure Syntax.missing
|
||||
| discr::discrs, alt::alts => do
|
||||
let info ← getHeadInfo alt
|
||||
let pat := alt.1.head!
|
||||
let alts ← (alt::alts).mapM fun alt => return ((← getHeadInfo alt).onMatch info.check, alt)
|
||||
let mut yesAlts := #[]
|
||||
let mut undecidedAlts := #[]
|
||||
|
|
@ -507,7 +506,7 @@ def match_syntax.expand (stx : Syntax) : TermElabM Syntax := do
|
|||
match stx with
|
||||
| `(match $[$discrs:term],* with $[| $[$patss],* => $rhss]*) => do
|
||||
if !patss.any (·.any (fun
|
||||
| `($id@$pat) => pat.isQuot
|
||||
| `($_@$pat) => pat.isQuot
|
||||
| pat => pat.isQuot)) then
|
||||
-- no quotations => fall back to regular `match`
|
||||
throwUnsupportedSyntax
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ private def elabModifyOp (stx modifyOp : Syntax) (sources : Array ExplicitSource
|
|||
|
||||
If the expected type is available and it is a structure, then we use it.
|
||||
Otherwise, we use the type of the first source. -/
|
||||
private def getStructName (stx : Syntax) (expectedType? : Option Expr) (sourceView : Source) : TermElabM Name := do
|
||||
private def getStructName (expectedType? : Option Expr) (sourceView : Source) : TermElabM Name := do
|
||||
tryPostponeIfNoneOrMVar expectedType?
|
||||
let useSource : Unit → TermElabM Name := fun _ => do
|
||||
match sourceView, expectedType? with
|
||||
|
|
@ -378,7 +378,7 @@ def Struct.setParams (s : Struct) (ps : Array (Name × Expr)) : Struct :=
|
|||
|
||||
private def expandCompositeFields (s : Struct) : Struct :=
|
||||
s.modifyFields fun fields => fields.map fun field => match field with
|
||||
| { lhs := FieldLHS.fieldName ref (Name.str Name.anonymous _ _) :: rest, .. } => field
|
||||
| { lhs := FieldLHS.fieldName _ (Name.str Name.anonymous _ _) :: _, .. } => field
|
||||
| { lhs := FieldLHS.fieldName ref n@(Name.str _ _ _) :: rest, .. } =>
|
||||
let newEntries := n.components.map <| FieldLHS.fieldName ref
|
||||
{ field with lhs := newEntries ++ rest }
|
||||
|
|
@ -472,7 +472,6 @@ mutual
|
|||
|
||||
private partial def groupFields (s : Struct) : TermElabM Struct := do
|
||||
let env ← getEnv
|
||||
let fieldNames := getStructureFields env s.structName
|
||||
withRef s.ref do
|
||||
s.modifyFieldsM fun fields => do
|
||||
let fieldMap ← mkFieldMap fields
|
||||
|
|
@ -742,7 +741,7 @@ partial def mkDefaultValueAux? (struct : Struct) : Expr → TermElabM (Option Ex
|
|||
else
|
||||
return none
|
||||
else
|
||||
if let some (_, param) := struct.params.find? fun (paramName, param) => paramName == n then
|
||||
if let some (_, param) := struct.params.find? fun (paramName, _) => paramName == n then
|
||||
-- Recall that we did not use to have support for parameter propagation here.
|
||||
if (← isDefEq (← inferType param) d) then
|
||||
mkDefaultValueAux? struct (b.instantiate1 param)
|
||||
|
|
@ -864,7 +863,7 @@ def propagate (struct : Struct) : TermElabM Unit :=
|
|||
end DefaultFields
|
||||
|
||||
private def elabStructInstAux (stx : Syntax) (expectedType? : Option Expr) (source : Source) : TermElabM Expr := do
|
||||
let structName ← getStructName stx expectedType? source
|
||||
let structName ← getStructName expectedType? source
|
||||
let struct ← liftMacroM <| mkStructView stx structName source
|
||||
let struct ← expandStruct struct
|
||||
trace[Elab.struct] "{struct}"
|
||||
|
|
|
|||
|
|
@ -293,8 +293,8 @@ private def getFieldType (infos : Array StructFieldInfo) (parentType : Expr) (fi
|
|||
(where `toGrandparent` is not a field of the current structure). -/
|
||||
let visit (e : Expr) : MetaM TransformStep := do
|
||||
if let Expr.const subProjName .. := e.getAppFn then
|
||||
if let some { ctorName, numParams, .. } ← getProjectionFnInfo? subProjName then
|
||||
let Name.str subStructName subFieldName .. := subProjName
|
||||
if let some { numParams, .. } ← getProjectionFnInfo? subProjName then
|
||||
let Name.str _ subFieldName .. := subProjName
|
||||
| throwError "invalid projection name {subProjName}"
|
||||
let args := e.getAppArgs
|
||||
if let some major := args.get? numParams then
|
||||
|
|
@ -374,7 +374,6 @@ where
|
|||
match e with
|
||||
| Expr.lam n d b c =>
|
||||
if c.binderInfo.isExplicit then
|
||||
let fieldName := n
|
||||
match fieldMap.find? n with
|
||||
| none => failed
|
||||
| some val =>
|
||||
|
|
@ -543,7 +542,7 @@ where
|
|||
kind := StructFieldKind.newField }
|
||||
go (i+1) defaultValsOverridden infos
|
||||
| some info =>
|
||||
let updateDefaultValue (fromParent : Bool) : TermElabM α := do
|
||||
let updateDefaultValue : TermElabM α := do
|
||||
match view.value? with
|
||||
| none => throwError "field '{view.name}' has been declared in parent structure"
|
||||
| some valStx =>
|
||||
|
|
@ -563,8 +562,8 @@ where
|
|||
match info.kind with
|
||||
| StructFieldKind.newField => throwError "field '{view.name}' has already been declared"
|
||||
| StructFieldKind.subobject => throwError "unexpected subobject field reference" -- improve error message
|
||||
| StructFieldKind.copiedField => updateDefaultValue false
|
||||
| StructFieldKind.fromParent => updateDefaultValue true
|
||||
| StructFieldKind.copiedField => updateDefaultValue
|
||||
| StructFieldKind.fromParent => updateDefaultValue
|
||||
else
|
||||
k infos
|
||||
|
||||
|
|
@ -789,7 +788,6 @@ private def elabStructureView (view : StructView) : TermElabM Unit := do
|
|||
if field.declName == view.ctor.declName then
|
||||
throwErrorAt field.ref "invalid field name '{field.name}', it is equal to structure constructor name"
|
||||
addAuxDeclarationRanges field.declName field.ref field.ref
|
||||
let numExplicitParams := view.params.size
|
||||
let type ← Term.elabType view.type
|
||||
unless validStructType type do throwErrorAt view.type "expected Type"
|
||||
withRef view.ref do
|
||||
|
|
@ -799,7 +797,6 @@ private def elabStructureView (view : StructView) : TermElabM Unit := do
|
|||
let u ← getResultUniverse type
|
||||
let univToInfer? ← shouldInferResultUniverse u
|
||||
withUsed view.scopeVars view.params fieldInfos fun scopeVars => do
|
||||
let numParams := scopeVars.size + numExplicitParams
|
||||
let fieldInfos ← levelMVarToParam scopeVars view.params fieldInfos univToInfer?
|
||||
let type ← withRef view.ref do
|
||||
if univToInfer?.isSome then
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ def checkRuleKind (given expected : SyntaxNodeKind) : Bool :=
|
|||
given == expected || given == expected ++ `antiquot
|
||||
|
||||
def inferMacroRulesAltKind : Syntax → CommandElabM SyntaxNodeKind
|
||||
| `(matchAltExpr| | $pat:term => $rhs) => do
|
||||
| `(matchAltExpr| | $pat:term => $_) => do
|
||||
if !pat.isQuot then
|
||||
throwUnsupportedSyntax
|
||||
let quoted := getQuotContent pat
|
||||
|
|
|
|||
|
|
@ -303,7 +303,6 @@ mutual
|
|||
|
||||
partial def runTactic (mvarId : MVarId) (tacticCode : Syntax) : TermElabM Unit := do
|
||||
/- Recall, `tacticCode` is the whole `by ...` expression. -/
|
||||
let byTk := tacticCode[0]
|
||||
let code := tacticCode[1]
|
||||
modifyThe Meta.State fun s => { s with mctx := s.mctx.instantiateMVarDeclMVars mvarId }
|
||||
let remainingGoals ← withInfoHole mvarId <| Tactic.run mvarId do
|
||||
|
|
|
|||
|
|
@ -161,7 +161,6 @@ mutual
|
|||
let rec loop
|
||||
| [] => throwErrorAt stx "tactic '{stx.getKind}' has not been implemented"
|
||||
| m::ms => do
|
||||
let scp ← getCurrMacroScope
|
||||
try
|
||||
withReader ({ · with elaborator := m.declName }) do
|
||||
withTacticInfoContext stx do
|
||||
|
|
@ -283,7 +282,7 @@ def appendGoals (mvarIds : List MVarId) : TacticM Unit :=
|
|||
modify fun s => { s with goals := s.goals ++ mvarIds }
|
||||
|
||||
def replaceMainGoal (mvarIds : List MVarId) : TacticM Unit := do
|
||||
let (mvarId :: mvarIds') ← getGoals | throwNoGoalsToBeSolved
|
||||
let (_ :: mvarIds') ← getGoals | throwNoGoalsToBeSolved
|
||||
modify fun _ => { goals := mvarIds ++ mvarIds' }
|
||||
|
||||
/-- Return the first goal. -/
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ partial def evalChoiceAux (tactics : Array Syntax) (i : Nat) : TacticM Unit :=
|
|||
@[builtinTactic choice] def evalChoice : Tactic := fun stx =>
|
||||
evalChoiceAux stx.getArgs 0
|
||||
|
||||
@[builtinTactic skip] def evalSkip : Tactic := fun stx => pure ()
|
||||
@[builtinTactic skip] def evalSkip : Tactic := fun _ => pure ()
|
||||
|
||||
@[builtinTactic unknown] def evalUnknown : Tactic := fun stx => do
|
||||
addCompletionInfo <| CompletionInfo.tactic stx (← getGoals)
|
||||
|
|
@ -171,24 +171,22 @@ partial def evalChoiceAux (tactics : Array Syntax) (i : Nat) : TacticM Unit :=
|
|||
if (← try evalTactic tactic; pure true catch _ => pure false) then
|
||||
throwError "tactic succeeded"
|
||||
|
||||
@[builtinTactic traceState] def evalTraceState : Tactic := fun stx => do
|
||||
@[builtinTactic traceState] def evalTraceState : Tactic := fun _ => do
|
||||
let gs ← getUnsolvedGoals
|
||||
addRawTrace (goalsToMessageData gs)
|
||||
|
||||
@[builtinTactic traceMessage] def evalTraceMessage : Tactic := fun stx => do
|
||||
match stx[1].isStrLit? with
|
||||
| none => throwIllFormedSyntax
|
||||
| some msg =>
|
||||
let gs ← getUnsolvedGoals
|
||||
withRef stx[0] <| addRawTrace msg
|
||||
| some msg => withRef stx[0] <| addRawTrace msg
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.assumption] def evalAssumption : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.assumption] def evalAssumption : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => do Meta.assumption mvarId; pure []
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.contradiction] def evalContradiction : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.contradiction] def evalContradiction : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => do Meta.contradiction mvarId; pure []
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.refl] def evalRefl : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.refl] def evalRefl : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => do Meta.refl mvarId; pure []
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.intro] def evalIntro : Tactic := fun stx => do
|
||||
|
|
@ -257,7 +255,7 @@ def forEachVar (hs : Array Syntax) (tac : MVarId → FVarId → MetaM MVarId) :
|
|||
| `(tactic| subst $hs*) => forEachVar hs Meta.subst
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.substVars] def evalSubstVars : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.substVars] def evalSubstVars : Tactic := fun _ =>
|
||||
liftMetaTactic fun mvarId => return [← substVars mvarId]
|
||||
|
||||
/--
|
||||
|
|
@ -329,7 +327,7 @@ private def getCaseGoals (tag : Syntax) : TacticM (MVarId × List MVarId) := do
|
|||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «case'»] def evalCase' : Tactic
|
||||
| stx@`(tactic| case' $tag $hs* =>%$arr $tac:tacticSeq) => do
|
||||
| `(tactic| case' $tag $hs* =>%$arr $tac:tacticSeq) => do
|
||||
let (g, gs) ← getCaseGoals tag
|
||||
let g ← renameInaccessibles g hs
|
||||
let mvarTag ← getMVarTag g
|
||||
|
|
@ -342,7 +340,7 @@ private def getCaseGoals (tag : Syntax) : TacticM (MVarId × List MVarId) := do
|
|||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «renameI»] def evalRenameInaccessibles : Tactic
|
||||
| stx@`(tactic| rename_i $hs*) => do replaceMainGoal [← renameInaccessibles (← getMainGoal) hs]
|
||||
| `(tactic| rename_i $hs*) => do replaceMainGoal [← renameInaccessibles (← getMainGoal) hs]
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic «first»] partial def evalFirst : Tactic := fun stx => do
|
||||
|
|
|
|||
|
|
@ -71,11 +71,11 @@ def changeLhs (lhs' : Expr) : TacticM Unit := do
|
|||
liftMetaTactic1 fun mvarId => do
|
||||
replaceTargetDefEq mvarId (mkLHSGoal (← mkEq lhs' rhs))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.whnf] def evalWhnf : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.whnf] def evalWhnf : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
changeLhs (← whnf (← getLhs))
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.reduce] def evalReduce : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.reduce] def evalReduce : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
changeLhs (← reduce (← getLhs))
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ def changeLhs (lhs' : Expr) : TacticM Unit := do
|
|||
def remarkAsConvGoal : TacticM Unit := do
|
||||
let newGoals ← (← getUnsolvedGoals).mapM fun mvarId => withMVarContext mvarId do
|
||||
let target ← getMVarType mvarId
|
||||
if let some (_, lhs, rhs) ← matchEq? target then
|
||||
if let some (_, _, rhs) ← matchEq? target then
|
||||
if rhs.getAppFn.isMVar then
|
||||
replaceTargetDefEq mvarId (mkLHSGoal target)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ def congr (mvarId : MVarId) : MetaM (List MVarId) :=
|
|||
else
|
||||
throwError "invalid 'congr' conv tactic, application or implication expected{indentExpr lhs}"
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.congr] def evalCongr : Tactic := fun stx => do
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.congr] def evalCongr : Tactic := fun _ => do
|
||||
replaceMainGoal (← congr (← getMainGoal))
|
||||
|
||||
private def selectIdx (tacticName : String) (mvarIds : List MVarId) (i : Int) : TacticM Unit := do
|
||||
|
|
@ -73,11 +73,11 @@ private def selectIdx (tacticName : String) (mvarIds : List MVarId) (i : Int) :
|
|||
return ()
|
||||
throwError "invalid '{tacticName}' conv tactic, application has only {mvarIds.length} (nondependent) argument(s)"
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.lhs] def evalLhs : Tactic := fun stx => do
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.lhs] def evalLhs : Tactic := fun _ => do
|
||||
let mvarIds ← congr (← getMainGoal)
|
||||
selectIdx "lhs" mvarIds ((mvarIds.length : Int) - 2)
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.rhs] def evalRhs : Tactic := fun stx => do
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.rhs] def evalRhs : Tactic := fun _ => do
|
||||
let mvarIds ← congr (← getMainGoal)
|
||||
selectIdx "rhs" mvarIds ((mvarIds.length : Int) - 1)
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ private def selectIdx (tacticName : String) (mvarIds : List MVarId) (i : Int) :
|
|||
private def extCore (mvarId : MVarId) (userName? : Option Name) : MetaM MVarId :=
|
||||
withMVarContext mvarId do
|
||||
let userNames := if let some userName := userName? then [userName] else []
|
||||
let (lhs, rhs) ← getLhsRhsCore mvarId
|
||||
let (lhs, _) ← getLhsRhsCore mvarId
|
||||
let lhs ← instantiateMVars lhs
|
||||
if lhs.isForall then
|
||||
let [mvarId, _] ← apply mvarId (← mkConstWithFreshMVarLevels ``forall_congr) | throwError "'apply forall_congr' unexpected result"
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def applySimpResult (result : Simp.Result) : TacticM Unit := do
|
|||
let result ← dischargeWrapper.with fun d? => simp lhs ctx (discharge? := d?)
|
||||
applySimpResult result
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.simpMatch] def evalSimpMatch : Tactic := fun stx => withMainContext do
|
||||
@[builtinTactic Lean.Parser.Tactic.Conv.simpMatch] def evalSimpMatch : Tactic := fun _ => withMainContext do
|
||||
applySimpResult (← Split.simpMatch (← getLhs))
|
||||
|
||||
end Lean.Elab.Tactic.Conv
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ def getFVarIds (ids : Array Syntax) : TacticM (Array FVarId) := do
|
|||
| `(tactic| apply $e) => evalApplyLikeTactic Meta.apply e
|
||||
| _ => throwUnsupportedSyntax
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.constructor] def evalConstructor : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.constructor] def evalConstructor : Tactic := fun _ =>
|
||||
withMainContext do
|
||||
let mvarIds' ← Meta.constructor (← getMainGoal)
|
||||
Term.synthesizeSyntheticMVarsNoPostponing
|
||||
|
|
@ -272,7 +272,7 @@ private def preprocessPropToDecide (expectedType : Expr) : TermElabM Expr := do
|
|||
throwError "expected type must not contain free or meta variables{indentExpr expectedType}"
|
||||
return expectedType
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.decide] def evalDecide : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.decide] def evalDecide : Tactic := fun _ =>
|
||||
closeMainGoalUsing fun expectedType => do
|
||||
let expectedType ← preprocessPropToDecide expectedType
|
||||
let d ← mkDecide expectedType
|
||||
|
|
@ -295,7 +295,7 @@ private def mkNativeAuxDecl (baseName : Name) (type val : Expr) : TermElabM Name
|
|||
compileDecl decl
|
||||
pure auxName
|
||||
|
||||
@[builtinTactic Lean.Parser.Tactic.nativeDecide] def evalNativeDecide : Tactic := fun stx =>
|
||||
@[builtinTactic Lean.Parser.Tactic.nativeDecide] def evalNativeDecide : Tactic := fun _ =>
|
||||
closeMainGoalUsing fun expectedType => do
|
||||
let expectedType ← preprocessPropToDecide expectedType
|
||||
let d ← mkDecide expectedType
|
||||
|
|
|
|||
|
|
@ -443,7 +443,6 @@ private def generalizeTargets (exprs : Array Expr) : TacticM (Array Expr) := do
|
|||
ElimApp.mkElimApp elimInfo targets tag
|
||||
trace[Elab.induction] "elimApp: {result.elimApp}"
|
||||
let elimArgs := result.elimApp.getAppArgs
|
||||
let motiveType ← inferType elimArgs[elimInfo.motivePos]
|
||||
ElimApp.setMotiveArg mvarId elimArgs[elimInfo.motivePos].mvarId! targetFVarIds
|
||||
let optPreTac := getOptPreTacOfOptInductionAlts optInductionAlts
|
||||
assignExprMVar mvarId result.elimApp
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ private def checkUnusedIds (mvarId : MVarId) (unusedIds : List Name) : MetaM Uni
|
|||
| Meta.InjectionResult.solved => checkUnusedIds mvarId ids; return []
|
||||
| Meta.InjectionResult.subgoal mvarId' _ unusedIds => checkUnusedIds mvarId unusedIds; return [mvarId']
|
||||
|
||||
@[builtinTactic «injections»] def evalInjections : Tactic := fun stx => do
|
||||
@[builtinTactic «injections»] def evalInjections : Tactic := fun _ => do
|
||||
liftMetaTactic fun mvarId => do
|
||||
match (← Meta.injections mvarId) with
|
||||
| none => return []
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ def rewriteLocalDecl (stx : Syntax) (symm : Bool) (fvarId : FVarId) (config : Re
|
|||
def withRWRulesSeq (token : Syntax) (rwRulesSeqStx : Syntax) (x : (symm : Bool) → (term : Syntax) → TacticM Unit) : TacticM Unit := do
|
||||
let lbrak := rwRulesSeqStx[0]
|
||||
let rules := rwRulesSeqStx[1].getArgs
|
||||
let rbrak := rwRulesSeqStx[2]
|
||||
-- show initial state up to (incl.) `[`
|
||||
withTacticInfoContext (mkNullNode #[token, lbrak]) (pure ())
|
||||
let numRules := (rules.size + 1) / 2
|
||||
|
|
|
|||
|
|
@ -595,7 +595,7 @@ def throwTypeMismatchError (header? : Option String) (expectedType : Expr) (eTyp
|
|||
-/
|
||||
match f? with
|
||||
| none => throwError "{← mkTypeMismatchError header? e eType expectedType}{extraMsg}"
|
||||
| some f => Meta.throwAppTypeMismatch f e extraMsg
|
||||
| some f => Meta.throwAppTypeMismatch f e
|
||||
|
||||
def withoutMacroStackAtErr (x : TermElabM α) : TermElabM α :=
|
||||
withTheReader Core.Context (fun (ctx : Core.Context) => { ctx with options := pp.macroStack.set ctx.options false }) x
|
||||
|
|
@ -951,9 +951,8 @@ def withSavedContext (savedCtx : SavedContext) (x : TermElabM α) : TermElabM α
|
|||
private def postponeElabTerm (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
|
||||
trace[Elab.postpone] "{stx} : {expectedType?}"
|
||||
let mvar ← mkFreshExprMVar expectedType? MetavarKind.syntheticOpaque
|
||||
let ctx ← read
|
||||
registerSyntheticMVar stx mvar.mvarId! (SyntheticMVarKind.postponed (← saveContext))
|
||||
pure mvar
|
||||
return mvar
|
||||
|
||||
def getSyntheticMVarDecl? (mvarId : MVarId) : TermElabM (Option SyntheticMVarDecl) :=
|
||||
return (← get).syntheticMVars.find? fun d => d.mvarId == mvarId
|
||||
|
|
@ -1103,8 +1102,8 @@ private def isExplicitApp (stx : Syntax) : Bool :=
|
|||
Example: `fun {α} (a : α) => a` -/
|
||||
private def isLambdaWithImplicit (stx : Syntax) : Bool :=
|
||||
match stx with
|
||||
| `(fun $binders* => $body) => binders.any fun b => b.isOfKind ``Lean.Parser.Term.implicitBinder || b.isOfKind `Lean.Parser.Term.instBinder
|
||||
| _ => false
|
||||
| `(fun $binders* => $_) => binders.any fun b => b.isOfKind ``Lean.Parser.Term.implicitBinder || b.isOfKind `Lean.Parser.Term.instBinder
|
||||
| _ => false
|
||||
|
||||
private partial def dropTermParens : Syntax → Syntax := fun stx =>
|
||||
match stx with
|
||||
|
|
@ -1130,8 +1129,8 @@ private def isNoImplicitLambda (stx : Syntax) : Bool :=
|
|||
|
||||
private def isTypeAscription (stx : Syntax) : Bool :=
|
||||
match stx with
|
||||
| `(($_ : $type)) => true
|
||||
| _ => false
|
||||
| `(($_ : $_)) => true
|
||||
| _ => false
|
||||
|
||||
def hasNoImplicitLambdaAnnotation (type : Expr) : Bool :=
|
||||
annotation? `noImplicitLambda type |>.isSome
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ def TagDeclarationExtension := SimplePersistentEnvExtension Name NameSet
|
|||
def mkTagDeclarationExtension (name : Name) : IO TagDeclarationExtension :=
|
||||
registerSimplePersistentEnvExtension {
|
||||
name := name,
|
||||
addImportedFn := fun as => {},
|
||||
addImportedFn := fun _ => {},
|
||||
addEntryFn := fun s n => s.insert n,
|
||||
toArrayFn := fun es => es.toArray.qsort Name.quickLt
|
||||
}
|
||||
|
|
@ -482,7 +482,7 @@ def MapDeclarationExtension (α : Type) := SimplePersistentEnvExtension (Name ×
|
|||
def mkMapDeclarationExtension [Inhabited α] (name : Name) : IO (MapDeclarationExtension α) :=
|
||||
registerSimplePersistentEnvExtension {
|
||||
name := name,
|
||||
addImportedFn := fun as => {},
|
||||
addImportedFn := fun _ => {},
|
||||
addEntryFn := fun s n => s.insert n.1 n.2 ,
|
||||
toArrayFn := fun es => es.toArray.qsort (fun a b => Name.quickLt a.1 b.1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class MetaEval (α : Type u) where
|
|||
eval : Environment → Options → α → (hideUnit : Bool) → IO Environment
|
||||
|
||||
instance {α : Type u} [Eval α] : MetaEval α :=
|
||||
⟨fun env opts a hideUnit => do Eval.eval (fun _ => a) hideUnit; pure env⟩
|
||||
⟨fun env _ a hideUnit => do Eval.eval (fun _ => a) hideUnit; pure env⟩
|
||||
|
||||
def runMetaEval {α : Type u} [MetaEval α] (env : Environment) (opts : Options) (a : α) : IO (String × Except IO.Error Environment) :=
|
||||
IO.FS.withIsolatedStreams (MetaEval.eval env opts a false |>.toBaseIO)
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ protected unsafe def init {γ} (df : Def γ) (attrDeclName : Name) : IO (KeyedDe
|
|||
| Expr.const c _ _ =>
|
||||
if c != df.valueTypeName then throwError "unexpected type at '{declName}', '{df.valueTypeName}' expected"
|
||||
else
|
||||
let env ← getEnv
|
||||
/- builtin_initialize @addBuiltin $(mkConst valueTypeName) $(mkConst attrDeclName) $(key) $(declName) $(mkConst declName) -/
|
||||
let val := mkAppN (mkConst `Lean.KeyedDeclsAttribute.addBuiltin) #[mkConst df.valueTypeName, mkConst attrDeclName, toExpr key, toExpr declName, mkConst declName]
|
||||
declareBuiltin declName val
|
||||
|
|
|
|||
|
|
@ -110,14 +110,6 @@ where
|
|||
-- See main function
|
||||
| Expr.mdata .. => unreachable!
|
||||
|
||||
lex (a b : Expr) : MetaM Bool :=
|
||||
if a.ctorWeight < b.ctorWeight then
|
||||
return true
|
||||
else if a.ctorWeight > b.ctorWeight then
|
||||
return false
|
||||
else
|
||||
lexSameCtor a b
|
||||
|
||||
allChildrenLt (a b : Expr) : MetaM Bool :=
|
||||
match a with
|
||||
| Expr.proj _ _ e .. => lt e b
|
||||
|
|
|
|||
|
|
@ -487,7 +487,7 @@ def instantiateLocalDeclMVars (localDecl : LocalDecl) : MetaM LocalDecl :=
|
|||
setMCtx sNew.mctx
|
||||
modifyThe Core.State fun s => { s with ngen := sNew.ngen, nextMacroScope := sNew.nextMacroScope }
|
||||
pure e
|
||||
| EStateM.Result.error (MetavarContext.MkBinding.Exception.revertFailure mctx lctx toRevert decl) sNew => do
|
||||
| EStateM.Result.error (.revertFailure ..) sNew => do
|
||||
setMCtx sNew.mctx
|
||||
modifyThe Core.State fun s => { s with ngen := sNew.ngen, nextMacroScope := sNew.nextMacroScope }
|
||||
throwError "failed to create binder due to failure when reverting variable dependencies"
|
||||
|
|
@ -758,7 +758,7 @@ mutual
|
|||
|
||||
private partial def isClassExpensive? (type : Expr) : MetaM (Option Name) :=
|
||||
withReducible do -- when testing whether a type is a type class, we only unfold reducible constants.
|
||||
forallTelescopeReducingAux type none fun xs type => do
|
||||
forallTelescopeReducingAux type none fun _ type => do
|
||||
let env ← getEnv
|
||||
match type.getAppFn with
|
||||
| Expr.const c _ _ => do
|
||||
|
|
@ -1010,7 +1010,6 @@ def withLocalInstances (decls : List LocalDecl) : n α → n α :=
|
|||
|
||||
private def withExistingLocalDeclsImp (decls : List LocalDecl) (k : MetaM α) : MetaM α := do
|
||||
let ctx ← read
|
||||
let numLocalInstances := ctx.localInstances.size
|
||||
let lctx := decls.foldl (fun (lctx : LocalContext) decl => lctx.addDecl decl) ctx.lctx
|
||||
withReader (fun ctx => { ctx with lctx := lctx }) do
|
||||
withLocalInstancesImp decls k
|
||||
|
|
@ -1165,7 +1164,7 @@ instance : Alternative MetaM where
|
|||
orElse := Meta.orElse
|
||||
|
||||
@[inline] private def orelseMergeErrorsImp (x y : MetaM α)
|
||||
(mergeRef : Syntax → Syntax → Syntax := fun r₁ r₂ => r₁)
|
||||
(mergeRef : Syntax → Syntax → Syntax := fun r₁ _ => r₁)
|
||||
(mergeMsg : MessageData → MessageData → MessageData := fun m₁ m₂ => m₁ ++ Format.line ++ m₂) : MetaM α := do
|
||||
let env ← getEnv
|
||||
let mctx ← getMCtx
|
||||
|
|
@ -1188,7 +1187,7 @@ instance : Alternative MetaM where
|
|||
The default `mergeRef` uses the `ref` (position information) for the first message.
|
||||
The default `mergeMsg` combines error messages using `Format.line ++ Format.line` as a separator. -/
|
||||
@[inline] def orelseMergeErrors [MonadControlT MetaM m] [Monad m] (x y : m α)
|
||||
(mergeRef : Syntax → Syntax → Syntax := fun r₁ r₂ => r₁)
|
||||
(mergeRef : Syntax → Syntax → Syntax := fun r₁ _ => r₁)
|
||||
(mergeMsg : MessageData → MessageData → MessageData := fun m₁ m₂ => m₁ ++ Format.line ++ Format.line ++ m₂) : m α := do
|
||||
controlAt MetaM fun runInBase => orelseMergeErrorsImp (runInBase x) (runInBase y) mergeRef mergeMsg
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ def CasesOnApp.addArg (c : CasesOnApp) (arg : Expr) (checkIfRefined : Bool := fa
|
|||
return { c with us, motive, alts, remaining }
|
||||
where
|
||||
updateAlts (argType : Expr) (auxType : Expr) : MetaM (Array Expr) := do
|
||||
let indName := c.declName.getPrefix
|
||||
let mut auxType := auxType
|
||||
let mut altsNew := #[]
|
||||
let mut refined := false
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ def mkHasTypeButIsExpectedMsg (givenType expectedType : Expr) : MetaM MessageDat
|
|||
let (givenType, expectedType) ← addPPExplicitToExposeDiff givenType expectedType
|
||||
return m!"has type{indentExpr givenType}\nbut is expected to have type{indentExpr expectedType}"
|
||||
|
||||
def throwAppTypeMismatch {α} (f a : Expr) (extraMsg : MessageData := Format.nil) : MetaM α := do
|
||||
def throwAppTypeMismatch (f a : Expr) : MetaM α := do
|
||||
let (expectedType, binfo) ← getFunctionDomain f
|
||||
let mut e := mkApp f a
|
||||
unless binfo.isExplicit do
|
||||
|
|
|
|||
|
|
@ -152,12 +152,12 @@ def mkNewLevelParam (u : Level) : ClosureM Level := do
|
|||
pure $ mkLevelParam p
|
||||
|
||||
partial def collectLevelAux : Level → ClosureM Level
|
||||
| u@(Level.succ v _) => return u.updateSucc! (← visitLevel collectLevelAux v)
|
||||
| u@(Level.max v w _) => return u.updateMax! (← visitLevel collectLevelAux v) (← visitLevel collectLevelAux w)
|
||||
| u@(Level.imax v w _) => return u.updateIMax! (← visitLevel collectLevelAux v) (← visitLevel collectLevelAux w)
|
||||
| u@(Level.mvar mvarId _) => mkNewLevelParam u
|
||||
| u@(Level.param _ _) => mkNewLevelParam u
|
||||
| u@(Level.zero _) => pure u
|
||||
| u@(Level.succ v _) => return u.updateSucc! (← visitLevel collectLevelAux v)
|
||||
| u@(Level.max v w _) => return u.updateMax! (← visitLevel collectLevelAux v) (← visitLevel collectLevelAux w)
|
||||
| u@(Level.imax v w _) => return u.updateIMax! (← visitLevel collectLevelAux v) (← visitLevel collectLevelAux w)
|
||||
| u@(Level.mvar ..) => mkNewLevelParam u
|
||||
| u@(Level.param ..) => mkNewLevelParam u
|
||||
| u@(Level.zero _) => pure u
|
||||
|
||||
def collectLevel (u : Level) : ClosureM Level := do
|
||||
-- u ← instantiateLevelMVars u
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ where
|
|||
mk? (f : Expr) (info : FunInfo) (kinds : Array CongrArgKind) : MetaM (Option CongrTheorem) := do
|
||||
try
|
||||
let fType ← inferType f
|
||||
forallBoundedTelescope fType kinds.size fun lhss xType => do
|
||||
forallBoundedTelescope fType kinds.size fun lhss _ => do
|
||||
if lhss.size != kinds.size then return none
|
||||
let rec go (i : Nat) (rhss : Array Expr) (eqs : Array (Option Expr)) (hyps : Array Expr) : MetaM CongrTheorem := do
|
||||
if i == kinds.size then
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ where
|
|||
checkpointDefEq do
|
||||
let args := b.getAppArgs
|
||||
let params := args[:ctorVal.numParams].toArray
|
||||
let info? := getStructureInfo? (← getEnv) ctorVal.induct
|
||||
for i in [ctorVal.numParams : args.size] do
|
||||
let j := i - ctorVal.numParams
|
||||
let proj ← mkProjFn ctorVal us params j a
|
||||
|
|
@ -785,7 +784,7 @@ end CheckAssignment
|
|||
namespace CheckAssignmentQuick
|
||||
|
||||
partial def check
|
||||
(hasCtxLocals ctxApprox : Bool)
|
||||
(hasCtxLocals : Bool)
|
||||
(mctx : MetavarContext) (lctx : LocalContext) (mvarDecl : MetavarDecl) (mvarId : MVarId) (fvars : Array Expr) (e : Expr) : Bool :=
|
||||
let rec visit (e : Expr) : Bool :=
|
||||
if !e.hasExprMVar && !e.hasFVar then
|
||||
|
|
@ -845,7 +844,7 @@ def checkAssignment (mvarId : MVarId) (fvars : Array Expr) (v : Expr) : MetaM (O
|
|||
let hasCtxLocals := fvars.any fun fvar => mvarDecl.lctx.containsFVar fvar
|
||||
let ctx ← read
|
||||
let mctx ← getMCtx
|
||||
if CheckAssignmentQuick.check hasCtxLocals ctx.config.ctxApprox mctx ctx.lctx mvarDecl mvarId fvars v then
|
||||
if CheckAssignmentQuick.check hasCtxLocals mctx ctx.lctx mvarDecl mvarId fvars v then
|
||||
pure (some v)
|
||||
else
|
||||
let v ← instantiateMVars v
|
||||
|
|
@ -1495,10 +1494,6 @@ private partial def isDefEqQuickOther (t s : Expr) : MetaM LBool := do
|
|||
|
||||
-- Both `t` and `s` are terms of the form `?m ...`
|
||||
private partial def isDefEqQuickMVarMVar (t s : Expr) : MetaM LBool := do
|
||||
let tFn := t.getAppFn
|
||||
let sFn := s.getAppFn
|
||||
let tMVarDecl ← getMVarDecl tFn.mvarId!
|
||||
let sMVarDecl ← getMVarDecl sFn.mvarId!
|
||||
if s.isMVar && !t.isMVar then
|
||||
/- Solve `?m t =?= ?n` by trying first `?n := ?m t`.
|
||||
Reason: this assignment is precise. -/
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ where
|
|||
let run (x : StateRefT Nat MetaM Expr) : MetaM (Expr × Nat) := StateRefT'.run x 0
|
||||
let (_, cnt) ← run <| transform domain fun e => do
|
||||
if let some name := e.constName? then
|
||||
if let some idx := ctx.typeInfos.findIdx? fun indVal => indVal.name == name then
|
||||
if let some _ := ctx.typeInfos.findIdx? fun indVal => indVal.name == name then
|
||||
modify (· + 1)
|
||||
return TransformStep.visit e
|
||||
|
||||
|
|
@ -176,7 +176,6 @@ where
|
|||
if let some name := f.constName? then
|
||||
if let some idx := ctx.typeInfos.findIdx?
|
||||
fun indVal => indVal.name == name then
|
||||
let indVal := ctx.typeInfos[idx]
|
||||
let hApp := mkAppN binder xs
|
||||
let t :=
|
||||
mkAppN vars.indVal[idx] $
|
||||
|
|
@ -257,7 +256,7 @@ partial def proveBrecOn (ctx : Context) (indVal : InductiveVal) (type : Expr) :
|
|||
let ms ← induction m vars
|
||||
let ms ← applyCtors ms
|
||||
let maxDepth := maxBackwardChainingDepth.get $ ←getOptions
|
||||
ms.forM (closeGoal vars maxDepth)
|
||||
ms.forM (closeGoal maxDepth)
|
||||
instantiateMVars main
|
||||
where
|
||||
intros (m : MVarId) : MetaM (MVarId × BrecOnVariables) := do
|
||||
|
|
@ -270,7 +269,7 @@ where
|
|||
|
||||
applyIH (m : MVarId) (vars : BrecOnVariables) : MetaM (List MVarId) := do
|
||||
match (← vars.indHyps.findSomeM?
|
||||
fun ih => do try pure <| some <| (←apply m $ mkFVar ih) catch ex => pure none) with
|
||||
fun ih => do try pure <| some <| (←apply m $ mkFVar ih) catch _ => pure none) with
|
||||
| some goals => pure goals
|
||||
| none => throwError "cannot apply induction hypothesis: {MessageData.ofGoal m}"
|
||||
|
||||
|
|
@ -291,11 +290,11 @@ where
|
|||
apply m recursor
|
||||
|
||||
applyCtors (ms : List MVarId) : MetaM $ List MVarId := do
|
||||
let mss ← ms.toArray.mapIdxM fun idx m => do
|
||||
let mss ← ms.toArray.mapIdxM fun _ m => do
|
||||
let m ← introNPRec m
|
||||
(← getMVarType m).withApp fun below args =>
|
||||
withMVarContext m do
|
||||
args.back.withApp fun ctor ctorArgs => do
|
||||
args.back.withApp fun ctor _ => do
|
||||
let ctorName := ctor.constName!.updatePrefix below.constName!
|
||||
let ctor := mkConst ctorName below.constLevels!
|
||||
let ctorInfo ← getConstInfoCtor ctorName
|
||||
|
|
@ -307,7 +306,7 @@ where
|
|||
introNPRec (m : MVarId) : MetaM MVarId := do
|
||||
if (← getMVarType m).isForall then introNPRec (←intro1P m).2 else return m
|
||||
|
||||
closeGoal (vars : BrecOnVariables) (maxDepth : Nat) (m : MVarId) : MetaM Unit := do
|
||||
closeGoal (maxDepth : Nat) (m : MVarId) : MetaM Unit := do
|
||||
unless (← isExprMVarAssigned m) do
|
||||
let m ← introNPRec m
|
||||
unless (← backwardsChaining m maxDepth) do
|
||||
|
|
@ -358,7 +357,6 @@ where
|
|||
partial def getBelowIndices (ctorName : Name) : MetaM $ Array Nat := do
|
||||
let ctorInfo ← getConstInfoCtor ctorName
|
||||
let belowCtorInfo ← getConstInfoCtor (ctorName.updatePrefix $ ctorInfo.induct ++ `below)
|
||||
let belowInductInfo ← getConstInfoInduct belowCtorInfo.induct
|
||||
forallTelescopeReducing ctorInfo.type fun xs _ => do
|
||||
loop xs belowCtorInfo.type #[] 0 0
|
||||
|
||||
|
|
@ -376,7 +374,7 @@ where
|
|||
let rest ← instantiateForall rest #[x]
|
||||
loop xs rest (belowIndices.push yIdx) (xIdx + 1) (yIdx + 1)
|
||||
else
|
||||
forallBoundedTelescope rest (some 1) fun ys rest =>
|
||||
forallBoundedTelescope rest (some 1) fun _ rest =>
|
||||
loop xs rest belowIndices xIdx (yIdx + 1)
|
||||
|
||||
private def belowType (motive : Expr) (xs : Array Expr) (idx : Nat) : MetaM $ Name × Expr := do
|
||||
|
|
@ -407,7 +405,7 @@ partial def mkBelowMatcher
|
|||
(below : Expr)
|
||||
(idx : Nat) : MetaM $ Expr × MetaM Unit := do
|
||||
let mkMatcherInput ← getMkMatcherInputInContext matcherApp
|
||||
let (indName, belowType, motive, matchType) ←
|
||||
let (indName, _, motive, matchType) ←
|
||||
forallBoundedTelescope mkMatcherInput.matchType mkMatcherInput.numDiscrs fun xs t => do
|
||||
let (indName, belowType) ← belowType belowMotive xs idx
|
||||
let matchType ←
|
||||
|
|
@ -442,7 +440,6 @@ partial def mkBelowMatcher
|
|||
-- if a wrong index is picked, the resulting matcher can be type-incorrect.
|
||||
-- we check here, so that errors can propagate higher up the call stack.
|
||||
check res.matcher
|
||||
let args := #[motive] ++ matcherApp.discrs.push below ++ alts
|
||||
let newApp := mkApp res.matcher motive
|
||||
let newApp := mkAppN newApp $ matcherApp.discrs.push below
|
||||
let newApp := mkAppN newApp alts
|
||||
|
|
@ -506,7 +503,6 @@ where
|
|||
return (additionalFVars, Pattern.as varId p hId)
|
||||
| Pattern.var varId =>
|
||||
let var := mkFVar varId
|
||||
(←inferType var).withApp fun ind args => do
|
||||
let (_, tgtType) ← belowType belowMotive #[var] 0
|
||||
withLocalDeclD (←mkFreshUserName `h) tgtType fun h => do
|
||||
let localDecl ← getFVarLocalDecl h
|
||||
|
|
@ -524,7 +520,7 @@ where
|
|||
let belowFieldExpr ← belowField.toExpr
|
||||
let belowCtor := mkApp belowCtor belowFieldExpr
|
||||
let patTy ← inferType belowFieldExpr
|
||||
patTy.withApp fun f args => do
|
||||
patTy.withApp fun f _ => do
|
||||
let constName := f.constName?
|
||||
if constName == indName then
|
||||
let (fvars, transformedField) ← convertToBelow indName belowField
|
||||
|
|
@ -560,7 +556,7 @@ where
|
|||
def findBelowIdx (xs : Array Expr) (motive : Expr) : MetaM $ Option (Expr × Nat) := do
|
||||
xs.findSomeM? fun x => do
|
||||
let xTy ← inferType x
|
||||
xTy.withApp fun f args =>
|
||||
xTy.withApp fun f _ =>
|
||||
match f.constName?, xs.indexOf? x with
|
||||
| some name, some idx => do
|
||||
if (← isInductivePredicate name) then
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ private def caseValueAux (mvarId : MVarId) (fvarId : FVarId) (value : Expr) (hNa
|
|||
trace[Meta] "subst domain: {thenSubst.domain.map (·.name)}"
|
||||
let thenH := (thenSubst.get thenH).fvarId!
|
||||
trace[Meta] "searching for decl"
|
||||
let decl ← getLocalDecl thenH
|
||||
let _ ← getLocalDecl thenH
|
||||
trace[Meta] "found decl"
|
||||
let thenSubgoal := { mvarId := thenMVarId, newH := (thenSubst.get thenH).fvarId!, subst := thenSubst : CaseValueSubgoal }
|
||||
pure (thenSubgoal, elseSubgoal)
|
||||
|
|
|
|||
|
|
@ -261,7 +261,6 @@ def assign (fvarId : FVarId) (v : Expr) : M Bool := do
|
|||
trace[Meta.Match.unify] "assign occurs check failed, {mkFVar fvarId} := {v}"
|
||||
return false
|
||||
else
|
||||
let ctx ← read
|
||||
if (← isAltVar fvarId) then
|
||||
trace[Meta.Match.unify] "{mkFVar fvarId} := {v}"
|
||||
modify fun s => { s with fvarSubst := s.fvarSubst.insert fvarId v }
|
||||
|
|
@ -300,8 +299,6 @@ private def unify? (altFVarDecls : List LocalDecl) (a b : Expr) : MetaM (Option
|
|||
|
||||
private def expandVarIntoCtor? (alt : Alt) (fvarId : FVarId) (ctorName : Name) : MetaM (Option Alt) :=
|
||||
withExistingLocalDecls alt.fvarDecls do
|
||||
let env ← getEnv
|
||||
let ldecl ← getLocalDecl fvarId
|
||||
let expectedType ← inferType (mkFVar fvarId)
|
||||
let expectedType ← whnfD expectedType
|
||||
let (ctorLevels, ctorParams) ← getInductiveUniverseAndParams expectedType
|
||||
|
|
@ -383,7 +380,6 @@ private def throwCasesException (p : Problem) (ex : Exception) : MetaM α := do
|
|||
|
||||
private def processConstructor (p : Problem) : MetaM (Array Problem) := do
|
||||
trace[Meta.Match.match] "constructor step"
|
||||
let env ← getEnv
|
||||
match p.vars with
|
||||
| [] => unreachable!
|
||||
| x :: xs => do
|
||||
|
|
@ -627,7 +623,7 @@ private def List.moveToFront [Inhabited α] (as : List α) (i : Nat) : List α :
|
|||
private def moveToFront (p : Problem) (i : Nat) : Problem :=
|
||||
if i == 0 then
|
||||
p
|
||||
else if h : i < p.vars.length then
|
||||
else if i < p.vars.length then
|
||||
{ p with
|
||||
vars := List.moveToFront p.vars i
|
||||
alts := p.alts.map fun alt => { alt with patterns := List.moveToFront alt.patterns i }
|
||||
|
|
@ -841,7 +837,7 @@ def mkMatcher (input : MkMatcherInput) : MetaM MatcherResult := do
|
|||
trace[Meta.Match.debug] "motiveType: {motiveType}"
|
||||
withLocalDeclD `motive motiveType fun motive => do
|
||||
if discrInfos.any fun info => info.hName?.isSome then
|
||||
forallBoundedTelescope matchType numDiscrs fun discrs' matchTypeBody => do
|
||||
forallBoundedTelescope matchType numDiscrs fun discrs' _ => do
|
||||
let (mvarType, isEqMask) ← withEqs discrs discrs' discrInfos fun eqs => do
|
||||
let mvarType ← mkForallFVars eqs (mkAppN motive discrs')
|
||||
let isEqMask ← eqs.mapM fun eq => return (← inferType eq).isEq
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Lean.Meta
|
|||
apply `cases xMajor`. -/
|
||||
partial def casesOnStuckLHS (mvarId : MVarId) : MetaM (Array MVarId) := do
|
||||
let target ← getMVarType mvarId
|
||||
if let some (_, lhs, rhs) ← matchEq? target then
|
||||
if let some (_, lhs, _) ← matchEq? target then
|
||||
if let some fvarId ← findFVar? lhs then
|
||||
return (← cases mvarId fvarId).map fun s => s.mvarId
|
||||
throwError "'casesOnStuckLHS' failed"
|
||||
|
|
|
|||
|
|
@ -146,7 +146,6 @@ goal from being littered with irrelevant names.
|
|||
|
||||
-/
|
||||
def collect (goalTarget : Expr) : MetaM (FVarIdSet × FVarIdSet) := do
|
||||
let lctx ← getLCtx
|
||||
if pp.inaccessibleNames.get (← getOptions) then
|
||||
-- If `pp.inaccessibleNames == true`, we still must compute `hiddenInaccessibleProp`.
|
||||
let hiddenInaccessible ← getInitialHiddenInaccessible (propOnly := true)
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ private partial def getNumParams (xs : Array Expr) (motive : Expr) (i : Nat) : N
|
|||
else
|
||||
i
|
||||
|
||||
private def getMajorPosDepElim (declName : Name) (majorPos? : Option Nat) (xs : Array Expr) (motive : Expr) (motiveArgs : Array Expr)
|
||||
private def getMajorPosDepElim (declName : Name) (majorPos? : Option Nat) (xs : Array Expr) (motiveArgs : Array Expr)
|
||||
: MetaM (Expr × Nat × Bool) := do
|
||||
match majorPos? with
|
||||
| some majorPos =>
|
||||
|
|
@ -207,7 +207,7 @@ private def mkRecursorInfoAux (cinfo : ConstantInfo) (majorPos? : Option Nat) :
|
|||
forallTelescopeReducing cinfo.type fun xs type => type.withApp fun motive motiveArgs => do
|
||||
checkMotive declName motive motiveArgs
|
||||
let numParams := getNumParams xs motive 0
|
||||
let (major, majorPos, depElim) ← getMajorPosDepElim declName majorPos? xs motive motiveArgs
|
||||
let (major, majorPos, depElim) ← getMajorPosDepElim declName majorPos? xs motiveArgs
|
||||
let numIndices := if depElim then motiveArgs.size - 1 else motiveArgs.size
|
||||
if majorPos < numIndices then
|
||||
throwError "invalid user defined recursor '{declName}', indices must occur before major premise"
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ where
|
|||
partial def mkSizeOfFn (recName : Name) (declName : Name): MetaM Unit := do
|
||||
trace[Meta.sizeOf] "recName: {recName}"
|
||||
let recInfo : RecursorVal ← getConstInfoRec recName
|
||||
forallTelescopeReducing recInfo.type fun xs type =>
|
||||
forallTelescopeReducing recInfo.type fun xs _ =>
|
||||
let levelParams := recInfo.levelParams.tail! -- universe parameters for declaration being defined
|
||||
let params := xs[:recInfo.numParams]
|
||||
let motiveFVars := xs[recInfo.numParams : recInfo.numParams + recInfo.numMotives]
|
||||
|
|
@ -180,7 +180,7 @@ def mkSizeOfSpecLemmaName (ctorName : Name) : Name :=
|
|||
ctorName ++ `sizeOf_spec
|
||||
|
||||
def mkSizeOfSpecLemmaInstance (ctorApp : Expr) : MetaM Expr :=
|
||||
matchConstCtor ctorApp.getAppFn (fun _ => throwError "failed to apply 'sizeOf' spec, constructor expected{indentExpr ctorApp}") fun ctorInfo ctorLevels => do
|
||||
matchConstCtor ctorApp.getAppFn (fun _ => throwError "failed to apply 'sizeOf' spec, constructor expected{indentExpr ctorApp}") fun ctorInfo _ => do
|
||||
let ctorArgs := ctorApp.getAppArgs
|
||||
let ctorFields := ctorArgs[ctorArgs.size - ctorInfo.numFields:]
|
||||
let lemmaName := mkSizeOfSpecLemmaName ctorInfo.name
|
||||
|
|
@ -254,7 +254,7 @@ mutual
|
|||
mkSizeOfAuxLemma lhs rhs
|
||||
|
||||
/-- Construct proof of auxiliary lemma. See `mkSizeOfAuxLemma` -/
|
||||
private partial def mkSizeOfAuxLemmaProof (info : InductiveVal) (lhs rhs : Expr) : M Expr := do
|
||||
private partial def mkSizeOfAuxLemmaProof (info : InductiveVal) (lhs : Expr) : M Expr := do
|
||||
let lhsArgs := lhs.getAppArgs
|
||||
let sizeOfBaseArgs := lhsArgs[:lhsArgs.size - info.numIndices - 1]
|
||||
let indicesMajor := lhsArgs[lhsArgs.size - info.numIndices - 1:]
|
||||
|
|
@ -309,7 +309,7 @@ mutual
|
|||
let specEq ← whnf (← inferType specLemma)
|
||||
match specEq.eq? with
|
||||
| none => throwFailed
|
||||
| some (_, rhs, rhsExpanded) =>
|
||||
| some (_, _, rhsExpanded) =>
|
||||
let lhs_eq_rhsExpanded ← mkMinorProof ys lhs rhsExpanded
|
||||
let rhsExpanded_eq_rhs ← mkEqSymm specLemma
|
||||
mkLambdaFVars ys (← mkEqTrans lhs_eq_rhsExpanded rhsExpanded_eq_rhs)
|
||||
|
|
@ -363,7 +363,7 @@ mutual
|
|||
let eq ← mkEq lhsNew rhsNew
|
||||
let thmParams := lhsArgsNew
|
||||
let thmType ← mkForallFVars thmParams eq
|
||||
let thmValue ← mkSizeOfAuxLemmaProof info lhsNew rhsNew
|
||||
let thmValue ← mkSizeOfAuxLemmaProof info lhsNew
|
||||
let thmValue ← mkLambdaFVars thmParams thmValue
|
||||
trace[Meta.sizeOf] "thmValue: {thmValue}"
|
||||
addDecl <| Declaration.thmDecl {
|
||||
|
|
|
|||
|
|
@ -639,7 +639,7 @@ private partial def preprocessArgs (type : Expr) (i : Nat) (args : Array Expr) :
|
|||
private def preprocessOutParam (type : Expr) : MetaM Expr :=
|
||||
forallTelescope type fun xs typeBody => do
|
||||
match typeBody.getAppFn with
|
||||
| c@(Expr.const constName us _) =>
|
||||
| c@(Expr.const constName _ _) =>
|
||||
let env ← getEnv
|
||||
if !hasOutParams env constName then
|
||||
return type
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ where
|
|||
| none => return Simp.Step.done { expr := e }
|
||||
| e, _ => return Simp.Step.done { expr := e }
|
||||
|
||||
@[builtinTactic ac_refl] def ac_refl_tactic : Lean.Elab.Tactic.Tactic := fun stx => do
|
||||
@[builtinTactic ac_refl] def ac_refl_tactic : Lean.Elab.Tactic.Tactic := fun _ => do
|
||||
let goal ← getMainGoal
|
||||
rewriteUnnormalized goal
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ private def reorderGoals (mvars : Array Expr) : ApplyNewGoals → MetaM (List MV
|
|||
let (nonDeps, deps) ← partitionDependentMVars mvars
|
||||
return nonDeps.toList ++ deps.toList
|
||||
| ApplyNewGoals.nonDependentOnly => do
|
||||
let (nonDeps, deps) ← partitionDependentMVars mvars
|
||||
let (nonDeps, _) ← partitionDependentMVars mvars
|
||||
return nonDeps.toList
|
||||
| ApplyNewGoals.all => return mvars.toList.map Lean.Expr.mvarId!
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ def applyRefl (mvarId : MVarId) (msg : MessageData := "refl failed") : MetaM Uni
|
|||
let some [] ← observing? do apply mvarId (mkConst ``Eq.refl [← mkFreshLevelMVar])
|
||||
| throwTacticEx `refl mvarId msg
|
||||
|
||||
def exfalso (mvarId : MVarId) (msg : MessageData := "exfalso failed") : MetaM MVarId :=
|
||||
def exfalso (mvarId : MVarId) : MetaM MVarId :=
|
||||
withMVarContext mvarId do
|
||||
checkNotAssigned mvarId `exfalso
|
||||
let target ← instantiateMVars (← getMVarType mvarId)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ where
|
|||
|
||||
addUsedFVar (fvarId : FVarId) : StateRefT (Bool × FVarIdSet) MetaM Unit := do
|
||||
unless (← get).2.contains fvarId do
|
||||
modify fun (modified, s) => (true, s.insert fvarId)
|
||||
modify fun (_, s) => (true, s.insert fvarId)
|
||||
addDeps fvarId
|
||||
|
||||
/- We include `p` in the used-set, if `p` is a proposition that contains a `x` that is in the used-set. -/
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue