-
-
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
Macro generating lambda containing ident("auto")
and genSym
causes SIGSEGV
#24048
Labels
Comments
johanobergman
changed the title
Macro generating lambda containing
Macro generating lambda containing Sep 2, 2024
ident("auto") and
genSym` causes SIGSEGVident("auto")
and genSym
causes SIGSEGV
!nim c import macros
proc map(fn: proc(val: int): void) = fn(1)
# This works fine, and is the exact same function call as what's
# generated by the macro `aBug`.
map proc(val: auto): void =
let variable = 123
macro aBug() =
# 1. let sym = ident("variable")
let sym = genSym(nskLet, "variable")
let letStmt = newLetStmt(sym, newLit(123))
let lambda = newProc(
params = @[
ident("void"),
newIdentDefs(ident("val"), ident("auto")),
# 2. newIdentDefs(ident("val"), ident("int")),
],
body = newStmtList(letStmt),
procType = nnkLambda
)
result = newCall(bindSym("map"), lambda)
echo repr result
echo treeRepr result
aBug() |
🐧 Linux bisect by @juancarlospaco (collaborator)devel 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) stable 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) 2.0.8 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) 2.0.0 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) 1.6.20 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) 1.4.8 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) 1.2.18 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) 1.0.10 👎 FAILOutput
IRCompiled filesize0 (0 bytes)
Stats
ASTnnkStmtList.newTree(
nnkImportStmt.newTree(
newIdentNode("macros")
),
nnkProcDef.newTree(
newIdentNode("map"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode(),
nnkIdentDefs.newTree(
newIdentNode("fn"),
nnkProcTy.newTree(
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("int"),
newEmptyNode()
)
),
newEmptyNode()
),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkCall.newTree(
newIdentNode("fn"),
newLit(1)
)
)
),
nnkCommand.newTree(
newIdentNode("map"),
nnkLambda.newTree(
newEmptyNode(),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("void"),
nnkIdentDefs.newTree(
newIdentNode("val"),
newIdentNode("auto"),
newEmptyNode()
)
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("variable"),
newEmptyNode(),
newLit(123)
)
)
)
)
),
nnkMacroDef.newTree(
newIdentNode("aBug"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newEmptyNode()
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("sym"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("genSym"),
newIdentNode("nskLet"),
newLit("variable")
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("letStmt"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newLetStmt"),
newIdentNode("sym"),
nnkCall.newTree(
newIdentNode("newLit"),
newLit(123)
)
)
)
),
nnkLetSection.newTree(
nnkIdentDefs.newTree(
newIdentNode("lambda"),
newEmptyNode(),
nnkCall.newTree(
newIdentNode("newProc"),
nnkExprEqExpr.newTree(
newIdentNode("params"),
nnkPrefix.newTree(
newIdentNode("@"),
nnkBracket.newTree(
nnkCall.newTree(
newIdentNode("ident"),
newLit("void")
),
nnkCall.newTree(
newIdentNode("newIdentDefs"),
nnkCall.newTree(
newIdentNode("ident"),
newLit("val")
),
nnkCall.newTree(
newIdentNode("ident"),
newLit("auto")
)
)
)
)
),
nnkExprEqExpr.newTree(
newIdentNode("body"),
nnkCall.newTree(
newIdentNode("newStmtList"),
newIdentNode("letStmt")
)
),
nnkExprEqExpr.newTree(
newIdentNode("procType"),
newIdentNode("nnkLambda")
)
)
)
),
nnkAsgn.newTree(
newIdentNode("result"),
nnkCall.newTree(
newIdentNode("newCall"),
nnkCall.newTree(
newIdentNode("bindSym"),
newLit("map")
),
newIdentNode("lambda")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("repr"),
newIdentNode("result")
)
),
nnkCommand.newTree(
newIdentNode("echo"),
nnkCommand.newTree(
newIdentNode("treeRepr"),
newIdentNode("result")
)
)
)
),
nnkCall.newTree(
newIdentNode("aBug")
)
) Stats
🤖 Bug found in |
metagn
added a commit
to metagn/Nim
that referenced
this issue
Sep 2, 2024
Araq
pushed a commit
that referenced
this issue
Sep 3, 2024
fixes #24048 Generic lambdas get instantiated via `replaceTypesInBody` which calls `replaceTypeVarsN` on the body of the lambda. This body can contain sym nodes of gensym symbols generated by macros, which have `nil` type. But a piece of code in `replaceTypeVarsN` checks whether the type of a symbol is equal to `void` without checking if it's `nil` first, which causes a segfault. Now it also checks that the type of the symbol isn't `nil` for it to be `void`.
That was quick - thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The macro
aBug
defined below generates the following code:Calling the macro crashes with
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
.It seems to be caused by a combination of the use of
genSym
, andauto
as the type for the lambda parameterval
.Reproduction
Using 1.
ident
instead ofgenSym
doesn't crash but doesn't generate a unique name.Using 2.
int
instead ofauto
as the type forval
doesn't crash.Nim Version
Nim Compiler Version 2.0.8 [MacOSX: amd64]
Compiled at 2024-09-02
Copyright (c) 2006-2023 by Andreas Rumpf
Current Output
Expected Output
No response
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: