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

@inbounds annotations for filter #30156

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ function filter!(f, a::AbstractVector)

for acurr in a
if f(acurr)
a[i] = acurr
@inbounds a[i] = acurr
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Is there a policy for @inbounds, AbstractArray and the iteration protocol. I.e is it ok to segfault if someone implemented the iteration protocol erroneously?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This is iterating over the index space of a: foreach(i -> a[i] = a[i], eachindex(a)). I think it's OK to assume that is required to hold.

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK the policy is that AbstractArray implementations which opt-in to using @boundscheck assert that they are correct, so it's OK to crash if that's not the case. See #20469 and linked issues.

y = iterate(idx, state)
y === nothing && (i += 1; break)
i, state = y
Expand Down