Skip to content

Commit 83bf082

Browse files
timholyKristofferC
authored andcommitted
Fix ~50 invalidations stemming from modules_to_be_loaded (#41878)
ChainRulesCore defines `==(a, b::AbstractThunk)` and its converse, and these end up invaliding parts of the REPL (including `eval_user_input`) via inference failures in `modules_to_be_loaded`. Co-authored by: Jameson Nash <[email protected]> (cherry picked from commit 7a6336d)
1 parent cd1945c commit 83bf082

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

stdlib/REPL/src/REPL.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ function eval_user_input(@nospecialize(ast), backend::REPLBackend)
167167
end
168168

169169
function check_for_missing_packages_and_run_hooks(ast)
170+
isa(ast, Expr) || return
170171
mods = modules_to_be_loaded(ast)
171172
filter!(mod -> isnothing(Base.identify_package(String(mod))), mods) # keep missing modules
172173
if !isempty(mods)
@@ -176,16 +177,18 @@ function check_for_missing_packages_and_run_hooks(ast)
176177
end
177178
end
178179

179-
function modules_to_be_loaded(ast, mods = Symbol[])
180+
function modules_to_be_loaded(ast::Expr, mods::Vector{Symbol} = Symbol[])
180181
ast.head == :quote && return mods # don't search if it's not going to be run during this eval
181182
if ast.head in [:using, :import]
182183
for arg in ast.args
183-
if first(arg.args) isa Symbol # i.e. `Foo`
184-
if first(arg.args) != :. # don't include local imports
185-
push!(mods, first(arg.args))
184+
arg = arg::Expr
185+
arg1 = first(arg.args)
186+
if arg1 isa Symbol # i.e. `Foo`
187+
if arg1 != :. # don't include local imports
188+
push!(mods, arg1)
186189
end
187190
else # i.e. `Foo: bar`
188-
push!(mods, first(first(arg.args).args))
191+
push!(mods, first((arg1::Expr).args))
189192
end
190193
end
191194
end
@@ -195,7 +198,6 @@ function modules_to_be_loaded(ast, mods = Symbol[])
195198
filter!(mod -> !in(String(mod), ["Base", "Main", "Core"]), mods) # Exclude special non-package modules
196199
return mods
197200
end
198-
modules_to_be_loaded(::Nothing) = Symbol[] # comments are parsed as nothing
199201

200202
"""
201203
start_repl_backend(repl_channel::Channel, response_channel::Channel)

stdlib/REPL/test/repl.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,6 @@ end
13601360
mods = REPL.modules_to_be_loaded(Base.parse_input_line("ex = :(using Foo)"))
13611361
@test isempty(mods)
13621362

1363-
mods = REPL.modules_to_be_loaded(Base.parse_input_line("# comment"))
1364-
@test isempty(mods)
13651363
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo"))
13661364
@test isempty(mods)
13671365
end

0 commit comments

Comments
 (0)