Skip to content

Commit 3d63491

Browse files
arnetheducknarimiran
authored andcommitted
Ensure that gc interface remains non-raising (#25006)
GC_fullCollect in particular has an annoying `Exception` effect (cherry picked from commit aba9361)
1 parent 1f205a0 commit 3d63491

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

lib/system/arc.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ at offset 0 then. The ``ref`` object header is independent from the
1414
runtime type and only contains a reference count.
1515
]#
1616

17+
{.push raises: [].}
18+
1719
when defined(gcOrc):
1820
const
1921
rcIncrement = 0b10000 # so that lowest 4 bits are not touched
@@ -269,3 +271,5 @@ when defined(gcDestructors):
269271
proc nimGetVTable(p: pointer, index: int): pointer
270272
{.compilerRtl, inline, raises: [].} =
271273
result = cast[ptr PNimTypeV2](p).vTable[index]
274+
275+
{.pop.} # raises: []

lib/system/cyclebreaker.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const
6262
colorMask = 0b011
6363

6464
type
65-
TraceProc = proc (p, env: pointer) {.nimcall, benign.}
66-
DisposeProc = proc (p: pointer) {.nimcall, benign.}
65+
TraceProc = proc (p, env: pointer) {.nimcall, benign, raises: [].}
66+
DisposeProc = proc (p: pointer) {.nimcall, benign, raises: [].}
6767

6868
template color(c): untyped = c.rc and colorMask
6969
template setColor(c, col) =

lib/system/gc.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ comparisons).
6262
]#
6363

6464
{.push profiler:off.}
65+
{.push raises: [].}
6566

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

918+
{.pop.} # raises: []
917919
{.pop.} # profiler: off, stackTrace: off

lib/system/gc_interface.nim

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,33 @@ when hasAlloc and not defined(js) and not usesDestructors:
2525
proc GC_enable*() {.rtl, inl, benign, raises: [].}
2626
## Enables the GC again.
2727

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

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

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

44-
proc GC_ref*[T](x: ref T) {.magic: "GCref", benign.}
45-
proc GC_ref*[T](x: seq[T]) {.magic: "GCref", benign.}
46-
proc GC_ref*(x: string) {.magic: "GCref", benign.}
44+
proc GC_ref*[T](x: ref T) {.magic: "GCref", benign, raises: [].}
45+
proc GC_ref*[T](x: seq[T]) {.magic: "GCref", benign, raises: [].}
46+
proc GC_ref*(x: string) {.magic: "GCref", benign, raises: [].}
4747
## Marks the object `x` as referenced, so that it will not be freed until
4848
## it is unmarked via `GC_unref`.
4949
## If called n-times for the same object `x`,
5050
## n calls to `GC_unref` are needed to unmark `x`.
5151
52-
proc GC_unref*[T](x: ref T) {.magic: "GCunref", benign.}
53-
proc GC_unref*[T](x: seq[T]) {.magic: "GCunref", benign.}
54-
proc GC_unref*(x: string) {.magic: "GCunref", benign.}
52+
proc GC_unref*[T](x: ref T) {.magic: "GCunref", benign, raises: [].}
53+
proc GC_unref*[T](x: seq[T]) {.magic: "GCunref", benign, raises: [].}
54+
proc GC_unref*(x: string) {.magic: "GCunref", benign, raises: [].}
5555
## See the documentation of `GC_ref <#GC_ref,string>`_.
5656
5757
proc nimGC_setStackBottom*(theStackBottom: pointer) {.compilerRtl, noinline, benign, raises: [].}

lib/system/orc.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# R.D. Lins / Information Processing Letters 109 (2008) 71–78
1515
#
1616

17+
{.push raises: [].}
18+
1719
include cellseqs_v2
1820

1921
const
@@ -27,8 +29,8 @@ const
2729
logOrc = defined(nimArcIds)
2830

2931
type
30-
TraceProc = proc (p, env: pointer) {.nimcall, benign.}
31-
DisposeProc = proc (p: pointer) {.nimcall, benign.}
32+
TraceProc = proc (p, env: pointer) {.nimcall, benign, raises: [].}
33+
DisposeProc = proc (p: pointer) {.nimcall, benign, raises: [].}
3234

3335
template color(c): untyped = c.rc and colorMask
3436
template setColor(c, col) =
@@ -545,3 +547,5 @@ proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerR
545547
dec cell.rc, rcIncrement
546548
#if cell.color == colPurple:
547549
rememberCycle(result, cell, desc)
550+
551+
{.pop.} # raises: []

0 commit comments

Comments
 (0)