nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.64k stars 1.47k forks source link

wrap `fields` iterations in `if true` scope [backport] #24343

Closed metagn closed 1 month ago

metagn commented 1 month ago

fixes #24338

When unrolling each iteration of a fields iterator, the compiler only opens a new scope for semchecking, but doesn't generate a node that signals to the codegen that a new scope should be created. This causes issues for reused template instantiations that reuse variable symbols between each iteration, which causes the codegen to generate multiple declarations for them in the same scope (regardless of inject or gensym). To fix this, we wrap the unrolled iterations in an if true: body node, which both opens a new scope and doesn't interfere with break.

github-actions[bot] commented 1 month ago

Thanks for your hard work on this PR! The lines below are statistics of the Nim compiler built from ca5df9ab25f1444025f9b8928cf21893a160489b

Hint: mm: orc; opt: speed; options: -d:release 175305 lines; 8.622s; 654.898MiB peakmem