From 3bc625aff1664eb4206ae90d0a132c8f717e651d Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 12 May 2021 22:00:37 +0200 Subject: ORC: progress (#18000) * ORC: progress * ORC: bugfix; don't follow acyclic data even if only at runtime the subtype is marked as acyclic * progress * minor style changes --- lib/system/orc.nim | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'lib/system/orc.nim') diff --git a/lib/system/orc.nim b/lib/system/orc.nim index 8a62ef4bb..df81afcf1 100644 --- a/lib/system/orc.nim +++ b/lib/system/orc.nim @@ -109,9 +109,21 @@ proc free(s: Cell; desc: PNimTypeV2) {.inline.} = nimRawDispose(p, desc.align) +template orcAssert(cond, msg) = + when logOrc: + if not cond: + cfprintf(cstderr, "[Bug!] %s\n", msg) + quit 1 + +when logOrc: + proc strstr(s, sub: cstring): cstring {.header: "", importc.} + proc nimTraceRef(q: pointer; desc: PNimTypeV2; env: pointer) {.compilerRtl, inline.} = let p = cast[ptr pointer](q) if p[] != nil: + + orcAssert strstr(desc.name, "TType") == nil, "following a TType but it's acyclic!" + var j = cast[ptr GcEnv](env) j.traceStack.add(head p[], desc) @@ -121,12 +133,6 @@ proc nimTraceRefDyn(q: pointer; env: pointer) {.compilerRtl, inline.} = var j = cast[ptr GcEnv](env) j.traceStack.add(head p[], cast[ptr PNimTypeV2](p[])[]) -template orcAssert(cond, msg) = - when logOrc: - if not cond: - cfprintf(cstderr, "[Bug!] %s\n", msg) - quit 1 - var roots {.threadvar.}: CellSeq @@ -402,6 +408,8 @@ proc registerCycle(s: Cell; desc: PNimTypeV2) = when logOrc: writeCell("[added root]", s, desc) + orcAssert strstr(desc.name, "TType") == nil, "added a TType as a root!" + proc GC_runOrc* = ## Forces a cycle collection pass. collectCycles() @@ -436,10 +444,15 @@ proc GC_disableMarkAndSweep*() = ## For `--gc:orc` an alias for `GC_disableOrc`. GC_disableOrc() +const + acyclicFlag = 1 # see also cggtypes.nim, proc genTypeInfoV2Impl + when optimizedOrc: - template markedAsCyclic(s: Cell): bool = (s.rc and maybeCycle) != 0 + template markedAsCyclic(s: Cell; desc: PNimTypeV2): bool = + (desc.flags and acyclicFlag) == 0 and (s.rc and maybeCycle) != 0 else: - template markedAsCyclic(s: Cell): bool = true + template markedAsCyclic(s: Cell; desc: PNimTypeV2): bool = + (desc.flags and acyclicFlag) == 0 proc rememberCycle(isDestroyAction: bool; s: Cell; desc: PNimTypeV2) {.noinline.} = if isDestroyAction: @@ -448,7 +461,7 @@ proc rememberCycle(isDestroyAction: bool; s: Cell; desc: PNimTypeV2) {.noinline. else: # do not call 'rememberCycle' again unless this cell # got an 'incRef' event: - if s.rootIdx == 0 and markedAsCyclic(s): + if s.rootIdx == 0 and markedAsCyclic(s, desc): s.setColor colBlack registerCycle(s, desc) -- cgit 1.4.1-2-gfad0