Open tersec opened 1 month ago
I don't understand how "Dereference operator never copies" can be a reasonable requirement. let x = p[]; p[].field = 3; # oops
In that case the copy comes effectively comes from the let x =
part, i.e. if p
is ptr[T]
then x
is a T
on the stack which needs to be populated somehow (e.g., via a copy). The dereference itself doesn't require it in that case.
Correct but then that's exactly where the copy comes from in the for
construct.
Ordinary for
loops don't copy the entire collection when they start. That's sort of their point.
Description
Here, the first
block
/for
loop triggers a whole-array copy:i.e. the
for
loop constructs thecolontmp_
variable as the object to loop over, given:By contrast, splitting that apart a bit:
results in:
Which does not have any copies. This is with
--mm:orc
;--mm:refc
has a similar pattern but with,refc
details, wherefor _ in cast[typeof(a)](a)[]:
triggers a copy andlet x = cast[typeof(a)](a)
/for _ in x[]:
doesn't.Nim Version
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response