Skip to content

Refactor: Extract combine and extractLast from Expression AST node to semantic layer#22618

Open
Adityazzzzz wants to merge 5 commits intodlang:masterfrom
Adityazzzzz:refactor-expression-helpers
Open

Refactor: Extract combine and extractLast from Expression AST node to semantic layer#22618
Adityazzzzz wants to merge 5 commits intodlang:masterfrom
Adityazzzzz:refactor-expression-helpers

Conversation

@Adityazzzzz
Copy link
Contributor

@Adityazzzzz Adityazzzzz commented Feb 23, 2026

Following up on pr #22597 the architectural guidance from @ibuclaw. It focuses on migrating functions that perform actual semantic mutation on the AST.
Changes:

  • expression.d: Removed the static AST-mutating member functions combine (all overloads) and extractLast from the Expression class.
  • expressionsem.d: Relocated these as free-standing extern(D) functions.
  • cxxfrontend.d: Added the appropriate D-to-C++ forwarders inside the extern (C++, "dmd") namespace to ensure GDC/LDC consumers can still access the exposed routines.
  • Updated all internal call sites across the compiler (clone.d, dcast.d, optimize.d, etc.) to use the free functions.

This successfully decouples tree-building logic from the pure data node while maintaining full C++ interoperability. I'd appreciate any review on whether the cxxfrontend.d wrappers align with the expected GDC/LDC integration patterns!

As part of the 'Separate Semantic Routines' project, this extracts the AST-mutating static methods `combine` and `extractLast` from the `Expression` class in `expression.d` and moves them to `expressionsem.d` as free functions. Also adds the appropriate D-to-C++ wrappers in `cxxfrontend.d` under the dmd namespace to maintain compatibility for GDC/LDC consumers.
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Adityazzzzz! 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#22618"

* expressionsem.d
*/

Expression combine(Expression e1, Expression e2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for these, they were already extern(D) so the C++ clients aren't using them.

@Adityazzzzz
Copy link
Contributor Author

Adityazzzzz commented Feb 24, 2026

@ibuclaw Since they were strictly extern(D) originally, the C++ clients were never hooking into them anyway. I've removed the wrappers from cxxfrontend.d,

I went ahead and removed the C++ wrappers from cxxfrontend.d as suggested, but it looks like it triggered massive failures across the CI pipeline (all the C++ interop and linker tests are failing). It seems the CI tests might actually be relying on those extern (D) forwarders indirectly!

Should I revert that specific commit to get the CI back to green, or is there a C++ header file somewhere else that I need to clean up?

@Adityazzzzz
Copy link
Contributor Author

Thanks again for the guidance on the cxxfrontend.d wrappers, @ibuclaw Getting this pipeline right was my main goal before drafting my formal GSoC proposal.
Speaking of the proposal, I'm currently mapping out my 12-week timeline for the 5 main TODOs from the project description (dstruct.d, dtemplate.d, aggregate.d, dmodule.d, func.d).
As I plan my milestones, do you have a recommendation on which of these 5 is the most logical starting point for week 1? (For example, I noticed resolve inside dmodule.d looks like a heavy semantic pass that needs moving). I'd love to structure my proposal around the order that makes the most architectural sense to the core team

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.

3 participants