-
-
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
Fix :noub inference for pointerset/pointerref, getfield with bounds checking disabled #57295
Open
xal-0
wants to merge
1
commit into
JuliaLang:master
Choose a base branch
from
xal-0:fix-intrinsic-effects
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1033,7 +1033,7 @@ end | |
# we may assume that we don't throw | ||
@assert !boundscheck | ||
ismod && return false | ||
name ⊑ Int || name ⊑ Symbol || return false | ||
name ⊑ Int || return false | ||
sty.name.n_uninitialized == 0 && return true | ||
nflds === nothing && return false | ||
for i = (datatype_min_ninitialized(sty)+1):nflds | ||
|
@@ -1053,10 +1053,10 @@ end | |
if isa(s, DataType) | ||
# Can't say anything about abstract types | ||
isabstracttype(s) && return false | ||
# If all fields are always initialized, and bounds check is disabled, | ||
# we can assume we don't throw | ||
# If all fields are always initialized, bounds check is disabled, and | ||
# name is an integer, we can assume we don't throw. | ||
if !boundscheck && s.name.n_uninitialized == 0 | ||
name ⊑ Int || name ⊑ Symbol || return false | ||
name ⊑ Int || return false | ||
return true | ||
end | ||
# Else we need to know what the field is | ||
|
@@ -2429,7 +2429,7 @@ const _ARGMEM_BUILTINS = Any[ | |
] | ||
|
||
const _INCONSISTENT_INTRINSICS = Any[ | ||
Intrinsics.pointerref, # this one is volatile | ||
Intrinsics.pointerref, | ||
Intrinsics.sqrt_llvm_fast, # this one may differ at runtime (by a few ulps) | ||
Intrinsics.have_fma, # this one depends on the runtime environment | ||
Intrinsics.cglobal, # cglobal lookup answer changes at runtime | ||
|
@@ -2486,6 +2486,7 @@ end | |
function getfield_effects(𝕃::AbstractLattice, argtypes::Vector{Any}, @nospecialize(rt)) | ||
length(argtypes) < 2 && return EFFECTS_THROWS | ||
obj = argtypes[1] | ||
name = argtypes[2] | ||
if isvarargtype(obj) | ||
return Effects(EFFECTS_TOTAL; | ||
consistent=CONSISTENT_IF_INACCESSIBLEMEMONLY, | ||
|
@@ -2499,18 +2500,16 @@ function getfield_effects(𝕃::AbstractLattice, argtypes::Vector{Any}, @nospeci | |
noub = ALWAYS_TRUE | ||
bcheck = getfield_boundscheck(argtypes) | ||
nothrow = getfield_nothrow(𝕃, argtypes, bcheck) | ||
if !nothrow | ||
if bcheck !== :on | ||
# If we cannot independently prove inboundsness, taint `:noub`. | ||
# The inbounds-ness assertion requires dynamic reachability, | ||
# while `:noub` needs to be true for all input values. | ||
# However, as a special exception, we do allow literal `:boundscheck`. | ||
# `:noub` will be tainted in any caller using `@inbounds` | ||
# based on the `:noinbounds` effect. | ||
# N.B. We do not taint for `--check-bounds=no` here. | ||
# That is handled in concrete evaluation. | ||
noub = ALWAYS_FALSE | ||
end | ||
if !(bcheck === :on || isdefined_tfunc(𝕃, obj, name) === Const(true)) | ||
# If we cannot independently prove inboundsness, taint `:noub`. | ||
# The inbounds-ness assertion requires dynamic reachability, | ||
# while `:noub` needs to be true for all input values. | ||
# However, as a special exception, we do allow literal `:boundscheck`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't look like it's true anymore (and wasn't before?) |
||
# `:noub` will be tainted in any caller using `@inbounds` | ||
# based on the `:noinbounds` effect. | ||
# N.B. We do not taint for `--check-bounds=no` here. | ||
# That is handled in concrete evaluation. | ||
noub = ALWAYS_FALSE | ||
end | ||
if hasintersect(widenconst(obj), Module) | ||
# Modeled more precisely in abstract_eval_getglobal | ||
|
@@ -2940,7 +2939,11 @@ function intrinsic_effects(f::IntrinsicFunction, argtypes::Vector{Any}) | |
effect_free = !(f === Intrinsics.pointerset) ? ALWAYS_TRUE : ALWAYS_FALSE | ||
nothrow = intrinsic_nothrow(f, argtypes) | ||
inaccessiblememonly = ALWAYS_TRUE | ||
return Effects(EFFECTS_TOTAL; consistent, effect_free, nothrow, inaccessiblememonly) | ||
noub = ALWAYS_TRUE | ||
if f === Intrinsics.pointerref || f === Intrinsics.pointerset | ||
noub = ALWAYS_FALSE | ||
end | ||
return Effects(EFFECTS_TOTAL; consistent, effect_free, nothrow, inaccessiblememonly, noub) | ||
end | ||
|
||
# TODO: this function is a very buggy and poor model of the return_type function | ||
|
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
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
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
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
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
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.
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.
Why this change?
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.
I was under the impression that
boundscheck=false
was a no-op whenname
is a symbol, since we always throw aFieldError
if it doesn't exist. Pre-change: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.
Post change: