diff --git a/compiler/isolation_check.nim b/compiler/isolation_check.nim index 0a27a4b815..a26cd74646 100644 --- a/compiler/isolation_check.nim +++ b/compiler/isolation_check.nim @@ -11,9 +11,9 @@ ## https://github.com/nim-lang/RFCs/issues/244 for more details. import - ast, types, renderer + ast, types, renderer, options, msgs, lineinfos -import std/intsets +import std/[intsets, strutils] when defined(nimPreviewSlimSystem): import std/assertions @@ -163,7 +163,10 @@ proc containsVariable(n: PNode): bool = if containsVariable(ch): return true result = false -proc checkIsolate*(n: PNode): bool = +proc checkIsolate*(conf: ConfigRef, n: PNode): bool = + if conf.selectedGC notin {gcArc, gcAtomicArc, gcOrc} and + containsGarbageCollectedRef(n.typ): + message(conf, n.info, warnGcIsolated, "Garbage-collected types '$#' cannot be isolated in refc" % [$n.typ]) if types.containsTyRef(n.typ): # XXX Maybe require that 'n.typ' is acyclic. This is not much # worse than the already existing inheritance and closure restrictions. @@ -177,7 +180,7 @@ proc checkIsolate*(n: PNode): bool = if tfNoSideEffect notin n[0].typ.flags: return false for i in 1.. 0: - result = checkIsolate(n[^1]) + result = checkIsolate(conf, n[^1]) else: result = false of nkSym: diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim index 397d407077..c6d54617c1 100644 --- a/compiler/lineinfos.nim +++ b/compiler/lineinfos.nim @@ -93,8 +93,9 @@ type warnBareExcept = "BareExcept", warnImplicitDefaultValue = "ImplicitDefaultValue", warnIgnoredSymbolInjection = "IgnoredSymbolInjection", - warnStdPrefix = "StdPrefix" - warnUnknownNotes = "UnknownNotes" + warnStdPrefix = "StdPrefix", + warnUnknownNotes = "UnknownNotes", + warnGcIsolated = "GcIsolated", warnUser = "User", warnGlobalVarConstructorTemporary = "GlobalVarConstructorTemporary", # hints @@ -202,6 +203,7 @@ const warnIgnoredSymbolInjection: "$1", warnStdPrefix: "$1 needs the 'std' prefix", warnUnknownNotes: "$1", + warnGcIsolated: "$1", warnUser: "$1", warnGlobalVarConstructorTemporary: "global variable '$1' initialization requires a temporary variable", hintSuccess: "operation successful: $#", diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 9de290f4ce..f7b45f61c5 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -683,7 +683,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode, of mZeroDefault: result = checkDefault(c, n) of mIsolate: - if not checkIsolate(n[1]): + if not checkIsolate(c.config, n[1]): localError(c.config, n.info, "expression cannot be isolated: " & $n[1]) result = n of mPrivateAccess: