chore: cleanup

This commit is contained in:
Leonardo de Moura 2020-09-28 14:04:35 -07:00
parent a394e1821b
commit a20b1beea4
2 changed files with 4 additions and 23 deletions

View file

@ -26,33 +26,14 @@ def ensureAssignmentHasNoMVars (mvarId : MVarId) : TermElabM Unit := do
val ← instantiateMVars (mkMVar mvarId);
when val.hasExprMVar $ throwError ("tactic failed, result still contain metavariables" ++ indentExpr val)
private partial def getTacticRCurly? : Syntax → Option Syntax
| stx =>
if stx.isOfKind `Lean.Parser.Term.byTactic then
getTacticRCurly? $ stx.getArg 1
else if stx.isOfKind `Lean.Parser.Tactic.seq && stx.getArgs.size == 1 then
getTacticRCurly? $ stx.getArg 0
else if stx.isOfKind `Lean.Parser.Tactic.nestedTacticBlockCurly then
some (stx.getArg 2)
else
none
private def getTacticErrorRef (tacticCode : Syntax) : TermElabM Syntax := do
ref ← getRef;
match getTacticRCurly? tacticCode with
| some rcurly => pure $ replaceRef rcurly ref
| none => pure $ replaceRef tacticCode ref
def runTactic (mvarId : MVarId) (tacticCode : Syntax) : TermElabM Unit := do
/- Recall, `tacticCode` is the whole `by ...` expression.
We store the `by` because in the future we want to save the initial state information at the `by` position. -/
let code := tacticCode.getArg 1;
modifyThe Meta.State $ fun s => { s with mctx := s.mctx.instantiateMVarDeclMVars mvarId };
remainingGoals ← liftTacticElabM mvarId $ do { evalTactic code; getUnsolvedGoals };
ref ← getTacticErrorRef tacticCode;
withRef ref do
unless remainingGoals.isEmpty (reportUnsolvedGoals remainingGoals);
ensureAssignmentHasNoMVars mvarId
unless remainingGoals.isEmpty (reportUnsolvedGoals remainingGoals);
ensureAssignmentHasNoMVars mvarId
/-- Auxiliary function used to implement `synthesizeSyntheticMVars`. -/
private def resumeElabTerm (stx : Syntax) (expectedType? : Option Expr) (errToSorry := true) : TermElabM Expr :=

View file

@ -379,8 +379,8 @@ fun stx => match_syntax stx with
@[builtinTactic paren] def evalParen : Tactic :=
fun stx => evalTactic (stx.getArg 1)
@[builtinTactic tacticSeq1Bracketed] def evalTacticSeq1Bracketed : Tactic :=
fun stx => focus $ (stx.getArg 1).forSepArgsM evalTactic
@[builtinTactic tacticSeqBracketed] def evalTacticSeqBracketed : Tactic :=
fun stx => withRef (stx.getArg 2) $ focus $ (stx.getArg 1).forSepArgsM evalTactic
/--
First method searches for a metavariable `g` s.t. `tag` is a suffix of its name.