Skip to content

Commit f80f38d

Browse files
Update lean-toolchain for leanprover/lean4#11220
2 parents 68933c0 + e53b625 commit f80f38d

File tree

5 files changed

+70
-51
lines changed

5 files changed

+70
-51
lines changed

Batteries/Data/String/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module
77

88
@[expose] public section
99

10-
instance : Coe String Substring := ⟨String.toSubstring
10+
instance : Coe String Substring.Raw := ⟨String.toRawSubstring
1111

1212
namespace String
1313

Batteries/Data/String/Lemmas.lean

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,11 @@ theorem map_eq (f : Char → Char) (s) : Legacy.map f s = ofList (s.toList.map f
855855

856856
@[nolint unusedHavesSuffices] -- false positive from unfolding String.takeWhileAux
857857
theorem takeWhileAux_of_valid (p : Char → Bool) : ∀ l m r,
858-
Substring.takeWhileAux (ofList (l ++ m ++ r)) ⟨utf8Len l + utf8Len m⟩ p ⟨utf8Len l⟩ =
858+
Substring.Raw.takeWhileAux (ofList (l ++ m ++ r)) ⟨utf8Len l + utf8Len m⟩ p ⟨utf8Len l⟩ =
859859
⟨utf8Len l + utf8Len (m.takeWhile p)⟩
860-
| l, [], r => by unfold Substring.takeWhileAux List.takeWhile; simp
860+
| l, [], r => by unfold Substring.Raw.takeWhileAux List.takeWhile; simp
861861
| l, c::m, r => by
862-
unfold Substring.takeWhileAux List.takeWhile
862+
unfold Substring.Raw.takeWhileAux List.takeWhile
863863
rw [dif_pos (by exact Nat.lt_add_of_pos_right add_utf8Size_pos)]
864864
simp only [List.append_assoc, List.cons_append, get_of_valid l (c :: (m ++ r)),
865865
Char.reduceDefault, List.headD_cons, utf8Len_cons, next_of_valid l c (m ++ r)]
@@ -891,10 +891,10 @@ end String
891891

892892
open String
893893

894-
namespace Substring
894+
namespace Substring.Raw
895895

896896
/-- Validity for a substring. -/
897-
structure Valid (s : Substring) : Prop where
897+
structure Valid (s : Substring.Raw) : Prop where
898898
/-- The start position of a valid substring is valid. -/
899899
startValid : s.startPos.Valid s.str
900900
/-- The stop position of a valid substring is valid. -/
@@ -906,7 +906,7 @@ theorem Valid_default : Valid default := ⟨Pos.Raw.valid_zero, Pos.Raw.valid_ze
906906

907907
/-- A substring is represented by three lists `l m r`, where `m` is the middle section
908908
(the actual substring) and `l ++ m ++ r` is the underlying string. -/
909-
inductive ValidFor (l m r : List Char) : Substring → Prop
909+
inductive ValidFor (l m r : List Char) : Substring.RawProp
910910
/-- The constructor for `ValidFor`. -/
911911
| mk : ValidFor l m r ⟨String.ofList (l ++ m ++ r), ⟨utf8Len l⟩, ⟨utf8Len l + utf8Len m⟩⟩
912912

@@ -925,7 +925,7 @@ theorem of_eq : ∀ s,
925925
exact ⟨⟩
926926

927927
theorem _root_.String.validFor_toSubstring (s : String) : ValidFor [] s.toList [] s :=
928-
.of_eq _ (by simp [toSubstring]) rfl (by simp [toSubstring, rawEndPos])
928+
.of_eq _ (by simp [toRawSubstring]) rfl (by simp [toRawSubstring, rawEndPos])
929929

930930
theorem str : ∀ {s}, ValidFor l m r s → s.str = String.ofList (l ++ m ++ r)
931931
| _, ⟨⟩ => rfl
@@ -937,17 +937,17 @@ theorem stopPos : ∀ {s}, ValidFor l m r s → s.stopPos = ⟨utf8Len l + utf8L
937937
| _, ⟨⟩ => rfl
938938

939939
theorem bsize : ∀ {s}, ValidFor l m r s → s.bsize = utf8Len m
940-
| _, ⟨⟩ => by simp [Substring.bsize, Nat.add_sub_cancel_left]
940+
| _, ⟨⟩ => by simp [Substring.Raw.bsize, Nat.add_sub_cancel_left]
941941

942942
theorem isEmpty : ∀ {s}, ValidFor l m r s → (s.isEmpty ↔ m = [])
943-
| _, h => by simp [Substring.isEmpty, h.bsize]
943+
| _, h => by simp [Substring.Raw.isEmpty, h.bsize]
944944

945945
theorem toString : ∀ {s}, ValidFor l m r s → s.toString = String.ofList m
946946
| _, ⟨⟩ => extract_of_valid l m r
947947

948948
theorem toIterator : ∀ {s}, ValidFor l m r s → s.toLegacyIterator.ValidFor l.reverse (m ++ r)
949949
| _, h => by
950-
simp only [Substring.toLegacyIterator]
950+
simp only [Substring.Raw.toLegacyIterator]
951951
exact .of_eq _ (by simp [h.str, List.reverseAux_eq]) (by simp [h.startPos])
952952

953953
theorem get : ∀ {s}, ValidFor l (m₁ ++ c :: m₂) r s → s.get ⟨utf8Len m₁⟩ = c
@@ -956,7 +956,8 @@ theorem get : ∀ {s}, ValidFor l (m₁ ++ c :: m₂) r s → s.get ⟨utf8Len m
956956
theorem next : ∀ {s}, ValidFor l (m₁ ++ c :: m₂) r s →
957957
s.next ⟨utf8Len m₁⟩ = ⟨utf8Len m₁ + c.utf8Size⟩
958958
| _, ⟨⟩ => by
959-
simp only [Substring.next, utf8Len_append, utf8Len_cons, List.append_assoc, List.cons_append]
959+
simp only [Substring.Raw.next, utf8Len_append, utf8Len_cons, List.append_assoc,
960+
List.cons_append]
960961
rw [if_neg (mt Pos.Raw.ext_iff.1 ?a)]
961962
case a =>
962963
simpa [Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using
@@ -966,12 +967,12 @@ theorem next : ∀ {s}, ValidFor l (m₁ ++ c :: m₂) r s →
966967
simp [Nat.add_assoc, Nat.add_sub_cancel_left]
967968

968969
theorem next_stop : ∀ {s}, ValidFor l m r s → s.next ⟨utf8Len m⟩ = ⟨utf8Len m⟩
969-
| _, ⟨⟩ => by simp [Substring.next, Pos.Raw.offsetBy_eq]
970+
| _, ⟨⟩ => by simp [Substring.Raw.next, Pos.Raw.offsetBy_eq]
970971

971972
theorem prev : ∀ {s}, ValidFor l (m₁ ++ c :: m₂) r s →
972973
s.prev ⟨utf8Len m₁ + c.utf8Size⟩ = ⟨utf8Len m₁⟩
973974
| _, ⟨⟩ => by
974-
simp only [Substring.prev, List.append_assoc, List.cons_append]
975+
simp only [Substring.Raw.prev, List.append_assoc, List.cons_append]
975976
rw [if_neg (mt Pos.Raw.ext_iff.1 <| Ne.symm ?a)]
976977
case a => simpa [Nat.add_comm] using @ne_add_utf8Size_add_self (utf8Len l) (utf8Len m₁) c
977978
have := prev_of_valid (l ++ m₁) c (m₂ ++ r)
@@ -981,13 +982,13 @@ theorem prev : ∀ {s}, ValidFor l (m₁ ++ c :: m₂) r s →
981982

982983
theorem nextn_stop : ∀ {s}, ValidFor l m r s → ∀ n, s.nextn n ⟨utf8Len m⟩ = ⟨utf8Len m⟩
983984
| _, _, 0 => rfl
984-
| _, h, n+1 => by simp [Substring.nextn, h.next_stop, h.nextn_stop n]
985+
| _, h, n+1 => by simp [Substring.Raw.nextn, h.next_stop, h.nextn_stop n]
985986

986987
theorem nextn : ∀ {s}, ValidFor l (m₁ ++ m₂) r s →
987988
∀ n, s.nextn n ⟨utf8Len m₁⟩ = ⟨utf8Len m₁ + utf8Len (m₂.take n)⟩
988-
| _, _, 0 => by simp [Substring.nextn]
989+
| _, _, 0 => by simp [Substring.Raw.nextn]
989990
| s, h, n+1 => by
990-
simp only [Substring.nextn]
991+
simp only [Substring.Raw.nextn]
991992
match m₂ with
992993
| [] => simp at h; simp [h.next_stop, h.nextn_stop]
993994
| c::m₂ =>
@@ -997,9 +998,9 @@ theorem nextn : ∀ {s}, ValidFor l (m₁ ++ m₂) r s →
997998

998999
theorem prevn : ∀ {s}, ValidFor l (m₁.reverse ++ m₂) r s →
9991000
∀ n, s.prevn n ⟨utf8Len m₁⟩ = ⟨utf8Len (m₁.drop n)⟩
1000-
| _, _, 0 => by simp [Substring.prevn]
1001+
| _, _, 0 => by simp [Substring.Raw.prevn]
10011002
| s, h, n+1 => by
1002-
simp only [Substring.prevn]
1003+
simp only [Substring.Raw.prevn]
10031004
match m₁ with
10041005
| [] => simp
10051006
| c::m₁ =>
@@ -1012,9 +1013,9 @@ theorem front : ∀ {s}, ValidFor l (c :: m) r s → s.front = c
10121013
theorem drop :
10131014
∀ {s}, ValidFor l m r s → ∀ n, ValidFor (l ++ m.take n) (m.drop n) r (s.drop n)
10141015
| s, h, n => by
1015-
have : Substring.nextn {..} .. = _ := h.nextn (m₁ := []) n
1016+
have : Substring.Raw.nextn {..} .. = _ := h.nextn (m₁ := []) n
10161017
simp only [utf8Len_nil, Pos.Raw.mk_zero, Nat.zero_add] at this
1017-
simp only [Substring.drop, this]
1018+
simp only [Substring.Raw.drop, this]
10181019
simp only [h.str, List.append_assoc, h.startPos, h.stopPos]
10191020
rw [← List.take_append_drop n m] at h
10201021
refine .of_eq _ (by simp) (by simp) ?_
@@ -1024,9 +1025,9 @@ theorem drop :
10241025
theorem take : ∀ {s}, ValidFor l m r s →
10251026
∀ n, ValidFor l (m.take n) (m.drop n ++ r) (s.take n)
10261027
| s, h, n => by
1027-
have : Substring.nextn {..} .. = _ := h.nextn (m₁ := []) n
1028+
have : Substring.Raw.nextn {..} .. = _ := h.nextn (m₁ := []) n
10281029
simp at this
1029-
simp only [Substring.take, this]
1030+
simp only [Substring.Raw.take, this]
10301031
simp only [h.str, List.append_assoc, h.startPos]
10311032
rw [← List.take_append_drop n m] at h
10321033
refine .of_eq _ ?_ (by simp) (by simp)
@@ -1036,13 +1037,14 @@ theorem take : ∀ {s}, ValidFor l m r s →
10361037
-- TODO: takeRight, dropRight
10371038

10381039
theorem atEnd : ∀ {s}, ValidFor l m r s → (s.atEnd ⟨p⟩ ↔ p = utf8Len m)
1039-
| _, ⟨⟩ => by simp [Substring.atEnd, Pos.Raw.ext_iff, Nat.add_left_cancel_iff]
1040+
| _, ⟨⟩ => by simp [Substring.Raw.atEnd, Pos.Raw.ext_iff, Nat.add_left_cancel_iff]
10401041

10411042
theorem extract' : ∀ {s}, ValidFor l (ml ++ mm ++ mr) r s →
10421043
ValidFor ml mm mr ⟨String.ofList (ml ++ mm ++ mr), b, e⟩ →
10431044
∃ l' r', ValidFor l' mm r' (s.extract b e)
10441045
| _, ⟨⟩, ⟨⟩ => by
1045-
simp only [Substring.extract, ge_iff_le, Pos.Raw.mk_le_mk, List.append_assoc, utf8Len_append]
1046+
simp only [Substring.Raw.extract, ge_iff_le, Pos.Raw.mk_le_mk, List.append_assoc,
1047+
utf8Len_append]
10461048
split
10471049
· next h =>
10481050
rw [utf8Len_eq_zero.1 <| Nat.le_zero.1 <| Nat.add_le_add_iff_left.1 h]
@@ -1063,33 +1065,33 @@ theorem extract : ∀ {s}, ValidFor l m r s →
10631065
-- TODO: splitOn
10641066

10651067
theorem foldl (f) (init : α) : ∀ {s}, ValidFor l m r s → s.foldl f init = m.foldl f init
1066-
| _, ⟨⟩ => by simp [-ofList_append, -List.append_assoc, Substring.foldl,
1068+
| _, ⟨⟩ => by simp [-ofList_append, -List.append_assoc, Substring.Raw.foldl,
10671069
foldlAux_of_valid]
10681070

10691071
theorem foldr (f) (init : α) : ∀ {s}, ValidFor l m r s → s.foldr f init = m.foldr f init
1070-
| _, ⟨⟩ => by simp [-ofList_append, -List.append_assoc, Substring.foldr,
1072+
| _, ⟨⟩ => by simp [-ofList_append, -List.append_assoc, Substring.Raw.foldr,
10711073
foldrAux_of_valid]
10721074

10731075
theorem any (f) : ∀ {s}, ValidFor l m r s → s.any f = m.any f
1074-
| _, ⟨⟩ => by simp [-ofList_append, -List.append_assoc, Substring.any, anyAux_of_valid]
1076+
| _, ⟨⟩ => by simp [-ofList_append, -List.append_assoc, Substring.Raw.any, anyAux_of_valid]
10751077

10761078
theorem all (f) : ∀ {s}, ValidFor l m r s → s.all f = m.all f
1077-
| _, h => by simp [Substring.all, h.any, List.all_eq_not_any_not]
1079+
| _, h => by simp [Substring.Raw.all, h.any, List.all_eq_not_any_not]
10781080

10791081
theorem contains (c) : ∀ {s}, ValidFor l m r s → (s.contains c ↔ c ∈ m)
1080-
| _, h => by simp [Substring.contains, h.any]
1082+
| _, h => by simp [Substring.Raw.contains, h.any]
10811083

10821084
theorem takeWhile (p : Char → Bool) : ∀ {s}, ValidFor l m r s →
10831085
ValidFor l (m.takeWhile p) (m.dropWhile p ++ r) (s.takeWhile p)
10841086
| _, ⟨⟩ => by
1085-
simp only [Substring.takeWhile, takeWhileAux_of_valid]
1087+
simp only [Substring.Raw.takeWhile, takeWhileAux_of_valid]
10861088
apply ValidFor.of_eq <;> simp
10871089
rw [← List.append_assoc, List.takeWhile_append_dropWhile]
10881090

10891091
theorem dropWhile (p : Char → Bool) : ∀ {s}, ValidFor l m r s →
10901092
ValidFor (l ++ m.takeWhile p) (m.dropWhile p) r (s.dropWhile p)
10911093
| _, ⟨⟩ => by
1092-
simp only [Substring.dropWhile, takeWhileAux_of_valid]
1094+
simp only [Substring.Raw.dropWhile, takeWhileAux_of_valid]
10931095
apply ValidFor.of_eq <;> simp
10941096
rw [Nat.add_assoc, ← utf8Len_append (m.takeWhile p), List.takeWhile_append_dropWhile]
10951097

@@ -1233,7 +1235,7 @@ theorem data_dropWhile (p) : ∀ {s}, Valid s →
12331235
-- TODO: takeRightWhile
12341236

12351237
end Valid
1236-
end Substring
1238+
end Substring.Raw
12371239

12381240
namespace String
12391241

Batteries/Data/String/Matcher.lean

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def m := Matcher.ofString "abba"
3333
-/
3434
structure Matcher extends Array.Matcher Char where
3535
/-- The pattern for the matcher -/
36-
pattern : Substring
36+
pattern : Substring.Raw
3737

3838
/-- Make KMP matcher from pattern substring -/
39-
@[inline] def Matcher.ofSubstring (pattern : Substring) : Matcher where
39+
@[inline] def Matcher.ofSubstring (pattern : Substring.Raw) : Matcher where
4040
toMatcher := Array.Matcher.ofStream pattern
4141
pattern := pattern
4242

@@ -48,11 +48,12 @@ structure Matcher extends Array.Matcher Char where
4848
abbrev Matcher.patternSize (m : Matcher) : Nat := m.pattern.bsize
4949

5050
/-- Find all substrings of `s` matching `m.pattern`. -/
51-
partial def Matcher.findAll (m : Matcher) (s : Substring) : Array Substring :=
51+
partial def Matcher.findAll (m : Matcher) (s : Substring.Raw) : Array Substring.Raw :=
5252
loop s m.toMatcher #[]
5353
where
5454
/-- Accumulator loop for `String.Matcher.findAll` -/
55-
loop (s : Substring) (am : Array.Matcher Char) (occs : Array Substring) : Array Substring :=
55+
loop (s : Substring.Raw) (am : Array.Matcher Char) (occs : Array Substring.Raw) :
56+
Array Substring.Raw :=
5657
match am.next? s with
5758
| none => occs
5859
| some (s, am) =>
@@ -61,7 +62,7 @@ where
6162
stopPos := s.startPos }
6263

6364
/-- Find the first substring of `s` matching `m.pattern`, or `none` if no such substring exists. -/
64-
def Matcher.find? (m : Matcher) (s : Substring) : Option Substring :=
65+
def Matcher.find? (m : Matcher) (s : Substring.Raw) : Option Substring.Raw :=
6566
match m.next? s with
6667
| none => none
6768
| some (s, _) =>
@@ -71,41 +72,57 @@ def Matcher.find? (m : Matcher) (s : Substring) : Option Substring :=
7172

7273
end String
7374

74-
namespace Substring
75+
namespace Substring.Raw
7576

7677
/--
7778
Returns all the substrings of `s` that match `pattern`.
7879
-/
79-
@[inline] def findAllSubstr (s pattern : Substring) : Array Substring :=
80+
@[inline] def findAllSubstr (s pattern : Substring.Raw) : Array Substring.Raw :=
8081
(String.Matcher.ofSubstring pattern).findAll s
8182

8283
/--
8384
Returns the first substring of `s` that matches `pattern`,
8485
or `none` if there is no such substring.
8586
-/
86-
@[inline] def findSubstr? (s pattern : Substring) : Option Substring :=
87+
@[inline] def findSubstr? (s pattern : Substring.Raw) : Option Substring.Raw :=
8788
(String.Matcher.ofSubstring pattern).find? s
8889

8990
/--
9091
Returns true iff `pattern` occurs as a substring of `s`.
9192
-/
92-
@[inline] def containsSubstr (s pattern : Substring) : Bool :=
93+
@[inline] def containsSubstr (s pattern : Substring.Raw) : Bool :=
9394
s.findSubstr? pattern |>.isSome
9495

95-
end Substring
96+
end Substring.Raw
97+
98+
section Deprecations
99+
100+
@[deprecated Substring.Raw.findAllSubstr (since := "2025-11-16"),
101+
inherit_doc Substring.Raw.findAllSubstr]
102+
abbrev Substring.findAllSubstr := Substring.Raw.findAllSubstr
103+
104+
@[deprecated Substring.Raw.findSubstr? (since := "2025-11-16"),
105+
inherit_doc Substring.Raw.findSubstr?]
106+
abbrev Substring.findSubstr? := Substring.Raw.findSubstr?
107+
108+
@[deprecated Substring.Raw.containsSubstr (since := "2025-11-16"),
109+
inherit_doc Substring.Raw.containsSubstr]
110+
abbrev Substring.containsSubstr := Substring.Raw.containsSubstr
111+
112+
end Deprecations
96113

97114
namespace String
98115

99-
@[inherit_doc Substring.findAllSubstr]
100-
abbrev findAllSubstr (s : String) (pattern : Substring) : Array Substring :=
116+
@[inherit_doc Substring.Raw.findAllSubstr]
117+
abbrev findAllSubstr (s : String) (pattern : Substring.Raw) : Array Substring.Raw :=
101118
(String.Matcher.ofSubstring pattern).findAll s
102119

103-
@[inherit_doc Substring.findSubstr?]
104-
abbrev findSubstr? (s : String) (pattern : Substring) : Option Substring :=
120+
@[inherit_doc Substring.Raw.findSubstr?]
121+
abbrev findSubstr? (s : String) (pattern : Substring.Raw) : Option Substring.Raw :=
105122
s.toSubstring.findSubstr? pattern
106123

107-
@[inherit_doc Substring.containsSubstr]
108-
abbrev containsSubstr (s : String) (pattern : Substring) : Bool :=
124+
@[inherit_doc Substring.Raw.containsSubstr]
125+
abbrev containsSubstr (s : String) (pattern : Substring.Raw) : Bool :=
109126
s.toSubstring.containsSubstr pattern
110127

111128
end String

Batteries/Lean/Meta/UnusedNames.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open Lean Lean.Meta
1313

1414
namespace Lean.Name
1515

16-
private def parseIndexSuffix (s : Substring) : Option Nat :=
16+
private def parseIndexSuffix (s : Substring.Raw) : Option Nat :=
1717
if s.isEmpty then
1818
none
1919
else if s.front == '_' then

lean-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
leanprover/lean4-pr-releases:pr-release-11220-0b9db11
1+
leanprover/lean4-pr-releases:pr-release-11220-73be069

0 commit comments

Comments
 (0)