From e096c21d0f3fe93944d676ecb7bbb9b39a4ceeb1 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 15 Oct 2025 21:19:13 +0200 Subject: [PATCH 1/2] Move LinearAlgebra out of the system image. Delay the loading until we start the REPL. Co-authored-by: Viral B. Shah --- base/client.jl | 16 ++++++++++++++++ base/sysimg.jl | 6 +++--- stdlib/REPL/src/REPL.jl | 3 ++- stdlib/stdlib.mk | 3 +-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/base/client.jl b/base/client.jl index 1b62f870ae1b8..dd83fb1eeab78 100644 --- a/base/client.jl +++ b/base/client.jl @@ -426,6 +426,21 @@ function load_InteractiveUtils(mod::Module=Main) return Core.eval(mod, :(using Base.MainInclude.InteractiveUtils; Base.MainInclude.InteractiveUtils)) end +function load_LinearAlgebra(mod::Module=Main) + # load LinearAlgebra stdlib + if !isdefined(MainInclude, :LinearAlgebra) + try + let LinearAlgebra = Base.require_stdlib(Base.PkgId(Base.UUID((0x37e2e46d_f89d_539d,0xb4ee_838fcccc9c8e)), "LinearAlgebra")) + MainInclude.LinearAlgebra = LinearAlgebra + end + catch ex + @warn "Failed to import LinearAlgebra into module $mod" exception=(ex, catch_backtrace()) + return nothing + end + end + return Core.eval(mod, :(using Base.MainInclude.LinearAlgebra; Base.MainInclude.LinearAlgebra)) +end + function load_REPL() # load interactive-only libraries try @@ -516,6 +531,7 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_f fallback_repl = parse(Bool, get(ENV, "JULIA_FALLBACK_REPL", "false")) if !fallback_repl && interactive load_InteractiveUtils() + load_LinearAlgebra() REPL = REPL_MODULE_REF[] if REPL === Base load_REPL() diff --git a/base/sysimg.jl b/base/sysimg.jl index fd71544c205cc..269fa06a75c47 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -84,8 +84,8 @@ let stdlibs = [ # No dependencies :FileWatching, # used by loading.jl -- implicit assumption that init runs - :Libdl, # Transitive through LinAlg - :Artifacts, # Transitive through LinAlg + :Libdl, + :Artifacts, :SHA, # transitive through Random :Sockets, # used by stream.jl @@ -94,7 +94,7 @@ let # libblastrampoline_jll # 1-depth packages - :LinearAlgebra, # Commits type-piracy and GEMM + # :LinearAlgebra, # Commits type-piracy and GEMM :Random, # Can't be removed due to rand being exported by Base ] end diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index f1f23ab1c382d..397d8de82a916 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -820,11 +820,12 @@ setmodifiers!(c::REPLCompletionProvider, m::LineEdit.Modifiers) = c.modifiers = Set `mod` as the default contextual module in the REPL, both for evaluating expressions and printing them. """ -function activate(mod::Module=Main; interactive_utils::Bool=true) +function activate(mod::Module=Main; interactive_utils::Bool=true, linearalgebra::Bool=true) mistate = (Base.active_repl::LineEditREPL).mistate mistate === nothing && return nothing mistate.active_module = mod interactive_utils && Base.load_InteractiveUtils(mod) + linearalgebra && Base.load_LinearAlgebra(mod) return nothing end diff --git a/stdlib/stdlib.mk b/stdlib/stdlib.mk index 3184ac9c3305f..762f156dad707 100644 --- a/stdlib/stdlib.mk +++ b/stdlib/stdlib.mk @@ -1,6 +1,5 @@ STDLIBS_WITHIN_SYSIMG := \ - Artifacts FileWatching Libdl SHA libblastrampoline_jll OpenBLAS_jll Random \ - LinearAlgebra Sockets + Artifacts FileWatching Libdl SHA Random Sockets INDEPENDENT_STDLIBS := \ ArgTools Base64 CRC32c Dates DelimitedFiles Distributed Downloads Future \ From b4c24481b10e0b05e718bd3ac3fd8d771a950061 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 16 Oct 2025 11:36:16 -0400 Subject: [PATCH 2/2] Update base/client.jl Co-authored-by: Jameson Nash --- base/client.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/client.jl b/base/client.jl index dd83fb1eeab78..eeb3128ea224f 100644 --- a/base/client.jl +++ b/base/client.jl @@ -438,7 +438,8 @@ function load_LinearAlgebra(mod::Module=Main) return nothing end end - return Core.eval(mod, :(using Base.MainInclude.LinearAlgebra; Base.MainInclude.LinearAlgebra)) + Core._using(mod, MainInclude.LinearAlgebra) + return MainInclude.LinearAlgebra end function load_REPL()