Skip to content

Commit 82fbd51

Browse files
chore: test reference manual automation
Revert "chore: convert `DHashMap` to a structure (leanprover#8761)" This reverts commit a750da5. This should change an error message in the reference manual and cause it to not build.
1 parent d3dda9f commit 82fbd51

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

src/Std/Data/DHashMap/Basic.lean

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ be used in nested inductive types. For these use cases, `Std.DHashMap.Raw` and
6161
For a variant that is more convenient for use in proofs because of extensionalities, see
6262
`Std.ExtDHashMap` which is defined in the module `Std.Data.ExtDHashMap`.
6363
-/
64-
structure DHashMap (α : Type u) (β : α → Type v) [BEq α] [Hashable α] where
65-
/-- Internal implementation detail of the hash map. -/
66-
inner : DHashMap.Raw α β
67-
/-- Internal implementation detail of the hash map. -/
68-
wf : inner.WF
64+
def DHashMap (α : Type u) (β : α → Type v) [BEq α] [Hashable α] := { m : DHashMap.Raw α β // m.WF }
6965

7066
namespace DHashMap
7167

src/Std/Data/DHashMap/Lemmas.lean

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ namespace Std.DHashMap
2929

3030
variable {m : DHashMap α β}
3131

32-
private theorem ext {t t' : DHashMap α β} : t.inner = t'.inner → t = t' := by
33-
cases t; cases t'; rintro rfl; rfl
34-
3532
@[simp, grind =]
3633
theorem isEmpty_emptyWithCapacity {c} : (emptyWithCapacity c : DHashMap α β).isEmpty :=
3734
Raw₀.isEmpty_emptyWithCapacity
@@ -54,10 +51,14 @@ theorem mem_iff_contains {a : α} : a ∈ m ↔ m.contains a :=
5451

5552
-- While setting up the API, often use this in the reverse direction,
5653
-- but prefer this direction for users.
57-
@[simp, grind _=_]
54+
@[simp, grind =]
5855
theorem contains_iff_mem {a : α} : m.contains a ↔ a ∈ m :=
5956
Iff.rfl
6057

58+
-- We need to specify the pattern for the reverse direction manually,
59+
-- as the default heuristic leaves the `DHashMap α β` argument as a wildcard.
60+
grind_pattern contains_iff_mem => @Membership.mem α (DHashMap α β) _ m a
61+
6162
theorem contains_congr [EquivBEq α] [LawfulHashable α] {a b : α} (hab : a == b) :
6263
m.contains a = m.contains b :=
6364
Raw₀.contains_congr _ m.2 hab
@@ -168,7 +169,7 @@ theorem size_insert_le [EquivBEq α] [LawfulHashable α] {k : α} {v : β k} :
168169

169170
@[simp, grind =]
170171
theorem erase_emptyWithCapacity {k : α} {c : Nat} : (emptyWithCapacity c : DHashMap α β).erase k = emptyWithCapacity c :=
171-
ext <| congrArg Subtype.val (Raw₀.erase_emptyWithCapacity (k := k))
172+
Subtype.eq (congrArg Subtype.val (Raw₀.erase_emptyWithCapacity (k := k)) :)
172173

173174
@[simp, grind =]
174175
theorem erase_empty {k : α} : (∅ : DHashMap α β).erase k = ∅ :=
@@ -217,7 +218,7 @@ theorem containsThenInsert_fst {k : α} {v : β k} : (m.containsThenInsert k v).
217218

218219
@[simp, grind =]
219220
theorem containsThenInsert_snd {k : α} {v : β k} : (m.containsThenInsert k v).2 = m.insert k v :=
220-
ext <| congrArg Subtype.val (Raw₀.containsThenInsert_snd _ (k := k))
221+
Subtype.eq <| (congrArg Subtype.val (Raw₀.containsThenInsert_snd _ (k := k)) :)
221222

222223
@[simp, grind =]
223224
theorem containsThenInsertIfNew_fst {k : α} {v : β k} :
@@ -227,7 +228,7 @@ theorem containsThenInsertIfNew_fst {k : α} {v : β k} :
227228
@[simp, grind =]
228229
theorem containsThenInsertIfNew_snd {k : α} {v : β k} :
229230
(m.containsThenInsertIfNew k v).2 = m.insertIfNew k v :=
230-
ext <| congrArg Subtype.val (Raw₀.containsThenInsertIfNew_snd _ (k := k))
231+
Subtype.eq <| (congrArg Subtype.val (Raw₀.containsThenInsertIfNew_snd _ (k := k)) :)
231232

232233
@[simp, grind =]
233234
theorem get?_emptyWithCapacity [LawfulBEq α] {a : α} {c} : (emptyWithCapacity c : DHashMap α β).get? a = none :=
@@ -1115,7 +1116,7 @@ theorem getThenInsertIfNew?_fst [LawfulBEq α] {k : α} {v : β k} :
11151116
@[simp, grind =]
11161117
theorem getThenInsertIfNew?_snd [LawfulBEq α] {k : α} {v : β k} :
11171118
(m.getThenInsertIfNew? k v).2 = m.insertIfNew k v :=
1118-
ext <| congrArg Subtype.val (Raw₀.getThenInsertIfNew?_snd _ (k := k))
1119+
Subtype.eq <| (congrArg Subtype.val (Raw₀.getThenInsertIfNew?_snd _ (k := k)) :)
11191120

11201121
namespace Const
11211122

@@ -1128,7 +1129,7 @@ theorem getThenInsertIfNew?_fst {k : α} {v : β} : (getThenInsertIfNew? m k v).
11281129
@[simp, grind =]
11291130
theorem getThenInsertIfNew?_snd {k : α} {v : β} :
11301131
(getThenInsertIfNew? m k v).2 = m.insertIfNew k v :=
1131-
ext <| congrArg Subtype.val (Raw₀.Const.getThenInsertIfNew?_snd _ (k := k))
1132+
Subtype.eq <| (congrArg Subtype.val (Raw₀.Const.getThenInsertIfNew?_snd _ (k := k)) :)
11321133

11331134
end Const
11341135

@@ -1401,16 +1402,16 @@ variable {ρ : Type w} [ForIn Id ρ ((a : α) × β a)]
14011402
@[simp, grind =]
14021403
theorem insertMany_nil :
14031404
m.insertMany [] = m :=
1404-
ext <| congrArg Subtype.val (Raw₀.insertMany_nil ⟨m.1, m.2.size_buckets_pos⟩)
1405+
Subtype.eq (congrArg Subtype.val (Raw₀.insertMany_nil ⟨m.1, m.2.size_buckets_pos⟩) :)
14051406

14061407
@[simp, grind =]
14071408
theorem insertMany_list_singleton {k : α} {v : β k} :
14081409
m.insertMany [⟨k, v⟩] = m.insert k v :=
1409-
ext <| congrArg Subtype.val (Raw₀.insertMany_list_singleton ⟨m.1, m.2.size_buckets_pos⟩)
1410+
Subtype.eq (congrArg Subtype.val (Raw₀.insertMany_list_singleton ⟨m.1, m.2.size_buckets_pos⟩) :)
14101411

14111412
@[grind _=_] theorem insertMany_cons {l : List ((a : α) × β a)} {k : α} {v : β k} :
14121413
m.insertMany (⟨k, v⟩ :: l) = (m.insert k v).insertMany l :=
1413-
ext <| congrArg Subtype.val (Raw₀.insertMany_cons ⟨m.1, m.2.size_buckets_pos⟩)
1414+
Subtype.eq (congrArg Subtype.val (Raw₀.insertMany_cons ⟨m.1, m.2.size_buckets_pos⟩) :)
14141415

14151416
@[grind _=_]
14161417
theorem insertMany_append {l₁ l₂ : List ((a : α) × β a)} :
@@ -1606,17 +1607,17 @@ variable {ρ : Type w} [ForIn Id ρ (α × β)]
16061607
@[simp, grind =]
16071608
theorem insertMany_nil :
16081609
insertMany m [] = m :=
1609-
ext <| congrArg Subtype.val (Raw₀.Const.insertMany_nil ⟨m.1, m.2.size_buckets_pos⟩)
1610+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertMany_nil ⟨m.1, m.2.size_buckets_pos⟩) :)
16101611

