Skip to content

Conversation

@MichaelRizkalla
Copy link

@MichaelRizkalla MichaelRizkalla commented Oct 14, 2020

Description

A small update that adds _CONSTEXPR20_DYNALLOC to allocator traits member functions to implement constexpr allocators when the compiler defines __cpp_constexpr_dynamic_alloc.

This pull request implements the default allocator changes in P0784R7 except for [allocator.traits.members] construct and destruct Effects.

Useful for #37

Checklist

Before submitting a pull request, please ensure that:

  • Identifiers in product code changes are properly _Ugly as per
    https://eel.is/c++draft/lex.name#3.1 or there are no product code changes.

  • These changes introduce no known ABI breaks (adding members, renaming members, adding virtual functions, changing whether a type is an aggregate or trivially copyable, etc.).

  • Your changes are written from scratch using only this repository, the C++ Working Draft (including any cited standards), other WG21 papers (excluding reference implementations outside of proposed standard wording), and LWG issues as reference material. If your changes are derived from a project that's already listed in NOTICE.txt, that's fine, but please mention it. If your changes are derived from any other project, you must mention it here, so we can determine whether the license is compatible and what else needs to be done.

@MichaelRizkalla MichaelRizkalla requested a review from a team as a code owner October 14, 2020 00:13
@ghost
Copy link

ghost commented Oct 14, 2020

CLA assistant check
All CLA requirements met.

@StephanTLavavej StephanTLavavej added the cxx20 C++20 feature label Oct 14, 2020
@miscco
Copy link
Contributor

miscco commented Oct 14, 2020

As @AdamBucior said, you need to add tests to tests\std\tests\P0784R7_library_support_for_more_constexpr_containers\test.cpp

Also as far as I know this would finish up P0784R7, so we should mark that in <yvals_core> as done

@miscco
Copy link
Contributor

miscco commented Oct 14, 2020

Not I have a wip branch lying around that essentially sprinkels constexpr all around vector.

The problem that we have is that it is not clear currently what to do about ::operator new and ::operator delete if they take the alignment parameter, because those are at least in clang not constexpr

@MichaelRizkalla
Copy link
Author

As @AdamBucior said, you need to add tests to tests\std\tests\P0784R7_library_support_for_more_constexpr_containers\test.cpp

Also as far as I know this would finish up P0784R7, so we should mark that in <yvals_core> as done

I'll add test coverage asap.

There are two missing changes for P0784R7 to be marked it as finished.
In [allocator.traits.members] paragraph 5 and 6:
allocator_trait::construct should invoke construct_at(p, std::forward<Args>(args)...) if the call is not well-formed
allocator_trait::destroy should invoke destroy_at(p) if the call is not well-formed

construct_at and destroy_at are defined in memory header file in #501, so they would not be visible to allocator_traits.
It seemed reasonable to move construct_at and destroy_at to xmemory but since I am new here, I decided to avoid moving functions around until a complete dev guide comes out :)

@miscco
Copy link
Contributor

miscco commented Oct 14, 2020

I am moving construct_at in a3e3dc8

Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

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

Thanks for your work here! It looks like there are some merge conflicts right now which is preventing the test run from kicking off. I'll take another look once you have a chance to resolve the conflicts and address the review comments!

Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

There are some correctness concerns regarding the special alignment changes we do

This suggests that there are insufficient tests there.

Also I am surprised that this works for sized deallocation, as that did not compile in ä1407 Cna you double check that these code paths are tested

Finaly, I am quite surprised that non of the libcxx tests are green now. Did you forget to mark them as passing for clang?

Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

I am sorry for bombarding you with comments :(

Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

Last comment, but after resolving what the maintainers prefer for changing the allocators this looks great

Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

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

Just a small nitpick in test.cpp and a question of consistency given the recent change with feature-test macros 🐱

Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for all of your work and follow up here! This is now ready for final review!

@mnatsuhara
Copy link
Contributor

FYI @MichaelRizkalla, I merged your branch with master to resolve the merge conflicts after #1544 was checked in!

@StephanTLavavej StephanTLavavej linked an issue Jan 7, 2021 that may be closed by this pull request
Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good! I had a number of comments but they're all straightforward to resolve; in the interests of time I will prepare a commit to address them.

Comment on lines 426 to 429
Alloc<A<int>> alloc{10};
assert(alloc.id == 10);

auto result = std::allocator_traits<Alloc<A<int>>>::allocate(alloc, 10);
Copy link
Member

Choose a reason for hiding this comment

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

Observation, no change requested: For clarity, I recommend using distinct values for distinct purposes in test code. Here, 10 is being used for the allocator's ID, and 10 is also the number of A<int> elements being allocated. This makes it more difficult to glance at the source code and immediately recognize the meaning of a 10.

@StephanTLavavej StephanTLavavej removed their assignment Jan 7, 2021
@StephanTLavavej
Copy link
Member

@MichaelRizkalla @mnatsuhara @miscco I believe this is ready to merge, but if you see any issues with the changes I just pushed (particularly the compiler guard changes), we can continue iterating.

@StephanTLavavej StephanTLavavej self-assigned this Jan 7, 2021
@StephanTLavavej StephanTLavavej merged commit 2561974 into microsoft:master Jan 8, 2021
@StephanTLavavej
Copy link
Member

It's merged! This will ship in VS 2019 16.10 Preview 1. Thanks for implementing this C++20 feature, and for enduring our exceptionally lengthy code review process, and congratulations on your first microsoft/STL commit! 🎉 🚀 😸

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

Labels

cxx20 C++20 feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P0784R7 Library Support For More constexpr Containers

7 participants