dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Fix Issue 21889 - __traits(isSame, Object, const Object) yields true

Open BorisCarvajal opened this issue 4 years ago • 13 comments

BorisCarvajal avatar May 03 '21 20:05 BorisCarvajal

Thanks for your pull request, @BorisCarvajal!

Bugzilla references

Auto-close Bugzilla Severity Description
21889 major __traits(isSame, Object, const Object) yields true

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#12497"

dlang-bot avatar May 03 '21 20:05 dlang-bot

automem fails but a pull is ready. https://github.com/atilaneves/automem/pull/61

BorisCarvajal avatar May 03 '21 23:05 BorisCarvajal

as this is a major issue, feel free to retarget this to stable and then open a PR to merge stable back into master

thewilsonator avatar May 03 '21 23:05 thewilsonator

Since code out there depends on traits(isSame) ignoring qualifiers, this requires a deprecation cycle. We can suggest in the deprecation message to use Unqual for the types if the previous behavior is desired.

RazvanN7 avatar May 04 '21 09:05 RazvanN7

ping @BorisCarvajal

RazvanN7 avatar May 06 '21 10:05 RazvanN7

Since code out there depends on traits(isSame) ignoring qualifiers, this requires a deprecation cycle. We can suggest in the deprecation message to use Unqual for the types if the previous behavior is desired.

I think that code is depending on undefined behavior because I don't see any info in the spec about using a type inside isSame, the closest thing is comparing tuples.

BorisCarvajal avatar May 06 '21 23:05 BorisCarvajal

It's not exactly undefined behavior. It just doesn't appear in the spec, but the behavior is that it compares types without taking into account qualifiers. The last thing we want is to break people's code. If automem was not included in the testing pipeline and the author upgraded the compiler, the project would have failed to compile without any indication of what the reason is. We don't know how many projects are in this state out in the wild. It could be 1 or 2 or it could be dozens. We don't know and that is why we should (1) issue a deprecation warning any time 2 types are compared with isSame and (2) add a changelog entry that offers more information about this.

Edit: this should also be accompanied with a spec PR clarifying the behavior in the presence of types.

RazvanN7 avatar May 07 '21 07:05 RazvanN7

cc @WalterBright @atilaneves

RazvanN7 avatar May 19 '21 07:05 RazvanN7

I defer to @WalterBright

atilaneves avatar May 24 '21 16:05 atilaneves

Can we have this merged, @WalterBright?

FYI, @andralex.

nordlow avatar Sep 02 '21 19:09 nordlow

@dkorpel What are your thoughts on this?

RazvanN7 avatar Apr 26 '22 08:04 RazvanN7

I don't use __traits(isSame), but it appears to be mostly used for comparing functions (e.g. "is this template parameter an identity function?") Using it for type comparison is unspecified, and we already have is(T == U) for that, so unless including it under isSame make sense in generic code, I would deprecate type comparisons in isSame.

@andralex I'm curious how the case in the bug report static assert(!__traits(isSame, Object, const Object)); came about, what was isSame being used for?

dkorpel avatar Apr 26 '22 09:04 dkorpel

I don't use __traits(isSame), but it appears to be mostly used for comparing functions (e.g. "is this template parameter an identity function?") Using it for type comparison is unspecified, and we already have is(T == U) for that, so unless including it under isSame make sense in generic code, I would deprecate type comparisons in isSame.

I would rather deprecate __traits(isSame) in favor of a generalized is(T == U) that covers all the sane cases of __traits(isSame, T, U).

nordlow avatar Apr 26 '22 10:04 nordlow

I marked this as WONTFIX in https://issues.dlang.org/show_bug.cgi?id=21889 for reasons given there. Needs a strong compelling reason to reopen it, especially since this change breaks existing code.

WalterBright avatar Mar 26 '24 05:03 WalterBright