chore: fix codebase
This commit is contained in:
parent
d9d44baabe
commit
68bd55af32
39 changed files with 68 additions and 68 deletions
|
|
@ -545,7 +545,7 @@ def getMax? (as : Array α) (lt : α → α → Bool) : Option α :=
|
|||
none
|
||||
|
||||
@[inline]
|
||||
def partition (p : α → Bool) (as : Array α) : Array α × Array α := do
|
||||
def partition (p : α → Bool) (as : Array α) : Array α × Array α := Id.run <| do
|
||||
let mut bs := #[]
|
||||
let mut cs := #[]
|
||||
for a in as do
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ def toSubarray (as : Array α) (start : Nat := 0) (stop : Nat := as.size) : Suba
|
|||
else
|
||||
{ as := as, start := as.size, stop := as.size, h₁ := Nat.le_refl _, h₂ := Nat.le_refl _ }
|
||||
|
||||
def ofSubarray (s : Subarray α) : Array α := do
|
||||
def ofSubarray (s : Subarray α) : Array α := Id.run <| do
|
||||
let mut as := mkEmpty (s.stop - s.start)
|
||||
for a in s do
|
||||
as := as.push a
|
||||
|
|
|
|||
|
|
@ -365,7 +365,7 @@ def mkIdent (val : Name) : Syntax :=
|
|||
@[inline] def mkGroupNode (args : Array Syntax := #[]) : Syntax :=
|
||||
mkNode groupKind args
|
||||
|
||||
def mkSepArray (as : Array Syntax) (sep : Syntax) : Array Syntax := do
|
||||
def mkSepArray (as : Array Syntax) (sep : Syntax) : Array Syntax := Id.run <| do
|
||||
let mut i := 0
|
||||
let mut r := #[]
|
||||
for a in as do
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ private def formatLitVal : LitVal → Format
|
|||
instance : ToFormat LitVal := ⟨formatLitVal⟩
|
||||
|
||||
private def formatCtorInfo : CtorInfo → Format
|
||||
| { name := name, cidx := cidx, usize := usize, ssize := ssize, .. } => do
|
||||
| { name := name, cidx := cidx, usize := usize, ssize := ssize, .. } => Id.run <| do
|
||||
let mut r := f!"ctor_{cidx}"
|
||||
if usize > 0 || ssize > 0 then
|
||||
r := f!"{r}.{usize}.{ssize}"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ def ensureHasDefault (alts : Array Alt) : Array Alt :=
|
|||
let alts := alts.pop;
|
||||
alts.push (Alt.default last.body)
|
||||
|
||||
private def getOccsOf (alts : Array Alt) (i : Nat) : Nat := do
|
||||
private def getOccsOf (alts : Array Alt) (i : Nat) : Nat := Id.run <| do
|
||||
let aBody := (alts.get! i).body
|
||||
let mut n := 1
|
||||
for j in [i+1:alts.size] do
|
||||
|
|
@ -24,7 +24,7 @@ private def getOccsOf (alts : Array Alt) (i : Nat) : Nat := do
|
|||
n := n+1
|
||||
return n
|
||||
|
||||
private def maxOccs (alts : Array Alt) : Alt × Nat := do
|
||||
private def maxOccs (alts : Array Alt) : Alt × Nat := Id.run <| do
|
||||
let mut maxAlt := alts[0]
|
||||
let mut max := getOccsOf alts 0
|
||||
for i in [1:alts.size] do
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ private partial def countDigits (n : Nat) : Nat :=
|
|||
|
||||
-- convert mantissa * 10^-exponent to 0.mantissa * 10^exponent
|
||||
protected def normalize : JsonNumber → Int × Nat × Int
|
||||
| ⟨m, e⟩ => do
|
||||
| ⟨m, e⟩ => Id.run <| do
|
||||
if m = 0 then (0, 0, 0)
|
||||
else
|
||||
let sign : Int := if m > 0 then 1 else -1
|
||||
|
|
@ -165,7 +165,7 @@ instance : BEq Json where
|
|||
|
||||
-- HACK(Marc): temporary ugliness until we can use RBMap for JSON objects
|
||||
def mkObj (o : List (String × Json)) : Json :=
|
||||
obj $ do
|
||||
obj <| Id.run <| do
|
||||
let mut kvPairs := RBNode.leaf
|
||||
for ⟨k, v⟩ in o do
|
||||
kvPairs := kvPairs.insert compare k v
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ private def escapeAux (acc : String) (c : Char) : String :=
|
|||
Nat.digitChar ((n % 256) / 16),
|
||||
Nat.digitChar (n % 16) ].asString
|
||||
|
||||
def escape (s : String) : String := do
|
||||
def escape (s : String) : String :=
|
||||
s.foldl escapeAux ""
|
||||
|
||||
def renderString (s : String) : String :=
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ def getBracketedBinderIds : Syntax → Array Name
|
|||
| `(bracketedBinder|[$ty]) => #[Name.anonymous]
|
||||
| _ => #[]
|
||||
|
||||
private def mkTermContext (ctx : Context) (s : State) (declName? : Option Name) : Term.Context := do
|
||||
private def mkTermContext (ctx : Context) (s : State) (declName? : Option Name) : Term.Context := Id.run <| do
|
||||
let scope := s.scopes.head!
|
||||
let mut sectionVars := {}
|
||||
for id in scope.varDecls.concatMap getBracketedBinderIds, uid in scope.varUIds do
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ private def updateParams (vars : Array Expr) (indTypes : List InductiveType) : T
|
|||
pure { ctor with type := ctorType }
|
||||
pure { indType with type := type, ctors := ctors }
|
||||
|
||||
private def collectLevelParamsInInductive (indTypes : List InductiveType) : Array Name := do
|
||||
private def collectLevelParamsInInductive (indTypes : List InductiveType) : Array Name := Id.run <| do
|
||||
let mut usedParams : CollectLevelParams.State := {}
|
||||
for indType in indTypes do
|
||||
usedParams := collectLevelParams usedParams indType.type
|
||||
|
|
@ -398,7 +398,7 @@ private def collectLevelParamsInInductive (indTypes : List InductiveType) : Arra
|
|||
usedParams := collectLevelParams usedParams ctor.type
|
||||
return usedParams.params
|
||||
|
||||
private def mkIndFVar2Const (views : Array InductiveView) (indFVars : Array Expr) (levelNames : List Name) : ExprMap Expr := do
|
||||
private def mkIndFVar2Const (views : Array InductiveView) (indFVars : Array Expr) (levelNames : List Name) : ExprMap Expr := Id.run <| do
|
||||
let levelParams := levelNames.map mkLevelParam;
|
||||
let mut m : ExprMap Expr := {}
|
||||
for i in [:views.size] do
|
||||
|
|
@ -427,7 +427,7 @@ private def replaceIndFVarsWithConsts (views : Array InductiveView) (indFVars :
|
|||
|
||||
abbrev Ctor2InferMod := Std.HashMap Name Bool
|
||||
|
||||
private def mkCtor2InferMod (views : Array InductiveView) : Ctor2InferMod := do
|
||||
private def mkCtor2InferMod (views : Array InductiveView) : Ctor2InferMod := Id.run <| do
|
||||
let mut m := {}
|
||||
for view in views do
|
||||
for ctorView in view.ctors do
|
||||
|
|
|
|||
|
|
@ -149,10 +149,10 @@ def ContextInfo.toPPContext (info : ContextInfo) (lctx : LocalContext) : PPConte
|
|||
def ContextInfo.ppSyntax (info : ContextInfo) (lctx : LocalContext) (stx : Syntax) : IO Format := do
|
||||
ppTerm (info.toPPContext lctx) stx
|
||||
|
||||
private def formatStxRange (ctx : ContextInfo) (stx : Syntax) : Format := do
|
||||
private def formatStxRange (ctx : ContextInfo) (stx : Syntax) : Format :=
|
||||
let pos := stx.getPos?.getD 0
|
||||
let endPos := stx.getTailPos?.getD pos
|
||||
return f!"{fmtPos pos stx.getHeadInfo}-{fmtPos endPos stx.getTailInfo}"
|
||||
f!"{fmtPos pos stx.getHeadInfo}-{fmtPos endPos stx.getTailInfo}"
|
||||
where fmtPos pos info :=
|
||||
let pos := format <| ctx.fileMap.toPosition pos
|
||||
match info with
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ Note that `g` is not a free variable at `(let g : B := ?m₂; body)`. We recover
|
|||
`f` depends on `g` because it contains `m₂`
|
||||
-/
|
||||
private def mkInitialUsedFVarsMap (mctx : MetavarContext) (sectionVars : Array Expr) (mainFVarIds : Array FVarId) (letRecsToLift : List LetRecToLift)
|
||||
: UsedFVarsMap := do
|
||||
: UsedFVarsMap := Id.run <| do
|
||||
let mut sectionVarSet := {}
|
||||
for var in sectionVars do
|
||||
sectionVarSet := sectionVarSet.insert var.fvarId!
|
||||
|
|
@ -418,7 +418,7 @@ abbrev FreeVarMap := FVarIdMap (Array FVarId)
|
|||
|
||||
private def mkFreeVarMap
|
||||
(mctx : MetavarContext) (sectionVars : Array Expr) (mainFVarIds : Array FVarId)
|
||||
(recFVarIds : Array FVarId) (letRecsToLift : List LetRecToLift) : FreeVarMap := do
|
||||
(recFVarIds : Array FVarId) (letRecsToLift : List LetRecToLift) : FreeVarMap := Id.run <| do
|
||||
let usedFVarsMap := mkInitialUsedFVarsMap mctx sectionVars mainFVarIds letRecsToLift
|
||||
let letRecFVarIds := letRecsToLift.map fun toLift => toLift.fvarId
|
||||
let usedFVarsMap := FixPoint.run letRecFVarIds usedFVarsMap
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import Lean.Elab.PreDefinition.Structural.Basic
|
|||
namespace Lean.Elab.Structural
|
||||
open Meta
|
||||
|
||||
private def getIndexMinPos (xs : Array Expr) (indices : Array Expr) : Nat := do
|
||||
private def getIndexMinPos (xs : Array Expr) (indices : Array Expr) : Nat := Id.run <| do
|
||||
let mut minPos := xs.size
|
||||
for index in indices do
|
||||
match xs.indexOf? index with
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ open Meta
|
|||
Return an array containing its "elements".
|
||||
Example: `mkTupleElems a 4` returns `#[a.1, a.2.1, a.2.2.1, a.2.2.2]`.
|
||||
-/
|
||||
private def mkTupleElems (t : Expr) (arity : Nat) : Array Expr := do
|
||||
private def mkTupleElems (t : Expr) (arity : Nat) : Array Expr := Id.run <| do
|
||||
let mut result := #[]
|
||||
let mut t := t
|
||||
for i in [:arity - 1] do
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ def TerminationHint.erase (t : TerminationHint) (clique : Array Name) : Terminat
|
|||
match t with
|
||||
| TerminationHint.none => TerminationHint.none
|
||||
| TerminationHint.one .. => TerminationHint.none
|
||||
| TerminationHint.many m => do
|
||||
| TerminationHint.many m => Id.run <| do
|
||||
for declName in clique do
|
||||
if m.contains declName then
|
||||
let m := m.erase declName
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ private def throwUnknownId (id : Name) : CommandElabM Unit :=
|
|||
private def levelParamsToMessageData (levelParams : List Name) : MessageData :=
|
||||
match levelParams with
|
||||
| [] => ""
|
||||
| u::us => do
|
||||
| u::us => Id.run <| do
|
||||
let mut m := m!".\{{u}"
|
||||
for u in us do
|
||||
m := m ++ ", " ++ toMessageData u
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ private partial def floatOutAntiquotTerms : Syntax → StateT (Syntax → TermEl
|
|||
Syntax.node i k (← args.mapM floatOutAntiquotTerms)
|
||||
| stx => pure stx
|
||||
|
||||
private def getSepFromSplice (splice : Syntax) : Syntax := do
|
||||
private def getSepFromSplice (splice : Syntax) : Syntax :=
|
||||
if let Syntax.atom _ sep := getAntiquotSpliceSuffix splice then
|
||||
Syntax.mkStrLit (sep.dropRight 1)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -471,7 +471,7 @@ where
|
|||
| none => throwError "failed to copied fields from parent structure{indentExpr parentType}" -- TODO improve error message
|
||||
return result
|
||||
|
||||
private partial def mkToParentName (parentStructName : Name) (p : Name → Bool) : Name := do
|
||||
private partial def mkToParentName (parentStructName : Name) (p : Name → Bool) : Name := Id.run <| do
|
||||
let base := Name.mkSimple $ "to" ++ parentStructName.eraseMacroScopes.getString!
|
||||
if p base then
|
||||
base
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ def tagUntaggedGoals (parentTag : Name) (newSuffix : Name) (newGoals : List MVar
|
|||
for g in newGoals do
|
||||
if mctx.isAnonymousMVar g then
|
||||
numAnonymous := numAnonymous + 1
|
||||
modifyMCtx fun mctx => do
|
||||
modifyMCtx fun mctx => Id.run <| do
|
||||
let mut mctx := mctx
|
||||
let mut idx := 1
|
||||
for g in newGoals do
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ structure CongrTheorem where
|
|||
proof : Expr
|
||||
argKinds : Array CongrArgKind
|
||||
|
||||
private def addPrimeToFVarUserNames (ys : Array Expr) (lctx : LocalContext) : LocalContext := do
|
||||
private def addPrimeToFVarUserNames (ys : Array Expr) (lctx : LocalContext) : LocalContext := Id.run <| do
|
||||
let mut lctx := lctx
|
||||
for y in ys do
|
||||
let decl := lctx.getFVar! y
|
||||
lctx := lctx.setUserName decl.fvarId (decl.userName.appendAfter "'")
|
||||
return lctx
|
||||
|
||||
private def setBinderInfosD (ys : Array Expr) (lctx : LocalContext) : LocalContext := do
|
||||
private def setBinderInfosD (ys : Array Expr) (lctx : LocalContext) : LocalContext := Id.run <| do
|
||||
let mut lctx := lctx
|
||||
for y in ys do
|
||||
let decl := lctx.getFVar! y
|
||||
|
|
|
|||
|
|
@ -330,7 +330,7 @@ where
|
|||
/- Return true if there are let-declarions between `xs[0]` and `xs[xs.size-1]`.
|
||||
We use it a quick-check to avoid the more expensive collection procedure. -/
|
||||
hasLetDeclsInBetween : MetaM Bool := do
|
||||
let check (lctx : LocalContext) : Bool := do
|
||||
let check (lctx : LocalContext) : Bool := Id.run <| do
|
||||
let start := lctx.getFVar! xs[0] |>.index
|
||||
let stop := lctx.getFVar! xs.back |>.index
|
||||
for i in [start+1:stop] do
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import Lean.Meta.Tactic.Assumption
|
|||
|
||||
namespace Lean.Meta
|
||||
|
||||
private def mkAnd? (args : Array Expr) : Option Expr := do
|
||||
private def mkAnd? (args : Array Expr) : Option Expr := Id.run <| do
|
||||
if args.isEmpty then
|
||||
return none
|
||||
else
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ private def isNatValueTransition (p : Problem) : Bool :=
|
|||
private def processSkipInaccessible (p : Problem) : Problem :=
|
||||
match p.vars with
|
||||
| [] => unreachable!
|
||||
| x :: xs => do
|
||||
| x :: xs =>
|
||||
let alts := p.alts.map fun alt => match alt.patterns with
|
||||
| Pattern.inaccessible _ :: ps => { alt with patterns := ps }
|
||||
| _ => unreachable!
|
||||
|
|
@ -537,7 +537,7 @@ private def processArrayLit (p : Problem) : MetaM (Array Problem) := do
|
|||
let newAlts := p.alts.filter isFirstPatternVar
|
||||
pure { p with mvarId := subgoal.mvarId, alts := newAlts, vars := x::xs }
|
||||
|
||||
private def expandNatValuePattern (p : Problem) : Problem := do
|
||||
private def expandNatValuePattern (p : Problem) : Problem :=
|
||||
let alts := p.alts.map fun alt => match alt.patterns with
|
||||
| Pattern.val (Expr.lit (Literal.natVal 0) _) :: ps => { alt with patterns := Pattern.ctor `Nat.zero [] [] [] :: ps }
|
||||
| Pattern.val (Expr.lit (Literal.natVal (n+1)) _) :: ps => { alt with patterns := Pattern.ctor `Nat.succ [] [] [Pattern.val (mkRawNatLit n)] :: ps }
|
||||
|
|
@ -588,12 +588,12 @@ private def List.moveToFront [Inhabited α] (as : List α) (i : Nat) : List α :
|
|||
b :: bs
|
||||
|
||||
/-- Move variable `#i` to the beginning of the to-do list `p.vars`. -/
|
||||
private def moveToFront (p : Problem) (i : Nat) : Problem := do
|
||||
private def moveToFront (p : Problem) (i : Nat) : Problem :=
|
||||
if i == 0 then
|
||||
p
|
||||
else if h : i < p.vars.length then
|
||||
let x := p.vars.get i h
|
||||
return { p with
|
||||
{ p with
|
||||
vars := List.moveToFront p.vars i
|
||||
alts := p.alts.map fun alt => { alt with patterns := List.moveToFront alt.patterns i }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ private partial def mkSplitterProof (matchDeclName : Name) (template : Expr) (al
|
|||
proveSubgoal mvarId
|
||||
instantiateMVars proof
|
||||
where
|
||||
mkMap : FVarIdMap Expr := do
|
||||
mkMap : FVarIdMap Expr := Id.run <| do
|
||||
let mut m := {}
|
||||
for alt in alts, altNew in altsNew do
|
||||
m := m.insert alt.fvarId! altNew
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ def collect (goalTarget : Expr) : MetaM (FVarIdSet × FVarIdSet) := do
|
|||
return ({}, {})
|
||||
else
|
||||
let lctx ← getLCtx
|
||||
let hiddenInaccessible := lctx.foldl (init := {}) fun hiddenInaccessible localDecl => do
|
||||
let hiddenInaccessible := lctx.foldl (init := {}) fun hiddenInaccessible localDecl => Id.run <| do
|
||||
if localDecl.userName.isInaccessibleUserName then
|
||||
hiddenInaccessible.insert localDecl.fvarId
|
||||
else
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ def wakeUp (answer : Answer) : Waiter → SynthM Unit
|
|||
modify fun s => { s with resumeStack := s.resumeStack.push (cNode, answer) }
|
||||
|
||||
def isNewAnswer (oldAnswers : Array Answer) (answer : Answer) : Bool :=
|
||||
oldAnswers.all fun oldAnswer => do
|
||||
oldAnswers.all fun oldAnswer =>
|
||||
-- Remark: isDefEq here is too expensive. TODO: if `==` is too imprecise, add some light normalization to `resultType` at `addAnswer`
|
||||
-- iseq ← isDefEq oldAnswer.resultType answer.resultType; pure (!iseq)
|
||||
oldAnswer.resultType != answer.resultType
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ def induction (mvarId : MVarId) (majorFVarId : FVarId) (recursorName : Name) (gi
|
|||
let (indices', mvarId) ← introNP mvarId indices.size
|
||||
let (majorFVarId', mvarId) ← intro1P mvarId
|
||||
-- Create FVarSubst with indices
|
||||
let baseSubst := do
|
||||
let baseSubst := Id.run <| do
|
||||
let mut subst : FVarSubst := {}
|
||||
let mut i := 0
|
||||
for index in indices do
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ partial def findSplit? (env : Environment) (e : Expr) : Option Expr :=
|
|||
else
|
||||
none
|
||||
where
|
||||
isCandidate (e : Expr) : Bool := do
|
||||
isCandidate (e : Expr) : Bool := Id.run <| do
|
||||
if e.isIte || e.isDIte then
|
||||
!(e.getArg! 1 5).hasLooseBVars
|
||||
else if let some info := isMatcherAppCore? env e then
|
||||
|
|
|
|||
|
|
@ -715,7 +715,7 @@ instance : MonadHashMapCacheAdapter ExprStructEq Expr M where
|
|||
modifyCache := fun f => modify fun s => { s with cache := f s.cache }
|
||||
|
||||
/-- Return the local declaration of the free variable `x` in `xs` with the smallest index -/
|
||||
private def getLocalDeclWithSmallestIdx (lctx : LocalContext) (xs : Array Expr) : LocalDecl := do
|
||||
private def getLocalDeclWithSmallestIdx (lctx : LocalContext) (xs : Array Expr) : LocalDecl := Id.run <| do
|
||||
let mut d : LocalDecl := lctx.getFVar! xs[0]
|
||||
for i in [1:xs.size] do
|
||||
let curr := lctx.getFVar! xs[i]
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ def isInductive [Monad m] [MonadEnv m] (declName : Name) : m Bool := do
|
|||
|
||||
def isRecCore (env : Environment) (declName : Name) : Bool :=
|
||||
match env.find? declName with
|
||||
| some (ConstantInfo.recInfo ..) => return true
|
||||
| _ => return false
|
||||
| some (ConstantInfo.recInfo ..) => true
|
||||
| _ => false
|
||||
|
||||
def isRec [Monad m] [MonadEnv m] (declName : Name) : m Bool :=
|
||||
return isRecCore (← getEnv) declName
|
||||
|
|
|
|||
|
|
@ -598,7 +598,7 @@ def notFollowedByFn (p : ParserFn) (msg : String) : ParserFn := fun c s =>
|
|||
fn := notFollowedByFn p.fn msg
|
||||
}
|
||||
|
||||
partial def manyAux (p : ParserFn) : ParserFn := fun c s => do
|
||||
partial def manyAux (p : ParserFn) : ParserFn := fun c s => Id.run <| do
|
||||
let iniSz := s.stackSize
|
||||
let iniPos := s.pos
|
||||
let mut s := p c s
|
||||
|
|
@ -631,7 +631,7 @@ partial def manyAux (p : ParserFn) : ParserFn := fun c s => do
|
|||
}
|
||||
|
||||
private partial def sepByFnAux (p : ParserFn) (sep : ParserFn) (allowTrailingSep : Bool) (iniSz : Nat) (pOpt : Bool) : ParserFn :=
|
||||
let rec parse (pOpt : Bool) (c s) := do
|
||||
let rec parse (pOpt : Bool) (c s) := Id.run <| do
|
||||
let sz := s.stackSize
|
||||
let pos := s.pos
|
||||
let mut s := p c s
|
||||
|
|
@ -1011,7 +1011,7 @@ def mkIdResult (startPos : Nat) (tk : Option Token) (val : Name) : ParserFn := f
|
|||
s.pushSyntax atom
|
||||
|
||||
partial def identFnAux (startPos : Nat) (tk : Option Token) (r : Name) : ParserFn :=
|
||||
let rec parse (r : Name) (c s) := do
|
||||
let rec parse (r : Name) (c s) := Id.run <| do
|
||||
let input := c.input
|
||||
let i := s.pos
|
||||
if input.atEnd i then
|
||||
|
|
@ -1392,7 +1392,7 @@ def invalidLongestMatchParser (s : ParserState) : ParserState :=
|
|||
|
||||
Remark: `p` must produce exactly one syntax node.
|
||||
Remark: the `left?` is not none when we are processing trailing parsers. -/
|
||||
def runLongestMatchParser (left? : Option Syntax) (startLhsPrec : Nat) (p : ParserFn) : ParserFn := fun c s => do
|
||||
def runLongestMatchParser (left? : Option Syntax) (startLhsPrec : Nat) (p : ParserFn) : ParserFn := fun c s => Id.run <| do
|
||||
/-
|
||||
We assume any registered parser `p` has one of two forms:
|
||||
* a direct call to `leadingParser` or `trailingParser`
|
||||
|
|
@ -1694,7 +1694,7 @@ def pushNone : Parser :=
|
|||
def antiquotNestedExpr : Parser := node `antiquotNestedExpr (symbolNoAntiquot "(" >> decQuotDepth termParser >> symbolNoAntiquot ")")
|
||||
def antiquotExpr : Parser := identNoAntiquot <|> antiquotNestedExpr
|
||||
|
||||
@[inline] def tokenWithAntiquotFn (p : ParserFn) : ParserFn := fun c s => do
|
||||
@[inline] def tokenWithAntiquotFn (p : ParserFn) : ParserFn := fun c s => Id.run <| do
|
||||
let s := p c s
|
||||
if s.hasError || c.quotDepth == 0 then
|
||||
return s
|
||||
|
|
@ -1739,7 +1739,7 @@ def mkAntiquot (name : String) (kind : Option SyntaxNodeKind) (anonymous := true
|
|||
checkNoWsBefore "no space before spliced term" >> antiquotExpr >>
|
||||
nameP
|
||||
|
||||
def tryAnti (c : ParserContext) (s : ParserState) : Bool := do
|
||||
def tryAnti (c : ParserContext) (s : ParserState) : Bool := Id.run <| do
|
||||
if c.quotDepth == 0 then
|
||||
return false
|
||||
let (s, stx) := peekToken c s
|
||||
|
|
@ -1768,7 +1768,7 @@ def mkAntiquotSplice (kind : SyntaxNodeKind) (p suffix : Parser) : Parser :=
|
|||
checkNoWsBefore "no space before spliced term" >> symbol "[" >> node nullKind p >> symbol "]" >>
|
||||
suffix
|
||||
|
||||
@[inline] def withAntiquotSuffixSpliceFn (kind : SyntaxNodeKind) (p suffix : ParserFn) : ParserFn := fun c s => do
|
||||
@[inline] def withAntiquotSuffixSpliceFn (kind : SyntaxNodeKind) (p suffix : ParserFn) : ParserFn := fun c s => Id.run <| do
|
||||
let s := p c s
|
||||
if s.hasError || c.quotDepth == 0 || !s.stxStack.back.isAntiquot then
|
||||
return s
|
||||
|
|
@ -1869,7 +1869,7 @@ private def mkResult (s : ParserState) (iniSz : Nat) : ParserState :=
|
|||
if s.stackSize == iniSz + 1 then s
|
||||
else s.mkNode nullKind iniSz -- throw error instead?
|
||||
|
||||
def leadingParserAux (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) : ParserFn := fun c s => do
|
||||
def leadingParserAux (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) : ParserFn := fun c s => Id.run <| do
|
||||
let iniSz := s.stackSize
|
||||
let (s, ps) := indexed tables.leadingTable c s behavior
|
||||
if s.hasError then
|
||||
|
|
@ -1886,7 +1886,7 @@ def leadingParserAux (kind : Name) (tables : PrattParsingTables) (behavior : Lea
|
|||
def trailingLoopStep (tables : PrattParsingTables) (left : Syntax) (ps : List (Parser × Nat)) : ParserFn := fun c s =>
|
||||
longestMatchFn left (ps ++ tables.trailingParsers) c s
|
||||
|
||||
partial def trailingLoop (tables : PrattParsingTables) (c : ParserContext) (s : ParserState) : ParserState := do
|
||||
partial def trailingLoop (tables : PrattParsingTables) (c : ParserContext) (s : ParserState) : ParserState := Id.run <| do
|
||||
let iniSz := s.stackSize
|
||||
let iniPos := s.pos
|
||||
let (s, ps) := indexed tables.trailingTable c s LeadingIdentBehavior.default
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ def isValidSyntaxNodeKind (env : Environment) (k : SyntaxNodeKind) : Bool :=
|
|||
let kinds := (parserExtension.getState env).kinds
|
||||
kinds.contains k
|
||||
|
||||
def getSyntaxNodeKinds (env : Environment) : List SyntaxNodeKind := do
|
||||
def getSyntaxNodeKinds (env : Environment) : List SyntaxNodeKind :=
|
||||
let kinds := (parserExtension.getState env).kinds
|
||||
kinds.foldl (fun ks k _ => k::ks) []
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ def isFOLike (motive : Expr) : MetaM Bool := do
|
|||
let f := motive.getAppFn
|
||||
f.isFVar || f.isConst
|
||||
|
||||
def isIdLike (arg : Expr) : Bool := do
|
||||
def isIdLike (arg : Expr) : Bool :=
|
||||
-- TODO: allow `id` constant as well?
|
||||
match arg with
|
||||
| Expr.lam _ _ (Expr.bvar ..) .. => true
|
||||
|
|
@ -190,7 +190,7 @@ private def valUnknown (e : Expr) : MetaM Bool := do
|
|||
private def typeUnknown (e : Expr) : MetaM Bool := do
|
||||
valUnknown (← inferType e)
|
||||
|
||||
def isHBinOp (e : Expr) : Bool := do
|
||||
def isHBinOp (e : Expr) : Bool := Id.run <| do
|
||||
-- TODO: instead of tracking these explicitly,
|
||||
-- consider a more general solution that checks for defaultInstances
|
||||
if e.getAppNumArgs != 6 then return false
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ def ScopedEnvExtension.activateScoped (ext : ScopedEnvExtension α β σ) (env :
|
|||
match s.scopedEntries.map.find? namespaceName with
|
||||
| none =>
|
||||
{ top with activeScopes := activeScopes }
|
||||
| some bs => do
|
||||
| some bs => Id.run <| do
|
||||
let mut state := top.state
|
||||
for b in bs do
|
||||
state := ext.descr.addEntry state b
|
||||
|
|
|
|||
|
|
@ -311,11 +311,11 @@ where
|
|||
let ⟨line, _⟩ := fileMap.toPosition pos
|
||||
if line != hoverLine then best?
|
||||
else match best? with
|
||||
| none => return (ctx, info)
|
||||
| none => (ctx, info)
|
||||
| some (_, best) =>
|
||||
let dBest := best.occursBefore? hoverPos |>.get!
|
||||
if d < dBest || (d == dBest && info.isSmaller best) then
|
||||
return (ctx, info)
|
||||
(ctx, info)
|
||||
else
|
||||
best?
|
||||
else
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ partial def handleReferences (p : ReferenceParams)
|
|||
| Info.ofFieldInfo fi => some (RefIdent.const fi.projName, false)
|
||||
| _ => none
|
||||
|
||||
findReferences (doc : EditableDocument) (snaps : List Snapshot) : Array Reference := do
|
||||
findReferences (doc : EditableDocument) (snaps : List Snapshot) : Array Reference := Id.run <| do
|
||||
let text := doc.meta.text
|
||||
let mut refs := #[]
|
||||
for snap in snaps do
|
||||
refs := refs.appendList <| snap.infoTree.deepestNodes fun _ info _ => do
|
||||
refs := refs.appendList <| snap.infoTree.deepestNodes fun _ info _ => Id.run <| do
|
||||
if let some (ident, isDeclaration) := identOf info then
|
||||
if let some range := info.range? then
|
||||
return some { ident, range := range.toLspRange text, isDeclaration }
|
||||
|
|
@ -279,7 +279,7 @@ partial def handleDocumentHighlight (p : DocumentHighlightParams)
|
|||
let text := doc.meta.text
|
||||
let pos := text.lspPosToUtf8Pos p.position
|
||||
let rec highlightReturn? (doRange? : Option Range) : Syntax → Option DocumentHighlight
|
||||
| stx@`(doElem|return%$i $e) => do
|
||||
| stx@`(doElem|return%$i $e) => Id.run <| do
|
||||
if let some range := i.getRange? then
|
||||
if range.contains pos then
|
||||
return some { range := doRange?.getD (range.toLspRange text), kind? := DocumentHighlightKind.text }
|
||||
|
|
@ -319,7 +319,7 @@ partial def handleDocumentSymbol (p : DocumentSymbolParams)
|
|||
| `(namespace $id) => sectionLikeToDocumentSymbols text stx stxs (id.getId.toString) SymbolKind.namespace id
|
||||
| `(section $(id)?) => sectionLikeToDocumentSymbols text stx stxs ((·.getId.toString) <$> id |>.getD "<section>") SymbolKind.namespace (id.getD stx)
|
||||
| `(end $(id)?) => ([], stx::stxs)
|
||||
| _ => do
|
||||
| _ => Id.run <| do
|
||||
let (syms, stxs') := toDocumentSymbols text stxs
|
||||
unless stx.isOfKind ``Lean.Parser.Command.declaration do
|
||||
return (syms, stxs')
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ def InfoTree.smallestInfo? (p : Info → Bool) (t : InfoTree) : Option (ContextI
|
|||
infos.toArray.getMax? (fun a b => a.1 > b.1) |>.map fun (_, ci, i) => (ci, i)
|
||||
|
||||
/-- Find an info node, if any, which should be shown on hover/cursor at position `hoverPos`. -/
|
||||
partial def InfoTree.hoverableInfoAt? (t : InfoTree) (hoverPos : String.Pos) : Option (ContextInfo × Info) := do
|
||||
let res := t.smallestInfo? fun i => do
|
||||
partial def InfoTree.hoverableInfoAt? (t : InfoTree) (hoverPos : String.Pos) : Option (ContextInfo × Info) := Id.run <| do
|
||||
let res := t.smallestInfo? fun i => Id.run <| do
|
||||
if i matches Info.ofFieldInfo _ || i.toElabInfo?.isSome then
|
||||
return i.contains hoverPos
|
||||
return false
|
||||
|
|
@ -205,7 +205,7 @@ structure GoalsAtResult where
|
|||
there is no nested tactic info (i.e. it is a leaf tactic; tactic combinators should decide for themselves
|
||||
where to show intermediate/final states)
|
||||
-/
|
||||
partial def InfoTree.goalsAt? (text : FileMap) (t : InfoTree) (hoverPos : String.Pos) : List GoalsAtResult := do
|
||||
partial def InfoTree.goalsAt? (text : FileMap) (t : InfoTree) (hoverPos : String.Pos) : List GoalsAtResult := Id.run <| do
|
||||
t.deepestNodes fun
|
||||
| ctx, i@(Info.ofTacticInfo ti), cs => OptionM.run do
|
||||
if let (some pos, some tailPos) := (i.pos?, i.tailPos?) then
|
||||
|
|
@ -220,7 +220,7 @@ partial def InfoTree.goalsAt? (text : FileMap) (t : InfoTree) (hoverPos : String
|
|||
| _, _, _ => none
|
||||
where
|
||||
hasNestedTactic (pos tailPos) : InfoTree → Bool
|
||||
| InfoTree.node i@(Info.ofTacticInfo _) cs => do
|
||||
| InfoTree.node i@(Info.ofTacticInfo _) cs => Id.run <| do
|
||||
if let `(by $t) := i.stx then
|
||||
return false -- ignore term-nested proofs such as in `simp [show p by ...]`
|
||||
if let (some pos', some tailPos') := (i.pos?, i.tailPos?) then
|
||||
|
|
@ -245,12 +245,12 @@ these head function symbols such as `f`,
|
|||
and later ignore identifiers at these positions.
|
||||
-/
|
||||
partial def InfoTree.termGoalAt? (t : InfoTree) (hoverPos : String.Pos) : Option (ContextInfo × Info) :=
|
||||
let headFns : Std.HashSet String.Pos := t.foldInfo (init := {}) fun ctx i headFns => do
|
||||
let headFns : Std.HashSet String.Pos := t.foldInfo (init := {}) fun ctx i headFns =>
|
||||
if let some pos := getHeadFnPos? i.stx then
|
||||
headFns.insert pos
|
||||
else
|
||||
headFns
|
||||
t.smallestInfo? fun i => do
|
||||
t.smallestInfo? fun i => Id.run <| do
|
||||
if i.contains hoverPos then
|
||||
if let Info.ofTermInfo ti := i then
|
||||
return !ti.stx.isIdent || !headFns.contains i.pos?.get!
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ where
|
|||
-- guaranteed.
|
||||
| _ => s!" {val} "
|
||||
|
||||
def hasMissing (stx : Syntax) : Bool := do
|
||||
def hasMissing (stx : Syntax) : Bool := Id.run <| do
|
||||
for stx in stx.topDown do
|
||||
if stx.isMissing then
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace InteractiveGoal
|
|||
private def addLine (fmt : Format) : Format :=
|
||||
if fmt.isNil then fmt else fmt ++ Format.line
|
||||
|
||||
def pretty (g : InteractiveGoal) : Format := do
|
||||
def pretty (g : InteractiveGoal) : Format := Id.run <| do
|
||||
let indent := 2 -- Use option
|
||||
let mut ret := match g.userName? with
|
||||
| some userName => f!"case {userName}"
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ partial def toArrayUnordered (h : Heap α) : Array α :=
|
|||
go #[] h
|
||||
where
|
||||
go (acc : Array α) : Heap α → Array α
|
||||
| heap ns => do
|
||||
| heap ns => Id.run <| do
|
||||
let mut acc := acc
|
||||
for n in ns do
|
||||
acc := acc.push n.val
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue