Skip to content

Conversation

@aviatesk
Copy link
Member

@aviatesk aviatesk commented 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 throwness check implementation 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 anyway 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 requested a review from vtjnash December 30, 2021 07:50
@ianatol ianatol self-requested a review December 30, 2021 17:18
@ianatol
Copy link
Member

ianatol commented Jan 3, 2022

Seems sensible to me, but I am not intimately familiar with this part of inference

end
if fld < 1 || fld > nf
return Bottom
elseif setfield && isconst(s, fld)
Copy link
Member Author

Choose a reason for hiding this comment

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

Also added a support for new const declaration for mutable struct field.

@aviatesk aviatesk added the compiler:inference Type inference label Jan 4, 2022
setfield!_tfunc(o, f, v) = (@nospecialize; v)
function setfield!_tfunc(o, f, v, order)
@nospecialize
if !isvarargtype(order)
Copy link
Member

Choose a reason for hiding this comment

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

I thought we only ever call tfuncs with real types

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately argtypes[end] can sometimes be varargtype:

push!(argtypes, unconstrain_vararg_length(vatype))

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we want to try to make sure that most tfuncs deal with real types?

aviatesk and others added 2 commits January 8, 2022 13:51
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 95cfbcc into master Jan 8, 2022
@aviatesk aviatesk deleted the avi/setfield! branch January 8, 2022 07:25
aviatesk added a commit to aviatesk/EscapeAnalysis.jl that referenced this pull request Jan 8, 2022
aviatesk added a commit 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
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
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