Skip to content

Commit 12a20b9

Browse files
authored
revert #20719; relieve std/assertions of the sysFatal dep (#20743)
* Revert "make `system/fatal` importable (#20718)" This reverts commit d735c44. * relieve `std/assertions` of the sysFatal dep
1 parent 8fb172c commit 12a20b9

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

lib/std/assertions.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
## This module implements assertion handling.
1111

12-
import system/fatal
13-
1412
import std/private/miscdollars
1513
# ---------------------------------------------------------------------------
1614
# helpers
@@ -30,7 +28,7 @@ when not defined(nimHasSinkInference):
3028

3129
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
3230
## Raises an `AssertionDefect` with `msg`.
33-
sysFatal(AssertionDefect, msg)
31+
raise newException(AssertionDefect, msg)
3432

3533
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
3634
## Raises an `AssertionDefect` with `msg`, but this is hidden

lib/system.nim

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,13 +1637,8 @@ when not defined(nimscript):
16371637
## for debug builds. Since it's usually used for debugging, this
16381638
## is proclaimed to have no IO effect!
16391639

1640-
1641-
when defined(nimHasExceptionsQuery):
1642-
const gotoBasedExceptions = compileOption("exceptions", "goto")
1643-
else:
1644-
const gotoBasedExceptions = false
1645-
1646-
import system/fatal
1640+
when not declared(sysFatal):
1641+
include "system/fatal"
16471642

16481643
when not defined(nimscript):
16491644
{.push stackTrace: off, profiler: off.}
@@ -1656,6 +1651,12 @@ when not defined(nimscript):
16561651
when defined(nimV2):
16571652
include system/arc
16581653

1654+
template newException*(exceptn: typedesc, message: string;
1655+
parentException: ref Exception = nil): untyped =
1656+
## Creates an exception object of type `exceptn` and sets its `msg` field
1657+
## to `message`. Returns the new exception object.
1658+
(ref exceptn)(msg: message, parent: parentException)
1659+
16591660
when not defined(nimPreviewSlimSystem):
16601661
{.deprecated: "assertions is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/assertions`".}
16611662
import std/assertions
@@ -1863,12 +1864,6 @@ proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect,
18631864
## for debugging routines marked as `noSideEffect
18641865
## <manual.html#pragmas-nosideeffect-pragma>`_.
18651866

1866-
template newException*(exceptn: typedesc, message: string;
1867-
parentException: ref Exception = nil): untyped =
1868-
## Creates an exception object of type `exceptn` and sets its `msg` field
1869-
## to `message`. Returns the new exception object.
1870-
(ref exceptn)(msg: message, parent: parentException)
1871-
18721867
when hostOS == "standalone" and defined(nogc):
18731868
proc nimToCStringConv(s: NimString): cstring {.compilerproc, inline.} =
18741869
if s == nil or s.len == 0: result = cstring""

lib/system/fatal.nim

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@
99

1010
{.push profiler: off.}
1111

12+
when defined(nimHasExceptionsQuery):
13+
const gotoBasedExceptions = compileOption("exceptions", "goto")
14+
else:
15+
const gotoBasedExceptions = false
16+
1217
when hostOS == "standalone":
1318
include "$projectpath/panicoverride"
1419

15-
func sysFatal*(exceptn: typedesc, message: string) {.inline.} =
20+
func sysFatal(exceptn: typedesc, message: string) {.inline.} =
1621
panic(message)
1722

18-
func sysFatal*(exceptn: typedesc, message, arg: string) {.inline.} =
23+
func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
1924
rawoutput(message)
2025
panic(arg)
2126

2227
elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
23-
import system/ansi_c
28+
import ansi_c
2429

2530
func name(t: typedesc): string {.magic: "TypeTrait".}
2631

27-
func sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
32+
func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
2833
when nimvm:
2934
# TODO when doAssertRaises works in CT, add a test for it
3035
raise (ref exceptn)(msg: message & arg)
@@ -41,14 +46,14 @@ elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
4146
cstderr.rawWrite buf
4247
quit 1
4348

44-
func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} =
49+
func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
4550
sysFatal(exceptn, message, "")
4651

4752
else:
48-
func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} =
53+
func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
4954
raise (ref exceptn)(msg: message)
5055

51-
func sysFatal*(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
56+
func sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
5257
raise (ref exceptn)(msg: message & arg)
5358

5459
{.pop.}

tests/assert/tassert_c.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tassert_c.nim(35) tassert_c
88
tassert_c.nim(34) foo
99
assertions.nim(*) failedAssertImpl
1010
assertions.nim(*) raiseAssert
11-
fatal.nim(*) sysFatal"""
11+
"""
1212

1313
proc tmatch(x, p: string): bool =
1414
var i = 0

tests/errmsgs/t9768.nim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
discard """
2-
errormsg: "unhandled exception:"
3-
file: "system/fatal.nim"
2+
errormsg: "unhandled exception: t9768.nim(24, 12) `a < 4` [AssertionDefect]"
3+
file: "std/assertions.nim"
44
nimout: '''
55
stack trace: (most recent call last)
6-
t9768.nim(28, 33) main
7-
t9768.nim(23, 11) foo1
6+
t9768.nim(29, 33) main
7+
t9768.nim(24, 11) foo1
88
'''
99
"""
1010

@@ -17,6 +17,7 @@ t9768.nim(23, 11) foo1
1717

1818

1919

20+
2021
## line 20
2122

2223
proc foo1(a: int): auto =

0 commit comments

Comments
 (0)