4 ms·
> The compiler knows better than the programmer what the hardware can copy fast This is true, but aliasing makes it extremely difficult to automatically decide
by assbuttbuttass 2y ago
> The compiler knows better than the programmer what the hardware can copy fast
This is true, but aliasing makes it extremely difficult to automatically decide between reference and copy. For example, suppose you have a function that takes your array, and also a mutable slice:
fn f(a: [float32; 3], out: &mut [float32])
And now you call it with the same argument twice:
let a = [1., 2., 3.];
f(a, &mut a)
The compiler cannot choose to pass a by reference here, since that would create simultaneous immutable and mutable references, which is forbidden by rust semantics