Skip to content

Ensure that gc interface remains non-raising #25006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/system/arc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ at offset 0 then. The ``ref`` object header is independent from the
runtime type and only contains a reference count.
]#

{.push raises: [].}

when defined(gcOrc):
const
rcIncrement = 0b10000 # so that lowest 4 bits are not touched
Expand Down Expand Up @@ -269,3 +271,5 @@ when defined(gcDestructors):
proc nimGetVTable(p: pointer, index: int): pointer
{.compilerRtl, inline, raises: [].} =
result = cast[ptr PNimTypeV2](p).vTable[index]

{.pop.} # raises: []
4 changes: 2 additions & 2 deletions lib/system/cyclebreaker.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const
colorMask = 0b011

type
TraceProc = proc (p, env: pointer) {.nimcall, benign.}
DisposeProc = proc (p: pointer) {.nimcall, benign.}
TraceProc = proc (p, env: pointer) {.nimcall, benign, raises: [].}
DisposeProc = proc (p: pointer) {.nimcall, benign, raises: [].}

template color(c): untyped = c.rc and colorMask
template setColor(c, col) =
Expand Down
2 changes: 2 additions & 0 deletions lib/system/gc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ comparisons).
]#

{.push profiler:off.}
{.push raises: [].}

const
CycleIncrease = 2 # is a multiplicative increase
Expand Down Expand Up @@ -914,4 +915,5 @@ when not defined(useNimRtl):
result.add "[GC] stack bottom: " & gch.stack.bottom.repr
result.add "[GC] max stack size: " & $gch.stat.maxStackSize & "\n"

{.pop.} # raises: []
{.pop.} # profiler: off, stackTrace: off
20 changes: 10 additions & 10 deletions lib/system/gc_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ when hasAlloc and not defined(js) and not usesDestructors:
proc GC_enable*() {.rtl, inl, benign, raises: [].}
## Enables the GC again.

proc GC_fullCollect*() {.rtl, benign.}
proc GC_fullCollect*() {.rtl, benign, raises: [].}
## Forces a full garbage collection pass.
## Ordinary code does not need to call this (and should not).

proc GC_enableMarkAndSweep*() {.rtl, benign.}
proc GC_disableMarkAndSweep*() {.rtl, benign.}
proc GC_enableMarkAndSweep*() {.rtl, benign, raises: [].}
proc GC_disableMarkAndSweep*() {.rtl, benign, raises: [].}
## The current implementation uses a reference counting garbage collector
## with a seldomly run mark and sweep phase to free cycles. The mark and
## sweep phase may take a long time and is not needed if the application
## does not create cycles. Thus the mark and sweep phase can be deactivated
## and activated separately from the rest of the GC.

proc GC_getStatistics*(): string {.rtl, benign.}
proc GC_getStatistics*(): string {.rtl, benign, raises: [].}
## Returns an informative string about the GC's activity. This may be useful
## for tweaking.

proc GC_ref*[T](x: ref T) {.magic: "GCref", benign.}
proc GC_ref*[T](x: seq[T]) {.magic: "GCref", benign.}
proc GC_ref*(x: string) {.magic: "GCref", benign.}
proc GC_ref*[T](x: ref T) {.magic: "GCref", benign, raises: [].}
proc GC_ref*[T](x: seq[T]) {.magic: "GCref", benign, raises: [].}
proc GC_ref*(x: string) {.magic: "GCref", benign, raises: [].}
## Marks the object `x` as referenced, so that it will not be freed until
## it is unmarked via `GC_unref`.
## If called n-times for the same object `x`,
## n calls to `GC_unref` are needed to unmark `x`.

proc GC_unref*[T](x: ref T) {.magic: "GCunref", benign.}
proc GC_unref*[T](x: seq[T]) {.magic: "GCunref", benign.}
proc GC_unref*(x: string) {.magic: "GCunref", benign.}
proc GC_unref*[T](x: ref T) {.magic: "GCunref", benign, raises: [].}
proc GC_unref*[T](x: seq[T]) {.magic: "GCunref", benign, raises: [].}
proc GC_unref*(x: string) {.magic: "GCunref", benign, raises: [].}
## See the documentation of `GC_ref <#GC_ref,string>`_.

proc nimGC_setStackBottom*(theStackBottom: pointer) {.compilerRtl, noinline, benign, raises: [].}
Expand Down
8 changes: 6 additions & 2 deletions lib/system/orc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# R.D. Lins / Information Processing Letters 109 (2008) 71–78
#

{.push raises: [].}

include cellseqs_v2

const
Expand All @@ -27,8 +29,8 @@ const
logOrc = defined(nimArcIds)

type
TraceProc = proc (p, env: pointer) {.nimcall, benign.}
DisposeProc = proc (p: pointer) {.nimcall, benign.}
TraceProc = proc (p, env: pointer) {.nimcall, benign, raises: [].}
DisposeProc = proc (p: pointer) {.nimcall, benign, raises: [].}

template color(c): untyped = c.rc and colorMask
template setColor(c, col) =
Expand Down Expand Up @@ -545,3 +547,5 @@ proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerR
dec cell.rc, rcIncrement
#if cell.color == colPurple:
rememberCycle(result, cell, desc)

{.pop.} # raises: []