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: look for :terminate_globally override in backedge termination check #44106

Merged
merged 1 commit into from
Feb 14, 2022

Conversation

aviatesk
Copy link
Sponsor Member

Now we can "fix" #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

@aviatesk aviatesk requested a review from Keno February 10, 2022 10:05
@aviatesk aviatesk changed the title inference: set :terminates_locally with :terminate_globally setting inference: set :terminates_locally with :terminates_globally setting Feb 10, 2022
base/expr.jl Outdated
@@ -532,11 +532,12 @@ macro assume_effects(args...)
elseif setting === :nothrow
nothrow = true
elseif setting === :terminates_globally
terminates_globally = true
terminates_globally = terminates_locally = true
Copy link
Member

Choose a reason for hiding this comment

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

Wondering whether it would be better for debugging not to set this override and instead just also check for the global override also on the backedge.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

yeah that sounds better.

Well, now I'm a bit confused about an expected usecase of :terminates_locally, since we usually take all control flow edges into account. Is it supposed to prove termination when constant propagation eliminates control flow edges that contain potentially-non-terminating calls?

…ation check

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
```
@aviatesk aviatesk changed the title inference: set :terminates_locally with :terminates_globally setting effects: look for :terminate_globally override in backedge termination check Feb 13, 2022
@aviatesk aviatesk changed the title effects: look for :terminate_globally override in backedge termination check effects: look for :terminate_globally override in backedge termination check Feb 13, 2022
@aviatesk aviatesk merged commit 5e7b6dd into master Feb 14, 2022
@aviatesk aviatesk deleted the avi/effects branch February 14, 2022 01:06
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request Feb 17, 2022
…ation check (JuliaLang#44106)

Now we can "fix" JuliaLang#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
```
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
…ation check (JuliaLang#44106)

Now we can "fix" JuliaLang#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
```
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…ation check (JuliaLang#44106)

Now we can "fix" JuliaLang#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
```
aviatesk added a commit that referenced this pull request Mar 11, 2022
While working on #44515, I found we missed to override edge effect with
effects set by `Base.@assume_effects`. This commit adds edge effect
override mechanism for `:consistent`/`:effect_free`/`:nothrow` settings
in the same way as we did for `:terminates_globally` in #44106.
Now we can do something like:
```julia
const ___CONST_DICT___ = Dict{Any,Any}(:a => 1, :b => 2)
Base.@assume_effects :consistent :effect_free :terminates_globally consteval(f, args...) = f(args...)
@test fully_eliminated() do
    consteval(getindex, ___CONST_DICT___, :a)
end
```
aviatesk added a commit that referenced this pull request Mar 11, 2022
While working on #44515, I found we missed to override edge effect with
effects set by `Base.@assume_effects`. This commit adds edge effect
override mechanism for `:consistent`/`:effect_free`/`:nothrow` settings
in the same way as we did for `:terminates_globally` in #44106.
Now we can do something like:
```julia
const ___CONST_DICT___ = Dict{Any,Any}(:a => 1, :b => 2)
Base.@assume_effects :consistent :effect_free :terminates_globally consteval(f, args...) = f(args...)
@test fully_eliminated() do
    consteval(getindex, ___CONST_DICT___, :a)
end
```
aviatesk added a commit that referenced this pull request Mar 14, 2022
While working on #44515, I found we missed to override edge effect with
effects set by `Base.@assume_effects`. This commit adds edge effect
override mechanism for `:consistent`/`:effect_free`/`:nothrow` settings
in the same way as we did for `:terminates_globally` in #44106.
Now we can do something like:
```julia
const ___CONST_DICT___ = Dict{Any,Any}(:a => 1, :b => 2)
Base.@assume_effects :consistent :effect_free :terminates_globally consteval(f, args...) = f(args...)
@test fully_eliminated() do
    consteval(getindex, ___CONST_DICT___, :a)
end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants