Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue - sort should move elements instead of copy... #7524

Merged
merged 1 commit into from
Jun 19, 2020

Conversation

MoonlightSentinel
Copy link
Contributor

@MoonlightSentinel MoonlightSentinel commented Jun 10, 2020

... because it's reordering elements. Calling opAssign on unitialized members might also cause errors if the implementation requires a valid instance (see TimSortImpl)

@MoonlightSentinel MoonlightSentinel changed the title Fix issue - sort should move elements instead of copying... Fix issue - sort should move elements instead of copy... Jun 10, 2020
@kinke
Copy link
Contributor

kinke commented Jun 10, 2020

Is this going to fix the run.d issues wrt. schwartzSort?

@MoonlightSentinel
Copy link
Contributor Author

Yes, because it won't call Tuple.opAssign on unitialised memory anymore.

MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Jun 12, 2020
Do a manual `schwartzSort` without using `Tuple` until all host
compilers have the fix implemented in dlang/phobos#7524.
@MoonlightSentinel MoonlightSentinel force-pushed the move-sort branch 2 times, most recently from 68b2c72 to 3d83b0d Compare June 12, 2020 18:56
MoonlightSentinel added a commit to MoonlightSentinel/dmd that referenced this pull request Jun 13, 2020
Do a manual `schwartzSort` without using `Tuple` until all host
compilers have the fix implemented in dlang/phobos#7524.
@MoonlightSentinel MoonlightSentinel force-pushed the move-sort branch 3 times, most recently from ea84c8c to 9f70bd9 Compare June 16, 2020 08:53
@12345swordy
Copy link

It's all green.

@MoonlightSentinel MoonlightSentinel marked this pull request as ready for review June 16, 2020 19:10
/// Helper method that moves from[fIdx] into to[tIdx] if both are lvalues and
/// uses a plain assignment if not (necessary for backwards compatibility)
void moveEntry(X, Y)(ref X from, const size_t fIdx, ref Y to, const size_t tIdx)
do
Copy link
Contributor

Choose a reason for hiding this comment

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

No contracts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to remove do as well. Slices and decent range implementations will check the index anyway.

@dlang-bot
Copy link
Contributor

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

... because it's reordering elements instead. Calling `opAssign` on
unitialized members might also  cause errors if the implementation
requires a valid instance (see `TimSortImpl`)
alias lessEqual = (a, b) => !less(b, a);
bool greater()(auto ref T a, auto ref T b) { return less(b, a); }
bool greaterEqual()(auto ref T a, auto ref T b) { return !less(a, b); }
bool lessEqual()(auto ref T a, auto ref T b) { return !less(b, a); }
Copy link
Member

Choose a reason for hiding this comment

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

Not introduced here, but it seems these are superfluous (everything can be elegantly expressed with less). greater is not even used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would agree for greaterEqual(a, b) vs !less(a,b). However, not for lessEqual(a, b) vs !less(b, a). More state for brain to track.

@andralex andralex merged commit d653014 into dlang:master Jun 19, 2020
@MoonlightSentinel MoonlightSentinel deleted the move-sort branch June 19, 2020 13:10
kinke pushed a commit to ldc-developers/dmd-testsuite that referenced this pull request Jun 20, 2020
Do a manual `schwartzSort` without using `Tuple` until all host
compilers have the fix implemented in dlang/phobos#7524.
kinke added a commit to kinke/ldc that referenced this pull request Jun 27, 2020
The schwartzSort() issue has been fixed in Phobos master
(dlang/phobos#7524, will land in 2.094) and worked around in the 2.093
run.d testrunner.

The tests all pass, so make it a requirement.
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.

7 participants