Open yuanweixin opened 1 year ago
workaround (fix tbh, genast is a superior replacement for quote do):
use genast
import std/[macros,genasts]
var x{.compiletime.} : NimNode =
genast():
echo "xxx"
thanks! was growing frustrated that I can't just quote things and pass them around. at least, this gets me past that segfault.
i suppose this is more of a user experience thing, but i find that putting genAst inside a tuple results in Error: named expression not allowed here
, so have to resort to assigning the genAst to a var and then using that var in the tuple.
!nim c
import std/macros
var x {.compileTime.} : NimNode =
quote do:
echo "xxx"
@juancarlospaco (contributor)devel :-1: FAIL
Output
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
2023-07-11T19:11:46Z
2023-07-11T19:12:17
2023-07-11T19:12:18
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
2023-07-11T19:11:46Z
2023-07-11T19:12:18
2023-07-11T19:12:19
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
2023-07-11T19:11:46Z
2023-07-11T19:12:23
2023-07-11T19:12:23
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
2023-07-11T19:11:46Z
2023-07-11T19:12:27
2023-07-11T19:12:28
now
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-07-11T19:11:46Z
2023-07-11T19:12:43
2023-07-11T19:12:44
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-07-11T19:11:46Z
2023-07-11T19:12:57
2023-07-11T19:12:58
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
2023-07-11T19:11:46Z
2023-07-11T19:13:08
2023-07-11T19:13:09
1 minute
nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --threads:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
Clyybber introduced a bug at 2020-07-29 16:17:20 +0200
on commit #2629d619a with message:
Fix forward declaration issues in template/macro context (#15091)
* Fix forward declaration issues in template/macro context
* Correct forward declaration resolving for overloads
* Remove old dead code
* WIP consistent gensym ids
* Minimize diff
* Remove obsoleted hack
* Add templInstCounter to give unique IDs to template instantiations
* Remove obsoleted code
* Eh, init in myOpen, not myProcess...
* Remove optNimV019
* Add testcase for #13484
The bug is in the files:
changelog.md
compiler/commands.nim
compiler/evaltempl.nim
compiler/lookups.nim
compiler/options.nim
compiler/procfind.nim
compiler/sem.nim
compiler/semdata.nim
compiler/semexprs.nim
compiler/semstmts.nim
compiler/semtempl.nim
compiler/types.nim
compiler/vm.nim
compiler/vmdef.nim
testament/important_packages.nim
tests/macros/tmacros_issues.nim
tests/template/tparams_gensymed.nim
The bug can be in the commits:
(Diagnostics sometimes off-by-one).
46 minutes
bisecting 4387
commits at 95
commits per second. Similar case: https://github.com/nim-lang/Nim/issues/22282#issuecomment-1636644896
import std/macros
proc f(): NimNode =
quote do:
123
var a = static f()
import std/macros
var myNode {.compileTime.} = newStmtList()
macro test(n: static NimNode) = discard
myNode.test()
This is enough to make the compiler segfault, too.
Description
Code
The context is that I am trying to build up a compile-time list, containing data and NimNode (representing codeblocks), intended to be passed into a macro. But it seems directly assigning from quote do crashes the compiler (no compile error or warnings whatsoever).
Nim Version
Nim Compiler Version 1.6.8 [Linux: amd64] Compiled at 2022-10-05 Copyright (c) 2006-2021 by Andreas Rumpf
git hash: c9f46ca8c9eeca8b5f68591b1abe14b962f80a4c active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response