Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
56 changes: 32 additions & 24 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2403,11 +2403,8 @@ const _ARGMEM_BUILTINS = Any[
]

const _INCONSISTENT_INTRINSICS = Any[
Intrinsics.pointerref, # this one is volatile
Intrinsics.sqrt_llvm_fast, # this one may differ at runtime (by a few ulps)
Intrinsics.have_fma, # this one depends on the runtime environment
Intrinsics.cglobal, # cglobal lookup answer changes at runtime
# ... and list fastmath intrinsics:
# all is_pure_intrinsic_infer plus
# ... all the unsound fastmath functions which should have been in is_pure_intrinsic_infer
# join(string.("Intrinsics.", sort(filter(endswith("_fast")∘string, names(Core.Intrinsics)))), ",\n")
Intrinsics.add_float_fast,
Intrinsics.div_float_fast,
Expand Down Expand Up @@ -2892,37 +2889,48 @@ function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Vector{Any})
return intrinsic_exct(SimpleInferenceLattice.instance, f, argtypes) === Union{}
end

# whether `f` is pure for inference
function is_pure_intrinsic_infer(f::IntrinsicFunction)
return !(f === Intrinsics.pointerref || # this one is volatile
f === Intrinsics.pointerset || # this one is never effect-free
f === Intrinsics.llvmcall || # this one is never effect-free
f === Intrinsics.sqrt_llvm_fast || # this one may differ at runtime (by a few ulps)
f === Intrinsics.have_fma || # this one depends on the runtime environment
f === Intrinsics.cglobal) # cglobal lookup answer changes at runtime
function _is_effect_free_infer(f::IntrinsicFunction)
return !(f === Intrinsics.pointerset ||
f === Intrinsics.atomic_pointerref ||
f === Intrinsics.atomic_pointerset ||
f === Intrinsics.atomic_pointerswap ||
# f === Intrinsics.atomic_pointermodify ||
f === Intrinsics.atomic_pointerreplace ||
f === Intrinsics.atomic_fence)
end

# whether `f` is effect free if nothrow
function intrinsic_effect_free_if_nothrow(@nospecialize f)
return f === Intrinsics.pointerref ||
f === Intrinsics.have_fma ||
is_pure_intrinsic_infer(f)
# whether `f` is pure for inference
function is_pure_intrinsic_infer(f::IntrinsicFunction, is_effect_free::Union{Nothing,Bool}=nothing)
if is_effect_free === nothing
is_effect_free = _is_effect_free_infer(f)
end
return is_effect_free && !(
f === Intrinsics.llvmcall || # can do arbitrary things
f === Intrinsics.atomic_pointermodify || # can do arbitrary things
f === Intrinsics.pointerref || # this one is volatile
f === Intrinsics.sqrt_llvm_fast || # this one may differ at runtime (by a few ulps)
f === Intrinsics.have_fma || # this one depends on the runtime environment
f === Intrinsics.cglobal) # cglobal lookup answer changes at runtime
end

function intrinsic_effects(f::IntrinsicFunction, argtypes::Vector{Any})
if f === Intrinsics.llvmcall
# llvmcall can do arbitrary things
return Effects()
elseif f === atomic_pointermodify
# atomic_pointermodify has memory effects, plus any effects from the ModifyOpInfo
return Effects()
end

if contains_is(_INCONSISTENT_INTRINSICS, f)
consistent = ALWAYS_FALSE
else
is_effect_free = _is_effect_free_infer(f)
effect_free = is_effect_free ? ALWAYS_TRUE : ALWAYS_FALSE
if ((is_pure_intrinsic_infer(f, is_effect_free) && !contains_is(_INCONSISTENT_INTRINSICS, f)) ||
f === Intrinsics.pointerset || f === Intrinsics.atomic_pointerset || f === Intrinsics.atomic_fence)
consistent = ALWAYS_TRUE
else
consistent = ALWAYS_FALSE
end
effect_free = !(f === Intrinsics.pointerset) ? ALWAYS_TRUE : ALWAYS_FALSE
nothrow = (isempty(argtypes) || !isvarargtype(argtypes[end])) && intrinsic_nothrow(f, argtypes)
inaccessiblememonly = ALWAYS_TRUE
inaccessiblememonly = is_effect_free && !(f === Intrinsics.pointerref) ? ALWAYS_TRUE : ALWAYS_FALSE
return Effects(EFFECTS_TOTAL; consistent, effect_free, nothrow, inaccessiblememonly)
end

Expand Down
6 changes: 6 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2330,3 +2330,9 @@ f54131 = F54131()
@test_broken REPLCompletions.KeywordArgumentCompletion("kwarg") in a
@test (@elapsed completions(s, lastindex(s), @__MODULE__, false)) < 1
end

# JuliaLang/julia#57780
const issue57780 = ["a", "b", "c"]
const issue57780_orig = copy(issue57780)
test_complete_context("empty!(issue57780).", Main)
@test issue57780 == issue57780_orig
34 changes: 34 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1405,3 +1405,37 @@ global v53613 = nothing
@test f53613() === nothing
@test g53613() === nothing
@test h53613() === nothing

# effects modeling for pointer-related intrinsics
let effects = Base.infer_effects(Core.Intrinsics.pointerref, Tuple{Vararg{Any}})
@test !Core.Compiler.is_consistent(effects)
@test Core.Compiler.is_effect_free(effects)
@test !Core.Compiler.is_inaccessiblememonly(effects)
end
let effects = Base.infer_effects(Core.Intrinsics.pointerset, Tuple{Vararg{Any}})
@test Core.Compiler.is_consistent(effects)
@test !Core.Compiler.is_effect_free(effects)
end
# effects modeling for atomic intrinsics
# these functions especially need to be marked !effect_free since they imply synchronization
for atomicfunc = Any[
Core.Intrinsics.atomic_pointerref,
Core.Intrinsics.atomic_pointerset,
Core.Intrinsics.atomic_pointerswap,
Core.Intrinsics.atomic_pointerreplace,
Core.Intrinsics.atomic_fence]
@test !Core.Compiler.is_effect_free(Base.infer_effects(atomicfunc, Tuple{Vararg{Any}}))
end

# effects modeling for intrinsics that can do arbitrary things
let effects = Base.infer_effects(Core.Intrinsics.llvmcall, Tuple{Vararg{Any}})
@test effects == Core.Compiler.Effects()
end
let effects = Base.infer_effects(Core.Intrinsics.atomic_pointermodify, Tuple{Vararg{Any}})
@test effects == Core.Compiler.Effects()
end

# JuliaLang/julia#57780
let effects = Base.infer_effects(Base._unsetindex!, (MemoryRef{String},))
@test !Core.Compiler.is_effect_free(effects)
end