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

Remove __cmp from object.d for aggregates #2633

Closed
wants to merge 1 commit into from
Closed

Remove __cmp from object.d for aggregates #2633

wants to merge 1 commit into from

Conversation

JinShil
Copy link
Contributor

@JinShil JinShil commented Jun 6, 2019

Surprisingly it doesn't appear to be utilized anywhere. Let's see what the test suite says.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @JinShil! 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 annotated coverage diff directly on GitHub with CodeCov's browser extension
  • 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 fetch digger
dub run digger -- build "master + druntime#2633"

@JinShil
Copy link
Contributor Author

JinShil commented Jun 6, 2019

Looks like it was introduced here: #1787

@andralex Was this intended to have an accompanying DMD PR, but was never followed through on?

@JinShil
Copy link
Contributor Author

JinShil commented Jun 6, 2019

Please don't merge this PR until @andralex responds. I'm wondering if we need to add a lowering to DMD instead. But it's strange that this overload of __cmp is private.

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.

Fine by me if the tests are passing.

@andralex
Copy link
Member

andralex commented Jun 6, 2019

The plan here was to have the compiler lower object comparison to this. Also @edi33416 is working on defining __cmp for structs as well (lexicographic in field order).

@JinShil
Copy link
Contributor Author

JinShil commented Jun 6, 2019

Thank you @andralex Closing pending a DMD PR that will utilize this.

@JinShil JinShil closed this Jun 6, 2019
@JinShil JinShil deleted the remove_object_cmp branch June 6, 2019 14:05
@JinShil JinShil restored the remove_object_cmp branch June 8, 2019 13:42
@JinShil JinShil reopened this Jun 8, 2019
@JinShil
Copy link
Contributor Author

JinShil commented Jun 8, 2019

I'm reopening this.

I don't know what the plan is for the code that this PR removes. @andralex, If this is not dead code, could you please elaborate on what needs to be done to utilize it.

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.

Sure, we can always bring this back if needed. The problem with opCmp is that it's a member so if it's final it can't operate on null object. cc @edi33416

@edi33416
Copy link
Contributor

edi33416 commented Jun 8, 2019

I have this dmd pr and druntime pr to lower calls to __cmp. This was influenced by work at ProtoObject. Should I still keep those or two ProtoObjects shouldn’t be compared and have the user do a dynamic/static cast at call site? I think it would be reasonable to ask the user to do so.

@JinShil
Copy link
Contributor Author

JinShil commented Jun 9, 2019

Thank you @edi33416 It appears the utility of this code has yet to be determined and is pending the adjudication of work on ProtoObject. I'll close this for now until those design decisions are made.

@JinShil JinShil closed this Jun 9, 2019
@JinShil
Copy link
Contributor Author

JinShil commented Jun 9, 2019

Should I still keep those or two ProtoObjects shouldn’t be compared and have the user do a dynamic/static cast at call site?

I don't know what's happening as I'm not intimately involved in the design of ProtoObject. I thought, based on this thread, that the value of comparing two objects was in question. I don't know what, if any, decision has been made about that, but I would be interested to know. As I mentioned in that thread, I would prefer a clear distinction between "reference comparisons", "value comparisons", and "hash comparisons".

@andralex
Copy link
Member

andralex commented Jun 9, 2019

@edi33416 we need that lowering to compare properly null objects. Otherwise code like this will crash:

class Widget { ... defines opCmp ... }
auto w1 = new Widget;
Widget w2 = null;
if (w2 < w1) {}

If all we do is lower to w1.opCmp(w2) we end up calling a method against a null reference. So please proceed and be bold.

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.

5 participants