Skip to content

Commit 2defa57

Browse files
authored
Excise REPL and its dependencies from sysimg (#51399)
1 parent a127ab7 commit 2defa57

File tree

18 files changed

+349
-226
lines changed

18 files changed

+349
-226
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ stdlibs-cache-release stdlibs-cache-debug : stdlibs-cache-% : julia-%
116116

117117
debug release : % : julia-% stdlibs-cache-%
118118

119-
docs: julia-sysimg-$(JULIA_BUILD_MODE)
119+
docs: julia-sysimg-$(JULIA_BUILD_MODE) stdlibs-cache-$(JULIA_BUILD_MODE)
120120
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/doc JULIA_EXECUTABLE='$(call spawn,$(JULIA_EXECUTABLE_$(JULIA_BUILD_MODE))) --startup-file=no'
121121

122122
docs-revise:
@@ -184,7 +184,7 @@ $(build_depsbindir)/stringreplace: $(JULIAHOME)/contrib/stringreplace.c | $(buil
184184
@$(call PRINT_CC, $(HOSTCC) -o $(build_depsbindir)/stringreplace $(JULIAHOME)/contrib/stringreplace.c)
185185

186186
julia-base-cache: julia-sysimg-$(JULIA_BUILD_MODE) | $(DIRS) $(build_datarootdir)/julia
187-
@JULIA_BINDIR=$(call cygpath_w,$(build_bindir)) WINEPATH="$(call cygpath_w,$(build_bindir));$$WINEPATH" \
187+
@JULIA_BINDIR=$(call cygpath_w,$(build_bindir)) JULIA_FALLBACK_REPL=1 WINEPATH="$(call cygpath_w,$(build_bindir));$$WINEPATH" \
188188
$(call spawn, $(JULIA_EXECUTABLE) --startup-file=no $(call cygpath_w,$(JULIAHOME)/etc/write_base_cache.jl) \
189189
$(call cygpath_w,$(build_datarootdir)/julia/base.cache))
190190

base/client.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,28 @@ function load_InteractiveUtils(mod::Module=Main)
405405
return getfield(mod, :InteractiveUtils)
406406
end
407407

408+
function load_REPL()
409+
# load interactive-only libraries
410+
try
411+
return Base.require(PkgId(UUID(0x3fa0cd96_eef1_5676_8a61_b3b8758bbffb), "REPL"))
412+
catch ex
413+
@warn "Failed to import REPL" exception=(ex, catch_backtrace())
414+
end
415+
return nothing
416+
end
417+
408418
global active_repl
409419

410420
# run the requested sort of evaluation loop on stdio
411421
function run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool, color_set::Bool)
412-
load_InteractiveUtils()
413-
414-
fallback_repl = get_bool_env("JULIA_FALLBACK_REPL", false)
422+
fallback_repl = parse(Bool, get(ENV, "JULIA_FALLBACK_REPL", "false"))
423+
if !fallback_repl && interactive
424+
load_InteractiveUtils()
425+
if !isassigned(REPL_MODULE_REF)
426+
load_REPL()
427+
end
428+
end
429+
# TODO cleanup REPL_MODULE_REF
415430

416431
if !fallback_repl && interactive && isassigned(REPL_MODULE_REF)
417432
invokelatest(REPL_MODULE_REF[]) do REPL
@@ -435,8 +450,8 @@ function run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_f
435450
end
436451
else
437452
# otherwise provide a simple fallback
438-
if interactive && !quiet
439-
@warn "REPL provider not available: using basic fallback"
453+
if !fallback_repl && interactive && !quiet
454+
@warn "REPL provider not available: using basic fallback" LOAD_PATH=join(Base.LOAD_PATH, Sys.iswindows() ? ';' : ':')
440455
end
441456
banner == :no || Base.banner(short=banner==:short)
442457
let input = stdin

base/docs/Docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ function docm(source::LineNumberNode, mod::Module, ex)
535535
elseif isassigned(Base.REPL_MODULE_REF)
536536
# TODO: this is a shim to continue to allow `@doc` for looking up docstrings
537537
REPL = Base.REPL_MODULE_REF[]
538-
return REPL.lookup_doc(ex)
538+
return invokelatest(REPL.lookup_doc, ex)
539539
end
540540
return nothing
541541
end

base/loading.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,9 +1818,6 @@ function __require_prelocked(uuidkey::PkgId, env=nothing)
18181818
insert_extension_triggers(uuidkey)
18191819
# After successfully loading, notify downstream consumers
18201820
run_package_callbacks(uuidkey)
1821-
if uuidkey == REPL_PKGID
1822-
REPL_MODULE_REF[] = newm
1823-
end
18241821
else
18251822
newm = root_module(uuidkey)
18261823
end

base/sysimg.jl

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,19 @@ let
3131
# Run with the `--exclude-jlls` option to filter out all JLL packages
3232
stdlibs = [
3333
# No dependencies
34-
:ArgTools,
35-
:Artifacts,
36-
:Base64,
37-
:CRC32c,
38-
:FileWatching,
39-
:Libdl,
40-
:Logging,
41-
:Mmap,
42-
:NetworkOptions,
43-
:SHA,
44-
:Serialization,
45-
:Sockets,
46-
:Unicode,
34+
:FileWatching, # used by loading.jl -- implicit assumption that init runs
35+
:Libdl, # Transitive through LinAlg
36+
:Artifacts, # Transitive through LinAlg
37+
:SHA, # transitive through Random
38+
:Sockets, # used by stream.jl
39+
40+
# Transitive through LingAlg
41+
# OpenBLAS_jll
42+
# libblastrampoline_jll
4743

4844
# 1-depth packages
49-
:LinearAlgebra,
50-
:Markdown,
51-
:Printf,
52-
:Random,
53-
:Tar,
54-
55-
# 2-depth packages
56-
:Dates,
57-
:Future,
58-
:InteractiveUtils,
59-
:LibGit2,
60-
:UUIDs,
61-
62-
# 3-depth packages
63-
:REPL,
64-
:TOML,
65-
66-
# 4-depth packages
67-
:LibCURL,
68-
69-
# 5-depth packages
70-
:Downloads,
45+
:LinearAlgebra, # Commits type-piracy and GEMM
46+
:Random, # Can't be removed due to rand being exported by Base
7147
]
7248
# PackageCompiler can filter out stdlibs so it can be empty
7349
maxlen = maximum(textwidth.(string.(stdlibs)); init=0)

base/terminfo.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ function read(data::IO, ::Type{TermInfoRaw})
9595
throw(ArgumentError("Terminfo did not contain a null byte after the flag section, expected to position the start of the numbers section on an even byte"))
9696
end
9797
# Numbers, Strings, Table
98-
numbers = reinterpret(NumInt, read(data, numbers_count * sizeof(NumInt))) .|> ltoh
99-
string_indices = reinterpret(UInt16, read(data, string_count * sizeof(UInt16))) .|> ltoh
98+
numbers = map(ltoh, reinterpret(NumInt, read(data, numbers_count * sizeof(NumInt))))
99+
string_indices = map(ltoh, reinterpret(UInt16, read(data, string_count * sizeof(UInt16))))
100100
strings_table = read(data, table_bytes)
101101
strings = map(string_indices) do idx
102102
if idx (0xffff, 0xfffe)
@@ -107,7 +107,7 @@ function read(data::IO, ::Type{TermInfoRaw})
107107
end
108108
end
109109
TermInfoRaw(term_names, flags, numbers, strings,
110-
if !eof(data) extendedterminfo(data; NumInt) end)
110+
if !eof(data) extendedterminfo(data, NumInt) end)
111111
end
112112

113113
"""
@@ -119,7 +119,7 @@ This will accept any terminfo content that conforms with `term(5)`.
119119
120120
See also: `read(::IO, ::Type{TermInfoRaw})`
121121
"""
122-
function extendedterminfo(data::IO; NumInt::Union{Type{UInt16}, Type{UInt32}})
122+
function extendedterminfo(data::IO, NumInt::Union{Type{UInt16}, Type{UInt32}})
123123
# Extended info
124124
if position(data) % 2 != 0
125125
0x00 == read(data, UInt8) ||
@@ -138,12 +138,15 @@ function extendedterminfo(data::IO; NumInt::Union{Type{UInt16}, Type{UInt32}})
138138
throw(ArgumentError("Terminfo did not contain a null byte after the extended flag section, expected to position the start of the numbers section on an even byte"))
139139
end
140140
numbers = map(n -> Int(ltoh(n)), reinterpret(NumInt, read(data, numbers_count * sizeof(NumInt))))
141-
table_indices = reinterpret(UInt16, read(data, table_count * sizeof(UInt16))) .|> ltoh
141+
table_indices = map(ltoh, reinterpret(UInt16, read(data, table_count * sizeof(UInt16))))
142142
table_strings = [String(readuntil(data, 0x00)) for _ in 1:length(table_indices)]
143+
info = Dict{Symbol, Union{Bool, Int, String}}()
143144
strings = table_strings[1:string_count]
144-
labels = Symbol.(table_strings[string_count+1:end])
145-
Dict{Symbol, Union{Bool, Int, String}}(
146-
labels .=> vcat(flags, numbers, strings))
145+
labels = table_strings[string_count+1:end]
146+
for (label, val) in zip(labels, vcat(flags, numbers, strings))
147+
info[Symbol(label)] = val
148+
end
149+
return info
147150
end
148151

149152
"""
@@ -178,7 +181,7 @@ function TermInfo(raw::TermInfoRaw)
178181
Symbol[]
179182
end
180183
TermInfo(raw.names, length(raw.flags),
181-
raw.numbers .!= typemax(eltype(raw.numbers)),
184+
map(n-> n != typemax(typeof(n)), raw.numbers),
182185
map(!isnothing, raw.strings),
183186
extensions, capabilities)
184187
end

base/util.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,9 @@ function runtests(tests = ["all"]; ncores::Int = ceil(Int, Sys.CPU_THREADS / 2),
700700
catch
701701
buf = PipeBuffer()
702702
original_load_path = copy(Base.LOAD_PATH); empty!(Base.LOAD_PATH); pushfirst!(Base.LOAD_PATH, "@stdlib")
703-
Base.require(Base, :InteractiveUtils).versioninfo(buf)
703+
let InteractiveUtils = Base.require(Base, :InteractiveUtils)
704+
@invokelatest InteractiveUtils.versioninfo(buf)
705+
end
704706
empty!(Base.LOAD_PATH); append!(Base.LOAD_PATH, original_load_path)
705707
error("A test has failed. Please submit a bug report (https://github.com/JuliaLang/julia/issues)\n" *
706708
"including error messages above and the output of versioninfo():\n$(read(buf, String))")

0 commit comments

Comments
 (0)