Skip to content

Commit 3318eeb

Browse files
committed
Fix ~50 invalidations stemming from modules_to_be_loaded
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]>
1 parent a03392a commit 3318eeb

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
@@ -168,6 +168,7 @@ function eval_user_input(@nospecialize(ast), backend::REPLBackend)
168168
end
169169

170170
function check_for_missing_packages_and_run_hooks(ast)
171+
isa(ast, Expr) || return
171172
mods = modules_to_be_loaded(ast)
172173
filter!(mod -> isnothing(Base.identify_package(String(mod))), mods) # keep missing modules
173174
if !isempty(mods)
@@ -177,16 +178,18 @@ function check_for_missing_packages_and_run_hooks(ast)
177178
end
178179
end
179180

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

201203
"""
202204
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)