summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-11-04 16:53:19 +0800
committerGitHub <noreply@github.com>2022-11-04 09:53:19 +0100
commit12a20b9fb67598558e60ae9ffa3ca9780c6d8cba (patch)
treed3d357aef3efc46f027106f31f696d5d5cfe58da /lib
parent8fb172c7a62732306ada098a276fada77f8f4805 (diff)
downloadNim-12a20b9fb67598558e60ae9ffa3ca9780c6d8cba.tar.gz
revert #20719; relieve `std/assertions` of the `sysFatal` dep (#20743)
* Revert "make `system/fatal` importable (#20718)"

This reverts commit d735c447d35948ef6fda8270d1665cbd66c4636a.

* relieve `std/assertions` of the sysFatal dep
Diffstat (limited to 'lib')
-rw-r--r--lib/std/assertions.nim4
-rw-r--r--lib/system.nim21
-rw-r--r--lib/system/fatal.nim19
3 files changed, 21 insertions, 23 deletions
diff --git a/lib/std/assertions.nim b/lib/std/assertions.nim
index a39aee6c8..03bab1b1b 100644
--- a/lib/std/assertions.nim
+++ b/lib/std/assertions.nim
@@ -9,8 +9,6 @@
 
 ## This module implements assertion handling.
 
-import system/fatal
-
 import std/private/miscdollars
 # ---------------------------------------------------------------------------
 # helpers
@@ -30,7 +28,7 @@ when not defined(nimHasSinkInference):
 
 proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
   ## Raises an `AssertionDefect` with `msg`.
-  sysFatal(AssertionDefect, msg)
+  raise newException(AssertionDefect, msg)
 
 proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
   ## Raises an `AssertionDefect` with `msg`, but this is hidden
diff --git a/lib/system.nim b/lib/system.nim
index e84971aa2..c670293d5 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -1637,13 +1637,8 @@ when not defined(nimscript):
     ## for debug builds. Since it's usually used for debugging, this
     ## is proclaimed to have no IO effect!
 
-
-when defined(nimHasExceptionsQuery):
-  const gotoBasedExceptions = compileOption("exceptions", "goto")
-else:
-  const gotoBasedExceptions = false
-
-import system/fatal
+when not declared(sysFatal):
+  include "system/fatal"
 
 when not defined(nimscript):
   {.push stackTrace: off, profiler: off.}
@@ -1656,6 +1651,12 @@ when not defined(nimscript):
 when defined(nimV2):
   include system/arc
 
+template newException*(exceptn: typedesc, message: string;
+                       parentException: ref Exception = nil): untyped =
+  ## Creates an exception object of type `exceptn` and sets its `msg` field
+  ## to `message`. Returns the new exception object.
+  (ref exceptn)(msg: message, parent: parentException)
+
 when not defined(nimPreviewSlimSystem):
   {.deprecated: "assertions is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/assertions`".}
   import std/assertions
@@ -1863,12 +1864,6 @@ proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect,
   ## for debugging routines marked as `noSideEffect
   ## <manual.html#pragmas-nosideeffect-pragma>`_.
 
-template newException*(exceptn: typedesc, message: string;
-                       parentException: ref Exception = nil): untyped =
-  ## Creates an exception object of type `exceptn` and sets its `msg` field
-  ## to `message`. Returns the new exception object.
-  (ref exceptn)(msg: message, parent: parentException)
-
 when hostOS == "standalone" and defined(nogc):
   proc nimToCStringConv(s: NimString): cstring {.compilerproc, inline.} =
     if s == nil or s.len == 0: result = cstring""
diff --git a/lib/system/fatal.nim b/lib/system/fatal.nim
index 6e2edf573..c01787a32 100644
--- a/lib/system/fatal.nim
+++ b/lib/system/fatal.nim
@@ -9,22 +9,27 @@
 
 {.push profiler: off.}
 
+when defined(nimHasExceptionsQuery):
+  const gotoBasedExceptions = compileOption("exceptions", "goto")
+else:
+  const gotoBasedExceptions = false
+
 when hostOS == "standalone":
   include "$projectpath/panicoverride"
 
-  func sysFatal*(exceptn: typedesc, message: string) {.inline.} =
+  func sysFatal(exceptn: typedesc, message: string) {.inline.} =
     panic(message)
 
-  func sysFatal*(exceptn: typedesc, message, arg: string) {.inline.} =
+  func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
     rawoutput(message)
     panic(arg)
 
 elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
-  import system/ansi_c
+  import ansi_c
 
   func name(t: typedesc): string {.magic: "TypeTrait".}
 
-  func sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
+  func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
     when nimvm:
       # TODO when doAssertRaises works in CT, add a test for it
       raise (ref exceptn)(msg: message & arg)
@@ -41,14 +46,14 @@ elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
         cstderr.rawWrite buf
       quit 1
 
-  func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} =
+  func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
     sysFatal(exceptn, message, "")
 
 else:
-  func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} =
+  func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
     raise (ref exceptn)(msg: message)
 
-  func sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
+  func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
     raise (ref exceptn)(msg: message & arg)
 
 {.pop.}