Skip to content

Commit

Permalink
bump to v4.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PratherConid committed Jan 4, 2025
1 parent 1d61943 commit 30441a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
14 changes: 14 additions & 0 deletions Auto/Lib/MetaExtra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ partial def Meta.normalizeNondependentForall (e : Expr) : MetaM Expr := do
let e' ← whnfNondependentForall e
match e' with
| .forallE name ty body bi =>
if body.hasLooseBVar 0 then
return e
let ty' ← normalizeNondependentForall ty
let body' ← normalizeNondependentForall body
return .forallE name ty' body' bi
Expand Down Expand Up @@ -142,4 +144,16 @@ def Meta.exToExcept (x : MetaM α) : MetaM (Except Exception α) :=
def Meta.runtimeExToExcept (x : MetaM α) : MetaM (Except Exception α) :=
tryCatchRuntimeEx (do let v ← x; return .ok v) (fun e => return .error e)

/--
Workaround for modifying the `lctx` field of `Meta.Context`
-/
def Meta.Context.modifyLCtx (ctx : Context) (lctx : LocalContext) : CoreM Context :=
MetaM.run' (withLCtx' lctx read) ctx

/--
Workaround for modifying the `localInstances` field of `Meta.Context`
-/
def Meta.Context.modifyLocalInstances (ctx : Context) (localInsts : LocalInstances) : CoreM Context :=
MetaM.run' (withLCtx ctx.lctx localInsts read) ctx

end Auto
19 changes: 12 additions & 7 deletions Auto/Lib/MetaState.lean
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private def runWithFVars (lctx : LocalContext) (fvarids : Array FVarId) (k : Met
| .ldecl _ fvarId userName type value nonDep kind =>
newlctx := newlctx.mkLetDecl fvarId userName type value nonDep kind
| .none => throwError "{decl_name%} :: Unknown free variable {Expr.fvar fid}"
withReader (fun ctx => {ctx with lctx := newlctx}) k
Meta.withLCtx' newlctx k

private def runWithIntroducedFVarsImp (m : MetaStateM (Array FVarId × α)) (k : α → MetaM β) : MetaM β := do
let s ← get
Expand Down Expand Up @@ -116,19 +116,22 @@ def mkLocalDecl (fvarId : FVarId) (userName : Name) (type : Expr)
(bi : BinderInfo := BinderInfo.default) (kind : LocalDeclKind := LocalDeclKind.default) : MetaStateM Unit := do
let ctx ← getToContext
let lctx := ctx.lctx
setToContext ({ctx with lctx := lctx.mkLocalDecl fvarId userName type bi kind})
let newCtx ← Meta.Context.modifyLCtx ctx (lctx.mkLocalDecl fvarId userName type bi kind)
setToContext newCtx

def mkLetDecl (fvarId : FVarId) (userName : Name) (type value : Expr)
(nonDep : Bool := false) (kind : LocalDeclKind := default) : MetaStateM Unit := do
let ctx ← getToContext
let lctx := ctx.lctx
setToContext ({ctx with lctx := lctx.mkLetDecl fvarId userName type value nonDep kind})
let newCtx ← Meta.Context.modifyLCtx ctx (lctx.mkLetDecl fvarId userName type value nonDep kind)
setToContext newCtx

private def withNewLocalInstance (className : Name) (fvar : Expr) : MetaStateM Unit := do
let localDecl ← runMetaM <| Meta.getFVarLocalDecl fvar
if !localDecl.isImplementationDetail then
let ctx ← getToContext
setToContext ({ ctx with localInstances := ctx.localInstances.push { className := className, fvar := fvar } })
let newCtx ← Meta.Context.modifyLocalInstances ctx (ctx.localInstances.push { className := className, fvar := fvar })
setToContext newCtx

private def withNewFVar (fvar fvarType : Expr) : MetaStateM Unit := do
if let some c ← runMetaM <| Meta.isClass? fvarType then
Expand All @@ -149,10 +152,12 @@ def withLetDecl (n : Name) (type : Expr) (val : Expr) (kind : LocalDeclKind) : M
return fvarId

def withTemporaryLCtx [MonadLiftT MetaStateM n] [Monad n] (lctx : LocalContext) (localInsts : LocalInstances) (k : n α) : n α := do
let initlctx ← getToContext
MetaState.setToContext {initlctx with lctx := lctx, localInstances := localInsts}
let initCtx ← getToContext
let newCtx ← (Meta.Context.modifyLCtx initCtx lctx : MetaStateM _)
let newCtx ← (Meta.Context.modifyLocalInstances newCtx localInsts : MetaStateM _)
MetaState.setToContext newCtx
let ret ← k
MetaState.setToContext initlctx
MetaState.setToContext initCtx
return ret

end Auto.MetaState
2 changes: 1 addition & 1 deletion lean-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
leanprover/lean4:v4.14.0
leanprover/lean4:v4.15.0

0 comments on commit 30441a8

Please sign in to comment.