16111612
@[simp, grind =]
16121613
theorem insertMany_list_singleton {k : α} {v : β} :
16131614
insertMany m [⟨k, v⟩] = m.insert k v :=
1614-
ext <| congrArg Subtype.val
1615-
(Raw₀.Const.insertMany_list_singleton ⟨m.1, m.2.size_buckets_pos⟩)
1615+
Subtype.eq (congrArg Subtype.val
1616+
(Raw₀.Const.insertMany_list_singleton ⟨m.1, m.2.size_buckets_pos⟩) :)
16161617

16171618
@[grind _=_] theorem insertMany_cons {l : List (α × β)} {k : α} {v : β} :
16181619
insertMany m (⟨k, v⟩ :: l) = insertMany (m.insert k v) l :=
1619-
ext <| congrArg Subtype.val (Raw₀.Const.insertMany_cons ⟨m.1, m.2.size_buckets_pos⟩)
1620+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertMany_cons ⟨m.1, m.2.size_buckets_pos⟩) :)
16201621

16211622
@[grind _=_]
16221623
theorem insertMany_append {l₁ l₂ : List (α × β)} :
@@ -1818,19 +1819,19 @@ variable {ρ : Type w} [ForIn Id ρ α]
18181819
@[simp]
18191820
theorem insertManyIfNewUnit_nil :
18201821
insertManyIfNewUnit m [] = m :=
1821-
ext <| congrArg Subtype.val
1822-
(Raw₀.Const.insertManyIfNewUnit_nil ⟨m.1, m.2.size_buckets_pos⟩)
1822+
Subtype.eq (congrArg Subtype.val
1823+
(Raw₀.Const.insertManyIfNewUnit_nil ⟨m.1, m.2.size_buckets_pos⟩) :)
18231824

