Skip to content

Conversation

@carblue
Copy link
Contributor

@carblue carblue commented Mar 30, 2018

A new attempt since #6295

https://github.com/dlang/phobos/blob/master/dip1000.mak with
aa[std.container.slist]=-dip1000
Errors when running: make -f posix.mak std/container/slist.test
...

T=`mktemp -d /tmp/.dmd-run-test.XXXXXX` &&                                                              \
  (                                                                                                     \
    ../dmd/generated/linux/release/64/dmd -od$T -conf= -I../druntime/import  -w -de -dip25 -m64 -fPIC -transition=complex -O -release -dip1000 -version=DIP1000  -main -unittest generated/linux/release/64/libphobos2.a -defaultlib= -debuglib= -L-ldl -cov -run std/container/slist.d ;     \
    RET=$? ; rm -rf $T ; exit $RET                                                                   \
  )
std/container/slist.d(280): Error: @safe function std.container.slist.SList!int.SList.__unittest_L278_C11 cannot call @system constructor std.container.slist.SList!int.SList.__ctor!int.this
std/container/slist.d(282): Error: @safe function std.container.slist.SList!int.SList.__unittest_L278_C11 cannot call @system constructor std.container.slist.SList!int.SList.__ctor!int.this
std/container/slist.d(27): Error: template instance `std.container.slist.SList!int` error instantiating
std/container/slist.d(801): Error: template instance `std.container.slist.SList!string` error instantiating

Changing to:
size_t insertFront(Stuff)(scope Stuff stuff)
if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))

compiles everything except: auto sl = SList!string(["a", "b", "d"]);

std/container/slist.d(365): Error: scope variable item may not be copied into allocated memory
std/container/slist.d(154): Error: template instance `std.container.slist.SList!string.SList.insertFront!(Range)` error instantiating
std/container/slist.d(250):        instantiated from here: __ctor!(Range)
std/container/slist.d(801):        instantiated from here: SList!string

Thus I'm going to try with a dedicated constructor (or ?) for the string types, probably including dup-ing consructor arguments. We'll see.

@carblue carblue requested a review from PetarKirov as a code owner March 30, 2018 06:23
@dlang-bot dlang-bot added the Review:WIP Work In Progress - not ready for review or pulling label Mar 30, 2018
@dlang-bot
Copy link
Contributor

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

@carblue carblue changed the title [WIP] std.container.slist: Fix -dip1000 compilable issues std.container.slist: Fix -dip1000 compilable issues Mar 30, 2018
{
auto newNode = new Node(null, item);
static if (isSomeString!T)
auto newNode = new Node(null, item.dup);
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we agree that this is bad because we duplicate memory without the user explicitly agreeing too.
Why not version(DIP1000) else out the test for now? And/or report the DMD error I reduced here: #6295 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, wouldn't special-casing strings this way break all other reference types anyway?

{
auto newNode = new Node(null, item);
static if (isSomeString!T)
auto newNode = new Node(null, item.dup);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, wouldn't special-casing strings this way break all other reference types anyway?

@carblue carblue closed this Apr 28, 2018
Complexity: $(BIGOH m), where $(D m) is the length of $(D stuff)
*/
size_t insertFront(Stuff)(Stuff stuff)
size_t insertFront(Stuff)(scope Stuff stuff)
Copy link
Member

@PetarKirov PetarKirov Apr 29, 2018

Choose a reason for hiding this comment

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

Inserting an element in a container is really escaping it, so this function can't accept scope arguments by design, unless it always stores a copy of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review:WIP Work In Progress - not ready for review or pulling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants