Improve effect propagation by skipping hooks in trackCall

This commit is contained in:
ringabout
2026-06-26 12:27:16 +08:00
parent 16b5129a1e
commit afee410f24
2 changed files with 12 additions and 2 deletions

View File

@@ -1158,7 +1158,9 @@ proc trackCall(tracked: PEffects; n: PNode) =
else:
if laxEffects notin tracked.c.config.legacyFeatures and a.kind == nkSym and
a.sym.kind in routineKinds:
propagateEffects(tracked, n, a.sym)
let (isHook, opKind) = findHookKind(a.sym.name.s)
if (not isHook) or opKind notin {attachedAsgn, attachedSink, attachedDup}:
propagateEffects(tracked, n, a.sym)
else:
mergeRaises(tracked, effectList[exceptionEffects], n)
mergeTags(tracked, effectList[tagEffects], n)

View File

@@ -13,4 +13,12 @@ proc send(x: string) =
let wrapper = Thing(x: x)
discard isolate(wrapper)
send("la")
send("la")
block:
func enqueue[T](buf: var array[10, T], elem: sink T) =
`=sink`(buf[0], elem)
var buf: array[10, int]
enqueue(buf, 42)
assert buf[0] == 42