Skip to content

[Regression] Closure + Generics lead to stack overflow in VM #8432

@timotheecour

Description

@timotheecour

to reproduce: checkout code from here:
mratsim/Arraymancer#259 (which itself fixes mratsim/Arraymancer#258 to work with nim devel)
(eg: git clone https://github.com/timotheecour/Arraymancer/ && git checkout fix_258)
then:
choosenim devel
nimble test

it fails with:
Error: Execution failed with exit code 35584
... Command: "/Users/timothee/.nimble/bin/nim" c --noNimblePath --path:"/Users/timothee/.nimble/pkgs/nimblas-0.2.1" --path:"/Users/timothee/.nimble/pkgs/nimlapack-0.1.1" --path:"/Users/timothee/.nimble/pkgs/nimcuda-0.1.5" --path:"/Users/timothee/.nimble/pkgs/nimcl-0.1.3" --path:"/Users/timothee/.nimble/pkgs/opencl-1.0" --path:"/Users/timothee/.nimble/pkgs/clblast-0.0.1" --path:"/Users/timothee/.nimble/pkgs/opencl-1.0" --path:"/Users/timothee/.nimble/pkgs/stb_image-2.1" "--out:./build/tests_cpu" "--run" "--nimcache:"nimcache"" "tests/tests_cpu.nim"

and, after further simplification, this also fails:

nim c --noNimblePath --path:/Users/timothee/.nimble/pkgs/nimblas-0.2.1 --path:/Users/timothee/.nimble/pkgs/nimlapack-0.1.1 --path:/Users/timothee/.nimble/pkgs/nimcuda-0.1.5 --path:/Users/timothee/.nimble/pkgs/nimcl-0.1.3 --path:/Users/timothee/.nimble/pkgs/opencl-1.0 --path:/Users/timothee/.nimble/pkgs/clblast-0.0.1 --path:/Users/timothee/.nimble/pkgs/opencl-1.0 --path:/Users/timothee/.nimble/pkgs/stb_image-2.1 -o:build/tests_cpu4 tests/tests_cpu.nim && echo ok || echo error

prints: error at the end (just because I added && echo ok || echo error) (and build/tests_cpu4 isn't generated)

note: it works with choosenim stable, so looks like a regression

NOTE: after using nim_temp from ./koch temp --out:$nimc_D/bin/nim_temp, it fails with:
segmentation fault (and no error)

NOTE: after further investigation, with lldb -- $nimc_D/bin/nim_temp ... I get following stacktrace under lldb (didn't work under gdb... not sure whether gdb is supported?):

this probably indicates stack overflow from infinite recursion:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7ffeef3ffec8)
    frame #0: 0x000000010007c04b nim_temp semTypeIdent_RiNpYDzSB8OUnjHue9b4s2g + 75
nim_temp`semTypeIdent_RiNpYDzSB8OUnjHue9b4s2g:
->  0x10007c04b <+75>: callq  0x1000c6170               ; pickSym_qEI19b8oSbENdUu5eGgUxew
    0x10007c050 <+80>: movq   %rax, %rbx
    0x10007c053 <+83>: testq  %rbx, %rbx
    0x10007c056 <+86>: je     0x10007c06f               ; <+111>
Target 0: (nim_temp) stopped.

(bt)

    frame #52267: 0x000000010008b481 nim_temp generateInstance_6DlcdI8m136DxICzC80OKg + 1905
    frame #52268: 0x0000000100096d10 nim_temp semResolvedCall_5MPXOtDbEsx5nrtQw8MPZQ + 1408
    frame #52269: 0x0000000100093acb nim_temp semOverloadedCall_nZLg3oTYOieG4PAqQ1zu0A + 1083
    frame #52270: 0x00000001000927bc nim_temp semOverloadedCallAnalyseEffects_DSb9bsrZYfDcxANKVwjl9chA + 44
    frame #52271: 0x0000000100078ceb nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 3979
    frame #52272: 0x00000001000b1a3e nim_temp semOperand_tayBCUAEli3HMPwxdS9aMbg_26 + 30
    frame #52273: 0x00000001000df21e nim_temp matchesAux_5B328Lq3sbOWOpGv9bkDcTg + 2894
    frame #52274: 0x00000001000e0958 nim_temp matches_x3U2uVO0diqi4Z4tOU2y9aw_2 + 120
    frame #52275: 0x0000000100095643 nim_temp pickBestCandidate_WAPzOw27cCNyE9anuZ9a9cMaA + 611
    frame #52276: 0x0000000100095988 nim_temp resolveOverloads_wzM2ip7QP0Y3Z7WmKZZoBA + 312
    frame #52277: 0x0000000100093763 nim_temp semOverloadedCall_nZLg3oTYOieG4PAqQ1zu0A + 211
    frame #52278: 0x00000001000927bc nim_temp semOverloadedCallAnalyseEffects_DSb9bsrZYfDcxANKVwjl9chA + 44
    frame #52279: 0x0000000100078ceb nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 3979
    frame #52280: 0x000000010007b04b nim_temp semExprWithType_tayBCUAEli3HMPwxdS9aMbg + 27
    frame #52281: 0x00000001000a8cad nim_temp semVarOrLet_6Rdn0jKaIRKP81jsTLDciw + 589
    frame #52282: 0x00000001000787cf nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 2671
    frame #52283: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52284: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52285: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52286: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52287: 0x00000001000a7a2f nim_temp semBlock_NBTNEqzl5NBSHnN0VGYkSQ_42 + 255
    frame #52288: 0x0000000100078212 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1202
    frame #52289: 0x0000000100082d1a nim_temp semAfterMacroCall_00z3ReZzIEXfRQL9czzyLtA + 266
    frame #52290: 0x0000000100085c46 nim_temp semMacroExpr_woULc1D9b2DCEYOx5yRZXRg + 342
    frame #52291: 0x000000010009267a nim_temp afterCallActions_9bA5HQzp5SlBuAZ9a1ZzejHQ + 58
    frame #52292: 0x0000000100078d00 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 4000
    frame #52293: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52294: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52295: 0x0000000100082d1a nim_temp semAfterMacroCall_00z3ReZzIEXfRQL9czzyLtA + 266
    frame #52296: 0x0000000100085c46 nim_temp semMacroExpr_woULc1D9b2DCEYOx5yRZXRg + 342
    frame #52297: 0x000000010009267a nim_temp afterCallActions_9bA5HQzp5SlBuAZ9a1ZzejHQ + 58
    frame #52298: 0x0000000100078d00 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 4000
    frame #52299: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52300: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52301: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52302: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52303: 0x00000001000acb6c nim_temp semTry_NBTNEqzl5NBSHnN0VGYkSQ_49 + 172
    frame #52304: 0x0000000100078914 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 2996
    frame #52305: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52306: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52307: 0x00000001000a71aa nim_temp semIf_NBTNEqzl5NBSHnN0VGYkSQ_38 + 330
    frame #52308: 0x0000000100078159 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1017
    frame #52309: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52310: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52311: 0x0000000100082d5a nim_temp semAfterMacroCall_00z3ReZzIEXfRQL9czzyLtA + 330
    frame #52312: 0x0000000100082bd0 nim_temp semTemplateExpr_InSQ3LpBhnCqFgw1Hbb18Q + 160
    frame #52313: 0x000000010009269b nim_temp afterCallActions_9bA5HQzp5SlBuAZ9a1ZzejHQ + 91
    frame #52314: 0x0000000100078d00 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 4000
    frame #52315: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52316: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52317: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52318: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52319: 0x00000001000acb6c nim_temp semTry_NBTNEqzl5NBSHnN0VGYkSQ_49 + 172
    frame #52320: 0x0000000100078914 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 2996
    frame #52321: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52322: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52323: 0x00000001000a7a2f nim_temp semBlock_NBTNEqzl5NBSHnN0VGYkSQ_42 + 255
    frame #52324: 0x0000000100078212 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1202
    frame #52325: 0x00000001000a7d50 nim_temp semStmtList_tayBCUAEli3HMPwxdS9aMbg_24 + 272
    frame #52326: 0x0000000100078225 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 1221
    frame #52327: 0x0000000100082d5a nim_temp semAfterMacroCall_00z3ReZzIEXfRQL9czzyLtA + 330
    frame #52328: 0x0000000100082bd0 nim_temp semTemplateExpr_InSQ3LpBhnCqFgw1Hbb18Q + 160
    frame #52329: 0x000000010009269b nim_temp afterCallActions_9bA5HQzp5SlBuAZ9a1ZzejHQ + 91
    frame #52330: 0x0000000100078d00 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 4000
    frame #52331: 0x00000001000b28f1 nim_temp semStmtAndGenerateGenerics_NBTNEqzl5NBSHnN0VGYkSQ_70 + 193
    frame #52332: 0x00000001000b2b85 nim_temp myProcess_9aYtClTzGl7gCIMK0iQSuhQ + 69
    frame #52333: 0x00000001000cdab2 nim_temp processModule_3A8vXpc6ePXdtcr9c1H1H9aA + 658
    frame #52334: 0x00000001001acde4 nim_temp compileModule_qzO5vYU9bpLpILLj3MVpbhg + 340
    frame #52335: 0x00000001001ace0e nim_temp importModule_re1epiGuwGWFjydVuzah3Q + 30
    frame #52336: 0x00000001000c32e3 nim_temp myImportModule_yJ71euPlK45hW8PmgqX9ahQ + 691
    frame #52337: 0x00000001000c3b8e nim_temp evalImport_rlI2ulrJgB3tjNcA8reHfg + 542
    frame #52338: 0x00000001000789a1 nim_temp semExpr_tayBCUAEli3HMPwxdS9aMbg_2 + 3137
    frame #52339: 0x00000001000b28f1 nim_temp semStmtAndGenerateGenerics_NBTNEqzl5NBSHnN0VGYkSQ_70 + 193
    frame #52340: 0x00000001000b2b85 nim_temp myProcess_9aYtClTzGl7gCIMK0iQSuhQ + 69
    frame #52341: 0x00000001000cdab2 nim_temp processModule_3A8vXpc6ePXdtcr9c1H1H9aA + 658
    frame #52342: 0x00000001001acde4 nim_temp compileModule_qzO5vYU9bpLpILLj3MVpbhg + 340
    frame #52343: 0x000000010005623c nim_temp commandCompileToC_ikP0vuP6oxqlYdG7q9cY7sA_2 + 188
    frame #52344: 0x0000000100057bad nim_temp mainCommand_ikP0vuP6oxqlYdG7q9cY7sA + 3197
    frame #52345: 0x0000000100001741 nim_temp handleCmdLine_I9aitIr13Z1B6wHv5vzMf2w + 1297
    frame #52346: 0x00000001000020d2 nim_temp NimMainModule + 114
    frame #52347: 0x000000010000219e nim_temp main + 94
    frame #52348: 0x00007fff53fdd015 libdyld.dylib start + 1
    frame #52349: 0x00007fff53fdd015 libdyld.dylib start + 1

NOTE: I'm on OSX

NOTE: the last msg (with --verbosity:3) was:
/Users/timothee/git_clone/nim/Nim/lib/pure/unittest.nim(487, 9) Hint: global variable declared here [GlobalVar]
var testStatusIMPL {.inject.} = OK

NOTE: this would be a perfect application of D's dustmite tool, if we adapted it to handle Nim (see #8276 )

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions