-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<mdspan>: Improve debug checks
#3821
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
Merged
StephanTLavavej
merged 29 commits into
microsoft:feature/mdspan2
from
JMazurkiewicz:mdspan/debug-guards
Jul 3, 2023
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ff64bc8
Improve `mdspan::empty`
JMazurkiewicz 8d7468c
Improve `_Is_index_space_size_representable` and rename it to `_Is_st…
JMazurkiewicz 3e791db
`layout_left`: Guard checks with `#if _CONTAINER_DEBUG_LEVEL > 0`
JMazurkiewicz 9363526
`layout_left`: Implement `mapping(const extents_type&)` constructor's…
JMazurkiewicz 7c29805
`layout_right`: Guard checks with `#if _CONTAINER_DEBUG_LEVEL > 0`
JMazurkiewicz e416aef
`layout_right`: Implement `mapping(const extents_type&)` constructor'…
JMazurkiewicz 6cd745b
`layout_stride`: Guard checks with `#if _CONTAINER_DEBUG_LEVEL > 0`
JMazurkiewicz e59d020
`layout_left`: Use `for` loop instead of huge lambda expression in pr…
JMazurkiewicz e1b3512
`layout_right`: Use `for` loop instead of huge lambda expression in p…
JMazurkiewicz 63e652b
`layout_stride`: implement default constructor's preconditions
JMazurkiewicz 1e5341e
`layout_stride`: implement `mapping(extents_type, array/span)` constr…
JMazurkiewicz 6ce8adc
`extents`: Improve `extents(exts...)` constructor's preconditions
JMazurkiewicz f6aed8d
`mdspan`: Implement `mdspan(other mdspan)` constructor's preconditions
JMazurkiewicz b3e4c4e
`extents`: expose `_Static_extents` array
JMazurkiewicz 360d1f7
`mdspan`: Implement precondition check in `operator[]`
JMazurkiewicz 76e0498
`mdspan`: Implement `mdspan::size`'s preconditions
JMazurkiewicz 1a04c33
`extents`: Document DevCom-10398426 workaround
JMazurkiewicz 6044c69
layouts: fix `_Contains_multidimensional_index` checks
JMazurkiewicz 77c4a0b
`layout_stride`: fix death test
JMazurkiewicz 0a3b516
Those invisible...
JMazurkiewicz f65dd87
Add missing `template` keyword
JMazurkiewicz 172f2d5
`mdspan`: Use `cmp_equal` instead of regular `==` in precondition check
JMazurkiewicz eb1ee89
Silence Clang's constexpr limit error in `layout_(left|right)`'s tests
JMazurkiewicz ca14e4b
Drive-by: use `ranges::adjacent_find` instead of `views::pairwise_tra…
JMazurkiewicz a7f66df
Drive-by: fix exhaustiveness check in `get_mapping_properties`.
JMazurkiewicz 72d2ff8
`layouts`: Improve preconditions checks in `operator()`
JMazurkiewicz fbee069
`mdspan`: Manually inline call to `extents_type::static_extent` in `s…
JMazurkiewicz 5fa6e18
`layouts`: `_IndexSeq` -> `_Index_seq`
JMazurkiewicz d847e1a
`mdspan`: Improve precondition in `mdspan::operator[]`
JMazurkiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\concepts_latest_matrix.lst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #define _CONTAINER_DEBUG_LEVEL 1 | ||
|
|
||
| #include <array> | ||
| #include <mdspan> | ||
|
|
||
| #include <test_death.hpp> | ||
|
|
||
| using namespace std; | ||
|
|
||
| constexpr array<int, 256> some_ints{}; | ||
|
|
||
| void test_construction_from_other_mdspan() { | ||
| auto mds1 = mdspan{some_ints.data(), 8, 2, 8}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an occurrence of "almost always auto" which we conventionally avoid. Occurs below. |
||
| // For each rank index r of extents_type, static_extent(r) == dynamic_extent || static_extent(r) == other.extent(r) | ||
| // must be true | ||
| [[maybe_unused]] mdspan<const int, extents<int, 8, 8, 2>> mds2{mds1}; | ||
| } | ||
|
|
||
| #ifdef __cpp_multidimensional_subscript // TRANSITION, P2128R6 | ||
| void test_access_with_invalid_multidimensional_index_1() { | ||
| auto mds = mdspan{some_ints.data(), 4, 4}; | ||
| // I must be a multidimensional index in extents() | ||
| (void) mds[3, 4]; | ||
| } | ||
| #endif // __cpp_multidimensional_subscript | ||
|
|
||
| void test_access_with_invalid_multidimensional_index_2() { | ||
| auto mds = mdspan{some_ints.data(), 5, 5}; | ||
| // I must be a multidimensional index in extents() | ||
| (void) mds[array{4, 5}]; | ||
| } | ||
|
|
||
| void test_size_when_index_type_is_signed() { | ||
| auto mds = mdspan{some_ints.data(), dextents<signed char, 3>{8, 8, 4}}; | ||
| // The size of the multidimensional index space extents() must be representable as a value of type size_type | ||
| (void) mds.size(); | ||
| } | ||
|
|
||
| void test_size_when_index_type_is_unsigned() { | ||
| auto mds = mdspan{some_ints.data(), dextents<unsigned char, 3>{8, 8, 4}}; | ||
| // The size of the multidimensional index space extents() must be representable as a value of type size_type | ||
| (void) mds.size(); | ||
| } | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| std_testing::death_test_executive exec; | ||
| exec.add_death_tests({ | ||
| test_construction_from_other_mdspan, | ||
| #ifdef __cpp_multidimensional_subscript // TRANSITION, P2128R6 | ||
| test_access_with_invalid_multidimensional_index_1, | ||
| #endif // __cpp_multidimensional_subscript | ||
| test_access_with_invalid_multidimensional_index_2, | ||
| test_size_when_index_type_is_signed, | ||
| test_size_when_index_type_is_unsigned, | ||
| }); | ||
| return exec.run(argc, argv); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.