From b1d9af4d5fe693b32185379625cdaff947966385 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Wed, 18 Jun 2025 14:38:01 +0200 Subject: [PATCH] Ensure that gc interface remains non-raising (#25006) GC_fullCollect in particular has an annoying `Exception` effect (cherry picked from commit aba93615105b8243b95c534f2d7c39aa69ace997) --- lib/system/arc.nim | 4 ++++ lib/system/cyclebreaker.nim | 4 ++-- lib/system/gc.nim | 2 ++ lib/system/gc_interface.nim | 20 ++++++++++---------- lib/system/orc.nim | 8 ++++++-- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/system/arc.nim b/lib/system/arc.nim index a2c2cd7466..e0498a07e1 100644 --- a/lib/system/arc.nim +++ b/lib/system/arc.nim @@ -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 @@ -239,3 +241,5 @@ template tearDownForeignThreadGc* = proc isObjDisplayCheck(source: PNimTypeV2, targetDepth: int16, token: uint32): bool {.compilerRtl, inl.} = result = targetDepth <= source.depth and source.display[targetDepth] == token + +{.pop.} # raises: [] diff --git a/lib/system/cyclebreaker.nim b/lib/system/cyclebreaker.nim index 45b0a5a650..d611322d96 100644 --- a/lib/system/cyclebreaker.nim +++ b/lib/system/cyclebreaker.nim @@ -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) = diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 606ff3c7c3..68d5f3db3b 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -60,6 +60,7 @@ comparisons). ]# {.push profiler:off.} +{.push raises: [].} const CycleIncrease = 2 # is a multiplicative increase @@ -912,4 +913,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 diff --git a/lib/system/gc_interface.nim b/lib/system/gc_interface.nim index 84145f33a9..4540db21f2 100644 --- a/lib/system/gc_interface.nim +++ b/lib/system/gc_interface.nim @@ -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: [].} diff --git a/lib/system/orc.nim b/lib/system/orc.nim index 73ecba0974..d9e422321b 100644 --- a/lib/system/orc.nim +++ b/lib/system/orc.nim @@ -14,6 +14,8 @@ # R.D. Lins / Information Processing Letters 109 (2008) 71–78 # +{.push raises: [].} + include cellseqs_v2 const @@ -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) = @@ -520,3 +522,5 @@ proc nimDecRefIsLastCyclicStatic(p: pointer; desc: PNimTypeV2): bool {.compilerR dec cell.rc, rcIncrement #if cell.color == colPurple: rememberCycle(result, cell, desc) + +{.pop.} # raises: []