-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VM callbacks can now raise (and be caught, or show their stacktrace) #13714
Conversation
@@ -540,6 +540,27 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = | |||
"ra", regDescr("ra", ra), "rb", regDescr("rb", instr.regB), | |||
"rc", regDescr("rc", instr.regC)] | |||
|
|||
proc onProcCall(prc: PSym, isClosure: bool, rb = 0, rc = 0, regs2: var seq[TFullReg]) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to reviewer: this code blocks is mostly moved without change; the only change involves instances of regs2
vs regs
(1 regs
left intentionally)
I can't find the test case. |
done PTAL |
72948e3
to
6ea4da8
Compare
# can add more hardcoded standard types here | ||
fun(OSError) | ||
fun(IOError) | ||
fun(AssertionError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is horrible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are adding a new compiler feature: internalproc
. Please make a separate PR for that feature alone. You can reference this PR there. I think that feature should be reviewed and tested independently.
This is not a full review yet. I just skimmed the diff.
# can add more hardcoded standard types here | ||
fun(OSError) | ||
fun(IOError) | ||
fun(AssertionError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does thins mean that only OSError
, IOError
and AssertionError
can be raised? Isn't there space to have a generic solution here that works on all error kinds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this bit needs improvement. Can't you just pass already created object and raise it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not possible to use compilerProc here then it needs to be moved into compiler
6ea4da8
to
6117e08
Compare
I have reviewed this PR and really like it.
|
I have checked again and i think it safe to assume that wrapped proc can always raise exception, little overhead is added for potential exception handling. |
# can add more hardcoded standard types here | ||
fun(OSError) | ||
fun(IOError) | ||
fun(AssertionError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this bit needs improvement. Can't you just pass already created object and raise it?
# can add more hardcoded standard types here | ||
fun(OSError) | ||
fun(IOError) | ||
fun(AssertionError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not possible to use compilerProc here then it needs to be moved into compiler
@@ -24,7 +24,7 @@ const | |||
## common pragmas for declarations, to a good approximation | |||
procPragmas* = declPragmas + {FirstCallConv..LastCallConv, | |||
wMagic, wNoSideEffect, wSideEffect, wNoreturn, wNosinks, wDynlib, wHeader, | |||
wCompilerProc, wNonReloadable, wCore, wProcVar, wVarargs, wCompileTime, wMerge, | |||
wCompilerProc, wNonReloadable, wCore, wInternalProc, wProcVar, wVarargs, wCompileTime, wMerge, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important to avoid introducing new pragmas
The addition to system.nim is terrible and the feature itself is of questionable value. Yes, I know you will not stop until everything from os.nim is available in the VM, but I don't like it and the existing mechanism might suffice. But as others remarked the worst part is the new pragma and the system.nim additions neither of which are required afaict. |
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
before PR
VM callbacks can't be caught, so code behaves differently at RT vs CT if VM code calls a callback that raises. eg:
catch
doesn't workafter PR
registerCallback(.., mayRaise=true)
walkDir(..,checkDir=true)
,writeFile
,removeDir
etc now work correctly in VMlistFiles(..,checkDir=true)
+ friends now work; I did not change the default semantic to be consistent withwalkDir
){.internalproc.}
), analog to{.compilerproc.}
, but for semantic phase instead of codegen. This enables writing handlers in pure nim code instead of having to manually write AST; this not only simplifies writing compiler code, but it also allows change those handlers without having to recompile nim. A key aspect is that these are private (such symbols don't need to be exported).example
before PR: no context shown, hard to debug in complex programs
after PR:
stacktrace inside VM callback
furthermore, when nim itself is compiled with
--stacktace
, the msg will also show the VM stacktrace (truncated to the useful part) eg:TODO for future PR's
opcNDynBindSym
links