fixes sink regression for ORC; ref #23354 (#23359)

ref #23354

The new move analyzer requires types that have the tfAsgn flag
(otherwise `lastRead` will return true); tfAsgn is included when the
destructor is not trival. But it should consider the assignement for
objects in this case because objects might have a trival destructors but
it's the assignement that matters when it is passed to sink parameters.
This commit is contained in:
ringabout
2024-03-03 23:03:53 +08:00
committed by GitHub
parent 31d7554524
commit 572b0b67ff
3 changed files with 19 additions and 2 deletions

View File

@@ -163,7 +163,8 @@ proc isLastReadImpl(n: PNode; c: var Con; scope: var Scope): bool =
result = false
proc isLastRead(n: PNode; c: var Con; s: var Scope): bool =
if not hasDestructor(c, n.typ): return true
# bug #23354; an object type could have a non-trival assignements when it is passed to a sink parameter
if not hasDestructor(c, n.typ) and (n.typ.kind != tyObject or isTrival(getAttachedOp(c.graph, n.typ, attachedAsgn))): return true
let m = skipConvDfa(n)
result = (m.kind == nkSym and sfSingleUsedTemp in m.sym.flags) or

View File

@@ -1252,7 +1252,7 @@ proc inst(g: ModuleGraph; c: PContext; t: PType; kind: TTypeAttachedOp; idgen: I
else:
localError(g.config, info, "unresolved generic parameter")
proc isTrival(s: PSym): bool {.inline.} =
proc isTrival*(s: PSym): bool {.inline.} =
s == nil or (s.ast != nil and s.ast[bodyPos].len == 0)
proc createTypeBoundOps(g: ModuleGraph; c: PContext; orig: PType; info: TLineInfo;

View File

@@ -0,0 +1,16 @@
discard """
matrix: "--mm:arc"
"""
type AnObject = object of RootObj
value*: int
proc mutate(shit: sink AnObject) =
shit.value = 1
proc foo = # bug #23359
var bar = AnObject(value: 42)
mutate(bar)
doAssert bar.value == 42
foo()