18241825
@[simp]
18251826
theorem insertManyIfNewUnit_list_singleton {k : α} :
18261827
insertManyIfNewUnit m [k] = m.insertIfNew k () :=
1827-
ext <| congrArg Subtype.val
1828-
(Raw₀.Const.insertManyIfNewUnit_list_singleton ⟨m.1, m.2.size_buckets_pos⟩)
1828+
Subtype.eq (congrArg Subtype.val
1829+
(Raw₀.Const.insertManyIfNewUnit_list_singleton ⟨m.1, m.2.size_buckets_pos⟩) :)
18291830

18301831
theorem insertManyIfNewUnit_cons {l : List α} {k : α} :
18311832
insertManyIfNewUnit m (k :: l) = insertManyIfNewUnit (m.insertIfNew k ()) l :=
1832-
ext <| congrArg Subtype.val
1833-
(Raw₀.Const.insertManyIfNewUnit_cons ⟨m.1, m.2.size_buckets_pos⟩)
1833+
Subtype.eq (congrArg Subtype.val
1834+
(Raw₀.Const.insertManyIfNewUnit_cons ⟨m.1, m.2.size_buckets_pos⟩) :)
18341835

18351836
@[elab_as_elim]
18361837
theorem insertManyIfNewUnit_ind {motive : DHashMap α (fun _ => Unit) → Prop}
@@ -2004,16 +2005,16 @@ namespace DHashMap
20042005
@[simp, grind =]
20052006
theorem ofList_nil :
20062007
ofList ([] : List ((a : α) × (β a))) = ∅ :=
2007-
ext <| congrArg Subtype.val (Raw₀.insertMany_emptyWithCapacity_list_nil (α := α))
2008+
Subtype.eq (congrArg Subtype.val (Raw₀.insertMany_emptyWithCapacity_list_nil (α := α)) :)
20082009

20092010
@[simp, grind =]
20102011
theorem ofList_singleton {k : α} {v : β k} :
20112012
ofList [⟨k, v⟩] = (∅: DHashMap α β).insert k v :=
2012-
ext <| congrArg Subtype.val (Raw₀.insertMany_emptyWithCapacity_list_singleton (α := α))
2013+
Subtype.eq (congrArg Subtype.val (Raw₀.insertMany_emptyWithCapacity_list_singleton (α := α)) :)
20132014

