Skip to content

Commit

Permalink
inference: look for :terminate_globally override in backedge termin…
Browse files Browse the repository at this point in the history
…ation check (#44106)

Now we can "fix" #41694:
```julia
Base.@assume_effects :terminates_globally function issue41694(x)
    res = 1
    1 < x < 20 || throw("bad")
    while x > 1
        res *= x
        x -= 1
    end
    return res
end
@test fully_eliminated() do
    issue41694(2)
end
```
  • Loading branch information
aviatesk committed Feb 14, 2022
1 parent 2842fe1 commit 5e7b6dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 6 additions & 3 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
effects.consistent ? ALWAYS_TRUE : TRISTATE_UNKNOWN,
effects.effect_free ? ALWAYS_TRUE : TRISTATE_UNKNOWN,
effects.nothrow ? ALWAYS_TRUE : TRISTATE_UNKNOWN,
effects.terminates ? ALWAYS_TRUE : TRISTATE_UNKNOWN,
effects.terminates_globally ? ALWAYS_TRUE : TRISTATE_UNKNOWN,
))
else
tristate_merge!(sv, Effects())
Expand Down Expand Up @@ -2052,8 +2052,11 @@ end
function handle_control_backedge!(frame::InferenceState, from::Int, to::Int)
if from > to
def = frame.linfo.def
if isa(def, Method) && decode_effects_override(def.purity).terminates_locally
return nothing
if isa(def, Method)
effects = decode_effects_override(def.purity)
if effects.terminates_globally || effects.terminates_locally
return nothing
end
end
tristate_merge!(frame, Effects(EFFECTS_TOTAL, terminates=TRISTATE_UNKNOWN))
end
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct EffectsOverride
consistent::Bool
effect_free::Bool
nothrow::Bool
terminates::Bool
terminates_globally::Bool
terminates_locally::Bool
end

Expand All @@ -98,7 +98,7 @@ function encode_effects_override(eo::EffectsOverride)
eo.consistent && (e |= 0x01)
eo.effect_free && (e |= 0x02)
eo.nothrow && (e |= 0x04)
eo.terminates && (e |= 0x08)
eo.terminates_globally && (e |= 0x08)
eo.terminates_locally && (e |= 0x10)
e
end
Expand Down
14 changes: 14 additions & 0 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1055,3 +1055,17 @@ function f_call_invoke_callback(f::FCallback)
return nothing
end
@test !fully_eliminated(f_call_invoke_callback, Tuple{FCallback})

# https://github.com/JuliaLang/julia/issues/41694
Base.@assume_effects :terminates_globally function issue41694(x)
res = 1
1 < x < 20 || throw("bad")
while x > 1
res *= x
x -= 1
end
return res
end
@test fully_eliminated() do
issue41694(2)
end

2 comments on commit 5e7b6dd

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

Please sign in to comment.