Skip to content

Commit 649982a

Browse files
authored
[REPLCompletions] support method invalidation (#52448)
1 parent 551b37a commit 649982a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,12 @@ CC.code_cache(interp::REPLInterpreter) = CC.WorldView(interp.code_cache, CC.Worl
521521
CC.get(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance, default) = get(wvc.cache.dict, mi, default)
522522
CC.getindex(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance) = getindex(wvc.cache.dict, mi)
523523
CC.haskey(wvc::CC.WorldView{REPLInterpreterCache}, mi::MethodInstance) = haskey(wvc.cache.dict, mi)
524-
CC.setindex!(wvc::CC.WorldView{REPLInterpreterCache}, ci::CodeInstance, mi::MethodInstance) = setindex!(wvc.cache.dict, ci, mi)
524+
function CC.setindex!(wvc::CC.WorldView{REPLInterpreterCache}, ci::CodeInstance, mi::MethodInstance)
525+
CC.add_invalidation_callback!(mi) do replaced::MethodInstance, max_world::UInt32
526+
delete!(wvc.cache.dict, replaced)
527+
end
528+
return setindex!(wvc.cache.dict, ci, mi)
529+
end
525530

526531
# REPLInterpreter is only used for type analysis, so it should disable optimization entirely
527532
CC.may_optimize(::REPLInterpreter) = false

stdlib/REPL/test/replcompletions.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,3 +2174,10 @@ for (DictT, KeyT) = Any[(Dict{Symbol,Any}, Symbol),
21742174
@test Core.Compiler.is_noub(effects)
21752175
end
21762176
end
2177+
2178+
# test invalidation support
2179+
replinterp_invalidation_callee(c::Bool=rand(Bool)) = Some(c ? r"foo" : r"bar")
2180+
replinterp_invalidation_caller() = replinterp_invalidation_callee().value
2181+
@test REPLCompletions.repl_eval_ex(:(replinterp_invalidation_caller()), @__MODULE__) == Regex
2182+
replinterp_invalidation_callee(c::Bool=rand(Bool)) = Some(c ? "foo" : "bar")
2183+
@test REPLCompletions.repl_eval_ex(:(replinterp_invalidation_caller()), @__MODULE__) == String

0 commit comments

Comments
 (0)