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

[REPLCompletions] improve REPLInterpreter effects of dict operations #52347

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[REPLCompletions] improve REPLInterpreter effects of dict operations
This should allow more completions for cases involving dict operations.
  • Loading branch information
aviatesk committed Dec 6, 2023
commit 0b0f2dbdfd2a022c62f33d366d704fea0d8404b3
4 changes: 4 additions & 0 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ end
end
# This line is unreachable
end
@assume_effects :noub ht_keyindex(h::Dict{Symbol,V}, key::Symbol) where V =
@invoke ht_keyindex(h::Dict{Symbol,V}, key::Any)

# get (index, sh) for the key
# index - where a key is stored, or -pos if not present
Expand Down Expand Up @@ -509,6 +511,8 @@ function getindex(h::Dict{K,V}, key) where V where K
index = ht_keyindex(h, key)
@inbounds return (index < 0) ? throw(KeyError(key)) : h.vals[index]::V
end
@assume_effects :noub getindex(h::Dict{Symbol,V}, key::Symbol) where V =
@invoke getindex(h::Dict{Symbol,V}, key::Any)

"""
get(collection, key, default)
Expand Down
18 changes: 18 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2156,3 +2156,21 @@ let t = REPLCompletions.repl_eval_ex(:(Base.PersistentDict(issue52099 => 3)), @_
@test length(t.val) == 1
end
end

# test REPLInterpreter effects for `getindex(::Dict, key)`
for (DictT, KeyT) = Any[(Dict{Symbol,Any}, Symbol),
(Dict{Int,Any}, Int),
(Dict{String,Any}, String)]
@testset let DictT=DictT, KeyT=KeyT
effects = Base.infer_effects(getindex, (DictT,KeyT); interp=REPL.REPLCompletions.REPLInterpreter())
@test Core.Compiler.is_effect_free(effects)
@test Core.Compiler.is_terminates(effects)
@test Core.Compiler.is_noub(effects) broken=(KeyT!==Symbol)
effects = Base.infer_effects((DictT,KeyT); interp=REPL.REPLCompletions.REPLInterpreter()) do d, key
key in keys(d)
end
@test Core.Compiler.is_effect_free(effects)
@test Core.Compiler.is_terminates(effects)
@test Core.Compiler.is_noub(effects) broken=(KeyT!==Symbol)
end
end