Conversation
|
This will allow us to avoid sprinkinling |
| next(a::Array,i) = (a[i],i+1) | ||
| function unsafe_next(a::Array,i) | ||
| @inbounds begin | ||
| return next(a,i) |
There was a problem hiding this comment.
Not sure if this is still the case, but @inbounds return was difficult for inference to reason about at one point in recent history. You're probably more aware of the current design than I am, but just FYI: #13461.
|
would it be possible to use the new |
|
I think boundscheck is too coarse since if lowering insert a unsafe_next has the advantage that the contract is only about the iterator passed as an argument, which is the only thing for-loop lowering guarantees |
Add an unsafe_next method which contract is that the iteration protocol was followed correctly.
|
I'm open to suggestions for design, maybe unsafe_next is too painful and it apparently could use the new boundscheck thing according to Jameson. In any case it is kind of silly that we boundcheck one of the only guaranteed safe indexing construct in the language :-) |
|
I guess an alternative approach would be to directly inject |
|
Or, write next(a::Array, i) = (@boundscheck checkbounds(a, i); @inbounds r=a[i]; (r, i+1))Though, to ellide the bounds check you still need to decorate the |
|
Closing, as I believe we do this now via |
|
Do we? I think this is about removing bounds check automatically for |
|
Any chance of resurrecting this PR in some form? |
Add an unsafe_next method which contract is that the iteration protocol was followed correctly. It has a generic fallback to next.
Lowering uses this instead of next. Wrapper iterators can also forward it.
This is demonstrated for Enumerate in this commit.
With this we can proudly say we compile a dead loop to nothing, yay...