Fix deprecation warning: UDA extraction for overload sets#93
Conversation
Handle overloaded symbols in getUDAs/autoGetUDAs by using __traits(getOverloads) and flattening per-overload UDAs before filtering. This avoids deprecated __traits(getAttributes) on overload sets and reduces the warning spam seen in builds against overloaded functions.
There was a problem hiding this comment.
Pull request overview
Updates Mir’s compile-time UDA introspection helpers to avoid deprecated __traits(getAttributes) calls on overload sets by switching to __traits(getOverloads) and aggregating attributes across overloads before filtering.
Changes:
- Update
getUDAs(alias symbol, alias attribute)to detect overload sets via__traits(getOverloads)and collect UDAs per overload. - Update
autoGetUDAs(alias symbol)with similar overload-set handling to return aggregated attributes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static if (__traits(compiles, __traits(getOverloads, symbol))) | ||
| { | ||
| alias overloads = __traits(getOverloads, symbol); | ||
| static if (overloads.length > 0) | ||
| { | ||
| alias getUDAsImpl(alias overload) = Filter!(isDesiredUDA!attribute, __traits(getAttributes, overload)); | ||
| alias getUDAs = AliasSeq!(staticMap!(getUDAsImpl, overloads)); | ||
| } |
There was a problem hiding this comment.
New behavior for overload sets is introduced here, but the file’s unittests don’t cover overloaded symbols (multiple overloads with/without the target UDA). Adding a dedicated unittest for an overloaded function name would help prevent regressions and confirm the intended aggregation semantics across overloads.
| static if (__traits(compiles, __traits(getOverloads, symbol))) | ||
| { | ||
| alias overloads = __traits(getOverloads, symbol); | ||
| static if (overloads.length > 0) | ||
| { | ||
| alias getUDAsImpl(alias overload) = Filter!(isDesiredUDA!attribute, __traits(getAttributes, overload)); | ||
| alias getUDAs = AliasSeq!(staticMap!(getUDAsImpl, overloads)); | ||
| } | ||
| else static if (__traits(compiles, __traits(getAttributes, symbol))) | ||
| { | ||
| alias getUDAs = Filter!(isDesiredUDA!attribute, __traits(getAttributes, symbol)); | ||
| } | ||
| else | ||
| alias getUDAs = AliasSeq!(); | ||
| } |
There was a problem hiding this comment.
The overload-handling logic in getUDAs largely duplicates the overload-handling logic added to autoGetUDAs below. Consider centralizing this by having getUDAs filter over a single helper that returns the flattened attributes (e.g., autoGetUDAs!symbol), so the overload detection rules stay consistent and future changes only need to be made once.
|
Thank you, Laeeth. mir-algorithm and mir-ion are tested with this commit on macOS/ldc 1.41.0. Tagged as v1.7.4 |
Handle overloaded symbols in getUDAs/autoGetUDAs by using __traits(getOverloads) and flattening per-overload UDAs before filtering.
This avoids deprecated __traits(getAttributes) on overload sets and reduces the warning spam seen in builds against overloaded functions.
NB: heavily AI-assisted and I have not had time to study this carefully.