20142015
@[grind _=_] theorem ofList_cons {k : α} {v : β k} {tl : List ((a : α) × (β a))} :
20152016
ofList (⟨k, v⟩ :: tl) = ((∅ : DHashMap α β).insert k v).insertMany tl :=
2016-
ext <| congrArg Subtype.val (Raw₀.insertMany_emptyWithCapacity_list_cons (α := α))
2017+
Subtype.eq (congrArg Subtype.val (Raw₀.insertMany_emptyWithCapacity_list_cons (α := α)) :)
20172018

20182019
theorem ofList_eq_insertMany_empty {l : List ((a : α) × β a)} :
20192020
ofList l = insertMany (∅ : DHashMap α β) l := rfl
@@ -2153,16 +2154,16 @@ variable {β : Type v}
21532154
@[simp, grind =]
21542155
theorem ofList_nil :
21552156
ofList ([] : List (α × β)) = ∅ :=
2156-
ext <| congrArg Subtype.val (Raw₀.Const.insertMany_emptyWithCapacity_list_nil (α:= α))
2157+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertMany_emptyWithCapacity_list_nil (α:= α)) :)
21572158

21582159
@[simp, grind =]
21592160
theorem ofList_singleton {k : α} {v : β} :
21602161
ofList [⟨k, v⟩] = (∅ : DHashMap α (fun _ => β)).insert k v :=
2161-
ext <| congrArg Subtype.val (Raw₀.Const.insertMany_emptyWithCapacity_list_singleton (α:= α))
2162+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertMany_emptyWithCapacity_list_singleton (α:= α)) :)
21622163

21632164
@[grind _=_] theorem ofList_cons {k : α} {v : β} {tl : List (α × β)} :
21642165
ofList (⟨k, v⟩ :: tl) = insertMany ((∅ : DHashMap α (fun _ => β)).insert k v) tl :=
2165-
ext <| congrArg Subtype.val (Raw₀.Const.insertMany_emptyWithCapacity_list_cons (α:= α))
2166+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertMany_emptyWithCapacity_list_cons (α:= α)) :)
21662167

21672168
theorem ofList_eq_insertMany_empty {l : List (α × β)} :
21682169
ofList l = insertMany (∅ : DHashMap α (fun _ => β)) l := rfl
@@ -2298,17 +2299,17 @@ theorem isEmpty_ofList [EquivBEq α] [LawfulHashable α]
22982299
@[simp]
22992300
theorem unitOfList_nil :
23002301
unitOfList ([] : List α) = ∅ :=
2301-
ext <| congrArg Subtype.val (Raw₀.Const.insertManyIfNewUnit_emptyWithCapacity_list_nil (α := α))
2302+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertManyIfNewUnit_emptyWithCapacity_list_nil (α := α)) :)
23022303

23032304
@[simp]
23042305
theorem unitOfList_singleton {k : α} :
23052306
unitOfList [k] = (∅ : DHashMap α (fun _ => Unit)).insertIfNew k () :=
2306-
ext <| congrArg Subtype.val (Raw₀.Const.insertManyIfNewUnit_emptyWithCapacity_list_singleton (α := α))
2307+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertManyIfNewUnit_emptyWithCapacity_list_singleton (α := α)) :)
23072308

23082309
theorem unitOfList_cons {hd : α} {tl : List α} :
23092310
unitOfList (hd :: tl) =
23102311
insertManyIfNewUnit ((∅ : DHashMap α (fun _ => Unit)).insertIfNew hd ()) tl :=
2311-
ext <| congrArg Subtype.val (Raw₀.Const.insertManyIfNewUnit_emptyWithCapacity_list_cons (α := α))
2312+
Subtype.eq (congrArg Subtype.val (Raw₀.Const.insertManyIfNewUnit_emptyWithCapacity_list_cons (α := α)) :)
23122313

23132314
@[simp]
23142315
theorem contains_unitOfList [EquivBEq α] [LawfulHashable α]

0 commit comments

Comments
 (0)