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 logic for setting interpreted submodules #67

Merged
merged 1 commit into from
Aug 22, 2022
Merged
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
58 changes: 34 additions & 24 deletions src/debugger_requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ function set_compiled_functions_modules!(items::Vector{String})

@debug "setting as compiled" items = items

remove_later_modules = Set(Module[])
# sort inputs once so that removed items are at the end
sort!(items, lt = function (a, b)
am = startswith(a, '-')
bm = startswith(b, '-')

return am == bm ? isless(a, b) : bm
end)

# user wants these compiled:
for acc in items
Expand All @@ -133,7 +139,7 @@ function set_compiled_functions_modules!(items::Vector{String})
if mod != Main
@debug "setting $mod and submodules as compiled via ALL_MODULES_EXCEPT_MAIN"
push!(JuliaInterpreter.compiled_modules, mod)
compile_mode_for_all_submodules(mod, Set([Main]))
toggle_mode_for_all_submodules(mod, true, Set([Main]))
end
end
push!(unset, acc)
Expand All @@ -159,36 +165,36 @@ function set_compiled_functions_modules!(items::Vector{String})
for m in methods(Base.unwrap_unionall(obj))
push!(JuliaInterpreter.interpreted_methods, m)
end
continue
catch err
@warn "Setting $obj as an interpreted method failed."
end
elseif obj isa Module
push!(remove_later_modules, obj)
# need to push this into unset because of ALL_MODULES_EXCEPT_MAIN
delete!(JuliaInterpreter.compiled_modules, obj)
if all_submodules
toggle_mode_for_all_submodules(obj, false)
end
# need to push these into unset because of ALL_MODULES_EXCEPT_MAIN
# being re-applied every time
push!(unset, oacc)
end
end

if obj isa Module
push!(JuliaInterpreter.compiled_modules, obj)
if all_submodules
compile_mode_for_all_submodules(obj)
end
elseif obj isa Base.Callable
for m in methods(Base.unwrap_unionall(obj))
push!(JuliaInterpreter.compiled_methods, m)
else
if obj isa Base.Callable
try
for m in methods(Base.unwrap_unionall(obj))
push!(JuliaInterpreter.compiled_methods, m)
end
catch err
@warn "Setting $obj as an interpreted method failed."
end
elseif obj isa Module
push!(JuliaInterpreter.compiled_modules, obj)
if all_submodules
toggle_mode_for_all_submodules(obj, true)
end
end
end
end

@debug "remove_later_modules:"
for mod in remove_later_modules
@debug "deleting $mod from compiled_modules"
delete!(JuliaInterpreter.compiled_modules, mod)
end

@debug "remaining items" unset = unset
return unset
end
Expand All @@ -200,14 +206,18 @@ function set_compiled_functions_modules!(params)
return []
end

function compile_mode_for_all_submodules(mod, seen = Set())
function toggle_mode_for_all_submodules(mod, compiled, seen = Set())
for name in names(mod; all = true)
if isdefined(mod, name)
obj = getfield(mod, name)
if obj !== mod && obj isa Module && !(obj in seen)
push!(seen, obj)
push!(JuliaInterpreter.compiled_modules, obj)
compile_mode_for_all_submodules(obj, seen)
if compiled
push!(JuliaInterpreter.compiled_modules, obj)
else
delete!(JuliaInterpreter.compiled_modules, obj)
end
toggle_mode_for_all_submodules(obj, compiled, seen)
end
end
end
Expand Down