Skip to content

Commit 24d61ef

Browse files
committed
merge master
2 parents da9b442 + 6e60d13 commit 24d61ef

File tree

549 files changed

+120498
-82929
lines changed

Some content is hidden

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

549 files changed

+120498
-82929
lines changed

.github/workflows/check-prelude.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ jobs:
1414
sparse-checkout: |
1515
src/Lean
1616
src/Std
17+
src/lake/Lake
1718
- name: Check Prelude
1819
run: |
1920
failed_files=""
2021
while IFS= read -r -d '' file; do
2122
if ! grep -q "^prelude$" "$file"; then
2223
failed_files="$failed_files$file\n"
2324
fi
24-
done < <(find src/Lean src/Std -name '*.lean' -print0)
25+
done < <(find src/Lean src/Std src/lake/Lake -name '*.lean' -print0)
2526
if [ -n "$failed_files" ]; then
2627
echo -e "The following files should use 'prelude':\n$failed_files"
2728
exit 1

doc/examples/test_single.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
source ../../tests/common.sh
33

4-
exec_check lean -Dlinter.all=false "$f"
4+
exec_check_raw lean -Dlinter.all=false "$f"

src/CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
122122
# From https://emscripten.org/docs/compiling/WebAssembly.html#backends:
123123
# > The simple and safe thing is to pass all -s flags at both compile and link time.
124124
set(EMSCRIPTEN_SETTINGS "-s ALLOW_MEMORY_GROWTH=1 -fwasm-exceptions -pthread -flto")
125-
string(APPEND LEANC_EXTRA_FLAGS " -pthread")
125+
string(APPEND LEANC_EXTRA_CC_FLAGS " -pthread")
126126
string(APPEND LEAN_EXTRA_CXX_FLAGS " -D LEAN_EMSCRIPTEN ${EMSCRIPTEN_SETTINGS}")
127127
string(APPEND LEAN_EXTRA_LINKER_FLAGS " ${EMSCRIPTEN_SETTINGS}")
128128
endif()
@@ -157,11 +157,11 @@ if ((${MULTI_THREAD} MATCHES "ON") AND (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
157157
endif ()
158158

159159
# We want explicit stack probes in huge Lean stack frames for robust stack overflow detection
160-
string(APPEND LEANC_EXTRA_FLAGS " -fstack-clash-protection")
160+
string(APPEND LEANC_EXTRA_CC_FLAGS " -fstack-clash-protection")
161161

162162
# This makes signed integer overflow guaranteed to match 2's complement.
163163
string(APPEND CMAKE_CXX_FLAGS " -fwrapv")
164-
string(APPEND LEANC_EXTRA_FLAGS " -fwrapv")
164+
string(APPEND LEANC_EXTRA_CC_FLAGS " -fwrapv")
165165

166166
if(NOT MULTI_THREAD)
167167
message(STATUS "Disabled multi-thread support, it will not be safe to run multiple threads in parallel")
@@ -451,7 +451,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
451451
string(APPEND TOOLCHAIN_SHARED_LINKER_FLAGS " -Wl,-Bsymbolic")
452452
endif()
453453
string(APPEND CMAKE_CXX_FLAGS " -fPIC -ftls-model=initial-exec")
454-
string(APPEND LEANC_EXTRA_FLAGS " -fPIC")
454+
string(APPEND LEANC_EXTRA_CC_FLAGS " -fPIC")
455455
string(APPEND TOOLCHAIN_SHARED_LINKER_FLAGS " -Wl,-rpath=\\$$ORIGIN/..:\\$$ORIGIN")
456456
string(APPEND LAKESHARED_LINKER_FLAGS " -Wl,--whole-archive ${CMAKE_BINARY_DIR}/lib/temp/libLake.a.export -Wl,--no-whole-archive")
457457
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-rpath=\\\$ORIGIN/../lib:\\\$ORIGIN/../lib/lean")
@@ -464,7 +464,7 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
464464
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-rpath,@executable_path/../lib -Wl,-rpath,@executable_path/../lib/lean")
465465
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
466466
string(APPEND CMAKE_CXX_FLAGS " -fPIC")
467-
string(APPEND LEANC_EXTRA_FLAGS " -fPIC")
467+
string(APPEND LEANC_EXTRA_CC_FLAGS " -fPIC")
468468
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
469469
string(APPEND LAKESHARED_LINKER_FLAGS " -Wl,--out-implib,${CMAKE_BINARY_DIR}/lib/lean/libLake_shared.dll.a -Wl,--whole-archive ${CMAKE_BINARY_DIR}/lib/temp/libLake.a.export -Wl,--no-whole-archive")
470470
endif()
@@ -479,7 +479,7 @@ if(NOT(${CMAKE_SYSTEM_NAME} MATCHES "Windows") AND NOT(${CMAKE_SYSTEM_NAME} MATC
479479
string(APPEND CMAKE_EXE_LINKER_FLAGS " -rdynamic")
480480
# hide all other symbols
481481
string(APPEND CMAKE_CXX_FLAGS " -fvisibility=hidden -fvisibility-inlines-hidden")
482-
string(APPEND LEANC_EXTRA_FLAGS " -fvisibility=hidden")
482+
string(APPEND LEANC_EXTRA_CC_FLAGS " -fvisibility=hidden")
483483
endif()
484484

485485
# On Windows, add bcrypt for random number generation
@@ -544,9 +544,10 @@ include_directories(${CMAKE_BINARY_DIR}/include) # config.h etc., "public" head
544544
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
545545
string(APPEND LEANC_OPTS " ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}")
546546

547-
# Do embed flag for finding system libraries in dev builds
547+
# Do embed flag for finding system headers and libraries in dev builds
548548
if(CMAKE_OSX_SYSROOT AND NOT LEAN_STANDALONE)
549-
string(APPEND LEANC_EXTRA_FLAGS " ${CMAKE_CXX_SYSROOT_FLAG}${CMAKE_OSX_SYSROOT}")
549+
string(APPEND LEANC_EXTRA_CC_FLAGS " ${CMAKE_CXX_SYSROOT_FLAG}${CMAKE_OSX_SYSROOT}")
550+
string(APPEND LEAN_EXTRA_LINKER_FLAGS " ${CMAKE_CXX_SYSROOT_FLAG}${CMAKE_OSX_SYSROOT}")
550551
endif()
551552

552553
add_subdirectory(initialize)

src/Init/Data/Array.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ import Init.Data.Array.Set
2121
import Init.Data.Array.Monadic
2222
import Init.Data.Array.FinRange
2323
import Init.Data.Array.Perm
24+
import Init.Data.Array.Find

src/Init/Data/Array/Attach.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ theorem getElem?_attach {xs : Array α} {i : Nat} :
251251
theorem getElem_attachWith {xs : Array α} {P : α → Prop} {H : ∀ a ∈ xs, P a}
252252
{i : Nat} (h : i < (xs.attachWith P H).size) :
253253
(xs.attachWith P H)[i] = ⟨xs[i]'(by simpa using h), H _ (getElem_mem (by simpa using h))⟩ :=
254-
getElem_pmap ..
254+
getElem_pmap _ _ h
255255

256256
@[simp]
257257
theorem getElem_attach {xs : Array α} {i : Nat} (h : i < xs.attach.size) :

src/Init/Data/Array/Basic.lean

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ def findSomeM? {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f
474474
| _ => pure ⟨⟩
475475
return none
476476

477+
/--
478+
Note that the universe level is contrained to `Type` here,
479+
to avoid having to have the predicate live in `p : α → m (ULift Bool)`.
480+
-/
477481
@[inline]
478482
def findM? {α : Type} {m : TypeType} [Monad m] (p : α → m Bool) (as : Array α) : m (Option α) := do
479483
for a in as do
@@ -585,8 +589,12 @@ def zipWithIndex (arr : Array α) : Array (α × Nat) :=
585589
arr.mapIdx fun i a => (a, i)
586590

587591
@[inline]
588-
def find? {α : Type} (p : α → Bool) (as : Array α) : Option α :=
589-
Id.run <| as.findM? p
592+
def find? {α : Type u} (p : α → Bool) (as : Array α) : Option α :=
593+
Id.run do
594+
for a in as do
595+
if p a then
596+
return a
597+
return none
590598

591599
@[inline]
592600
def findSome? {α : Type u} {β : Type v} (f : α → Option β) (as : Array α) : Option β :=

src/Init/Data/Array/Lemmas.lean

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,13 @@ theorem findRevM?_toArray [Monad m] [LawfulMonad m] (f : α → m Bool) (l : Lis
230230

231231
@[simp] theorem find?_toArray (f : α → Bool) (l : List α) :
232232
l.toArray.find? f = l.find? f := by
233-
rw [Array.find?, ← findM?_id, findM?_toArray, Id.run]
233+
rw [Array.find?]
234+
simp only [Id.run, Id, Id.pure_eq, Id.bind_eq, forIn_toArray]
235+
induction l with
236+
| nil => simp
237+
| cons a l ih =>
238+
simp only [forIn_cons, Id.pure_eq, Id.bind_eq, find?]
239+
by_cases f a <;> simp_all
234240

235241
theorem isPrefixOfAux_toArray_succ [BEq α] (l₁ l₂ : List α) (hle : l₁.length ≤ l₂.length) (i : Nat) :
236242
Array.isPrefixOfAux l₁.toArray l₂.toArray hle (i + 1) =
@@ -779,11 +785,26 @@ theorem getElem_set (a : Array α) (i : Nat) (h' : i < a.size) (v : α) (j : Nat
779785
else
780786
simp [setIfInBounds, h]
781787

788+
theorem getElem_setIfInBounds (a : Array α) (i : Nat) (v : α) (j : Nat)
789+
(hj : j < (setIfInBounds a i v).size) :
790+
(setIfInBounds a i v)[j]'hj = if i = j then v else a[j]'(by simpa using hj) := by
791+
simp only [setIfInBounds]
792+
split
793+
· simp [getElem_set]
794+
· simp only [size_setIfInBounds] at hj
795+
rw [if_neg]
796+
omega
797+
782798
@[simp] theorem getElem_setIfInBounds_eq (a : Array α) {i : Nat} (v : α) (h : _) :
783799
(setIfInBounds a i v)[i]'h = v := by
784800
simp at h
785801
simp only [setIfInBounds, h, ↓reduceDIte, getElem_set_eq]
786802

803+
@[simp] theorem getElem_setIfInBounds_ne (a : Array α) {i : Nat} (v : α) {j : Nat}
804+
(hj : j < (setIfInBounds a i v).size) (h : i ≠ j) :
805+
(setIfInBounds a i v)[j]'hj = a[j]'(by simpa using hj) := by
806+
simp [getElem_setIfInBounds, h]
807+
787808
@[simp]
788809
theorem getElem?_setIfInBounds_eq (a : Array α) {i : Nat} (p : i < a.size) (v : α) :
789810
(a.setIfInBounds i v)[i]? = some v := by
@@ -985,11 +1006,6 @@ theorem get_set (a : Array α) (i : Nat) (hi : i < a.size) (j : Nat) (hj : j < a
9851006
(h : i ≠ j) : (a.set i v)[j]'(by simp [*]) = a[j] := by
9861007
simp only [set, getElem_eq_getElem_toList, List.getElem_set_ne h]
9871008

988-
theorem getElem_setIfInBounds (a : Array α) (i : Nat) (v : α) (h : i < (setIfInBounds a i v).size) :
989-
(setIfInBounds a i v)[i] = v := by
990-
simp at h
991-
simp only [setIfInBounds, h, ↓reduceDIte, getElem_set_eq]
992-
9931009
theorem set_set (a : Array α) (i : Nat) (h) (v v' : α) :
9941010
(a.set i v h).set i v' (by simp [h]) = a.set i v' := by simp [set, List.set_set]
9951011

@@ -1855,8 +1871,6 @@ instance [DecidableEq α] (a : α) (as : Array α) : Decidable (a ∈ as) :=
18551871

18561872
/-! ### swap -/
18571873

1858-
open Fin
1859-
18601874
@[simp] theorem getElem_swap_right (a : Array α) {i j : Nat} {hi hj} :
18611875
(a.swap i j hi hj)[j]'(by simpa using hj) = a[i] := by
18621876
simp [swap_def, getElem_set]
@@ -1875,7 +1889,7 @@ theorem getElem_swap' (a : Array α) (i j : Nat) {hi hj} (k : Nat) (hk : k < a.s
18751889
· simp_all only [getElem_swap_left]
18761890
· split <;> simp_all
18771891

1878-
theorem getElem_swap (a : Array α) (i j : Nat) {hi hj}(k : Nat) (hk : k < (a.swap i j).size) :
1892+
theorem getElem_swap (a : Array α) (i j : Nat) {hi hj} (k : Nat) (hk : k < (a.swap i j).size) :
18791893
(a.swap i j hi hj)[k] = if k = i then a[j] else if k = j then a[i] else a[k]'(by simp_all) := by
18801894
apply getElem_swap'
18811895

@@ -1938,6 +1952,13 @@ theorem eraseIdx_eq_eraseIdxIfInBounds {a : Array α} {i : Nat} (h : i < a.size)
19381952
(as.zip bs).size = min as.size bs.size :=
19391953
as.size_zipWith bs Prod.mk
19401954

1955+
@[simp] theorem getElem_zipWith (as : Array α) (bs : Array β) (f : α → β → γ) (i : Nat)
1956+
(hi : i < (as.zipWith bs f).size) :
1957+
(as.zipWith bs f)[i] = f (as[i]'(by simp at hi; omega)) (bs[i]'(by simp at hi; omega)) := by
1958+
cases as
1959+
cases bs
1960+
simp
1961+
19411962
/-! ### findSomeM?, findM?, findSome?, find? -/
19421963

19431964
@[simp] theorem findSomeM?_toList [Monad m] [LawfulMonad m] (p : α → m (Option β)) (as : Array α) :
@@ -2238,6 +2259,11 @@ theorem foldr_map' (g : α → β) (f : α → α → α) (f' : β → β → β
22382259
cases as
22392260
simp
22402261

2262+
@[simp] theorem getElem_reverse (as : Array α) (i : Nat) (hi : i < as.reverse.size) :
2263+
(as.reverse)[i] = as[as.size - 1 - i]'(by simp at hi; omega) := by
2264+
cases as
2265+
simp [Array.getElem_reverse]
2266+
22412267
/-! ### findSomeRevM?, findRevM?, findSomeRev?, findRev? -/
22422268

22432269
@[simp] theorem findSomeRevM?_eq_findSomeM?_reverse

src/Init/Data/BitVec/Basic.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,17 @@ end relations
351351
section cast
352352

353353
/-- `cast eq x` embeds `x` into an equal `BitVec` type. -/
354-
@[inline] def cast (eq : n = m) (x : BitVec n) : BitVec m := .ofNatLt x.toNat (eq ▸ x.isLt)
354+
@[inline] protected def cast (eq : n = m) (x : BitVec n) : BitVec m := .ofNatLt x.toNat (eq ▸ x.isLt)
355355

356356
@[simp] theorem cast_ofNat {n m : Nat} (h : n = m) (x : Nat) :
357-
cast h (BitVec.ofNat n x) = BitVec.ofNat m x := by
357+
(BitVec.ofNat n x).cast h = BitVec.ofNat m x := by
358358
subst h; rfl
359359

360360
@[simp] theorem cast_cast {n m k : Nat} (h₁ : n = m) (h₂ : m = k) (x : BitVec n) :
361-
cast h₂ (cast h₁ x) = cast (h₁ ▸ h₂) x :=
361+
(x.cast h₁).cast h₂ = x.cast (h₁ ▸ h₂) :=
362362
rfl
363363

364-
@[simp] theorem cast_eq {n : Nat} (h : n = n) (x : BitVec n) : cast h x = x := rfl
364+
@[simp] theorem cast_eq {n : Nat} (h : n = n) (x : BitVec n) : x.cast h = x := rfl
365365

366366
/--
367367
Extraction of bits `start` to `start + len - 1` from a bit vector of size `n` to yield a

0 commit comments

Comments
 (0)