Skip to content

Commit fb26192

Browse files
authored
refactor: use withImplicitBinderInfos and mkArrowN in more places (#11492)
This PR uses the the helper functions withImplicitBinderInfos and mkArrowN in more places.
1 parent 0173444 commit fb26192

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

src/Lean/Elab/Tactic/Ext.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def withExtHyps (struct : Name) (flat : Bool)
4646
throwError "Internal error when constructing `ext` hypotheses: `{struct}` is not a structure"
4747
let structC ← mkConstWithLevelParams struct
4848
forallTelescope (← inferType structC) fun params _ => do
49-
withNewBinderInfos (params.map (·.fvarId!, BinderInfo.implicit)) do
49+
withImplicitBinderInfos params do
5050
withLocalDecl `x .implicit (mkAppN structC params) fun x => do
5151
withLocalDecl `y .implicit (mkAppN structC params) fun y => do
5252
let mut hyps := #[]

src/Lean/Meta/CongrTheorems.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ where
339339
go (i+1) (rhss.push rhs) (eqs.push none) hyps
340340
| .subsingletonInst =>
341341
-- The `lhs` does not need to instance implicit since it can be inferred from the LHS
342-
withNewBinderInfos #[(lhss[i]!.fvarId!, .implicit)] do
342+
withImplicitBinderInfos #[lhss[i]!] do
343343
let lhs := lhss[i]!
344344
let lhsType ← inferType lhs
345345
let rhsType := lhsType.replaceFVars (lhss[*...rhss.size]) rhss

src/Lean/Meta/Constructions/CtorIdx.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public def mkCtorIdx (indName : Name) : MetaM Unit :=
4646

4747
let us := info.levelParams.map mkLevelParam
4848
forallBoundedTelescope info.type (info.numParams + info.numIndices) fun xs _ => do
49-
withNewBinderInfos (xs.map (⟨·.fvarId!, .implicit⟩)) do
49+
withImplicitBinderInfos xs do
5050
let params : Array Expr := xs[:info.numParams]
5151
let indices : Array Expr := xs[info.numParams:]
5252
let indType := mkAppN (mkConst indName us) xs

src/Lean/Meta/Injective.lean

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ private def mkInjectiveTheoremTypeCore? (ctorVal : ConstructorVal) (useEq : Bool
7272
if useEq then
7373
mkArgs2 0 type #[] #[]
7474
else
75-
withNewBinderInfos (params.map fun param => (param.fvarId!, BinderInfo.implicit)) <|
76-
withNewBinderInfos (args1.map fun arg1 => (arg1.fvarId!, BinderInfo.implicit)) <|
75+
withImplicitBinderInfos (params ++ args1) do
7776
mkArgs2 0 type #[] #[]
7877

7978
private def mkInjectiveTheoremType? (ctorVal : ConstructorVal) : MetaM (Option Expr) :=
@@ -189,9 +188,6 @@ def getCtorAppIndices? (ctorApp : Expr) : MetaM (Option (Array Expr)) := do
189188
if val.numIndices == 0 then return some #[]
190189
return some typeArgs[val.numParams...*].toArray
191190

192-
private def mkArrows (hs : Array Expr) (type : Expr) : CoreM Expr := do
193-
hs.foldrM (init := type) mkArrow
194-
195191
private structure MkHInjTypeResult where
196192
thmType : Expr
197193
us : List Level
@@ -202,6 +198,7 @@ private def mkHInjType? (ctorVal : ConstructorVal) : MetaM (Option MkHInjTypeRes
202198
let type ← elimOptParam ctorVal.type
203199
forallBoundedTelescope type ctorVal.numParams fun params type =>
204200
forallTelescope type fun args1 _ => do
201+
withImplicitBinderInfos (params ++ args1) do
205202
let k (args2 : Array Expr) : MetaM (Option MkHInjTypeResult) := do
206203
let lhs := mkAppN (mkAppN (mkConst ctorVal.name us) params) args1
207204
let rhs := mkAppN (mkAppN (mkConst ctorVal.name us) params) args2
@@ -213,7 +210,7 @@ private def mkHInjType? (ctorVal : ConstructorVal) : MetaM (Option MkHInjTypeRes
213210
let some idxs2 ← getCtorAppIndices? rhs | return none
214211
-- **Note**: We dot not skip here because the type of `noConfusion` does not.
215212
let idxEqs ← mkEqs idxs1 idxs2 (skipIfPropOrEq := false)
216-
let result ← mkArrows idxEqs result
213+
let result ← mkArrowN idxEqs result
217214
let thmType ← mkForallFVars params (← mkForallFVars args1 (← mkForallFVars args2 result))
218215
return some { thmType, us, numIndices := idxs1.size }
219216
else
@@ -226,9 +223,7 @@ private def mkHInjType? (ctorVal : ConstructorVal) : MetaM (Option MkHInjTypeRes
226223
mkArgs2 (i + 1) (b.instantiate1 arg2) (args2.push arg2)
227224
else
228225
k args2
229-
withNewBinderInfos (params.map fun param => (param.fvarId!, BinderInfo.implicit)) <|
230-
withNewBinderInfos (args1.map fun arg1 => (arg1.fvarId!, BinderInfo.implicit)) <|
231-
mkArgs2 0 type #[]
226+
mkArgs2 0 type #[]
232227

233228
private def failedToGenHInj (ctorVal : ConstructorVal) : MetaM α :=
234229
throwError "failed to generate heterogeneous injectivity theorem for `{ctorVal.name}`"

src/Lean/Meta/Match/MatchEqs.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ where go baseName splitterName := withConfig (fun c => { c with etaStruct := .no
571571
let lhs := mkAppN (mkConst constInfo.name us) (params ++ #[motive] ++ patterns ++ alts)
572572
let rhs := mkAppN alt rhsArgs
573573
let thmType ← mkEq lhs rhs
574-
let thmType ← hs.foldrM (init := thmType) (mkArrow · ·)
574+
let thmType ← mkArrowN hs thmType
575575
let thmType ← mkForallFVars (params ++ #[motive] ++ ys ++ alts) thmType
576576
let thmType ← unfoldNamedPattern thmType
577577
let thmVal ← proveCondEqThm matchDeclName thmType
@@ -684,7 +684,7 @@ where go baseName := withConfig (fun c => { c with etaStruct := .none }) do
684684
notAlt ← mkForallFVars (discrs ++ altVars) notAlt
685685
let lhs := mkAppN (mkConst constInfo.name us) (params ++ #[motive] ++ discrs ++ alts)
686686
let thmType ← mkHEq lhs rhs
687-
let thmType ← hs.foldrM (init := thmType) (mkArrow · ·)
687+
let thmType ← mkArrowN hs thmType
688688
let thmType ← mkForallFVars (params ++ #[motive] ++ discrs ++ alts ++ altVars ++ heqs) thmType
689689
let thmType ← Match.unfoldNamedPattern thmType
690690
-- Here we prove the theorem from scratch. One could likely also use the (non-generalized)

0 commit comments

Comments
 (0)