Skip to content

Conversation

@aviatesk
Copy link
Member

@aviatesk aviatesk commented Dec 29, 2021

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 abstractions). These checks are also useful for third
consumers like JET.

@aviatesk aviatesk added the compiler:inference Type inference label Dec 29, 2021
@aviatesk aviatesk force-pushed the avi/arrayerrorcheck branch from 9e9add7 to 2ec059a Compare December 29, 2021 15:09
@aviatesk aviatesk changed the title inference: introduce error checks for array primitives inference: introduce more error/throwness checks for array primitives Dec 29, 2021
@aviatesk aviatesk requested a review from vtjnash December 29, 2021 16:34
ary Array || return false
if isa(dim, Const)
dimval = dim.val
return isa(dimval, Int) && dimval > 0
Copy link
Member

Choose a reason for hiding this comment

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

Does an OOMError count? Probably not.

Copy link
Member Author

@aviatesk aviatesk Dec 29, 2021

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I read a bit too quickly and thought it was about array construction. Might have mixed it up with some other PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

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,
Copy link
Member Author

@aviatesk aviatesk Dec 29, 2021

Choose a reason for hiding this comment

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

Hm now I think arraysize may not be eligible to be "pure" function since it is volatile. nvm, it's valid to eliminate such calls as far as their result aren't used anywhere and guaranteed not to throw.

@aviatesk aviatesk force-pushed the avi/arrayerrorcheck branch from 2ec059a to e6bec20 Compare December 30, 2021 07:31
aviatesk added a commit that referenced this pull request Dec 30, 2021
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.
@ianatol ianatol self-requested a review December 30, 2021 17:18
aviatesk added a commit to aviatesk/julia that referenced this pull request Jan 3, 2022
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.
aviatesk added a commit that referenced this pull request Jan 4, 2022
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.
@aviatesk aviatesk force-pushed the avi/arrayerrorcheck branch from e6bec20 to 5e8bd96 Compare January 4, 2022 06:46
hasintersect(widenconst(boundcheck), Bool) || return false
hasintersect(widenconst(ary), Array) || return false
for i = 1:length(idxs)
idx = idxs[i]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
idx = idxs[i]
idx = getfield(idxs, i)

Copy link
Member Author

Choose a reason for hiding this comment

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

Why don't we want to rely on getindex abstraction here?

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

LGTM

aviatesk added a commit that referenced this pull request Jan 8, 2022
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.
aviatesk and others added 3 commits January 8, 2022 13:36
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.
@aviatesk aviatesk force-pushed the avi/arrayerrorcheck branch from 820b679 to 0fbf3df Compare January 8, 2022 04:36
aviatesk added a commit that referenced this pull request Jan 8, 2022
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.
aviatesk added a commit that referenced this pull request Jan 8, 2022
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.
@aviatesk aviatesk merged commit acb6e16 into master Jan 8, 2022
@aviatesk aviatesk deleted the avi/arrayerrorcheck branch January 8, 2022 07:26
aviatesk added a commit to aviatesk/EscapeAnalysis.jl that referenced this pull request Jan 8, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
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.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
…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.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
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.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:inference Type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants