Skip to content

Commit

Permalink
use callsite @assume_effects annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Dec 5, 2023
1 parent 2007979 commit 3fe726e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function empty!(h::Dict{K,V}) where V where K
end

# get the index where a key is stored, or -1 if not present
@assume_effects :terminates_locally function ht_keyindex(h::Dict{K,V}, key) where V where K
function ht_keyindex(h::Dict{K,V}, key) where V where K
isempty(h) && return -1
sz = length(h.keys)
iter = 0
Expand All @@ -280,9 +280,9 @@ end
index, sh = hashindex(key, sz)
keys = h.keys

@inbounds while true
@assume_effects :terminates_locally :noub @inbounds while true
isslotempty(h,index) && return -1
if h.slots[index] == sh
if sh == h.slots[index]
k = keys[index]
if (key === k || isequal(key, k))
return index
Expand All @@ -294,8 +294,6 @@ 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,10 +507,8 @@ end

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
return index < 0 ? throw(KeyError(key)) : @assume_effects :noub @inbounds 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
4 changes: 2 additions & 2 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2165,12 +2165,12 @@ for (DictT, KeyT) = Any[(Dict{Symbol,Any}, Symbol),
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)
@test Core.Compiler.is_noub(effects)
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)
@test Core.Compiler.is_noub(effects)
end
end

0 comments on commit 3fe726e

Please sign in to comment.