forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
645: make `goto` exceptions the default r=saem a=zerbina ## Summary This is a preparation for the removal of the `setjmp` and `quirky` exceptions modes. `goto` exceptions were already the default when using `--gc:arc|orc`. * fix the programs crashing when a thread was created and both thread- local storage emulation and `--exceptions:goto` were enabled * fix execution continuing after a call to an RVO-using closure when using `--exceptions:goto` * fix an issue where assignments were observable if the right-hand expression is a call that raised an exception * remove the `segfaults` standard library module; its current implementation is incompatible with anything besides setjmp-exceptions * `--exceptions:native` now means `--exceptions:goto` when using the C target There's currently an issue with the ordering of routines in the `system` module, which prevents `nimrtl` from compiling when using `--exceptions:goto`. ## Details The infinite recursion error that occurred when using emulated thread- local storage is caused by the procedure for accessing emulated threadvars (`GetThreadLocalVars`) getting an error flag query (read, access of a threadvar) injected, now that `system` procedures are no longer treated as never raising a defect. The intermediate solution: disable error flag injection for all `.compilerproc`s. As a consequence, exceptional control-flow inside their immediate bodies is no longer possible. In order to still support raise-dispatcher-like compilerprocs (e.g. `raiseFloatOverflow`), an unconditional return is inserted after the call to a `noreturn` procedure when inside a procedure that has the error flag disabled. In addition, special-case the `threadProcWrapper` system procedure to also have the the error flag (and thus exceptional control-flow) disabled, as it is responsible for setting up the emulated thread-local storage. ### Standard Library The `segfaults` module implicitly relied on `setjmp`-exceptions, as only `longjmp` is able to leave the signal handler and enter the NimSkull exception handler without additional support from the code generator. Since it would become non-functional with the planned removal of `setjmp`-exceptions, it is removed already. Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
18 changed files
with
116 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
# imported by other modules, unlike helpers.nim which is included | ||
# xxx this is now included instead of imported, we should import instead | ||
|
||
# NOTE: these routines are used by compilerprocs raising exceptions, which | ||
# currently cannot rely on finalizers (both explicit and implicit). In other | ||
# words, the routines here need to make sure that they don't inject any local | ||
# or temporary that requires destruction. | ||
|
||
proc formatErrorIndexBoundStr(i, a, b: sink string): string = | ||
"index " & $i & " not in " & $a & " .. " & $b | ||
|
||
template formatErrorIndexBound*[T](i, a, b: T): string = | ||
when defined(standalone): | ||
"indexOutOfBounds" | ||
else: | ||
if b < a: "index out of bounds, the container is empty" | ||
else: "index " & $i & " not in " & $a & " .. " & $b | ||
else: formatErrorIndexBoundStr($i, $a, $b) | ||
|
||
template formatErrorIndexBound*[T](i, n: T): string = | ||
formatErrorIndexBound(i, 0, n) | ||
|
||
template formatFieldDefect*(f, discVal): string = | ||
proc formatFieldDefect*(f, discVal: sink string): string = | ||
f & discVal & "'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
discard """ | ||
targets: c | ||
description: ''' | ||
Regression tests related for C code-generator issues related to | ||
goto-exceptions | ||
''' | ||
""" | ||
|
||
block missing_exception_control_flow: | ||
# no if-error-goto-exit was injected after the call to a closure procedure | ||
# using RVO. At the time of writing, arrays always use RVO when using the C | ||
# target. | ||
proc outer(p: ptr int): array[4, int] = | ||
proc inner(): array[4, int] = | ||
discard p # capture something | ||
raise CatchableError.newException("") | ||
|
||
result = inner() | ||
p[] = 1 # `p` is nil; the assignment must never be reached | ||
|
||
var caught = false | ||
try: | ||
discard outer(nil) | ||
except CatchableError: | ||
caught = true | ||
|
||
doAssert caught |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
discard """ | ||
targets: "c js vm" | ||
description: ''' | ||
Tests for assignments where an exception is raised during evaluation of | ||
the right-hand side | ||
''' | ||
""" | ||
|
||
block unobservable_rvo_assignment: | ||
# assigning the result of an RVO-using call to a variable that is also used | ||
# as one of the arguments must not be oversable when the call raises an | ||
# exception | ||
proc raiseEx(x: array[4, int]): array[4, int] = | ||
result[0] = 1 | ||
raise CatchableError.newException("") | ||
|
||
proc test() = | ||
var x: array[4, int] | ||
try: | ||
x = raiseEx(x) | ||
except CatchableError: | ||
doAssert x[0] == 0, "handler observed changed value" | ||
|
||
doAssert x[0] == 0, "following statement observed changed value" | ||
|
||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
discard """ | ||
ccodeCheck: "\\i @'__attribute__((noreturn))' .*" | ||
action: compile | ||
""" | ||
|
||
|
Oops, something went wrong.