effects: exclude swap() from "indirect calls" assumption (#15504)

swap() will never call any procs passed to it, and so it can be safely
excluded from the "assume indirect calls are taken" effects tracking
rule.
This commit is contained in:
Paul Tan
2020-10-07 00:05:31 +08:00
committed by GitHub
parent 695f955f70
commit fa84121421
2 changed files with 13 additions and 1 deletions

View File

@@ -552,7 +552,7 @@ proc isNoEffectList(n: PNode): bool {.inline.} =
n.len == 0 or (n[tagEffects] == nil and n[exceptionEffects] == nil)
proc isTrival(caller: PNode): bool {.inline.} =
result = caller.kind == nkSym and caller.sym.magic in {mEqProc, mIsNil, mMove, mWasMoved}
result = caller.kind == nkSym and caller.sym.magic in {mEqProc, mIsNil, mMove, mWasMoved, mSwap}
proc trackOperandForIndirectCall(tracked: PEffects, n: PNode, paramType: PType; caller: PNode) =
let a = skipConvAndClosure(n)

View File

@@ -0,0 +1,12 @@
discard """
action: compile
"""
# https://github.com/nim-lang/Nim/issues/15495
proc f() {.raises: [].} =
var a: proc ()
var b: proc ()
swap(a, b)
f()