inference: introduce more error/throwness checks for array primitives#43587
inference: introduce more error/throwness checks for array primitives#43587
Conversation
9e9add7 to
2ec059a
Compare
| ary ⊑ Array || return false | ||
| if isa(dim, Const) | ||
| dimval = dim.val | ||
| return isa(dimval, Int) && dimval > 0 |
There was a problem hiding this comment.
Does an OOMError count? Probably not.
There was a problem hiding this comment.
I don't think arraysize can yield OOMError though? AFAIU array resizing may result in OOMError, but all them are invoked by foreigncall, which currently is handled conservatively i.e. considered as "may throw" always.
There was a problem hiding this comment.
Yes, I read a bit too quickly and thought it was about array construction. Might have mixed it up with some other PR.
There was a problem hiding this comment.
yeah array constructions are handled by #43565, and it does account for OOMError.
| const _PURE_OR_ERROR_BUILTINS = [ | ||
| fieldtype, apply_type, isa, UnionAll, | ||
| getfield, arrayref, const_arrayref, isdefined, Core.sizeof, | ||
| getfield, arrayref, const_arrayref, arraysize, isdefined, Core.sizeof, |
There was a problem hiding this comment.
Hm now I think nvm, it's valid to eliminate such calls as far as their result aren't used anywhere and guaranteed not to throw.arraysize may not be eligible to be "pure" function since it is volatile.
2ec059a to
e6bec20
Compare
In a similar spirit to #43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
In a similar spirit to JuliaLang#43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
In a similar spirit to #43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
e6bec20 to
5e8bd96
Compare
base/compiler/tfuncs.jl
Outdated
| hasintersect(widenconst(boundcheck), Bool) || return false | ||
| hasintersect(widenconst(ary), Array) || return false | ||
| for i = 1:length(idxs) | ||
| idx = idxs[i] |
There was a problem hiding this comment.
| idx = idxs[i] | |
| idx = getfield(idxs, i) |
There was a problem hiding this comment.
Why don't we want to rely on getindex abstraction here?
In a similar spirit to #43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
Obvious errors are usually caught in higher places like `convert`, but it's better to have error checks at each builtin level in order to enable early bail out from errorneous code compilation (when somehow it does not rely on common abstraction). These checks are also useful for third consumers like JET.
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
820b679 to
0fbf3df
Compare
In a similar spirit to #43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
In a similar spirit to #43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
In a similar spirit to JuliaLang#43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
…JuliaLang#43587) Obvious errors are usually caught in higher places like `convert`, but it's better to have error checks at each builtin level in order to enable early bail out from errorneous code compilation (when somehow it does not rely on common abstraction). These checks are also useful for third consumers like JET.
In a similar spirit to JuliaLang#43587, this commit introduces error check for `setfield!`. We can bail out from inference if we can prove either of: - the object is not mutable type - the object is `Module` object - the value being assigned is incompatible with the declared type of object field This commit also adds the throwness check for `setfield!` (i.e. `setfield!_nothrow`). This throwness check won't be used in the current native compilation pipeline since `setfield!` call can't be eliminated even if we can prove that it never throws. But this throwness check would be used by EscapeAnalysis.jl integration and so I'd like to include it in Base.
…JuliaLang#43587) Obvious errors are usually caught in higher places like `convert`, but it's better to have error checks at each builtin level in order to enable early bail out from errorneous code compilation (when somehow it does not rely on common abstraction). These checks are also useful for third consumers like JET.
Obvious errors are usually caught in higher places like
convert, butit's better to have error checks at each builtin level in order to enable
early bail out from errorneous code compilation (when somehow it does not
rely on common abstractions). These checks are also useful for third
consumers like JET.