Skip to content

Missing move for sink parameter + closure environment (refc) #25047

@arnetheduck

Description

@arnetheduck

Nim Version

2.2.4

Description

proc makeiter(v: sink string): iterator(): string =
  return iterator(): string =
    yield v

var iter = makeiter("test")()
for c in iter:
  echo "works ", c

An environment is created for the v parameter. With orc, v is correctly moved into the closure:

N_LIB_PRIVATE N_NIMCALL(void, _ZN6testit7makeenvE4sinkI6stringE)(
    NimStringV2 v_p0, tyProc__LCMSFwcIs5O0HdDmqpX05g *Result) {
...
    _ZN6system7eqsink_E3varI6stringE6string((&(*colonenv__1).v0), v_p0);
    _ZN6system11eqwasMoved_E3varI6stringE((&v_p0));
...

With refc, the move analysis is missing and a copy is made instead:

N_LIB_PRIVATE N_NIMCALL(void, _ZN6testit8makeiterE4sinkI6stringE)(
    NimStringDesc *v_p0, tyProc__qUd1Y01q9a25ztxBaH1qzRQ *Result) {
...
    (*colonenv__1).v0 = copyStringRC1(v_p0);
...

The same also applies to a proc closure environment!

Current Output


Expected Output


Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions