Skip to content

Conversation

@gorsing
Copy link
Contributor

@gorsing gorsing commented Dec 22, 2025

Description: This PR refactors the User Defined Attribute (UDA) semantic analysis logic within dmd.attribsem. The primary goals are to improve compiler stability and ensure consistent attribute iteration.

Changes:

getAttributes:

Added early exit to avoid heap allocation for empty attribute blocks.
Improved recursive collection of attributes from parent declarations.

foreachUda:

Bug Fix: Added null-check for the attribute list to prevent crashes during semantic analysis.
Feature: Implemented support for single (non-tuple) attributes. Previously, standalone UDAs might have been skipped during iteration.

Cleanup: Removed redundant/unreachable code blocks and unified the iteration logic using each!.

@dlang-bot
Copy link
Contributor

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

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

If this fixes bugs, please add their reproductions to the test suite

@gorsing gorsing marked this pull request as draft December 22, 2025 13:27
@gorsing gorsing force-pushed the refactoring_attribsem_v2 branch from e13bdcd to c235355 Compare December 22, 2025 16:00
@gorsing
Copy link
Contributor Author

gorsing commented Dec 22, 2025

@thewilsonator Thanks for the feedback! I've updated the PR to address all your comments:

Code Cleanup: Removed all redundant comments (// Optimization, // PROTECTION, etc.) as they were unnecessary.

Ddoc Formatting: Restored and fixed the indentation in the documentation blocks.

Logic Refinement: Restructured foreachUda to use an explicit else branch for handling single UDA expressions, making the flow clearer.

Regression Test: Added a new test case compiler/test/runnable/test22287.d which covers single UDAs, tuple UDAs, and recursive attribute collection.

@gorsing gorsing marked this pull request as ready for review December 22, 2025 16:14
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