Re: array-assign! can have different effects with specialized and generalized arrays. Bradley Lucier 17 Nov 2026 00:24 UTC

Proposed significant change to sample implementation below.

On 11/16/26 15:08, Bradley Lucier wrote:
> Or should we give copiers have the semantics of memcpy instead of
> memmove?  This would go against the specification of vector-copy! in
> SRFI 133:
>
>   (vector-copy! to at from [start [end]]) -> unspecified
>      [R7RS-small] Copies the elements of vector from between start and
> end to vector to, starting at at. The order in which elements are copied
> is unspecified, except that if the source and destination overlap,
> copying takes place as if the source is first copied into a temporary
> vector and then into the destination. This can be achieved without
> allocating storage by making sure to copy in the correct direction in
> such circumstances.

This definition may indeed be The Right Thing to do with vectors, where

(a) it is easy to detect whether the source and destination overlap and

(b) the algorithmic change when they do overlap is straightforward.

With arrays, however, it is NP-hard (maybe NP-complete, I haven't
checked all the details) to determine whether two affine function access
patterns overlap in memory.  See

https://github.com/numpy/numpy/blob/maintenance/1.11.x/numpy/core/src/private/mem_overlap.c

Thus, in the general case, the best one can do with array-assign! is to
either:

(a) copy the source array to a temporary array before moving elements to
the destination array, preserving memmove semantics at the expense of
moving elements twice, or

(b) copy elements one by one, in lexicographical order, from the source
array to the destination array, which is the semantics of memcpy, not
memmove.

Right now the sample implementation uses (a) when arrays are specialized
and packed and have the same storage class and (b) in all other cases.

And that ain't right.

I don't know what to do about the sample implementation of SRFI 231, but
I plan to choose option (b) in the implementation of SRFI 231-bis, i.e,
use vector copy routines with memcpy semantics for storage class copiers.

Brad