Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit c85453d

Browse files
urkudScott Morrisonbryangingechengebnermergify[bot]
authored
fix(tactic/refine_struct): don't add unnecessary eq.mpr or id (#2319)
* fix(tactic/interactive): don't unfold non-Prop goals The old behaviour caused `eq.mpr`'s in `pi_instance` output. * add a test file * move test * actually move test * Update test/refine_struct.lean * test: fix compile * Apply suggestions from code review Co-Authored-By: Gabriel Ebner <gebner@gebner.org> * Try a fix by @gebner and @cipher1024 * Update test/refine_struct.lean Co-Authored-By: Gabriel Ebner <gebner@gebner.org> * apply Gabriel's suggestion Co-authored-by: Scott Morrison <scott.morrison@anu.edu.au> Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: Gabriel Ebner <gebner@gebner.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent df64ea9 commit c85453d

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/tactic/interactive.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ do tgt ← target,
352352
gs ← with_enable_tags (
353353
mzip_with (λ (n : name × name) v, do
354354
set_goals [v],
355-
try (interactive.unfold (provided.map $ λ ⟨s,f⟩, f.update_prefix s) (loc.ns [none])),
355+
try (dsimp_target simp_lemmas.mk),
356356
apply_auto_param
357357
<|> apply_opt_param
358358
<|> (set_main_tag [`_field,n.2,n.1]),

test/refine_struct.lean

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
11
import tactic.interactive
22

3-
section refine_struct
3+
/-!
4+
`refine_struct` caused a variety of interesting problems,
5+
which were identified in
6+
https://github.com/leanprover-community/mathlib/pull/2251
7+
and
8+
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Need.20help.20with.20class.20instance.20resolution
9+
10+
These tests are quite specific to testing the patch made in
11+
https://github.com/leanprover-community/mathlib/pull/2319
12+
and are not a complete test suite for `refine_struct`.
13+
-/
14+
15+
instance pi_has_one {α : Type*} {β : α → Type*} [Π x, has_one (β x)] : has_one (Π x, β x) :=
16+
by refine_struct { .. }; exact λ _, 1
17+
18+
open tactic
19+
20+
run_cmd (do
21+
(declaration.defn _ _ _ b _ _) ← get_decl ``pi_has_one,
22+
-- Make sure that `eq.mpr` really doesn't occur in the body:
23+
eq_mpr ← mk_const `eq.mpr,
24+
k ← kabstract b eq_mpr, -- `expr.occurs` doesn't work here, always giving `ff` even before the patch.
25+
when (b.list_constant.contains ``eq.mpr) $
26+
fail "result generated by `refine_struct` contained an unnecessary `eq.mpr`",
27+
-- Make sure that `id` really doesn't occur in the body:
28+
id ← mk_const `id,
29+
k ← kabstract b id,
30+
guard (k = b) <|>
31+
fail "result generated by `refine_struct` contained an unnecessary `id`")
32+
33+
-- Next we check that fields defined for embedded structures are unfolded
34+
-- when seen by fields in the outer structure.
35+
structure foo (α : Type):=
36+
(a : α)
37+
38+
structure bar (α : Type) extends foo α :=
39+
(b : a = a)
40+
41+
example : bar ℕ :=
42+
begin
43+
refine_struct { a := 1, .. },
44+
-- We're making sure that the goal is
45+
-- ⊢ 1 = 1
46+
-- rather than
47+
-- ⊢ {a := 1}.a = {a := 1}.a
48+
guard_target 1 = 1,
49+
trivial
50+
end
451

52+
section
553
variables {α : Type} [_inst : monoid α]
654
include _inst
755

@@ -13,8 +61,7 @@ begin
1361
guard_tags _field mul_left_inv group, admit, },
1462
trivial
1563
end
16-
17-
end refine_struct
64+
end
1865

1966
def my_foo {α} (x : semigroup α) (y : group α) : true := trivial
2067

0 commit comments

Comments
 (0)