-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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: improve :consistent
-cy analysis on getfield
#46199
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aviatesk
force-pushed
the
avi/noglobal-getfield
branch
from
July 27, 2022 19:26
d8e5b7f
to
2a59b70
Compare
aviatesk
force-pushed
the
avi/noglobal-getfield
branch
3 times, most recently
from
July 27, 2022 19:37
910b23e
to
ba632b0
Compare
vtjnash
reviewed
Jul 27, 2022
base/compiler/typeutils.jl
Outdated
@@ -333,6 +333,7 @@ function _is_effect_free_type(@nospecialize ty) | |||
if isType(ty) || ty === DataType || ty === String || ty === Symbol || ty === SimpleVector | |||
return true | |||
end | |||
ty === Module && return true # TODO add comment on why this is valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
ty === Module && return true # TODO add comment on why this is valid | |
ty === Module && return true # there is no inferable constructor (with effect_free consistency), so this object must have already existed |
aviatesk
force-pushed
the
avi/noglobal-getfield
branch
2 times, most recently
from
July 28, 2022 23:55
3369020
to
ed77aa5
Compare
aviatesk
force-pushed
the
avi/noglobal-getfield
branch
3 times, most recently
from
July 30, 2022 22:21
d679b05
to
469c14d
Compare
aviatesk
force-pushed
the
avi/noglobal-getfield
branch
from
July 30, 2022 23:05
469c14d
to
77ced42
Compare
This commit improves the accuracy of the `:consistent`-cy effect analysis by handling `getfield` accessing local mutable objects. The existing analysis taints `:consistent`-cy upon any `getfield` call accessing mutable object because we really don't have a knowledge about the object lifetime and so we need to conservatively take into account a possibility of the mutable object being a global variable. However we can "recover" `:consistent`-cy tainted by `getfield` on mutable object when the newly added `:noglobal` helper effect has been proven because in that case we can conclude that all mutable objects accessed within the method are purely local and thus `:consistent` (more precisely we also need to confirm that all the call arguments are known not to be mutable global objects to derive this conclusion). For example now we can prove `:consistent`-cy of the function below and it will be concrete-evaluated: ```julia julia> @noinline function mutable_consistent(s) broadcast(identity, Ref(s)) end mutable_consistent (generic function with 1 method) julia> Base.infer_effects(mutable_consistent, (String,)) (+c,+e,!n,+t,+s,+g) julia> code_typed() do mutable_consistent(:foo) end 1-element Vector{Any}: CodeInfo( 1 ─ return :foo ) => Symbol ```
aviatesk
force-pushed
the
avi/noglobal-getfield
branch
from
August 3, 2022 05:33
77ced42
to
7bd5ea3
Compare
Merged
ffucci
pushed a commit
to ffucci/julia
that referenced
this pull request
Aug 11, 2022
…6199) This commit improves the accuracy of the `:consistent`-cy effect analysis by handling `getfield` accessing local mutable objects. The existing analysis taints `:consistent`-cy upon any `getfield` call accessing mutable object because we really don't have a knowledge about the object lifetime and so we need to conservatively take into account a possibility of the mutable object being a global variable. However we can "recover" `:consistent`-cy tainted by `getfield` on mutable object when the newly added `:noglobal` helper effect has been proven because in that case we can conclude that all mutable objects accessed within the method are purely local and thus `:consistent` (more precisely we also need to confirm that all the call arguments are known not to be mutable global objects to derive this conclusion). For example now we can prove `:consistent`-cy of the function below and it will be concrete-evaluated: ```julia julia> @noinline function mutable_consistent(s) broadcast(identity, Ref(s)) end mutable_consistent (generic function with 1 method) julia> Base.infer_effects(mutable_consistent, (String,)) (+c,+e,!n,+t,+s,+g) julia> code_typed() do mutable_consistent(:foo) end 1-element Vector{Any}: CodeInfo( 1 ─ return :foo ) => Symbol ```
pcjentsch
pushed a commit
to pcjentsch/julia
that referenced
this pull request
Aug 18, 2022
…6199) This commit improves the accuracy of the `:consistent`-cy effect analysis by handling `getfield` accessing local mutable objects. The existing analysis taints `:consistent`-cy upon any `getfield` call accessing mutable object because we really don't have a knowledge about the object lifetime and so we need to conservatively take into account a possibility of the mutable object being a global variable. However we can "recover" `:consistent`-cy tainted by `getfield` on mutable object when the newly added `:noglobal` helper effect has been proven because in that case we can conclude that all mutable objects accessed within the method are purely local and thus `:consistent` (more precisely we also need to confirm that all the call arguments are known not to be mutable global objects to derive this conclusion). For example now we can prove `:consistent`-cy of the function below and it will be concrete-evaluated: ```julia julia> @noinline function mutable_consistent(s) broadcast(identity, Ref(s)) end mutable_consistent (generic function with 1 method) julia> Base.infer_effects(mutable_consistent, (String,)) (+c,+e,!n,+t,+s,+g) julia> code_typed() do mutable_consistent(:foo) end 1-element Vector{Any}: CodeInfo( 1 ─ return :foo ) => Symbol ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit improves the accuracy of the
:consistent
-cy effect analysisby handling
getfield
accessing local mutable objects.The existing analysis taints
:consistent
-cy upon anygetfield
callaccessing mutable object because we really don't have a knowledge about
the object lifetime and so we need to conservatively take into account a
possibility of the mutable object being a global variable.
However we can "recover"
:consistent
-cy tainted by access to mutableobject when the newly added
:noglobal
helper effect has been provenbecause in that case we can conclude that all mutable objects accessed
within the method are purely local and thus
:consistent
(moreprecisely we also need to confirm that all the call arguments are known
not to be mutable global objects to derive this conclusion).
For example now we can prove
:consistent
-cy of the function below andit will be concrete-evaluated: