From fa841214212cba21ebbf9a0a18a9ce367fab15d2 Mon Sep 17 00:00:00 2001 From: Paul Tan Date: Wed, 7 Oct 2020 00:05:31 +0800 Subject: [PATCH] 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. --- compiler/sempass2.nim | 2 +- tests/effects/teffects10.nim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/effects/teffects10.nim diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 4eac6ef13c..f0d6c6c7af 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -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) diff --git a/tests/effects/teffects10.nim b/tests/effects/teffects10.nim new file mode 100644 index 0000000000..8193b394a7 --- /dev/null +++ b/tests/effects/teffects10.nim @@ -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()