Skip to content

Fixes #21235, #23602, #24978, #25018 #25030

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

Merged
merged 2 commits into from
Jul 8, 2025
Merged

Fixes #21235, #23602, #24978, #25018 #25030

merged 2 commits into from
Jul 8, 2025

Conversation

yglukhov
Copy link
Member

@yglukhov yglukhov commented Jul 6, 2025

Reworked closureiter transformation.

  • Convolutedly nested finallies should cause no problems now.
  • CurrentException state now follows nim runtime rules (pushes and pops appropriately), and mimics normal code, which is somewhat buggy, see Exceptions not cleared if except control flow is interrupted #25031
  • Previously state optimization (removing empty states or extra jumps) missed some opportunities, I've reimplemented it to do everything possible to optimize the states. At this point any extra states or jumps should be considered a bug.

The resulting codegen (compiled binaries) is also slightly smaller.

BUT:

  • I had to change C++ reraising logic, see expt.nim. Because with closure iters currentException is not always in sync with C++'s notion of current exception. From my tests and understanding of C++ runtime there should not be any problems, but I'm only 99% sure :)
  • I've reused nfNoRewrite flag in one specific case during the transformation. This flag is also used in term-rewriting logic. Again, 99% sure, these 2 scenarios will never intersect.

@yglukhov yglukhov changed the title WIP: Fixes #21235, #23602, #24978, #25018 Fixes #21235, #23602, #24978, #25018 Jul 7, 2025
@yglukhov
Copy link
Member Author

yglukhov commented Jul 7, 2025

packages Windows_amd64_batch1_3 job seems to always time out. I can't tell if it is my changes causing it :(

@Araq Araq merged commit 36f8cef into nim-lang:devel Jul 8, 2025
16 of 18 checks passed
@Araq
Copy link
Member

Araq commented Jul 8, 2025

timeouts seemed to be unrelated.

Copy link
Contributor

github-actions bot commented Jul 8, 2025

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

Hint: mm: orc; opt: speed; options: -d:release
182768 lines; 8.984s; 659.508MiB peakmem

narimiran pushed a commit that referenced this pull request Jul 8, 2025
Reworked closureiter transformation.

- Convolutedly nested finallies should cause no problems now.
- CurrentException state now follows nim runtime rules (pushes and pops
appropriately), and mimics normal code, which is somewhat buggy, see
#25031
- Previously state optimization (removing empty states or extra jumps)
missed some opportunities, I've reimplemented it to do everything
possible to optimize the states. At this point any extra states or jumps
should be considered a bug.

The resulting codegen (compiled binaries) is also slightly smaller.

**BUT:**
- I had to change C++ reraising logic, see expt.nim. Because with
closure iters `currentException` is not always in sync with C++'s notion
of current exception. From my tests and understanding of C++ runtime
there should not be any problems, but I'm only 99% sure :)
- I've reused `nfNoRewrite` flag in one specific case during the
transformation. This flag is also used in term-rewriting logic. Again,
99% sure, these 2 scenarios will never intersect.

(cherry picked from commit 36f8cef)
@yglukhov yglukhov deleted the finally branch July 9, 2025 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants