summary refs log tree commit diff stats
path: root/compiler/injectdestructors.nim
diff options
context:
space:
mode:
authorb3liever <43617260+b3liever@users.noreply.github.com>2020-05-11 20:12:25 +0300
committerGitHub <noreply@github.com>2020-05-11 19:12:25 +0200
commita081b10b54ff78539e49d320ca12aabc20fc3ad8 (patch)
tree5fd21684e038bd6cc32283f7f34d28e04e2fc1ed /compiler/injectdestructors.nim
parentfee71d466cdb7cda96b55592abbf7d433639ab51 (diff)
downloadNim-a081b10b54ff78539e49d320ca12aabc20fc3ad8.tar.gz
small refactoring (#14303)
Co-authored-by: Antonis <b3liever@yandex.com>
Diffstat (limited to 'compiler/injectdestructors.nim')
-rw-r--r--compiler/injectdestructors.nim7
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim
index 09c072da7..009c683ae 100644
--- a/compiler/injectdestructors.nim
+++ b/compiler/injectdestructors.nim
@@ -382,8 +382,9 @@ proc sinkParamIsLastReadCheck(c: var Con, s: PNode) =
     localError(c.graph.config, c.otherRead.info, "sink parameter `" & $s.sym.name.s &
         "` is already consumed at " & toFileLineCol(c. graph.config, s.info))
 
-proc isClosureEnv(n: PNode): bool =
-  n.kind == nkDotExpr and n[0].kind == nkHiddenDeref and n[0][0].typ.kind == tyRef
+proc isCapturedVar(n: PNode): bool =
+  n.kind == nkDotExpr and n[0].kind == nkHiddenDeref and
+      n[0][0].kind == nkSym and n[0][0].sym.name.s[0] == ':'
 
 proc passCopyToSink(n: PNode; c: var Con): PNode =
   result = newNodeIT(nkStmtListExpr, n.info, n.typ)
@@ -395,7 +396,7 @@ proc passCopyToSink(n: PNode; c: var Con): PNode =
     var m = genCopy(c, tmp, n)
     m.add p(n, c, normal)
     result.add m
-    if isLValue(n) and not isClosureEnv(n) and n.typ.skipTypes(abstractInst).kind != tyRef and c.inSpawn == 0:
+    if isLValue(n) and not isCapturedVar(n) and n.typ.skipTypes(abstractInst).kind != tyRef and c.inSpawn == 0:
       message(c.graph.config, n.info, hintPerformance,
         ("passing '$1' to a sink parameter introduces an implicit copy; " &
         "if possible, rearrange your program's control flow to prevent it") % $n)