This is an archive of the discontinued LLVM Phabricator instance.

Extending make_shared to Support Arrays (Partially) - P0674R1
AbandonedPublic

Authored by zoecarver on Jan 29 2019, 10:58 AM.

Details

Summary

Hi there,

I am a new contributor to libc++, so this patch will probably need some help. This patch incorporates some of the details highlighted in P0674R1. If all goes well, I will submit another one (or update this one) with the rest of the changes.

Example

shared_ptr<double[1024]> p = make_shared<double[1024]>();

Questions

  1. Is it okay to define __shared_ptr_emplace__destroy, a helper function, where and how I did?
  2. Was removing is_constructible<_Tp, _Args...>::value okay (see comment in code)?
  3. What are the next steps? Do I need to write more tests? Do I need to write some documentation?

Diff Detail

Event Timeline

zoecarver created this revision.Jan 29 2019, 10:58 AM
zoecarver updated this revision to Diff 184932.Feb 2 2019, 11:24 PM

Add tests and fix naming of _N (_N -> __n).

@EricWF and @ldionne friendly ping -- could you review this patch?

mclow.lists added inline comments.Feb 4 2019, 7:22 PM
include/memory
3705

Is there a reason you can't use _VSTD::destroy_at?

3712

Is there a reason you can't use _VSTD::destroy_n?

4358

It's checking to see if you can construct a _Tp from that list of arguments.

test/libcxx/memory/shared_ptr_array.pass.cpp
27

We actually have an ASSERT_SAME_TYPE macro in "test_macros.h"

29

I think you want to test that 64 constructors got called, and (afterwards) that 64 destructors got called.

zoecarver added inline comments.Feb 4 2019, 7:43 PM
include/memory
3705

I need to destroy it differently if it is an array.

Also, just out of curiosity, I thought _VSTD:: was synonymous to std:: is that true?

Is destroy_at / destroy_n prefured to simply calling the destructor?

zoecarver marked 4 inline comments as done.Feb 4 2019, 8:01 PM
zoecarver added inline comments.
include/memory
4358

hmm -- just went back and enabled this, seemed to be fine. Not sure why I disabled it in the first place ¯\_(ツ)_/¯

test/libcxx/memory/shared_ptr_array.pass.cpp
29

Good idea, is there a macro for this or something?

zoecarver marked an inline comment as done.Feb 4 2019, 8:19 PM
zoecarver marked an inline comment as done.Feb 4 2019, 8:40 PM
zoecarver added inline comments.
test/libcxx/memory/shared_ptr_array.pass.cpp
29

Nevermind: I figured it out.

zoecarver updated this revision to Diff 185231.Feb 4 2019, 9:02 PM

I added a test to make sure the right number of constructors/destructors were called.

I could not get ASSERT_SAME_TYPE working, I looked at some examples but eventually gave up. From the snippet I gave can you see what is wrong?

Thanks again for helping me through this process :)

ldionne requested changes to this revision.Feb 13 2019, 11:40 AM

This is a good start, but please make sure you implement and test the full paper.

include/memory
3707

You have two underscores between emplace and destroy.

3709

This here should be _VSTD::destroy_at(&t), and t needs to be mangled.

3716

I would use this instead:

_VSTD::destroy(_VSTD::begin(t), _VSTD::end(t))

Also, t needs to be mangled to __t.

4717

You'll need other overloads as outlined in http://wg21.link/p0674. Please add them in this review, otherwise it's too difficult to tell whether the paper is being implemented correctly across reviews.

test/libcxx/memory/shared_ptr_array.pass.cpp
24

test_constructors (typo)

53

https://wandbox.org/permlink/YuADEmFtbD8ZlNS3

The result of dereferencing a pointer like **pi is a lvalue (int& in this case).

This revision now requires changes to proceed.Feb 13 2019, 11:40 AM
zoecarver marked an inline comment as done.Feb 13 2019, 11:58 AM

Thanks for the edits, I will fix them now.

include/memory
4717

Fair enough, I will implement those in this review then.

@ldionne I am having trouble with how to implement arrays with unknown length, could you take a look?

zoecarver marked 7 inline comments as done.Feb 16 2019, 11:23 AM

Sorry about the delay updating this patch. I think I got everything except the additional overloads.

I spent some time trying to add the other overloads. Unless I am not seeing something (which is very possible) I think the shared_ptr class might have to have some serious work in order to support array types with undefined length.

include/memory
3709

Could be wrong about this but I think that this needs to work in C++11 but destroy wasn't introduced until C++17.

3716

Same as above comment.

test/libcxx/memory/shared_ptr_array.pass.cpp
24

How did I not see this 🤦‍♂️

53

Very helpful thank you.

zoecarver marked 2 inline comments as done.
zoecarver abandoned this revision.Jun 6 2019, 8:09 PM

Abandoned in favor of D62641