Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

Keno
Copy link
Member

@Keno Keno commented Mar 17, 2023

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.

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`.
Comment on lines 427 to 431
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
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
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

Copy link
Member Author

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

Comment on lines -1012 to +1042
_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
Copy link
Member

@aviatesk aviatesk Mar 20, 2023

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?

Copy link
Member Author

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?

Copy link
Member Author

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.

@Keno Keno closed this Mar 21, 2023
@giordano giordano deleted the kf/xoshiroremovable branch February 25, 2024 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants