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

feature/spaceship: Clause 22: Containers #1046

Merged

Conversation

ahanamuk
Copy link
Contributor

@ahanamuk ahanamuk commented Jul 15, 2020

This implements #62 for Clause 22, Containers.

@ahanamuk ahanamuk requested a review from a team as a code owner July 15, 2020 14:33
@StephanTLavavej StephanTLavavej added cxx20 C++20 feature spaceship C++20 operator <=> labels Jul 15, 2020
@StephanTLavavej

This comment has been minimized.

@StephanTLavavej StephanTLavavej changed the title Feature/spaceship feature/spaceship: Clause 22: Containers Jul 15, 2020
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 for this first batch of 🛸 work! I've reviewed everything and it looks solid; although some fixes are necessary, I think they should be relatively straightforward. (The biggest unknown is how to test synth-three-way and I would be comfortable marking that as a FIXME if you want.) Then it should be ready to be merged into the feature branch.

stl/inc/stack Outdated Show resolved Hide resolved
stl/inc/array Outdated Show resolved Hide resolved
stl/inc/array Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
stl/inc/array Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
@StephanTLavavej

This comment has been minimized.

queue<T, NonSpaceshipContainer> might be instantiated for a
non-three_way_comparable NonSpaceshipContainer. In that case, it
shouldn't attempt to grant friendship to the spaceship operator,
because that would attempt to form
compare_three_way_result_t<NonSpaceshipContainer>.

As far as I can tell, there's no way in the Core Language for a queue
to grant friendship to only one specialization of its non-member
spaceship operator while respecting the constraint. (See
WG21-N4861 [temp.friend]/9.) Instead, we need to template the
friendship declaration, such that queue grants friendship to all of its
spaceship operators. This is safe, just verbose.
@StephanTLavavej

This comment has been minimized.

stl/inc/array Show resolved Hide resolved
stl/inc/list Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/P0896R4_P1614R2_spaceship/test.cpp Outdated Show resolved Hide resolved
@StephanTLavavej

This comment has been minimized.

stl/inc/vector Outdated Show resolved Hide resolved
@StephanTLavavej

This comment has been minimized.

Testing `_Differing_bits == 0` might seem like it's asking the compiler
to do more work (always XORing). But it allows the compiler to see that
the input to `_Countr_zero` is nonzero, and that allows it to optimize
away the runtime ISA check, unconditionally emitting a `tzcnt`
instruction.

Then, at the end of the function, we know something that the compiler
doesn't realize: `_Mask` selects a differing bit (the least significant
one), so `(_Left & _Mask)` and `(_Right & _Mask)` are zero/nonzero
or vice versa. Therefore, we only need to inspect one side!

I've verified that each of these changes improves the codegen.

Co-authored-by: Casey Carter <[email protected]>
@StephanTLavavej

This comment has been minimized.

stl/inc/vector Show resolved Hide resolved
stl/inc/vector Outdated Show resolved Hide resolved
Copy link
Member

@CaseyCarter CaseyCarter left a comment

Choose a reason for hiding this comment

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

Two small suggestions.

tests/std/test.lst Outdated Show resolved Hide resolved
stl/inc/vector Outdated Show resolved Hide resolved
stl/inc/map Outdated Show resolved Hide resolved
stl/inc/utility Outdated Show resolved Hide resolved
stl/inc/utility Outdated Show resolved Hide resolved
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.

Going to merge this into the feature branch after the tests run! 🎉 😸 🛸

I've added a note to the Spaceship Project that we need to implement spaceships for the container iterators too (which are Clause 22); that shouldn't hold up this significant PR.

@StephanTLavavej StephanTLavavej merged commit 889b8c8 into microsoft:feature/spaceship Jul 28, 2020
@StephanTLavavej
Copy link
Member

Thanks for implementing the important synth-three-way machinery and all of these operators! I can hardly contain my excitement. 😎 🛸

@StephanTLavavej StephanTLavavej removed their assignment Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cxx20 C++20 feature spaceship C++20 operator <=>
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants