JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.54k stars 5.47k forks source link

`Base.active_module()` design is very badly broken on master #54888

Closed vtjnash closed 1 month ago

vtjnash commented 3 months ago

In addition to existing milestone-blocking issues with Base.active_module function being broken and thread-unsafe, it can also outright crash the session if it gets into a slightly bad state:

[ Info: Precompiling REPLExt [e5eb5ef1-03cf-53a7-ae1d-5a66b08e832b] 
ERROR: TypeError: 
Stacktrace:
  [1] active_module()
    @ REPL ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:630
  [2] #invokelatest#2
    @ ./essentials.jl:1045 [inlined]
  [3] invokelatest
    @ ./essentials.jl:1042 [inlined]
  [4] active_module
    @ ./show.jl:519 [inlined]
  [5] 
SYSTEM (REPL): showing an error caused an error
ERROR: TypeError: 
Stacktrace:
  [1] active_module()
    @ REPL ~/julia/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:630
  [2] #invokelatest#2
    @ ./essentials.jl:1045 [inlined]
  [3] invokelatest
    @ ./essentials.jl:1042 [inlined]
  [4] active_module
    @ ./show.jl:519 [inlined]
  [5] 
SYSTEM (REPL): caught exception of type TypeError while trying to handle a nested exception; giving up

julia> Base.active_module()

SYSTEM: caught exception of type :TypeError while trying to print a failed Task notice; giving up
ERROR: TaskFailedException
Stacktrace:
  [1] fatal: error thrown and no exception handler available.
TypeError(func=:typeassert, context="", expected=REPL.AbstractREPL, got=REPL.LineEditREPL(t=REPL.Terminals.TTYTerminal(term_type="xterm-256color", in_stream=Base.TTY(handle=0x000000012ef05da0, status=3, buffer=Base.GenericIOBuffer{Memory{UInt8}}(data=Memory{UInt8}(65536, 0x120600048)[0x28, 0x5b, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00
# this keeps printing until the terminal crashes
KristofferC commented 3 months ago

The assumptions for how the loading system now works with the new "upgradable stdlib" stuff is only known by one person now I think so I assign this to that one person heh.

nsajko commented 2 months ago

On NixOS, but not (?) on Arch, this affects v1.11, not just nightly: #55309

KristofferC commented 2 months ago

AFAIU, the issue is that we have two REPL modules loaded and Base.active_repl will be a different type of REPL than what is type asserted at https://github.com/JuliaLang/julia/blob/125bac4b9022ad9ff9c355e4810f94512739bac6/stdlib/REPL/src/REPL.jl#L764.

Basically, there is a mismatch between Base.active_repl and Base.REPL_MODULE_REF[]?