Skip to content

Commit

Permalink
Merge 254b268 into 151ef23
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk authored Sep 20, 2023
2 parents 151ef23 + 254b268 commit 8ef9db4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,11 @@ function should_infer_this_call(interp::AbstractInterpreter, sv::InferenceState)
end
function should_infer_for_effects(sv::InferenceState)
effects = sv.ipo_effects
return is_terminates(effects) && is_effect_free(effects)
override = decode_effects_override((sv.linfo.def::Method).purity)
effects.consistent === ALWAYS_FALSE && !is_effect_overridden(override, :consistent) && return false
effects.effect_free === ALWAYS_FALSE && !is_effect_overridden(override, :effect_free) && return false
!effects.terminates && !is_effect_overridden(override, :terminates) && return false
return true
end
should_infer_this_call(::AbstractInterpreter, ::IRInterpretationState) = true

Expand Down
18 changes: 17 additions & 1 deletion test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ end |> Core.Compiler.is_foldable
getfield(w, s)
end |> Core.Compiler.is_foldable

# Flow-sensitive consistenct for _typevar
# Flow-sensitive consistent for _typevar
@test Base.infer_effects() do
return WrapperOneField == (WrapperOneField{T} where T)
end |> Core.Compiler.is_foldable_nothrow
Expand Down Expand Up @@ -1001,6 +1001,22 @@ isassigned_effects(s) = isassigned(Ref(s))
isassigned_effects(:foo)
end

# inference on throw block should be disabled only when the effects are already known to be
# concrete-eval ineligible:
function optimize_throw_block_for_effects(x)
a = [x]
if x < 0
throw(ArgumentError(lazy"negative number given: $x"))
end
return a
end
let effects = Base.infer_effects(optimize_throw_block_for_effects, (Int,))
@test Core.Compiler.is_consistent_if_notreturned(effects)
@test Core.Compiler.is_effect_free(effects)
@test !Core.Compiler.is_nothrow(effects)
@test Core.Compiler.is_terminates(effects)
end

# :isdefined effects
@test @eval Base.infer_effects() do
@isdefined($(gensym("some_undef_symbol")))
Expand Down

0 comments on commit 8ef9db4

Please sign in to comment.