Skip to content

Commit 46d7506

Browse files
Update lean-toolchain for leanprover/lean4#11220
2 parents f80f38d + 90e3bf6 commit 46d7506

File tree

8 files changed

+102
-32
lines changed

8 files changed

+102
-32
lines changed

Batteries/Data/Int.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,3 @@ def ofBits (f : Fin n → Bool) :=
5656
theorem testBit_ofBits (f : Fin n → Bool) :
5757
(ofBits f).testBit i = if h : i < n then f ⟨i, h⟩ else decide (ofBits f < 0) := by
5858
split <;> simp_all
59-
60-
-- Forward port of lean4#10739
61-
instance {n : Int} : NeZero (n^0) := ⟨by simp⟩

Batteries/Data/String/Legacy.lean

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,70 @@ Examples:
9292
@[inline] def Legacy.map (f : Char → Char) (s : String) : String :=
9393
mapAux f 0 s
9494

95+
/--
96+
Removes the specified number of characters (Unicode code points) from the start of the string.
97+
98+
If `n` is greater than `s.length`, returns `""`.
99+
100+
This is an old implementation, preserved here for users of the lemmas in
101+
`Batteries.Data.String.Lemmas`. Its runtime behavior is equivalent to that of `String.drop`.
102+
103+
Examples:
104+
* `"red green blue".drop 4 = "green blue"`
105+
* `"red green blue".drop 10 = "blue"`
106+
* `"red green blue".drop 50 = ""`
107+
-/
108+
@[inline] def Legacy.drop (s : String) (n : Nat) : String :=
109+
(s.toRawSubstring.drop n).toString
110+
111+
/--
112+
Creates a new string that contains the first `n` characters (Unicode code points) of `s`.
113+
114+
If `n` is greater than `s.length`, returns `s`.
115+
116+
This is an old implementation, preserved here for users of the lemmas in
117+
`Batteries.Data.String.Lemmas`. Its runtime behavior is equivalent to that of `String.take`.
118+
119+
Examples:
120+
* `"red green blue".take 3 = "red"`
121+
* `"red green blue".take 1 = "r"`
122+
* `"red green blue".take 0 = ""`
123+
* `"red green blue".take 100 = "red green blue"`
124+
-/
125+
@[inline] def Legacy.take (s : String) (n : Nat) : String :=
126+
(s.toRawSubstring.take n).toString
127+
128+
/--
129+
Creates a new string that contains the longest prefix of `s` in which `p` returns `true` for all
130+
characters.
131+
132+
This is an old implementation, preserved here for users of the lemmas in
133+
`Batteries.Data.String.Lemmas`. Its runtime behavior is equivalent to that of `String.takeWhile`.
134+
135+
Examples:
136+
* `"red green blue".takeWhile (·.isLetter) = "red"`
137+
* `"red green blue".takeWhile (· == 'r') = "r"`
138+
* `"red green blue".takeWhile (· != 'n') = "red gree"`
139+
* `"red green blue".takeWhile (fun _ => true) = "red green blue"`
140+
-/
141+
@[inline] def Legacy.takeWhile (s : String) (p : Char → Bool) : String :=
142+
(s.toRawSubstring.takeWhile p).toString
143+
144+
/--
145+
Creates a new string by removing the longest prefix from `s` in which `p` returns `true` for all
146+
characters.
147+
148+
This is an old implementation, preserved here for users of the lemmas in
149+
`Batteries.Data.String.Lemmas`. Its runtime behavior is equivalent to that of `String.takeWhile`.
150+
151+
Examples:
152+
* `"red green blue".dropWhile (·.isLetter) = " green blue"`
153+
* `"red green blue".dropWhile (· == 'r') = "ed green blue"`
154+
* `"red green blue".dropWhile (· != 'n') = "n blue"`
155+
* `"red green blue".dropWhile (fun _ => true) = ""`
156+
-/
157+
@[inline] def Legacy.dropWhile (s : String) (p : Char → Bool) : String :=
158+
(s.toRawSubstring.dropWhile p).toString
159+
160+
95161
end String

Batteries/Data/String/Lemmas.lean

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ theorem extract_of_valid (l m r : List Char) :
515515
Pos.Raw.extract.go₁_append_right _ _ _ _ _ (by rfl)]
516516
apply Pos.Raw.extract.go₂_append_left; apply Nat.add_comm
517517

518+
-- Commented out as failing on nightly-2025-11-20.
519+
/-
518520
theorem splitAux_of_valid (p l m r acc) :
519521
splitAux (ofList (l ++ m ++ r)) p ⟨utf8Len l⟩ ⟨utf8Len l + utf8Len m⟩ acc =
520522
acc.reverse ++ (List.splitOnP.go p r m.reverse).map ofList := by
@@ -542,10 +544,11 @@ theorem splitToList_of_valid (s p) : splitToList s p = (List.splitOnP p s.toList
542544
@[deprecated splitToList_of_valid (since := "2025-10-18")]
543545
theorem split_of_valid (s p) : splitToList s p = (List.splitOnP p s.toList).map ofList :=
544546
splitToList_of_valid s p
547+
-/
545548

546549
-- TODO: splitOn
547550

548-
@[simp] theorem toString_toSubstring (s : String) : s.toSubstring.toString = s :=
551+
@[simp] theorem toString_toSubstring (s : String) : s.toRawSubstring.toString = s :=
549552
extract_zero_rawEndPos _
550553

551554
attribute [simp] toSubstring'
@@ -767,17 +770,19 @@ end Legacy.Iterator
767770

768771
@[nolint unusedHavesSuffices] -- false positive from unfolding String.offsetOfPosAux
769772
theorem offsetOfPosAux_of_valid : ∀ l m r n,
770-
offsetOfPosAux (ofList (l ++ m ++ r)) ⟨utf8Len l + utf8Len m⟩ ⟨utf8Len l⟩ n = n + m.length
771-
| l, [], r, n => by unfold offsetOfPosAux; simp
773+
String.Pos.Raw.offsetOfPosAux (ofList (l ++ m ++ r)) ⟨utf8Len l + utf8Len m⟩ ⟨utf8Len l⟩ n =
774+
n + m.length
775+
| l, [], r, n => by unfold String.Pos.Raw.offsetOfPosAux; simp
772776
| l, c::m, r, n => by
773-
unfold offsetOfPosAux
777+
unfold String.Pos.Raw.offsetOfPosAux
774778
rw [if_neg (by exact Nat.not_le.2 (Nat.lt_add_of_pos_right add_utf8Size_pos))]
775779
simp only [List.append_assoc, atEnd_of_valid l (c::m++r)]
776780
simp only [List.cons_append, utf8Len_cons, next_of_valid l c (m ++ r)]
777781
simpa [← Nat.add_assoc, Nat.add_right_comm] using
778782
offsetOfPosAux_of_valid (l++[c]) m r (n + 1)
779783

780-
theorem offsetOfPos_of_valid (l r) : offsetOfPos (ofList (l ++ r)) ⟨utf8Len l⟩ = l.length := by
784+
theorem offsetOfPos_of_valid (l r) :
785+
String.Pos.Raw.offsetOfPos (ofList (l ++ r)) ⟨utf8Len l⟩ = l.length := by
781786
simpa using offsetOfPosAux_of_valid [] l r 0
782787

783788
@[nolint unusedHavesSuffices] -- false positive from unfolding String.foldlAux
@@ -1239,32 +1244,34 @@ end Substring.Raw
12391244

12401245
namespace String
12411246

1242-
theorem drop_eq (s : String) (n : Nat) : s.drop n = ofList (s.toList.drop n) :=
1247+
theorem drop_eq (s : String) (n : Nat) : Legacy.drop s n = ofList (s.toList.drop n) :=
12431248
(s.validFor_toSubstring.drop n).toString
12441249

1245-
@[simp] theorem toList_drop (s : String) (n : Nat) : (s.drop n).toList = s.toList.drop n := by
1250+
@[simp] theorem toList_drop (s : String) (n : Nat) :
1251+
(Legacy.drop s n).toList = s.toList.drop n := by
12461252
simp [drop_eq]
12471253

1248-
@[simp] theorem drop_empty {n : Nat} : "".drop n = "" := by simp [drop_eq, List.drop_nil]
1254+
@[simp] theorem drop_empty {n : Nat} : Legacy.drop "" n = "" := by simp [drop_eq, List.drop_nil]
12491255

1250-
theorem take_eq (s : String) (n : Nat) : s.take n = ofList (s.toList.take n) :=
1256+
theorem take_eq (s : String) (n : Nat) : Legacy.take s n = ofList (s.toList.take n) :=
12511257
(s.validFor_toSubstring.take n).toString
12521258

1253-
@[simp] theorem toList_take (s : String) (n : Nat) : (s.take n).toList = s.toList.take n := by
1259+
@[simp] theorem toList_take (s : String) (n : Nat) :
1260+
(Legacy.take s n).toList = s.toList.take n := by
12541261
simp [take_eq]
12551262

12561263
theorem takeWhile_eq (p : Char → Bool) (s : String) :
1257-
s.takeWhile p = ofList (s.toList.takeWhile p) :=
1264+
Legacy.takeWhile s p = ofList (s.toList.takeWhile p) :=
12581265
(s.validFor_toSubstring.takeWhile p).toString
12591266

12601267
@[simp] theorem toList_takeWhile (p : Char → Bool) (s : String) :
1261-
(s.takeWhile p).toList = s.toList.takeWhile p := by simp [takeWhile_eq]
1268+
(Legacy.takeWhile s p).toList = s.toList.takeWhile p := by simp [takeWhile_eq]
12621269

12631270
theorem dropWhile_eq (p : Char → Bool) (s : String) :
1264-
s.dropWhile p = ofList (s.toList.dropWhile p) :=
1271+
Legacy.dropWhile s p = ofList (s.toList.dropWhile p) :=
12651272
(s.validFor_toSubstring.dropWhile p).toString
12661273

12671274
@[simp] theorem toList_dropWhile (p : Char → Bool) (s : String) :
1268-
(s.dropWhile p).toList = s.toList.dropWhile p := by simp [dropWhile_eq]
1275+
(Legacy.dropWhile s p).toList = s.toList.dropWhile p := by simp [dropWhile_eq]
12691276

12701277
end String

Batteries/Data/String/Matcher.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ abbrev findAllSubstr (s : String) (pattern : Substring.Raw) : Array Substring.Ra
119119

120120
@[inherit_doc Substring.Raw.findSubstr?]
121121
abbrev findSubstr? (s : String) (pattern : Substring.Raw) : Option Substring.Raw :=
122-
s.toSubstring.findSubstr? pattern
122+
s.toRawSubstring.findSubstr? pattern
123123

124124
@[inherit_doc Substring.Raw.containsSubstr]
125125
abbrev containsSubstr (s : String) (pattern : Substring.Raw) : Bool :=
126-
s.toSubstring.containsSubstr pattern
126+
s.toRawSubstring.containsSubstr pattern
127127

128128
end String

Batteries/Lean/Float.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def toStringFull (f : Float) : String :=
7070
Nat.repr intPart
7171
else
7272
let rem := Nat.repr ((2^e + v' % 2^e) * 5^e)
73-
let rem := rem.dropRightWhile (· == '0')
74-
s!"{intPart}.{String.Pos.Raw.extract rem ⟨1⟩ rem.rawEndPos}"
73+
let rem := rem.dropEndWhile (· == '0')
74+
s!"{intPart}.{rem.drop 1}"
7575
if v < 0 then s!"-{s}" else s
7676
else f.toString -- inf, -inf, nan
7777

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.Raw) : Option Nat :=
16+
private def parseIndexSuffix (s : String.Slice) : Option Nat :=
1717
if s.isEmpty then
1818
none
1919
else if s.front == '_' then

Batteries/Tactic/HelpCmd.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private def elabHelpAttr (id : Option Ident) : CommandElabM Unit := do
121121
for (name, decl) in decls do
122122
let mut msg1 := s!"[{name}]: {decl.descr}"
123123
if let some doc ← findDocString? env decl.ref then
124-
msg1 := s!"{msg1}\n{doc.trim}"
124+
msg1 := s!"{msg1}\n{doc.trimAscii}"
125125
msg := msg ++ .nest 2 msg1 ++ .line ++ .line
126126
logInfo msg
127127

@@ -199,7 +199,7 @@ private def elabHelpCats (id : Option Ident) : CommandElabM Unit := do
199199
for (name, cat) in decls do
200200
let mut msg1 := m!"category {name} [{mkConst cat.declName}]"
201201
if let some doc ← findDocString? env cat.declName then
202-
msg1 := msg1 ++ Format.line ++ doc.trim
202+
msg1 := msg1 ++ Format.line ++ doc.trimAscii.copy
203203
msg := msg ++ .nest 2 msg1 ++ (.line ++ .line : Format)
204204
logInfo msg
205205

@@ -235,12 +235,12 @@ private def elabHelpCat (more : Option Syntax) (catStx : Ident) (id : Option Str
235235
for (k, _) in cat.kinds do
236236
let mut used := false
237237
if let some tk := do getHeadTk (← (← env.find? k).value?) then
238-
let tk := tk.trim
238+
let tk := tk.trimAscii
239239
if let some id := id then
240-
if !id.isPrefixOf tk then
240+
if !tk.startsWith id then
241241
continue
242242
used := true
243-
decls := decls.insert tk ((decls.getD tk #[]).push k)
243+
decls := decls.insert tk.copy ((decls.getD tk.copy #[]).push k)
244244
if !used && id.isNone then
245245
rest := rest.insert (k.toString false) k
246246
let mut msg := MessageData.nil
@@ -252,7 +252,7 @@ private def elabHelpCat (more : Option Syntax) (catStx : Ident) (id : Option Str
252252
let addMsg (k : SyntaxNodeKind) (msg msg1 : MessageData) : CommandElabM MessageData := do
253253
let mut msg1 := msg1
254254
if let some doc ← findDocString? env k then
255-
msg1 := msg1 ++ Format.line ++ doc.trim
255+
msg1 := msg1 ++ Format.line ++ doc.trimAscii.copy
256256
msg1 := .nest 2 msg1
257257
if more.isSome then
258258
let addElabs {α} (type : String) (attr : KeyedDeclsAttribute α)
@@ -262,7 +262,7 @@ private def elabHelpCat (more : Option Syntax) (catStx : Ident) (id : Option Str
262262
let x := e.declName
263263
msg := msg ++ Format.line ++ m!"+ {type} {mkConst x}"
264264
if let some doc ← findDocString? env x then
265-
msg := msg ++ .nest 2 (Format.line ++ doc.trim)
265+
msg := msg ++ .nest 2 (Format.line ++ doc.trimAscii.copy)
266266
pure msg
267267
msg1 ← addElabs "macro" macroAttribute msg1
268268
match catName with
@@ -286,7 +286,7 @@ elab_rules : command
286286
/--
287287
format the string to be included in a single markdown bullet
288288
-/
289-
def _root_.String.makeBullet (s:String) := "* " ++ ("\n ").intercalate (s.splitOn "\n")
289+
private def _root_.String.makeBullet (s:String) := "* " ++ ("\n ").intercalate (s.splitOn "\n")
290290

291291
open Lean Parser Batteries.Util.LibraryNote in
292292
/--
@@ -319,7 +319,7 @@ elab "#help " colGt &"note" colGt ppSpace name:strLit : command => do
319319
logInfo <| "\n\n".intercalate <|
320320
grouped_valid_entries.map
321321
fun l => "library_note \"" ++ l.head!.fst ++ "\"\n" ++
322-
"\n\n".intercalate (l.map (·.snd.trim.makeBullet))
322+
"\n\n".intercalate (l.map (·.snd.trimAscii.copy.makeBullet))
323323

324324
/--
325325
The command `#help term` shows all term syntaxes that have been defined in the current environment.

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-73be069
1+
leanprover/lean4-pr-releases:pr-release-11220-9bb4009

0 commit comments

Comments
 (0)