Skip to content

Adding move-only for Dlang arrays #10781

New issue

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

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

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

GalaxyRider111
Copy link

Hello, I have tried to add move-only support for dlang arrays. In theory everything should work just fine. But, I'm gonna (maybe) continue updating this PR, if something goes wrong. If you have any suggestions, please, don't hesitate to reach out and help me.

@dlang-bot
Copy link
Contributor

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

@@ -1293,7 +1546,7 @@ if (!is(immutable T == immutable bool))
assert(a[].equal(["test"]));
}

@safe unittest
@system unittest
Copy link
Member

Choose a reason for hiding this comment

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

Making previously memory safe operations unsafe is an unfortunate breakage.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not just unfortunate, it's absolutely unacceptable. All operations that were @safe prior to this PR must remain @safe.

Copy link
Author

Choose a reason for hiding this comment

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

Ok guys, sorry, I had a bunch of errors about @safe, and I have tried this workaround to see if it would work, and somehow, it really did

@@ -1593,7 +1848,7 @@ if (!is(immutable T == immutable bool))
}

// https://issues.dlang.org/show_bug.cgi?id=11459
@safe unittest
@system unittest
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -1612,7 +1867,7 @@ if (!is(immutable T == immutable bool))
}

// https://issues.dlang.org/show_bug.cgi?id=8282
@safe unittest
@system unittest
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@@ -1656,7 +1911,7 @@ if (!is(immutable T == immutable bool))
assert(c.i == 42); //fails
}

@safe unittest
@system unittest
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines +92 to +97






Copy link
Member

Choose a reason for hiding this comment

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

Please trim this excessive whitespace to a single empty line.

Comment on lines 329 to +333





Copy link
Member

Choose a reason for hiding this comment

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

Please trim excessive whitespace to a single empty line.

Comment on lines +3878 to +3882





Copy link
Member

Choose a reason for hiding this comment

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

Please trim excessive whitespace to a single empty line.

Comment on lines +5460 to +5505
/*
unittest
{
// Test front and back
Array!NoCopy arr;
arr.insertBack(NoCopy(10));
arr.insertBack(NoCopy(20));
assert(arr.front.x == 10);
assert(arr.back.x == 20);
}

unittest
{
// Test insertFront
Array!NoCopy arr;
arr.insertFront(NoCopy(5));
arr.insertFront(NoCopy(3));
assert(arr.length == 2);
assert(arr[0].x == 3);
assert(arr[1].x == 5);
}

unittest
{
// Test clear
Array!NoCopy arr;
arr.insertBack(NoCopy(7));
arr.insertBack(NoCopy(8));
arr.clear();
assert(arr.empty);
}

unittest
{
// Test popFront / popBack
Array!NoCopy arr;
arr.insertBack(NoCopy(100));
arr.insertBack(NoCopy(200));
arr.popFront();
assert(arr.length == 1);
assert(arr.front.x == 200);

arr.popBack();
assert(arr.empty);
}
*/
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason these unittests are commented out?

Copy link
Author

Choose a reason for hiding this comment

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

Oh yeah, forgot about these, thanks a lot for heads up. I had some erros about these, and commented them to focus on some other errors, and come back to them when I finish, but I kinda forgot. Thanks

Comment on lines +21 to 28
import std.algorithm.mutation : move, moveEmplace;

import std.traits : Unqual;


import core.exception : RangeError;
import std.range.primitives;
import std.traits;
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the unnecessary empty line(s).

Comment on lines +369 to +370
if (_a == _b) return;

Copy link
Member

Choose a reason for hiding this comment

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

Inconsistent style: L378-379

Comment on lines +378 to +379
if (i == j)
return;
Copy link
Member

Choose a reason for hiding this comment

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

Inconsistent style: L369-370

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, will do

@@ -1391,6 +1645,7 @@ if (!is(immutable T == immutable bool))
assert(a.length == 7);
assert(equal(a[1 .. 4], [1, 2, 3]));
}
*/
Copy link
Member

Choose a reason for hiding this comment

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

Disabling unittests doesn’t seem like a good idea.

@disable this(this);
this(int v) @safe pure nothrow @nogc { x = v; }

// ADĂUGAT
Copy link
Member

Choose a reason for hiding this comment

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

Please either replace this with an English term or remove it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants