-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Consolidate local context extensions. (#403)
- Loading branch information
1 parent
e6035b0
commit 97395fb
Showing
5 changed files
with
52 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/- | ||
Copyright (c) 2022 Mario Carneiro. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Mario Carneiro, Jannis Limperg | ||
-/ | ||
import Lean.LocalContext | ||
|
||
namespace Lean | ||
|
||
/-- | ||
Set the kind of a `LocalDecl`. | ||
-/ | ||
def LocalDecl.setKind : LocalDecl → LocalDeclKind → LocalDecl | ||
| cdecl index fvarId userName type bi _, kind => | ||
cdecl index fvarId userName type bi kind | ||
| ldecl index fvarId userName type value nonDep _, kind => | ||
ldecl index fvarId userName type value nonDep kind | ||
|
||
namespace LocalContext | ||
|
||
/-- | ||
Given an `FVarId`, this function returns the corresponding user name, | ||
but only if the name can be used to recover the original FVarId. | ||
-/ | ||
def getRoundtrippingUserName? (lctx : LocalContext) (fvarId : FVarId) : Option Name := do | ||
let ldecl₁ ← lctx.find? fvarId | ||
let ldecl₂ ← lctx.findFromUserName? ldecl₁.userName | ||
guard <| ldecl₁.fvarId == ldecl₂.fvarId | ||
some ldecl₁.userName | ||
|
||
/-- | ||
Set the kind of the given fvar. | ||
-/ | ||
def setKind (lctx : LocalContext) (fvarId : FVarId) | ||
(kind : LocalDeclKind) : LocalContext := | ||
lctx.modifyLocalDecl fvarId (·.setKind kind) | ||
|
||
/-- | ||
Sort the given `FVarId`s by the order in which they appear in `lctx`. If any of | ||
the `FVarId`s do not appear in `lctx`, the result is unspecified. | ||
-/ | ||
def sortFVarsByContextOrder (lctx : LocalContext) (hyps : Array FVarId) : Array FVarId := | ||
let hyps := hyps.map λ fvarId => | ||
match lctx.fvarIdToDecl.find? fvarId with | ||
| none => (0, fvarId) | ||
| some ldecl => (ldecl.index, fvarId) | ||
hyps.qsort (λ h i => h.fst < i.fst) |>.map (·.snd) | ||
|
||
end LocalContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters