Skip to content

Commit 4007930

Browse files
committed
merge upstream/nightly-with-mathlib
2 parents d411d9e + 0173444 commit 4007930

File tree

1,052 files changed

+229669
-161626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,052 files changed

+229669
-161626
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ jobs:
271271
// `reverse-ffi` fails to link in sanitizers
272272
// `interactive` and `async_select_channel` fail nondeterministically, would need to
273273
// be investigated.
274-
"CTEST_OPTIONS": "-E 'StackOverflow|reverse-ffi|interactive|async_select_channel'"
274+
// 9366 is too close to timeout
275+
"CTEST_OPTIONS": "-E 'StackOverflow|reverse-ffi|interactive|async_select_channel|9366'"
275276
},
276277
{
277278
"name": "macOS",

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
4444
set(CADICAL_CXX c++)
4545
if (CADICAL_USE_CUSTOM_CXX)
4646
set(CADICAL_CXX ${CMAKE_CXX_COMPILER})
47-
set(CADICAL_CXXFLAGS "${LEAN_EXTRA_CXX_FLAGS}")
47+
# Use same platform flags as for Lean executables, in particular from `prepare-llvm-linux.sh`,
48+
# but not Lean-specific `LEAN_EXTRA_CXX_FLAGS` such as fsanitize.
49+
set(CADICAL_CXXFLAGS "${CMAKE_CXX_FLAGS}")
4850
set(CADICAL_LDFLAGS "-Wl,-rpath=\\$$ORIGIN/../lib")
4951
endif()
5052
find_program(CCACHE ccache)

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ if(LLVM AND ${STAGE} GREATER 0)
448448
# - In particular, `host/bin/llvm-config` produces flags like `-Lllvm-host/lib/libLLVM`, while
449449
# we need the path to be `-Lllvm/lib/libLLVM`. Thus, we perform this replacement here.
450450
string(REPLACE "llvm-host" "llvm" LEANSHARED_LINKER_FLAGS ${LEANSHARED_LINKER_FLAGS})
451-
string(REPLACE "llvm-host" "llvm" LEAN_EXTRA_CXX_FLAGS ${LEAN_EXTRA_CXX_FLAGS})
452-
message(VERBOSE "leanshared linker flags: '${LEANSHARED_LINKER_FLAGS}' | lean extra cxx flags '${LEAN_EXTR_CXX_FLAGS}'")
451+
string(REPLACE "llvm-host" "llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
452+
message(VERBOSE "leanshared linker flags: '${LEANSHARED_LINKER_FLAGS}' | lean extra cxx flags '${CMAKE_CXX_FLAGS}'")
453453
endif()
454454

455455
# get rid of unused parts of C++ stdlib

src/Init/Data/Int/Basic.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ set_option bootstrap.genMatcherCode false in
278278
def decNonneg (m : @& Int) : Decidable (NonNeg m) :=
279279
match m with
280280
| ofNat m => isTrue <| NonNeg.mk m
281-
| -[_ +1] => isFalse <| fun h => nomatch h
281+
| -[i +1] => isFalse <| fun h =>
282+
have : ∀ j, (j = -[i +1]) → NonNeg j → False := fun _ hj hnn =>
283+
Int.NonNeg.casesOn (motive := fun j _ => j = -[i +1] → False) hnn
284+
(fun _ h => Int.noConfusion h) hj
285+
this -[i +1] rfl h
282286

283287
/-- Decides whether `a ≤ b`.
284288

src/Init/Data/List/Nat/Perm.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ theorem set_set_perm {as : List α} {i j : Nat} (h₁ : i < as.length) (h₂ : j
6060

6161
namespace Perm
6262

63-
/-- Variant of `List.Perm.take` specifying the the permutation is constant after `i` elementwise. -/
63+
/-- Variant of `List.Perm.take` specifying that the permutation is constant after `i` elementwise. -/
6464
theorem take_of_getElem? {l₁ l₂ : List α} (h : l₁ ~ l₂) {i : Nat} (w : ∀ j, i ≤ j → l₁[j]? = l₂[j]?) :
6565
l₁.take i ~ l₂.take i := by
6666
refine h.take (Perm.of_eq ?_)
6767
ext1 j
6868
simpa using w (i + j) (by omega)
6969

70-
/-- Variant of `List.Perm.drop` specifying the the permutation is constant before `i` elementwise. -/
70+
/-- Variant of `List.Perm.drop` specifying that the permutation is constant before `i` elementwise. -/
7171
theorem drop_of_getElem? {l₁ l₂ : List α} (h : l₁ ~ l₂) {i : Nat} (w : ∀ j, j < i → l₁[j]? = l₂[j]?) :
7272
l₁.drop i ~ l₂.drop i := by
7373
refine h.drop (Perm.of_eq ?_)

src/Init/Data/Slice/Notation.lean

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ prelude
99
public import Init.Data.Range.Polymorphic.PRange
1010

1111
set_option doc.verso true
12+
set_option linter.missingDocs true
1213

1314
public section
1415

@@ -30,6 +31,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
3031
The type of the resulting slices is {lit}`γ`.
3132
-/
3233
class Rcc.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
34+
/--
35+
Slices {name}`carrier` from {lean}`range.lower` to {lean}`range.upper`, both inclusive.
36+
-/
3337
mkSlice (carrier : α) (range : Rcc β) : γ
3438

3539
/--
@@ -39,6 +43,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
3943
The type of resulting the slices is {lit}`γ`.
4044
-/
4145
class Rco.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
46+
/--
47+
Slices {name}`carrier` from {lean}`range.lower` (inclusive) to {lean}`range.upper` (exclusive).
48+
-/
4249
mkSlice (carrier : α) (range : Rco β) : γ
4350

4451
/--
@@ -48,6 +55,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
4855
The type of the resulting slices is {lit}`γ`.
4956
-/
5057
class Rci.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
58+
/--
59+
Slices {name}`carrier` from {lean}`range.lower` (inclusive).
60+
-/
5161
mkSlice (carrier : α) (range : Rci β) : γ
5262

5363
/--
@@ -57,6 +67,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
5767
The type of the resulting slices is {lit}`γ`.
5868
-/
5969
class Roc.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
70+
/--
71+
Slices {name}`carrier` from {lean}`range.lower` (exclusive) to {lean}`range.upper` (inclusive).
72+
-/
6073
mkSlice (carrier : α) (range : Roc β) : γ
6174

6275
/--
@@ -66,6 +79,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
6679
The type of the resulting slices is {lit}`γ`.
6780
-/
6881
class Roo.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
82+
/--
83+
Slices {name}`carrier` from {lean}`range.lower` to {lean}`range.upper`, both exclusive.
84+
-/
6985
mkSlice (carrier : α) (range : Roo β) : γ
7086

7187
/--
@@ -75,6 +91,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
7591
The type of the resulting slices is {lit}`γ`.
7692
-/
7793
class Roi.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
94+
/--
95+
Slices {name}`carrier` from {lean}`range.lower` (exclusive).
96+
-/
7897
mkSlice (carrier : α) (range : Roi β) : γ
7998

8099
/--
@@ -84,6 +103,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
84103
The type of the resulting slices is {lit}`γ`.
85104
-/
86105
class Ric.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
106+
/--
107+
Slices {name}`carrier` up to {lean}`range.upper` (inclusive).
108+
-/
87109
mkSlice (carrier : α) (range : Ric β) : γ
88110

89111
/--
@@ -93,6 +115,9 @@ This typeclass indicates how to obtain slices of elements of {lit}`α` over rang
93115
The type of the resulting slices is {lit}`γ`.
94116
-/
95117
class Rio.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
118+
/--
119+
Slices {name}`carrier` up to {lean}`range.upper` (exclusive).
120+
-/
96121
mkSlice (carrier : α) (range : Rio β) : γ
97122

98123
/--
@@ -102,6 +127,9 @@ index type {lit}`β`.
102127
The type of the resulting slices is {lit}`γ`.
103128
-/
104129
class Rii.Sliceable (α : Type u) (β : outParam (Type v)) (γ : outParam (Type w)) where
130+
/--
131+
Slices {name}`carrier` with no bounds.
132+
-/
105133
mkSlice (carrier : α) (range : Rii β) : γ
106134

107135
macro_rules

src/Init/Data/String/Basic.lean

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -824,16 +824,25 @@ The region of `s` from `b` (inclusive) to `e` (exclusive) is copied to a newly-a
824824
825825
If `b`'s offset is greater than or equal to that of `e`, then the resulting string is `""`.
826826
827+
If possible, prefer `String.slice`, which avoids the allocation.
827828
-/
828829
@[extern "lean_string_utf8_extract"]
829-
def Pos.extract {s : @& String} (b e : @& s.Pos) : String where
830+
def extract {s : @& String} (b e : @& s.Pos) : String where
830831
toByteArray := s.toByteArray.extract b.offset.byteIdx e.offset.byteIdx
831832
isValidUTF8 := b.isValidUTF8_extract e
832833

834+
@[deprecated String.extract (since := "2025-12-01")]
835+
def Pos.extract {s : String} (b e : @& s.Pos) : String :=
836+
s.extract b e
837+
838+
@[simp]
839+
theorem toByteArray_extract {s : String} {b e : s.Pos} :
840+
(s.extract b e).toByteArray = s.toByteArray.extract b.offset.byteIdx e.offset.byteIdx := (rfl)
841+
833842
/-- Creates a `String` from a `String.Slice` by copying the bytes. -/
834843
@[inline]
835844
def Slice.copy (s : Slice) : String :=
836-
s.startInclusive.extract s.endExclusive
845+
s.str.extract s.startInclusive s.endExclusive
837846

838847
theorem Slice.toByteArray_copy {s : Slice} :
839848
s.copy.toByteArray = s.str.toByteArray.extract s.startInclusive.offset.byteIdx s.endExclusive.offset.byteIdx := (rfl)
@@ -1387,54 +1396,58 @@ theorem Pos.offset_ofCopy {s : Slice} {pos : s.copy.Pos} : pos.ofCopy.offset = p
13871396

13881397
/-- Given a slice `s` and a position on `s`, obtain the corresponding position on `s.copy.` -/
13891398
@[inline]
1390-
def Slice.Pos.toCopy {s : Slice} (pos : s.Pos) : s.copy.Pos where
1399+
def Slice.Pos.copy {s : Slice} (pos : s.Pos) : s.copy.Pos where
13911400
offset := pos.offset
13921401
isValid := Pos.Raw.isValid_copy_iff.2 pos.isValidForSlice
13931402

1403+
@[deprecated Slice.Pos.copy (since := "2025-12-01")]
1404+
def Slice.Pos.toCopy {s : Slice} (pos : s.Pos) : s.copy.Pos :=
1405+
pos.copy
1406+
13941407
@[simp]
1395-
theorem Slice.Pos.offset_toCopy {s : Slice} {pos : s.Pos} : pos.toCopy.offset = pos.offset := (rfl)
1408+
theorem Slice.Pos.offset_copy {s : Slice} {pos : s.Pos} : pos.copy.offset = pos.offset := (rfl)
13961409

13971410
@[simp]
1398-
theorem Slice.Pos.ofCopy_toCopy {s : Slice} {pos : s.Pos} : pos.toCopy.ofCopy = pos :=
1411+
theorem Slice.Pos.ofCopy_copy {s : Slice} {pos : s.Pos} : pos.copy.ofCopy = pos :=
13991412
Slice.Pos.ext (by simp)
14001413

14011414
@[simp]
1402-
theorem Pos.toCopy_ofCopy {s : Slice} {pos : s.copy.Pos} : pos.ofCopy.toCopy = pos :=
1415+
theorem Pos.copy_ofCopy {s : Slice} {pos : s.copy.Pos} : pos.ofCopy.copy = pos :=
14031416
Pos.ext (by simp)
14041417

14051418
theorem Pos.ofCopy_inj {s : Slice} {pos pos' : s.copy.Pos} : pos.ofCopy = pos'.ofCopy ↔ pos = pos' :=
1406-
fun h => by simpa using congrArg Slice.Pos.toCopy h, (· ▸ rfl)⟩
1419+
fun h => by simpa using congrArg Slice.Pos.copy h, (· ▸ rfl)⟩
14071420

14081421
@[simp]
1409-
theorem Slice.startPos_copy {s : Slice} : s.copy.startPos = s.startPos.toCopy :=
1422+
theorem Slice.startPos_copy {s : Slice} : s.copy.startPos = s.startPos.copy :=
14101423
String.Pos.ext (by simp)
14111424

14121425
@[simp]
1413-
theorem Slice.endPos_copy {s : Slice} : s.copy.endPos = s.endPos.toCopy :=
1426+
theorem Slice.endPos_copy {s : Slice} : s.copy.endPos = s.endPos.copy :=
14141427
String.Pos.ext (by simp)
14151428

1416-
theorem Slice.Pos.get_toCopy {s : Slice} {pos : s.Pos} (h) :
1417-
pos.toCopy.get h = pos.get (by rintro rfl; simp at h) := by
1429+
theorem Slice.Pos.get_copy {s : Slice} {pos : s.Pos} (h) :
1430+
pos.copy.get h = pos.get (by rintro rfl; simp at h) := by
14181431
rw [String.Pos.get, Slice.Pos.get_eq_utf8DecodeChar, Slice.Pos.get_eq_utf8DecodeChar]
1419-
simp only [str_toSlice, toByteArray_copy, startInclusive_toSlice, startPos_copy, offset_toCopy,
1432+
simp only [str_toSlice, toByteArray_copy, startInclusive_toSlice, startPos_copy, offset_copy,
14201433
Slice.offset_startPos, Pos.Raw.byteIdx_zero, Pos.offset_toSlice, Nat.zero_add]
14211434
rw [ByteArray.utf8DecodeChar_eq_utf8DecodeChar_extract]
14221435
conv => lhs; congr; rw [ByteArray.extract_extract]
14231436
conv => rhs; rw [ByteArray.utf8DecodeChar_eq_utf8DecodeChar_extract]
14241437
exact ByteArray.utf8DecodeChar_extract_congr _ _ _
14251438

1426-
theorem Slice.Pos.get_eq_get_toCopy {s : Slice} {pos : s.Pos} {h} :
1427-
pos.get h = pos.toCopy.get (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1428-
(get_toCopy _).symm
1439+
theorem Slice.Pos.get_eq_get_copy {s : Slice} {pos : s.Pos} {h} :
1440+
pos.get h = pos.copy.get (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1441+
(get_copy _).symm
14291442

1430-
theorem Slice.Pos.byte_toCopy {s : Slice} {pos : s.Pos} (h) :
1431-
pos.toCopy.byte h = pos.byte (by rintro rfl; simp at h) := by
1443+
theorem Slice.Pos.byte_copy {s : Slice} {pos : s.Pos} (h) :
1444+
pos.copy.byte h = pos.byte (by rintro rfl; simp at h) := by
14321445
rw [String.Pos.byte, Slice.Pos.byte, Slice.Pos.byte]
14331446
simp [getUTF8Byte, String.getUTF8Byte, toByteArray_copy, ByteArray.getElem_extract]
14341447

1435-
theorem Slice.Pos.byte_eq_byte_toCopy {s : Slice} {pos : s.Pos} {h} :
1436-
pos.byte h = pos.toCopy.byte (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1437-
(byte_toCopy _).symm
1448+
theorem Slice.Pos.byte_eq_byte_copy {s : Slice} {pos : s.Pos} {h} :
1449+
pos.byte h = pos.copy.byte (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1450+
(byte_copy _).symm
14381451

14391452
/-- Given a position in `s.sliceFrom p₀`, obtain the corresponding position in `s`. -/
14401453
@[inline]
@@ -1521,7 +1534,7 @@ theorem Slice.Pos.copy_eq_append_get {s : Slice} {pos : s.Pos} (h : pos ≠ s.en
15211534
∃ t₁ t₂ : String, s.copy = t₁ ++ singleton (pos.get h) ++ t₂ ∧ t₁.utf8ByteSize = pos.offset.byteIdx := by
15221535
obtain ⟨t₂, ht₂⟩ := (s.sliceFrom pos).copy.eq_singleton_append (by simpa [← Pos.ofCopy_inj, ← ofSliceFrom_inj])
15231536
refine ⟨(s.sliceTo pos).copy, t₂, ?_, by simp⟩
1524-
simp only [Slice.startPos_copy, get_toCopy, get_eq_get_ofSliceFrom, ofSliceFrom_startPos] at ht₂
1537+
simp only [Slice.startPos_copy, get_copy, get_eq_get_ofSliceFrom, ofSliceFrom_startPos] at ht₂
15251538
rw [append_assoc, ← ht₂, ← copy_eq_copy_sliceTo]
15261539

15271540
theorem Slice.Pos.utf8ByteSize_byte {s : Slice} {pos : s.Pos} {h : pos ≠ s.endPos} :
@@ -1751,8 +1764,8 @@ theorem Pos.offset_cast {s t : String} {pos : s.Pos} {h : s = t} :
17511764
theorem Pos.cast_rfl {s : String} {pos : s.Pos} : pos.cast rfl = pos :=
17521765
Pos.ext (by simp)
17531766

1754-
theorem Pos.toCopy_toSlice_eq_cast {s : String} (p : s.Pos) :
1755-
p.toSlice.toCopy = p.cast copy_toSlice.symm :=
1767+
theorem Pos.copy_toSlice_eq_cast {s : String} (p : s.Pos) :
1768+
p.toSlice.copy = p.cast copy_toSlice.symm :=
17561769
Pos.ext (by simp)
17571770

17581771
/-- Given a byte position within a string slice, obtains the smallest valid position that is
@@ -2435,6 +2448,35 @@ def Pos.slice! {s : String} (pos : s.Pos) (p₀ p₁ : s.Pos) :
24352448
(s.slice! p₀ p₁).Pos :=
24362449
Slice.Pos.slice! pos.toSlice _ _
24372450

2451+
theorem extract_eq_copy_slice {s : String} (p₀ p₁ : s.Pos) (h : p₀ ≤ p₁) :
2452+
s.extract p₀ p₁ = (s.slice p₀ p₁ h).copy := by
2453+
simp [← toByteArray_inj, Slice.toByteArray_copy]
2454+
2455+
/--
2456+
Copies a region of a slice to a new string.
2457+
2458+
The region of `s` from `b` (inclusive) to `e` (exclusive) is copied to a newly-allocated `String`.
2459+
2460+
If `b`'s offset is greater than or equal to that of `e`, then the resulting string is `""`.
2461+
2462+
If possible, prefer `Slice.slice`, which avoids the allocation.
2463+
-/
2464+
@[inline]
2465+
def Slice.extract (s : Slice) (p₀ p₁ : s.Pos) : String :=
2466+
s.str.extract p₀.str p₁.str
2467+
2468+
@[simp]
2469+
theorem Slice.Pos.str_le_str_iff {s : Slice} {p q : s.Pos} : p.str ≤ q.str ↔ p ≤ q := by
2470+
simp [String.Pos.le_iff, Slice.Pos.le_iff, Pos.Raw.le_iff]
2471+
2472+
@[simp]
2473+
theorem Slice.Pos.str_lt_str_iff {s : Slice} {p q : s.Pos} : p.str < q.str ↔ p < q := by
2474+
simp [String.Pos.lt_iff, Slice.Pos.lt_iff, Pos.Raw.lt_iff]
2475+
2476+
theorem Slice.extract_eq_copy_slice {s : Slice} (p₀ p₁ : s.Pos) (h : p₀ ≤ p₁) :
2477+
s.extract p₀ p₁ = (s.slice p₀ p₁ h).copy := by
2478+
simp [← toByteArray_inj, Slice.toByteArray_copy, Slice.extract]
2479+
24382480
/--
24392481
Advances the position `p` `n` times.
24402482
@@ -2734,10 +2776,6 @@ where
27342776
| [], _, _ => []
27352777
| c::cs, i, e => if i = e then [] else c :: go₂ cs (i + c) e
27362778

2737-
@[extern "lean_string_utf8_extract", expose, deprecated Pos.Raw.extract (since := "2025-10-14")]
2738-
def extract : (@& String) → (@& Pos.Raw) → (@& Pos.Raw) → String
2739-
| s, b, e => Pos.Raw.extract s b e
2740-
27412779
def Pos.Raw.offsetOfPosAux (s : String) (pos : Pos.Raw) (i : Pos.Raw) (offset : Nat) : Nat :=
27422780
if i >= pos then offset
27432781
else if h : i.atEnd s then

src/Init/Data/String/Lemmas/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ theorem singleton_ne_empty {c : Char} : singleton c ≠ "" := by
4040
simp [singleton]
4141

4242
@[simp]
43-
theorem Slice.Pos.toCopy_inj {s : Slice} {p₁ p₂ : s.Pos} : p₁.toCopy = p₂.toCopy ↔ p₁ = p₂ := by
43+
theorem Slice.Pos.copy_inj {s : Slice} {p₁ p₂ : s.Pos} : p₁.copy = p₂.copy ↔ p₁ = p₂ := by
4444
simp [String.Pos.ext_iff, Pos.ext_iff]
4545

4646
@[simp]

0 commit comments

Comments
 (0)