Skip to content

Commit

Permalink
fix(tactic/{use,ring}): instantiate metavariables in goal (#1520)
Browse files Browse the repository at this point in the history
`use` now tidies up the subgoals that it leaves behind after instantiating constructors.

`ring` is sensitive to the presence of such metavariables, and we can't guarantee that it doesn't see any,
so it should check for them before it runs.
  • Loading branch information
robertylewis authored and mergify[bot] committed Oct 9, 2019
1 parent 45633aa commit a17a9a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/tactic/core.lean
Expand Up @@ -674,6 +674,18 @@ meta def choose : expr → list name → tactic unit
v ← get_unused_name >>= choose1 h n,
choose v ns

/--
Instantiates metavariables that appear in the current goal.
-/
meta def instantiate_mvars_in_target : tactic unit :=
target >>= instantiate_mvars >>= change

/--
Instantiates metavariables in all goals.
-/
meta def instantiate_mvars_in_goals : tactic unit :=
all_goals $ instantiate_mvars_in_target

/-- This makes sure that the execution of the tactic does not change the tactic state.
This can be helpful while using rewrite, apply, or expr munging.
Remember to instantiate your metavariables before you're done! -/
Expand Down Expand Up @@ -728,7 +740,7 @@ instance : monad id :=
let out := format.to_string format!"{{ {fs} }",
return [(out,"")] }

/-- Like `resolve_name` except when the list of goals is
/-- Like `resolve_name` except when the list of goals is
empty. In that situation `resolve_name` fails whereas
`resolve_name'` simply proceeds on a dummy goal -/
meta def resolve_name' (n : name) : tactic pexpr :=
Expand Down Expand Up @@ -1005,7 +1017,9 @@ private meta def tactic.use_aux (h : pexpr) : tactic unit :=
(focus1 (refine h >> done)) <|> (fconstructor >> tactic.use_aux)

protected meta def use (l : list pexpr) : tactic unit :=
focus1 $ l.mmap' $ λ h, tactic.use_aux h <|> fail format!"failed to instantiate goal with {h}"
focus1 $ seq (l.mmap' $ λ h, tactic.use_aux h <|> fail format!"failed to instantiate goal with {h}")
instantiate_mvars_in_target


meta def clear_aux_decl_aux : list expr → tactic unit
| [] := skip
Expand Down
2 changes: 1 addition & 1 deletion src/tactic/ring.lean
Expand Up @@ -501,7 +501,7 @@ end
`ring!` will use a more aggressive reducibility setting to identify atoms. -/
meta def ring (red : parse (tk "!")?) (SOP : parse ring.mode) (loc : parse location) : tactic unit :=
match loc with
| interactive.loc.ns [none] := ring1 red
| interactive.loc.ns [none] := instantiate_mvars_in_target >> ring1 red
| _ := failed
end <|>
do ns ← loc.get_locals,
Expand Down

0 comments on commit a17a9a6

Please sign in to comment.