-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix: crash when passing NimNode to static parameter #1449
fix: crash when passing NimNode to static parameter #1449
Conversation
The VM serialization logic already supports AST literals, but `mirgen` didn't let them through. Now it does.
`NimNode` values returned directly from VM execution were neither checked (for cycles), nor wrapped in a `nkNimNodeLit` tree, leaving them in an invalid state. The `vmcompilerserdes` handling for NimNodes is split into a separate procedure, which is then used by both `vmcompilerserdes` and `regToNode`.
The test covers both fixed issues, since the `newStmtList` call is fully evaluated first before it is passed to the macro (where it is then processed by `constDataToMir`).
The implementation relied on `regToNode` returning the the raw `PNode` for `NimNode` values. It no longer does, so the `opcRepr` logic is adjusted to manually handle the `NimNode` case.
@@ -2490,6 +2490,8 @@ proc constDataToMir*(env: var MirEnv, n: PNode): MirTree = | |||
bu.use toFloatLiteral(env, n) | |||
of nkStrLiterals: | |||
bu.use strLiteral(env, n.strVal, typ) | |||
of nkNimNodeLit: |
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.
Yay, nkNimNodeLit
is becoming more pervasive, this means fewer places where AST is ambiguously passed around.
newNodeIT(nkEmpty, info, formal), | ||
PAstDiag(kind: adCyclicTree, cyclic: n)) | ||
else: | ||
result = newTreeIT(nkNimNodeLit, info, formal): n |
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.
Don't see this as an issue now, and probably ever, but it looks like we're going to treat nkNimNodeLit
to mean either a literal/static AST value or dynamic AST value. Where the latter one is generated on the fly, at compile time.
/merge |
Merge requested by: @saem Contents after the first section break of the PR description has been removed and preserved below: |
Summary
static
parameterNimNode
-returning constantexpression
Details
There were two problems:
nkNimNodeLit
wasn't handled in constant data expression bymirgen
NimNode
values returned directly from a VM invocation weren'twrapped in
nkNimNodeLit
treesFor handling
NimNode
values invm.regToNode
, the existingdeserialization logic for
NimNode
values invmcompilerserdes
ismoved to a separate procedure, so that it can be used by
regToNode
.The
opcRepr
implementation relied onregToNode
always returningan unwrapped
PNode
-- it is adjusted to manually handleNimNode
values.
A test covering both issues is added.
Fixes #1448.