-
-
Notifications
You must be signed in to change notification settings - Fork 421
Lower dmd CmpExp between classes to __cmp call #2562
Conversation
|
Thanks for your pull request and interest in making D better, @edi33416! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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 referencesYour 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 locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + druntime#2562" |
|
Temporarily removing tests that call the compiler lowering code, in order to unblock the build process. |
|
Just to be aware, this will now include C++ and Objective-C classes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for C++ and Objective-C classes or adjust the signature and the DMD PR if this should not be called with C++ and Objective-C classes.
59ca5be to
1f81b6e
Compare
|
@JinShil @jacob-carlborg I updated the code accordingly to the feedback |
src/object.d
Outdated
| // Compare class objects for ordering. | ||
| int __cmp(C1, C2)(C1 lhs, C2 rhs) | ||
| if (((is(C1 == class) || is(C1 == typeof(null))) && is(C1 : Object)) && | ||
| ((is(C2 == class) || is(C2 == typeof(null))) && is(C2 : Object))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s the advantage of this signature compared to the old one?
You can use __traits(getLinkage) alternatively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it allows for a more optimal implementation if C1 or C2 is explicitly null. I also think the function can be evaluated at compile-time if one of the arguments is explicitly null. That's what it looks like to me, but I could be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If what I said above is true, it would be nice to add some unittest code to demonstrate that and ensure it remains that way now and into the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the check for both class and Object looks redundant to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing C++ classes is different to comparing D classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jacob-carlborg we don't want to restrict comparison to constant objects. Per https://run.dlang.io/is/iTtY7T, it seems the simplest comprehensive sig is:
int __cmp(C1, C2)(C1 lhs, C2 rhs)
if (is(C1 == class) || is(C1 == interface) || is(C1 : const typeof(null))
&&
is(C2 == class) || is(C2 == interface) || is(C2 : const typeof(null)));There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edi33416 later as we introduce ProtoObject we can change the sig appropriately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: __cmp should return auto, not int so as to accommodate classes that define opCmp to return e.g. float.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want to restrict comparison to constant objects.
You can pass anything to a const parameter: mutable, immutable and const. But of course opCmp would need to be const. Is that the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int __cmp(C1, C2)(C1 lhs, C2 rhs) if (is(C1 == class) || is(C1 == interface) || is(C1 : const typeof(null)) && is(C2 == class) || is(C2 == interface) || is(C2 : const typeof(null)));
The above constraint will include C++ and Objective-C classes and interfaces and COM interfaces. Is that intentional? In that case there needs to be tests for all of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the sig as discussed.
src/object.d
Outdated
| private int __cmp(Obj)(Obj lhs, Obj rhs) | ||
| if (is(Obj : Object)) | ||
| // Compare class objects for ordering. | ||
| int __cmp(C1, C2)(C1 lhs, C2 rhs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be private and the compiler bypasses the protection? Or is there a use case for calling this directly?
|
@edi33416 this seems almost finished. Any change on taking it to the finish line? |
1f81b6e to
cc18239
Compare
cc18239 to
dc4e7b5
Compare
No description provided.