Skip to content

Commit

Permalink
Fix ~50 invalidations stemming from modules_to_be_loaded (#41878)
Browse files Browse the repository at this point in the history
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 <vtjnash@gmail.com>
  • Loading branch information
timholy authored Aug 18, 2021
1 parent 232ee11 commit 7a6336d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 8 additions & 6 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ function eval_user_input(@nospecialize(ast), backend::REPLBackend)
end

function check_for_missing_packages_and_run_hooks(ast)
isa(ast, Expr) || return
mods = modules_to_be_loaded(ast)
filter!(mod -> isnothing(Base.identify_package(String(mod))), mods) # keep missing modules
if !isempty(mods)
Expand All @@ -177,16 +178,18 @@ function check_for_missing_packages_and_run_hooks(ast)
end
end

function modules_to_be_loaded(ast, mods = Symbol[])
function modules_to_be_loaded(ast::Expr, mods::Vector{Symbol} = Symbol[])
ast.head == :quote && return mods # don't search if it's not going to be run during this eval
if ast.head in [:using, :import]
for arg in ast.args
if first(arg.args) isa Symbol # i.e. `Foo`
if first(arg.args) != :. # don't include local imports
push!(mods, first(arg.args))
arg = arg::Expr
arg1 = first(arg.args)
if arg1 isa Symbol # i.e. `Foo`
if arg1 != :. # don't include local imports
push!(mods, arg1)
end
else # i.e. `Foo: bar`
push!(mods, first(first(arg.args).args))
push!(mods, first((arg1::Expr).args))
end
end
end
Expand All @@ -196,7 +199,6 @@ function modules_to_be_loaded(ast, mods = Symbol[])
filter!(mod -> !in(String(mod), ["Base", "Main", "Core"]), mods) # Exclude special non-package modules
return mods
end
modules_to_be_loaded(::Nothing) = Symbol[] # comments are parsed as nothing

"""
start_repl_backend(repl_channel::Channel, response_channel::Channel)
Expand Down
2 changes: 0 additions & 2 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,6 @@ end
mods = REPL.modules_to_be_loaded(Base.parse_input_line("ex = :(using Foo)"))
@test isempty(mods)

mods = REPL.modules_to_be_loaded(Base.parse_input_line("# comment"))
@test isempty(mods)
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo"))
@test isempty(mods)
end
Expand Down

0 comments on commit 7a6336d

Please sign in to comment.