Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Lower dmd CmpExp between classes to __cmp call #2562

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

edi33416
Copy link
Contributor

No description provided.

@edi33416 edi33416 requested a review from andralex April 16, 2019 21:06
@edi33416 edi33416 requested a review from MartinNowak as a code owner April 16, 2019 21:06
@dlang-bot
Copy link
Contributor

dlang-bot commented Apr 16, 2019

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 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 + druntime#2562"

@edi33416
Copy link
Contributor Author

Temporarily removing tests that call the compiler lowering code, in order to unblock the build process.
This is required as the PRs depend on each other.

src/object.d Outdated Show resolved Hide resolved
@jacob-carlborg
Copy link
Contributor

Just to be aware, this will now include C++ and Objective-C classes.

Copy link
Contributor

@jacob-carlborg jacob-carlborg left a 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.

@edi33416 edi33416 force-pushed the lower_class_CmpExp branch from 59ca5be to 1f81b6e Compare April 17, 2019 22:50
@edi33416
Copy link
Contributor Author

@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)))
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

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)));

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor

@jacob-carlborg jacob-carlborg Jun 9, 2019

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?

Copy link
Contributor

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.

Copy link
Member

@andralex andralex left a 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)
Copy link
Contributor

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?

@dlang-bot dlang-bot added Needs Rebase needs a `git rebase` performed stalled labels May 27, 2021
@RazvanN7
Copy link
Contributor

@edi33416 this seems almost finished. Any change on taking it to the finish line?

@dlang-bot dlang-bot removed the stalled label Dec 13, 2021
@dlang-bot dlang-bot removed the Needs Rebase needs a `git rebase` performed label Dec 14, 2021
src/object.d Outdated Show resolved Hide resolved
@dlang-bot dlang-bot merged commit c213ff6 into dlang:master Dec 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants