-
-
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
Set various array and Random effects #49039
Conversation
My primary motivation here was to get the Xoshiro constructor to be removed if the RNG is unused (I have a struct that always has an RNG in it, which may or may not be used). I first tried to do that in a more fine-grained way, but #47595 currently makes that infeasible. Nevertheless, I figured it was worth leaving those improvements in so we can switch over once #47595 is resolved. In the meantime, annotate the top-level Xoshiro constructor as `:removable`.
function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer) | ||
@assume_effects :consistent :nothrow :terminates_globally | ||
ccall(:memset, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), a, convert(eltype(a), x), length(a)) | ||
return a | ||
end |
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.
function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer) | |
@assume_effects :consistent :nothrow :terminates_globally | |
ccall(:memset, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), a, convert(eltype(a), x), length(a)) | |
return a | |
end | |
# native-integer specific method with the guaranteed `:nothrow` annotation | |
function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::BitInteger) | |
@assume_effects :consistent :nothrow :terminates_globall | |
ccall(:memset, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), a, convert(eltype(a), x), length(a)) | |
return a | |
end | |
# general method without the `:nothrow` annotation | |
function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer) | |
@assume_effects :consistent :terminates_globall | |
ccall(:memset, Ptr{Cvoid}, (Ptr{Cvoid}, Cint, Csize_t), a, convert(eltype(a), x), length(a)) | |
return a | |
end |
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.
Probably better to pull out the memset and set effects on it
_growbeg!(a::Vector, delta::Integer) = | ||
function _growbeg!(a::Vector, delta::Integer) | ||
@assume_effects :terminates_globally | ||
ccall(:jl_array_grow_beg, Cvoid, (Any, UInt), a, delta) | ||
_growend!(a::Vector, delta::Integer) = | ||
end | ||
function _growend!(a::Vector, delta::Integer) | ||
@assume_effects :terminates_globally | ||
ccall(:jl_array_grow_end, Cvoid, (Any, UInt), a, delta) | ||
_growat!(a::Vector, i::Integer, delta::Integer) = | ||
end | ||
function _growat!(a::Vector, i::Integer, delta::Integer) | ||
@assume_effects :terminates_globally | ||
ccall(:jl_array_grow_at, Cvoid, (Any, Int, UInt), a, i - 1, delta) | ||
end | ||
|
||
# efficiently delete part of an array | ||
|
||
_deletebeg!(a::Vector, delta::Integer) = | ||
function _deletebeg!(a::Vector, delta::Integer) | ||
@assume_effects :terminates_globally | ||
ccall(:jl_array_del_beg, Cvoid, (Any, UInt), a, delta) | ||
_deleteend!(a::Vector, delta::Integer) = | ||
end | ||
function _deleteend!(a::Vector, delta::Integer) | ||
@assume_effects :terminates_globally | ||
ccall(:jl_array_del_end, Cvoid, (Any, UInt), a, delta) | ||
_deleteat!(a::Vector, i::Integer, delta::Integer) = | ||
end | ||
function _deleteat!(a::Vector, i::Integer, delta::Integer) | ||
@assume_effects :terminates_globally | ||
ccall(:jl_array_del_at, Cvoid, (Any, Int, UInt), a, i - 1, delta) | ||
end |
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.
We may want to first merge #47154 in and remove these annotations?
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.
How does that change alleviate the need for these annotations?
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.
Ah, sorry, I see you edited the comment.
My primary motivation here was to get the Xoshiro constructor to be removed if the RNG is unused (I have a struct that always has an RNG in it, which may or may not be used). I first tried to do that in a more fine-grained way, but #47595 currently makes that infeasible. Nevertheless, I figured it was worth leaving those improvements in so we can switch over once #47595 is resolved. In the meantime, annotate the top-level Xoshiro constructor as
:removable
.