allow old styled RTTI for arc/orc (#15331)
This commit is contained in:
parent
0aaf4e2dfa
commit
fd31e8ff6f
23 changed files with 512 additions and 303 deletions
|
|
@ -78,14 +78,14 @@ type
|
|||
GcEnv = object
|
||||
traceStack: CellSeq
|
||||
|
||||
proc trace(p: pointer; desc: PNimType; j: var GcEnv) {.inline.} =
|
||||
proc trace(p: pointer; desc: PNimTypeV2; j: var GcEnv) {.inline.} =
|
||||
when false:
|
||||
cprintf("[Trace] desc: %p %p\n", desc, p)
|
||||
cprintf("[Trace] trace: %p\n", desc.traceImpl)
|
||||
if desc.traceImpl != nil:
|
||||
cast[TraceProc](desc.traceImpl)(p, addr(j))
|
||||
|
||||
proc nimTraceRef(q: pointer; desc: PNimType; env: pointer) {.compilerRtl.} =
|
||||
proc nimTraceRef(q: pointer; desc: PNimTypeV2; env: pointer) {.compilerRtl.} =
|
||||
let p = cast[ptr pointer](q)
|
||||
when traceCollector:
|
||||
cprintf("[Trace] raw: %p\n", p)
|
||||
|
|
@ -101,11 +101,11 @@ proc nimTraceRefDyn(q: pointer; env: pointer) {.compilerRtl.} =
|
|||
cprintf("[TraceDyn] deref: %p\n", p[])
|
||||
if p[] != nil:
|
||||
var j = cast[ptr GcEnv](env)
|
||||
j.traceStack.add(p, cast[ptr PNimType](p[])[])
|
||||
j.traceStack.add(p, cast[ptr PNimTypeV2](p[])[])
|
||||
|
||||
var markerGeneration: int
|
||||
|
||||
proc breakCycles(s: Cell; desc: PNimType) =
|
||||
proc breakCycles(s: Cell; desc: PNimTypeV2) =
|
||||
let markerColor = if (markerGeneration and 1) == 0: colRed
|
||||
else: colYellow
|
||||
atomicInc markerGeneration
|
||||
|
|
@ -147,7 +147,7 @@ proc thinout*[T](x: ref T) {.inline.} =
|
|||
## and thus would keep the graph from being freed are `nil`'ed.
|
||||
## This is a form of cycle collection that works well with Nim's ARC
|
||||
## and its associated cost model.
|
||||
proc getDynamicTypeInfo[T](x: T): PNimType {.magic: "GetTypeInfo", noSideEffect, locks: 0.}
|
||||
proc getDynamicTypeInfo[T](x: T): PNimTypeV2 {.magic: "GetTypeInfoV2", noSideEffect, locks: 0.}
|
||||
|
||||
breakCycles(head(cast[pointer](x)), getDynamicTypeInfo(x[]))
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ proc thinout*[T: proc](x: T) {.inline.} =
|
|||
""".}
|
||||
|
||||
let p = rawEnv(x)
|
||||
breakCycles(head(p), cast[ptr PNimType](p)[])
|
||||
breakCycles(head(p), cast[ptr PNimTypeV2](p)[])
|
||||
|
||||
proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} =
|
||||
if p != nil:
|
||||
|
|
@ -171,7 +171,7 @@ proc nimDecRefIsLastCyclicDyn(p: pointer): bool {.compilerRtl, inl.} =
|
|||
# According to Lins it's correct to do nothing else here.
|
||||
#cprintf("[DeCREF] %p\n", p)
|
||||
|
||||
proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimType): bool {.compilerRtl, inl.} =
|
||||
proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerRtl, inl.} =
|
||||
if p != nil:
|
||||
var cell = head(p)
|
||||
if (cell.rc and not rcMask) == 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue