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

inference: propagate variable changes to all exception frames #42081

Merged
merged 4 commits into from
Sep 3, 2021

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Sep 1, 2021

Switch to precomputing the handler_at for each statement, instead of copying around a linked list for more efficiency, and chain backwards on that linked list to update all places the exception might get thrown to.

Fix #42022

@vtjnash vtjnash added bugfix This change fixes an existing bug backport 1.6 Change should be backported to release-1.6 backport 1.7 labels Sep 1, 2021
@vtjnash vtjnash requested a review from aviatesk September 1, 2021 17:39
test/compiler/inference.jl Outdated Show resolved Hide resolved
Copy link
Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

I like this changes. The code looks much cleaner and easier to reason about.

test/compiler/inference.jl Outdated Show resolved Hide resolved
base/compiler/abstractinterpretation.jl Show resolved Hide resolved
cur_hand #::Union{Nothing, Pair{LineNum, prev_handler}}
handler_at::Vector{Any}
n_handlers::Int
handler_at::Vector{LineNum}
Copy link
Member

Choose a reason for hiding this comment

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

I think "handler_at" naming is actually a bit confusing ? To me "entered_at" sounds more reasonable ("handler" usually mean catch clause ... ?).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is the same to say it is handled by the try statement. The catch / leave is where we stop handling errors (which is why it is simpler to point to the try statement also, since we have more information there)

Comment on lines +1926 to +1935
if stupdate1!(states[l]::VarTable, changes::StateUpdate) !== false
if l < frame.pc´´
frame.pc´´ = l
end
push!(W, l)
end
Copy link
Member

Choose a reason for hiding this comment

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

Well, why do we want to propagate changes via :enter ? Can't we propagate changes directly to :leave statements here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The l value here is short for :leave (strictly speaking, it doesn't have to be a :leave, but it normally will be)

Copy link
Member

Choose a reason for hiding this comment

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

frame.src.code[l] is supposed to be :enter expression always, no ?
My understanding is that the algorithm accumulates all changes within try/catch clauses to :enter expression's states, and then :enter will propagate the changes to :leave.

So I wonder why we don't want to do:

if isa(changes, StateUpdate)
    while cur_hand != 0
        let l = frame.handler_at[cur_hand + 1]
            # propagate new type info to exception handler
            enter = frame.src.code[l]
            @assert isexpr(enter, :enter)
            leavestate = states[enter.args[1]::Int]::VarTable
            stupdate1!(leavestate, changes::StateUpdate) !== false
        end
        cur_hand = frame.handler_at[cur_hand]
    end
end

Copy link
Member Author

Choose a reason for hiding this comment

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

Because l is almost always a :leave expr there

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, or was supposed to be, until I rearranged the code, and then it wasn't anymore

@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Sep 2, 2021
@aviatesk aviatesk merged commit e83b317 into master Sep 3, 2021
@aviatesk aviatesk deleted the jn/42022 branch September 3, 2021 01:21
KristofferC pushed a commit that referenced this pull request Sep 3, 2021
* inference: propagate variable changes to all exception frames

Fix #42022

* Update test/compiler/inference.jl

* Update test/compiler/inference.jl

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

* fixup! inference: propagate variable changes to all exception frames

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
(cherry picked from commit e83b317)
@KristofferC KristofferC mentioned this pull request Sep 3, 2021
75 tasks
@KristofferC
Copy link
Member

This has quite a few merge conflicts with 1.6 so would need a rebase somewhere that can be cherry picked

@aviatesk
Copy link
Member

aviatesk commented Sep 3, 2021

Directly cherry-picking this PR on the backport branch is an option ? I think I can take it.

@KristofferC
Copy link
Member

Directly cherry-picking this PR on the backport branch is an option ?

Yes.

@vtjnash
Copy link
Member Author

vtjnash commented Sep 3, 2021

@aviatesk when merging, please check that the commit message is also correct. Fixup should never appear, for example.

@aviatesk
Copy link
Member

aviatesk commented Sep 3, 2021

So the commit message of this merge commit should be like:

inference: propagate variable changes to all exception frames (#42081)

Fix #42022

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

?

@vtjnash
Copy link
Member Author

vtjnash commented Sep 3, 2021

Yes, though I am not sure you want to claim co-authorship, since you are already claiming the reviewer, and it would imply you are claiming ownership of the content also.

aviatesk added a commit that referenced this pull request Sep 3, 2021
cherry-picked from #42081

Co-Authored-By: Jameson Nash <vtjnash+github@gmail.com>
aviatesk added a commit that referenced this pull request Sep 3, 2021
cherry-picked from #42081

Co-Authored-By: Jameson Nash <vtjnash+github@gmail.com>
aviatesk added a commit that referenced this pull request Sep 4, 2021
…42110)

cherry-picked from #42081

Co-Authored-By: Jameson Nash <vtjnash+github@gmail.com>
KristofferC pushed a commit that referenced this pull request Sep 6, 2021
…42110)

cherry-picked from #42081

Co-Authored-By: Jameson Nash <vtjnash+github@gmail.com>
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Sep 6, 2021
@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label Sep 7, 2021
KristofferC pushed a commit that referenced this pull request Sep 8, 2021
* inference: propagate variable changes to all exception frames

Fix #42022

* Update test/compiler/inference.jl

* Update test/compiler/inference.jl

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

* fixup! inference: propagate variable changes to all exception frames

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
(cherry picked from commit e83b317)
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
…ang#42081)

* inference: propagate variable changes to all exception frames

Fix JuliaLang#42022

* Update test/compiler/inference.jl

* Update test/compiler/inference.jl

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

* fixup! inference: propagate variable changes to all exception frames

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…ang#42081)

* inference: propagate variable changes to all exception frames

Fix JuliaLang#42022

* Update test/compiler/inference.jl

* Update test/compiler/inference.jl

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>

* fixup! inference: propagate variable changes to all exception frames

Co-authored-by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
staticfloat pushed a commit that referenced this pull request Dec 23, 2022
…42110)

cherry-picked from #42081

Co-Authored-By: Jameson Nash <vtjnash+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variable update not reflected outside nested try blocks
4 participants