Skip to content

Restart inference of foreach nested functions when lowering returns#22685

Open
limepoutine wants to merge 2 commits intodlang:masterfrom
limepoutine:foreach-infer
Open

Restart inference of foreach nested functions when lowering returns#22685
limepoutine wants to merge 2 commits intodlang:masterfrom
limepoutine:foreach-infer

Conversation

@limepoutine
Copy link
Contributor

@limepoutine limepoutine commented Mar 3, 2026

Fixes #22666, also fixes #22639. Also fixes Bugzilla 19408.

I'm turning a trivial bug fix into a big feature again. This PR restarts inference when lowering returns inside a foreach, commits when returns are rewritten, and runs semantic on opApply calls. Not particularly maintainable because we now need to patch lowering of foreach in semantic3. Contains pattern matching on lowered ASTs, speculative inference, and a reinvented wheel of counting sort.

This is not quite "full inference" yet, but quite compliant to the specs. Less compliant yet more lightweight are #22642 and #22672.

@limepoutine limepoutine requested a review from ibuclaw as a code owner March 3, 2026 04:32
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @limepoutine! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22685"

@limepoutine
Copy link
Contributor Author

limepoutine commented Mar 3, 2026

The buildkite failure is a true positive. PR: vibe-d/vibe-core#445

@limepoutine limepoutine force-pushed the foreach-infer branch 2 times, most recently from 28cedfe to effc9ad Compare March 3, 2026 06:58
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.

Attribute violation is allowed when returning inside foreach body Regression: opApply triggers GC allocation error with -betterC

2 participants