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

effects: give the most conservative effects to unhandled builtins #57856

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
73 changes: 68 additions & 5 deletions Compiler/src/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2425,10 +2425,6 @@ const _INCONSISTENT_INTRINSICS = Any[
# Intrinsics.muladd_float, # this is not interprocedurally consistent
]

const _SPECIAL_BUILTINS = Any[
Core._apply_iterate,
]

# Intrinsics that require all arguments to be floats
const _FLOAT_INTRINSICS = Any[
Intrinsics.neg_float,
Expand Down Expand Up @@ -2535,6 +2531,71 @@ function getfield_effects(𝕃::AbstractLattice, argtypes::Vector{Any}, @nospeci
return Effects(EFFECTS_TOTAL; consistent, nothrow, inaccessiblememonly, noub)
end

# add a new builtin function to this list only after making sure that
# `builtin_effects` is properly implemented for it
const _EFFECTS_KNOWN_BUILTINS = Any[
<:,
===,
# Core._abstracttype,
# _apply_iterate,
# Core._call_in_world_total,
# Core._compute_sparams,
# Core._defaultctors,
# Core._equiv_typedef,
Core._expr,
# Core._primitivetype,
# Core._setsuper!,
# Core._structtype,
# Core._svec_ref,
# Core._typebody!,
Core._typevar,
apply_type,
compilerbarrier,
Core.current_scope,
donotdelete,
Core.finalizer,
Core.get_binding_type,
Core.ifelse,
# Core.invoke_in_world,
# invokelatest,
Core.memorynew,
memoryref_isassigned,
memoryrefget,
# Core.memoryrefmodify!,
memoryrefnew,
memoryrefoffset,
# Core.memoryrefreplace!,
memoryrefset!,
# Core.memoryrefsetonce!,
# Core.memoryrefswap!,
Core.sizeof,
svec,
Core.throw_methoderror,
applicable,
fieldtype,
getfield,
getglobal,
# invoke,
isa,
isdefined,
# isdefinedglobal,
modifyfield!,
# modifyglobal!,
nfields,
replacefield!,
# replaceglobal!,
setfield!,
# setfieldonce!,
# setglobal!,
# setglobalonce!,
swapfield!,
# swapglobal!,
throw,
tuple,
typeassert,
typeof
]

"""
builtin_effects(𝕃::AbstractLattice, f::Builtin, argtypes::Vector{Any}, rt) -> Effects

Expand All @@ -2545,7 +2606,9 @@ function builtin_effects(𝕃::AbstractLattice, @nospecialize(f::Builtin), argty
return intrinsic_effects(f, argtypes)
end

@assert !contains_is(_SPECIAL_BUILTINS, f)
if !(f in _EFFECTS_KNOWN_BUILTINS)
return Effects()
end

if f === getfield
return getfield_effects(𝕃, argtypes, rt)
Expand Down
6 changes: 6 additions & 0 deletions Compiler/test/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1461,3 +1461,9 @@ end
let effects = Base.infer_effects(Base._unsetindex!, (MemoryRef{String},))
@test !Compiler.is_effect_free(effects)
end

# builtin functions that can do arbitrary things should have the top effects
@test Base.infer_effects(Core._call_in_world_total, Tuple{Vararg{Any}}) == Compiler.Effects()
@test Base.infer_effects(Core.invoke_in_world, Tuple{Vararg{Any}}) == Compiler.Effects()
@test Base.infer_effects(invokelatest, Tuple{Vararg{Any}}) == Compiler.Effects()
@test Base.infer_effects(invoke, Tuple{Vararg{Any}}) == Compiler.Effects()