summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <ariabushenko@gmail.com>2020-10-30 11:42:06 +0000
committerGitHub <noreply@github.com>2020-10-30 11:42:06 +0000
commit6fe2e8977d0227a454cfb606c821cc455a9d0e07 (patch)
tree9a6d71119f219f91ecc645acb508822481c398d0
parentec059240b030161111d7ffdbd07a8c677bc17994 (diff)
downloadNim-6fe2e8977d0227a454cfb606c821cc455a9d0e07.tar.gz
canAlias improvement (#15773)
* canAlias improvement

* fix comment
-rw-r--r--compiler/isolation_check.nim13
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/isolation_check.nim b/compiler/isolation_check.nim
index 8c40dd4ad..01f0a002a 100644
--- a/compiler/isolation_check.nim
+++ b/compiler/isolation_check.nim
@@ -64,9 +64,18 @@ proc canAlias(arg, ret: PType; marker: var IntSet): bool =
   else:
     result = false
 
+proc isValueOnlyType(t: PType): bool = 
+  # t doesn't contain pointers and references
+  proc wrap(t: PType): bool {.nimcall.} = t.kind in {tyRef, tyPtr, tyVar, tyLent}
+  result = not types.searchTypeFor(t, wrap)
+
 proc canAlias*(arg, ret: PType): bool =
-  var marker = initIntSet()
-  result = canAlias(arg, ret, marker)
+  if isValueOnlyType(arg):
+    # can alias only with unsafeAddr(arg.x) and we don't care if it is not safe
+    result = false
+  else:
+    var marker = initIntSet()
+    result = canAlias(arg, ret, marker)
 
 proc checkIsolate*(n: PNode): bool =
   if types.containsTyRef(n.typ):