RFC: prevent mapslices from mutating the original array#17266
Conversation
|
I should have marked this "RFC" since the proper behavior is of course debatable. |
|
The case I was imagining was pushing slices into an Array and expecting to have |
|
If this gets merged, we should also change the description of the breaking change to |
|
Thanks for explaining. I agree this would break such functions, but (as you seem to feel) I don't think we need to bend over backwards to support such uses. |
should probably do that here before merging |
35d7564 to
d9ce339
Compare
|
Looks like there are no real objections to this change in strategy. |
This is a broader fix for #17153, making it so that
mapslicesnever modifies the input array. It allocates temporary storage and copies each slice into it before calling the user-function.@simonster commented (#17153 (comment)) that this would still be breaking compared to the old behavior (which created a new array with
A[idx...]on every iteration), but except for "pathalogical functions" (e.g., those whose behavior might depend on the array's pointer address) I confess I fail to see how this is the case.