Skip to content

Commit

Permalink
[REPLCompletions] support method invalidation (#52448)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Dec 9, 2023
1 parent 551b37a commit 649982a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ CC.code_cache(interp::REPLInterpreter) = CC.WorldView(interp.code_cache, CC.Worl
CC.get(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance, default) = get(wvc.cache.dict, mi, default)
CC.getindex(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance) = getindex(wvc.cache.dict, mi)
CC.haskey(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance) = haskey(wvc.cache.dict, mi)
CC.setindex!(wvc::CC.WorldView{REPLInterpreterCache}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.dict, ci, mi)
function CC.setindex!(wvc::CC.WorldView{REPLInterpreterCache}, ci::CodeInstance, mi::MethodInstance)
CC.add_invalidation_callback!(mi) do replaced::MethodInstance, max_world::UInt32
delete!(wvc.cache.dict, replaced)
end
return setindex!(wvc.cache.dict, ci, mi)
end

# REPLInterpreter is only used for type analysis, so it should disable optimization entirely
CC.may_optimize(::REPLInterpreter) = false
Expand Down
7 changes: 7 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2174,3 +2174,10 @@ for (DictT, KeyT) = Any[(Dict{Symbol,Any}, Symbol),
@test Core.Compiler.is_noub(effects)
end
end

# test invalidation support
replinterp_invalidation_callee(c::Bool=rand(Bool)) = Some(c ? r"foo" : r"bar")
replinterp_invalidation_caller() = replinterp_invalidation_callee().value
@test REPLCompletions.repl_eval_ex(:(replinterp_invalidation_caller()), @__MODULE__) == Regex
replinterp_invalidation_callee(c::Bool=rand(Bool)) = Some(c ? "foo" : "bar")
@test REPLCompletions.repl_eval_ex(:(replinterp_invalidation_caller()), @__MODULE__) == String

0 comments on commit 649982a

Please sign in to comment.