Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ~50 invalidations stemming from modules_to_be_loaded #41878

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
simeonschaub marked this conversation as resolved.
Show resolved Hide resolved
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