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

improve effects of objectid and getindex(::Dict) #49447

Merged
3 changes: 2 additions & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,12 @@ function empty!(h::Dict{K,V}) where V where K
end

# get the index where a key is stored, or -1 if not present
function ht_keyindex(h::Dict{K,V}, key) where V where K
@assume_effects :terminates_locally function ht_keyindex(h::Dict{K,V}, key) where V where K
isempty(h) && return -1
sz = length(h.keys)
iter = 0
maxprobe = h.maxprobe
@assert maxprobe <= sz # needed for terminates_locally to be valid
index, sh = hashindex(key, sz)
keys = h.keys

Expand Down
5 changes: 4 additions & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ If `x === y` then `objectid(x) == objectid(y)`, and usually when `x !== y`, `obj

See also [`hash`](@ref), [`IdDict`](@ref).
"""
objectid(@nospecialize(x)) = ccall(:jl_object_id, UInt, (Any,), x)
function objectid(@nospecialize(x))
@_foldable_meta
ccall(:jl_object_id, UInt, (Any,), x)
end

# concrete datatype predicates

Expand Down