nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.47k stars 1.47k forks source link

`move(table)` does not move the table #23759

Closed arnetheduck closed 3 months ago

arnetheduck commented 3 months ago

Description

import tables
var a, b: Table[int, int]
a = move(b)

a copy is generated even if a move is requested:

    genericSeqAssign((&a__testit_u10.data), b__testit_u11.data, (&NTIkeyvaluepairseq__E8pi9b5QNahsURYzXMjh3qw_));
    a__testit_u10.counter = b__testit_u11.counter;
    unsureAsgnRef((void**)&b__testit_u11.data, NIM_NIL);
    b__testit_u11.counter = 0;

orc moves.

Nim Version

2.0.6/refc

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

arnetheduck commented 3 months ago

swap(a, b); reset(b) works around :facepalm:

Araq commented 3 months ago

Let me tell you a secret: refc really does not support move semantics. Or destructors. Or sink parameters.

arnetheduck commented 3 months ago

Let me tell you a secret: refc really does not support move semantics. Or destructors. Or sink parameters.

works for seq - don't see why it shouldn't work here?

juancarlospaco commented 3 months ago

refc really does not support move semantics. Or destructors. Or sink parameters.

Maybe that should be made more explicit in the docs ? 🤔

Araq commented 3 months ago

Maybe that should be made more explicit in the docs ? 🤔

Sure but there is a reason we used the version number 2.0 and it defaults to mm:orc. Supporting refc with move semantics is a whack-a-mole game as it was never designed for this.

ringabout commented 3 months ago

@arnetheduck it doesn't work for base cases for seq though

var a, b: seq[int]
a = move(b)

Which generates genericSeqAssign in the c code.

ringabout commented 3 months ago

https://github.com/nim-lang/Nim/pull/22229 made it conversative to move data since 2.0.0. 1.6.x does move tables.

arnetheduck commented 3 months ago

https://github.com/nim-lang/Nim/pull/22229 made it conversative to move data since 2.0.0. 1.6.x does moves tables.

ok, I'm not going mad at least, I was pretty sure I had seen move take effect when investigating poor performance while on 1.6 ;)

move helps us migrate signfificant amounts of code away from shallowCopy and other pure-refc constructs but we cannot do that if it makes the applications significantly slower (which additional copies do) - it would be great if we could address some of these lack-of-move issues for refc in 2.0 (we don't care about other orc:isms such as destructors since these are new features - sink, lent etc are pre-2.0 and pre-orc features that are important migration bridges)