* Revert "make `system/fatal` importable (#20718)"
This reverts commit d735c447d3.
* relieve `std/assertions` of the sysFatal dep
This commit is contained in:
parent
8fb172c7a6
commit
12a20b9fb6
5 changed files with 27 additions and 28 deletions
|
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
## This module implements assertion handling.
|
## This module implements assertion handling.
|
||||||
|
|
||||||
import system/fatal
|
|
||||||
|
|
||||||
import std/private/miscdollars
|
import std/private/miscdollars
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# helpers
|
# helpers
|
||||||
|
|
@ -30,7 +28,7 @@ when not defined(nimHasSinkInference):
|
||||||
|
|
||||||
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
proc raiseAssert*(msg: string) {.noinline, noreturn, nosinks.} =
|
||||||
## Raises an `AssertionDefect` with `msg`.
|
## Raises an `AssertionDefect` with `msg`.
|
||||||
sysFatal(AssertionDefect, msg)
|
raise newException(AssertionDefect, msg)
|
||||||
|
|
||||||
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||||
## Raises an `AssertionDefect` with `msg`, but this is hidden
|
## Raises an `AssertionDefect` with `msg`, but this is hidden
|
||||||
|
|
|
||||||
|
|
@ -1637,13 +1637,8 @@ when not defined(nimscript):
|
||||||
## for debug builds. Since it's usually used for debugging, this
|
## for debug builds. Since it's usually used for debugging, this
|
||||||
## is proclaimed to have no IO effect!
|
## is proclaimed to have no IO effect!
|
||||||
|
|
||||||
|
when not declared(sysFatal):
|
||||||
when defined(nimHasExceptionsQuery):
|
include "system/fatal"
|
||||||
const gotoBasedExceptions = compileOption("exceptions", "goto")
|
|
||||||
else:
|
|
||||||
const gotoBasedExceptions = false
|
|
||||||
|
|
||||||
import system/fatal
|
|
||||||
|
|
||||||
when not defined(nimscript):
|
when not defined(nimscript):
|
||||||
{.push stackTrace: off, profiler: off.}
|
{.push stackTrace: off, profiler: off.}
|
||||||
|
|
@ -1656,6 +1651,12 @@ when not defined(nimscript):
|
||||||
when defined(nimV2):
|
when defined(nimV2):
|
||||||
include system/arc
|
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):
|
when not defined(nimPreviewSlimSystem):
|
||||||
{.deprecated: "assertions is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/assertions`".}
|
{.deprecated: "assertions is about to move out of system; use `-d:nimPreviewSlimSystem` and import `std/assertions`".}
|
||||||
import std/assertions
|
import std/assertions
|
||||||
|
|
@ -1863,12 +1864,6 @@ proc debugEcho*(x: varargs[typed, `$`]) {.magic: "Echo", noSideEffect,
|
||||||
## for debugging routines marked as `noSideEffect
|
## for debugging routines marked as `noSideEffect
|
||||||
## <manual.html#pragmas-nosideeffect-pragma>`_.
|
## <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):
|
when hostOS == "standalone" and defined(nogc):
|
||||||
proc nimToCStringConv(s: NimString): cstring {.compilerproc, inline.} =
|
proc nimToCStringConv(s: NimString): cstring {.compilerproc, inline.} =
|
||||||
if s == nil or s.len == 0: result = cstring""
|
if s == nil or s.len == 0: result = cstring""
|
||||||
|
|
|
||||||
|
|
@ -9,22 +9,27 @@
|
||||||
|
|
||||||
{.push profiler: off.}
|
{.push profiler: off.}
|
||||||
|
|
||||||
|
when defined(nimHasExceptionsQuery):
|
||||||
|
const gotoBasedExceptions = compileOption("exceptions", "goto")
|
||||||
|
else:
|
||||||
|
const gotoBasedExceptions = false
|
||||||
|
|
||||||
when hostOS == "standalone":
|
when hostOS == "standalone":
|
||||||
include "$projectpath/panicoverride"
|
include "$projectpath/panicoverride"
|
||||||
|
|
||||||
func sysFatal*(exceptn: typedesc, message: string) {.inline.} =
|
func sysFatal(exceptn: typedesc, message: string) {.inline.} =
|
||||||
panic(message)
|
panic(message)
|
||||||
|
|
||||||
func sysFatal*(exceptn: typedesc, message, arg: string) {.inline.} =
|
func sysFatal(exceptn: typedesc, message, arg: string) {.inline.} =
|
||||||
rawoutput(message)
|
rawoutput(message)
|
||||||
panic(arg)
|
panic(arg)
|
||||||
|
|
||||||
elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
|
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 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:
|
when nimvm:
|
||||||
# TODO when doAssertRaises works in CT, add a test for it
|
# TODO when doAssertRaises works in CT, add a test for it
|
||||||
raise (ref exceptn)(msg: message & arg)
|
raise (ref exceptn)(msg: message & arg)
|
||||||
|
|
@ -41,14 +46,14 @@ elif (defined(nimQuirky) or defined(nimPanics)) and not defined(nimscript):
|
||||||
cstderr.rawWrite buf
|
cstderr.rawWrite buf
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
||||||
sysFatal(exceptn, message, "")
|
sysFatal(exceptn, message, "")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
func sysFatal*(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
func sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
||||||
raise (ref exceptn)(msg: message)
|
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)
|
raise (ref exceptn)(msg: message & arg)
|
||||||
|
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ tassert_c.nim(35) tassert_c
|
||||||
tassert_c.nim(34) foo
|
tassert_c.nim(34) foo
|
||||||
assertions.nim(*) failedAssertImpl
|
assertions.nim(*) failedAssertImpl
|
||||||
assertions.nim(*) raiseAssert
|
assertions.nim(*) raiseAssert
|
||||||
fatal.nim(*) sysFatal"""
|
"""
|
||||||
|
|
||||||
proc tmatch(x, p: string): bool =
|
proc tmatch(x, p: string): bool =
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "unhandled exception:"
|
errormsg: "unhandled exception: t9768.nim(24, 12) `a < 4` [AssertionDefect]"
|
||||||
file: "system/fatal.nim"
|
file: "std/assertions.nim"
|
||||||
nimout: '''
|
nimout: '''
|
||||||
stack trace: (most recent call last)
|
stack trace: (most recent call last)
|
||||||
t9768.nim(28, 33) main
|
t9768.nim(29, 33) main
|
||||||
t9768.nim(23, 11) foo1
|
t9768.nim(24, 11) foo1
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -17,6 +17,7 @@ t9768.nim(23, 11) foo1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## line 20
|
## line 20
|
||||||
|
|
||||||
proc foo1(a: int): auto =
|
proc foo1(a: int): auto =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue