Skip to content

Commit 816c5a7

Browse files
authored
Merge branch 'leanprover:master' into master
2 parents e672572 + f31d4dc commit 816c5a7

File tree

1,029 files changed

+276482
-219823
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,029 files changed

+276482
-219823
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ jobs:
467467
with:
468468
files: artifacts/*/*
469469
fail_on_unmatched_files: true
470+
prerelease: ${{ !startsWith(github.ref, 'refs/tags/v') || contains(github.ref, '-rc') }}
470471
env:
471472
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
472473

flake.nix

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,28 @@
3535
lean-packages = pkgs.callPackage (./nix/packages.nix) { src = ./.; inherit nix lean4-mode; };
3636

3737
devShellWithDist = pkgsDist: pkgs.mkShell.override {
38-
stdenv = pkgs.overrideCC pkgs.stdenv lean-packages.llvmPackages.clang;
39-
} ({
40-
buildInputs = with pkgs; [
41-
cmake gmp ccache
42-
lean-packages.llvmPackages.llvm # llvm-symbolizer for asan/lsan
43-
# TODO: only add when proven to not affect the flakification
44-
#pkgs.python3
45-
tree # for CI
46-
];
47-
# https://github.com/NixOS/nixpkgs/issues/60919
48-
hardeningDisable = [ "all" ];
49-
# more convenient `ctest` output
50-
CTEST_OUTPUT_ON_FAILURE = 1;
51-
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
52-
GMP = pkgsDist.gmp.override { withStatic = true; };
53-
GLIBC = pkgsDist.glibc;
54-
GLIBC_DEV = pkgsDist.glibc.dev;
55-
GCC_LIB = pkgsDist.gcc.cc.lib;
56-
ZLIB = pkgsDist.zlib;
57-
GDB = pkgsDist.gdb;
58-
});
38+
stdenv = pkgs.overrideCC pkgs.stdenv lean-packages.llvmPackages.clang;
39+
} ({
40+
buildInputs = with pkgs; [
41+
cmake gmp ccache
42+
lean-packages.llvmPackages.llvm # llvm-symbolizer for asan/lsan
43+
gdb
44+
# TODO: only add when proven to not affect the flakification
45+
#pkgs.python3
46+
tree # for CI
47+
];
48+
# https://github.com/NixOS/nixpkgs/issues/60919
49+
hardeningDisable = [ "all" ];
50+
# more convenient `ctest` output
51+
CTEST_OUTPUT_ON_FAILURE = 1;
52+
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
53+
GMP = pkgsDist.gmp.override { withStatic = true; };
54+
GLIBC = pkgsDist.glibc;
55+
GLIBC_DEV = pkgsDist.glibc.dev;
56+
GCC_LIB = pkgsDist.gcc.cc.lib;
57+
ZLIB = pkgsDist.zlib;
58+
GDB = pkgsDist.gdb;
59+
});
5960
in {
6061
packages = lean-packages // rec {
6162
debug = lean-packages.override { debug = true; };

nix/bootstrap.nix

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@ rec {
8787
leanFlags = [ "-DwarningAsError=true" ];
8888
} // args);
8989
Init' = build { name = "Init"; deps = []; };
90-
Lean' = build { name = "Lean"; deps = [ Init' ]; };
90+
Std' = build { name = "Std"; deps = [ Init' ]; };
91+
Lean' = build { name = "Lean"; deps = [ Std' ]; };
9192
attachSharedLib = sharedLib: pkg: pkg // {
9293
inherit sharedLib;
9394
mods = mapAttrs (_: m: m // { inherit sharedLib; propagatedLoadDynlibs = []; }) pkg.mods;
9495
};
9596
in (all: all // all.lean) rec {
9697
inherit (Lean) emacs-dev emacs-package vscode-dev vscode-package;
9798
Init = attachSharedLib leanshared Init';
98-
Lean = attachSharedLib leanshared Lean' // { allExternalDeps = [ Init ]; };
99+
Std = attachSharedLib leanshared Std' // { allExternalDeps = [ Init ]; };
100+
Lean = attachSharedLib leanshared Lean' // { allExternalDeps = [ Std ]; };
99101
Lake = build {
100102
name = "Lake";
101103
src = src + "/src/lake";
@@ -109,23 +111,24 @@ rec {
109111
linkFlags = lib.optional stdenv.isLinux "-rdynamic";
110112
src = src + "/src/lake";
111113
};
112-
stdlib = [ Init Lean Lake ];
114+
stdlib = [ Init Std Lean Lake ];
113115
modDepsFiles = symlinkJoin { name = "modDepsFiles"; paths = map (l: l.modDepsFile) (stdlib ++ [ Leanc ]); };
114116
depRoots = symlinkJoin { name = "depRoots"; paths = map (l: l.depRoots) stdlib; };
115117
iTree = symlinkJoin { name = "ileans"; paths = map (l: l.iTree) stdlib; };
116118
Leanc = build { name = "Leanc"; src = lean-bin-tools-unwrapped.leanc_src; deps = stdlib; roots = [ "Leanc" ]; };
117-
stdlibLinkFlags = "-L${Init.staticLib} -L${Lean.staticLib} -L${Lake.staticLib} -L${leancpp}/lib/lean";
119+
stdlibLinkFlags = "${lib.concatMapStringsSep " " (l: "-L${l.staticLib}") stdlib} -L${leancpp}/lib/lean";
118120
libInit_shared = runCommand "libInit_shared" { buildInputs = [ stdenv.cc ]; libName = "libInit_shared${stdenv.hostPlatform.extensions.sharedLibrary}"; } ''
119121
mkdir $out
120-
LEAN_CC=${stdenv.cc}/bin/cc ${lean-bin-tools-unwrapped}/bin/leanc -shared -Wl,-Bsymbolic \
121-
-Wl,--whole-archive -lInit ${leancpp}/lib/libleanrt_initial-exec.a -Wl,--no-whole-archive -lstdc++ -lm ${stdlibLinkFlags} \
122-
$(${llvmPackages.libllvm.dev}/bin/llvm-config --ldflags --libs) \
123-
-o $out/$libName
122+
touch empty.c
123+
${stdenv.cc}/bin/cc -shared -o $out/$libName empty.c
124124
'';
125125
leanshared = runCommand "leanshared" { buildInputs = [ stdenv.cc ]; libName = "libleanshared${stdenv.hostPlatform.extensions.sharedLibrary}"; } ''
126126
mkdir $out
127-
LEAN_CC=${stdenv.cc}/bin/cc ${lean-bin-tools-unwrapped}/bin/leanc -shared -Wl,-Bsymbolic \
128-
${libInit_shared}/* -Wl,--whole-archive -lLean -lleancpp -Wl,--no-whole-archive -lstdc++ -lm ${stdlibLinkFlags} \
127+
LEAN_CC=${stdenv.cc}/bin/cc ${lean-bin-tools-unwrapped}/bin/leanc -shared ${lib.optionalString stdenv.isLinux "-Wl,-Bsymbolic"} \
128+
${if stdenv.isDarwin
129+
then "-Wl,-force_load,${Init.staticLib}/libInit.a -Wl,-force_load,${Std.staticLib}/libStd.a -Wl,-force_load,${Lean.staticLib}/libLean.a -Wl,-force_load,${leancpp}/lib/lean/libleancpp.a ${leancpp}/lib/libleanrt_initial-exec.a -lc++"
130+
else "-Wl,--whole-archive -lInit -lStd -lLean -lleancpp ${leancpp}/lib/libleanrt_initial-exec.a -Wl,--no-whole-archive -lstdc++"} \
131+
-lm ${stdlibLinkFlags} \
129132
$(${llvmPackages.libllvm.dev}/bin/llvm-config --ldflags --libs) \
130133
-o $out/$libName
131134
'';
@@ -151,11 +154,9 @@ rec {
151154
'';
152155
meta.mainProgram = "lean";
153156
};
154-
cacheRoots = linkFarmFromDrvs "cacheRoots" [
157+
cacheRoots = linkFarmFromDrvs "cacheRoots" ([
155158
stage0 lean leanc lean-all iTree modDepsFiles depRoots Leanc.src
156-
# .o files are not a runtime dependency on macOS because of lack of thin archives
157-
Lean.oTree Lake.oTree
158-
];
159+
] ++ map (lib: lib.oTree) stdlib);
159160
test = buildCMake {
160161
name = "lean-test-${desc}";
161162
realSrc = lib.sourceByRegex src [ "src.*" "tests.*" ];
@@ -178,7 +179,7 @@ rec {
178179
'';
179180
};
180181
update-stage0 =
181-
let cTree = symlinkJoin { name = "cs"; paths = [ Init.cTree Lean.cTree Lake.cTree ]; }; in
182+
let cTree = symlinkJoin { name = "cs"; paths = map (lib: lib.cTree) stdlib; }; in
182183
writeShellScriptBin "update-stage0" ''
183184
CSRCS=${cTree} CP_C_PARAMS="--dereference --no-preserve=all" ${src + "/script/lib/update-stage0"}
184185
'';

nix/buildLeanPackage.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let lean-final' = lean-final; in
55
lib.makeOverridable (
66
{ name, src, fullSrc ? src, srcPrefix ? "", srcPath ? "$PWD/${srcPrefix}",
77
# Lean dependencies. Each entry should be an output of buildLeanPackage.
8-
deps ? [ lean.Lean ],
8+
deps ? [ lean.Init lean.Std lean.Lean ],
99
# Static library dependencies. Each derivation `static` should contain a static library in the directory `${static}`.
1010
staticLibDeps ? [],
1111
# Whether to wrap static library inputs in a -Wl,--start-group [...] -Wl,--end-group to ensure dependencies are resolved.
@@ -224,7 +224,8 @@ with builtins; let
224224
allLinkFlags = lib.foldr (shared: acc: acc ++ [ "-L${shared}" "-l${shared.linkName or shared.name}" ]) linkFlags allNativeSharedLibs;
225225

226226
objects = mapAttrs (_: m: m.obj) mods';
227-
staticLib = runCommand "${name}-lib" { buildInputs = [ stdenv.cc.bintools.bintools ]; } ''
227+
bintools = if stdenv.isDarwin then darwin.cctools else stdenv.cc.bintools.bintools;
228+
staticLib = runCommand "${name}-lib" { buildInputs = [ bintools ]; } ''
228229
mkdir -p $out
229230
ar Trcs $out/lib${libName}.a ${lib.concatStringsSep " " (map (drv: "${drv}/${drv.oPath}") (attrValues objects))};
230231
'';
@@ -249,7 +250,7 @@ in rec {
249250
${if stdenv.isDarwin then "-Wl,-force_load,${staticLib}/lib${libName}.a" else "-Wl,--whole-archive ${staticLib}/lib${libName}.a -Wl,--no-whole-archive"} \
250251
${lib.concatStringsSep " " (map (d: "${d.sharedLib}/*") deps)}'';
251252
executable = lib.makeOverridable ({ withSharedStdlib ? true }: let
252-
objPaths = map (drv: "${drv}/${drv.oPath}") (attrValues objects) ++ lib.optional withSharedStdlib "${lean-final.libInit_shared}/* ${lean-final.leanshared}/*";
253+
objPaths = map (drv: "${drv}/${drv.oPath}") (attrValues objects) ++ lib.optional withSharedStdlib "${lean-final.leanshared}/*";
253254
in runCommand executableName { buildInputs = [ stdenv.cc leanc ]; } ''
254255
mkdir -p $out/bin
255256
leanc ${staticLibLinkWrapper (lib.concatStringsSep " " (objPaths ++ map (d: "${d}/*.a") allStaticLibDeps))} \

src/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
313313
set(LEAN_CXX_STDLIB "-lc++")
314314
endif()
315315

316-
string(APPEND TOOLCHAIN_STATIC_LINKER_FLAGS " ${LEAN_CXX_STDLIB}")
316+
string(APPEND TOOLCHAIN_STATIC_LINKER_FLAGS " ${LEAN_CXX_STDLIB} -lStd")
317317
string(APPEND TOOLCHAIN_SHARED_LINKER_FLAGS " ${LEAN_CXX_STDLIB}")
318318

319319
# in local builds, link executables and not just dynlibs against C++ stdlib as well,
@@ -514,11 +514,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
514514
endif()
515515

516516
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
517-
set(LEANSHARED_LINKER_FLAGS "-Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libInit.a -Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libLean.a -Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libleancpp.a ${CMAKE_BINARY_DIR}/runtime/libleanrt_initial-exec.a ${LEANSHARED_LINKER_FLAGS}")
517+
set(LEANSHARED_LINKER_FLAGS "-Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libInit.a -Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libStd.a -Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libLean.a -Wl,-force_load,${CMAKE_BINARY_DIR}/lib/lean/libleancpp.a ${CMAKE_BINARY_DIR}/runtime/libleanrt_initial-exec.a ${LEANSHARED_LINKER_FLAGS}")
518518
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
519-
set(LEANSHARED_LINKER_FLAGS "-Wl,--whole-archive ${CMAKE_BINARY_DIR}/lib/temp/libLean.a.export -lleancpp -Wl,--no-whole-archive -lInit_shared -Wl,--out-implib,${CMAKE_BINARY_DIR}/lib/lean/libleanshared.dll.a")
519+
set(LEANSHARED_LINKER_FLAGS "-Wl,--whole-archive ${CMAKE_BINARY_DIR}/lib/temp/libStd.a.export ${CMAKE_BINARY_DIR}/lib/temp/libLean.a.export -lleancpp -Wl,--no-whole-archive -lInit_shared -Wl,--out-implib,${CMAKE_BINARY_DIR}/lib/lean/libleanshared.dll.a")
520520
else()
521-
set(LEANSHARED_LINKER_FLAGS "-Wl,--whole-archive -lInit -lLean -lleancpp -Wl,--no-whole-archive ${CMAKE_BINARY_DIR}/runtime/libleanrt_initial-exec.a ${LEANSHARED_LINKER_FLAGS}")
521+
set(LEANSHARED_LINKER_FLAGS "-Wl,--whole-archive -lInit -lStd -lLean -lleancpp -Wl,--no-whole-archive ${CMAKE_BINARY_DIR}/runtime/libleanrt_initial-exec.a ${LEANSHARED_LINKER_FLAGS}")
522522
endif()
523523

524524
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
@@ -540,7 +540,7 @@ add_custom_target(make_stdlib ALL
540540
# The actual rule is in a separate makefile because we want to prefix it with '+' to use the Make job server
541541
# for a parallelized nested build, but CMake doesn't let us do that.
542542
# We use `lean` from the previous stage, but `leanc`, headers, etc. from the current stage
543-
COMMAND $(MAKE) -f ${CMAKE_BINARY_DIR}/stdlib.make Init Lean
543+
COMMAND $(MAKE) -f ${CMAKE_BINARY_DIR}/stdlib.make Init Std Lean
544544
VERBATIM)
545545

546546
# if we have LLVM enabled, then build `lean.h.bc` which has the LLVM bitcode

src/Init/Control/Except.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected def adapt {ε' α : Type u} (f : ε → ε') : ExceptT ε m α → Exc
131131
end ExceptT
132132

133133
@[always_inline]
134-
instance (m : Type u → Type v) (ε₁ : Type u) (ε₂ : Type u) [Monad m] [MonadExceptOf ε₁ m] : MonadExceptOf ε₁ (ExceptT ε₂ m) where
134+
instance (m : Type u → Type v) (ε₁ : Type u) (ε₂ : Type u) [MonadExceptOf ε₁ m] : MonadExceptOf ε₁ (ExceptT ε₂ m) where
135135
throw e := ExceptT.mk <| throwThe ε₁ e
136136
tryCatch x handle := ExceptT.mk <| tryCatchThe ε₁ x handle
137137

src/Init/Control/Lawful/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Init.Meta
99

1010
open Function
1111

12-
@[simp] theorem monadLift_self [Monad m] (x : m α) : monadLift x = x :=
12+
@[simp] theorem monadLift_self {m : Type u → Type v} (x : m α) : monadLift x = x :=
1313
rfl
1414

1515
/--

src/Init/Control/Lawful/Instances.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open Function
1414

1515
namespace ExceptT
1616

17-
theorem ext [Monad m] {x y : ExceptT ε m α} (h : x.run = y.run) : x = y := by
17+
theorem ext {x y : ExceptT ε m α} (h : x.run = y.run) : x = y := by
1818
simp [run] at h
1919
assumption
2020

@@ -50,7 +50,7 @@ theorem run_bind [Monad m] (x : ExceptT ε m α)
5050
protected theorem seq_eq {α β ε : Type u} [Monad m] (mf : ExceptT ε m (α → β)) (x : ExceptT ε m α) : mf <*> x = mf >>= fun f => f <$> x :=
5151
rfl
5252

53-
protected theorem bind_pure_comp [Monad m] [LawfulMonad m] (f : α → β) (x : ExceptT ε m α) : x >>= pure ∘ f = f <$> x := by
53+
protected theorem bind_pure_comp [Monad m] (f : α → β) (x : ExceptT ε m α) : x >>= pure ∘ f = f <$> x := by
5454
intros; rfl
5555

5656
protected theorem seqLeft_eq {α β ε : Type u} {m : Type u → Type v} [Monad m] [LawfulMonad m] (x : ExceptT ε m α) (y : ExceptT ε m β) : x <* y = const β <$> x <*> y := by
@@ -200,11 +200,11 @@ theorem ext {x y : StateT σ m α} (h : ∀ s, x.run s = y.run s) : x = y :=
200200
show (f >>= fun g => g <$> x).run s = _
201201
simp
202202

203-
@[simp] theorem run_seqRight [Monad m] [LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) : (x *> y).run s = (x.run s >>= fun p => y.run p.2) := by
203+
@[simp] theorem run_seqRight [Monad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) : (x *> y).run s = (x.run s >>= fun p => y.run p.2) := by
204204
show (x >>= fun _ => y).run s = _
205205
simp
206206

207-
@[simp] theorem run_seqLeft {α β σ : Type u} [Monad m] [LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) : (x <* y).run s = (x.run s >>= fun p => y.run p.2 >>= fun p' => pure (p.1, p'.2)) := by
207+
@[simp] theorem run_seqLeft {α β σ : Type u} [Monad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) : (x <* y).run s = (x.run s >>= fun p => y.run p.2 >>= fun p' => pure (p.1, p'.2)) := by
208208
show (x >>= fun a => y >>= fun _ => pure a).run s = _
209209
simp
210210

src/Init/Control/Option.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ instance : MonadExceptOf Unit (OptionT m) where
6767
throw := fun _ => OptionT.fail
6868
tryCatch := OptionT.tryCatch
6969

70-
instance (ε : Type u) [Monad m] [MonadExceptOf ε m] : MonadExceptOf ε (OptionT m) where
70+
instance (ε : Type u) [MonadExceptOf ε m] : MonadExceptOf ε (OptionT m) where
7171
throw e := OptionT.mk <| throwThe ε e
7272
tryCatch x handle := OptionT.mk <| tryCatchThe ε x handle
7373

src/Init/Control/Reader.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ instance : MonadControl m (ReaderT ρ m) where
3232
restoreM x _ := x
3333

3434
@[always_inline]
35-
instance ReaderT.tryFinally [MonadFinally m] [Monad m] : MonadFinally (ReaderT ρ m) where
35+
instance ReaderT.tryFinally [MonadFinally m] : MonadFinally (ReaderT ρ m) where
3636
tryFinally' x h ctx := tryFinally' (x ctx) (fun a? => h a? ctx)
3737

3838
@[reducible] def ReaderM (ρ : Type u) := ReaderT ρ Id

0 commit comments

Comments
 (0)