Skip to content

[internal/traits] Fix regression in hasElaborateDestructor - #22554

Merged
thewilsonator merged 5 commits into
dlang:masterfrom
ntrel:has-dtor-fix
Feb 18, 2026
Merged

thewilsonator merged 5 commits into
dlang:masterfrom
ntrel:has-dtor-fix

Conversation

@ntrel

@ntrel ntrel commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes dlang/phobos#10950.

I had to use version (CoreUnittest) to test the fix because it is dependent on the order of declarations. So it can't use a unitest {}.

@dlang-bot

Copy link
Copy Markdown

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

@ntrel
ntrel marked this pull request as draft February 10, 2026 18:00
Comment thread druntime/src/core/internal/traits.d Resolved
Comment thread druntime/src/core/internal/traits.d Outdated
// enum hasElaborateDestructor = __traits(hasMember, S, "__xdtor");

enum hasElaborateDestructor = hasDtor([__traits(allMembers, S)]);
enum hasElaborateDestructor = __traits(compiles, (S s) => (cast() s).__xdtor);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is certainly a more clever fix than I was thinking of doing. Of course, it really should be the solution with hasMember, but the compiler seems incapable of dealing with __xdtor properly with either hasMember or allMembers at the moment. :|

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This has the side effect of instantiating opDispatch speculatively, which is likely why b6400 fails...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was the problem, thanks!

@jmdavis

jmdavis commented Feb 11, 2026

Copy link
Copy Markdown
Member

It looks like the failures are unrelated, though there are enough of them that it's possible that one of them is related, since I didn't dig through all of them.

@ntrel

ntrel commented Feb 14, 2026

Copy link
Copy Markdown
Contributor Author

dmd's runnable/b6400.d test is failing, I have no idea why.

@ntrel
ntrel marked this pull request as ready for review February 18, 2026 13:25
@thewilsonator
thewilsonator merged commit 0d626a0 into dlang:master Feb 18, 2026
39 checks passed
@tim-dlang

Copy link
Copy Markdown
Contributor

It looks like this caused a different regression: #22609

@kinke

kinke commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

It might be cleaner to add a new builtin trait for this - we already have isPOD, has{Copy,Move}Constructor and hasPostblit; a hasElaborateDestructor [edit: or just needsDestruction or so; edit2: hmm no, that might be misleading for class types] would fit right in there, and, if needed, could (try to) do eager sema (the __xdtor alias is the AggregateDeclaration.dtor field in the AST), as apparently already done for the isCopyable trait (note the dsymbolSemantic() for struct types):

if (e.ident == Id.isCopyable)
{
if (dim != 1)
return dimError(1);
auto o = (*e.args)[0];
auto t = isType(o);
if (!t)
{
error(e.loc, "type expected as second argument of __traits `%s` instead of `%s`",
e.ident.toChars(), o.toChars());
return ErrorExp.get();
}
t = t.toBasetype(); // get the base in case `t` is an `enum`
if (auto ts = t.isTypeStruct())
{
ts.sym.dsymbolSemantic(sc);
}
return isCopyable(t) ? True() : False();
}

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.

Possible regression in hasElaborateDestructor detection since DMD 2.111.0

7 participants