From fef32ae37d7cf0803ac7c4886edf3ee303718288 Mon Sep 17 00:00:00 2001 From: Jeremy Maitin-Shepard Date: Tue, 22 Oct 2024 21:08:58 -0700 Subject: [PATCH] Rename {ABSL->TENSORSTORE}_ATTRIBUTE_LIFETIME_BOUND for API documentation This permits the definition to be overridden when generating the C++ API documentation. PiperOrigin-RevId: 688800852 Change-Id: I0543738f3bcdeb48cad9bd5828c773718f7714d7 --- tensorstore/BUILD | 4 +- tensorstore/array.h | 34 ++++----- tensorstore/box.h | 33 ++++----- tensorstore/generate_make_array_overloads.py | 5 +- tensorstore/internal/attributes.h | 8 +++ tensorstore/make_array.inc | 76 +++++++++++--------- tensorstore/util/BUILD | 6 +- tensorstore/util/bit_span.h | 3 +- tensorstore/util/future.h | 10 +-- tensorstore/util/result.h | 34 +++++---- tensorstore/util/small_bit_set.h | 16 +++-- tensorstore/util/span.h | 19 ++--- 12 files changed, 140 insertions(+), 108 deletions(-) diff --git a/tensorstore/BUILD b/tensorstore/BUILD index d4bb5efd1..02d099e0a 100644 --- a/tensorstore/BUILD +++ b/tensorstore/BUILD @@ -23,6 +23,7 @@ tensorstore_cc_library( ":rank", ":static_cast", ":strided_layout", + "//tensorstore/internal:attributes", "//tensorstore/internal:element_copy_function", "//tensorstore/internal:elementwise_function", "//tensorstore/internal:integer_overflow", @@ -42,7 +43,6 @@ tensorstore_cc_library( "//tensorstore/util:status", "//tensorstore/util:str_cat", "//tensorstore/util/garbage_collection", - "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/status", @@ -177,6 +177,7 @@ tensorstore_cc_library( ":index_interval", ":rank", ":static_cast", + "//tensorstore/internal:attributes", "//tensorstore/internal:gdb_scripting", "//tensorstore/internal:multi_vector", "//tensorstore/internal:multi_vector_view", @@ -187,7 +188,6 @@ tensorstore_cc_library( "//tensorstore/util:span", "//tensorstore/util:str_cat", "//tensorstore/util/garbage_collection", - "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/status", ], diff --git a/tensorstore/array.h b/tensorstore/array.h index 621a7f8a6..3e13c9be8 100644 --- a/tensorstore/array.h +++ b/tensorstore/array.h @@ -33,7 +33,6 @@ #include #include -#include "absl/base/attributes.h" #include "absl/log/absl_check.h" #include "absl/meta/type_traits.h" #include "absl/status/status.h" @@ -42,6 +41,7 @@ #include "tensorstore/contiguous_layout.h" #include "tensorstore/data_type.h" #include "tensorstore/index.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/internal/elementwise_function.h" #include "tensorstore/internal/meta.h" #include "tensorstore/internal/type_traits.h" @@ -1215,7 +1215,7 @@ Array::element_type, 1> MakeArrayView( /// \id array template ArrayView MakeArrayView( - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0]) { static constexpr Index shape[] = {N0}; static constexpr Index byte_strides[] = {sizeof(Element)}; StridedLayoutView<1> layout(shape, byte_strides); @@ -1223,7 +1223,7 @@ ArrayView MakeArrayView( } template ArrayView MakeArrayView( - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0]) { + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0]) { static constexpr Index shape[] = {N0}; static constexpr Index byte_strides[] = {sizeof(Element)}; StridedLayoutView<1> layout(shape, byte_strides); @@ -1231,7 +1231,7 @@ ArrayView MakeArrayView( } template ArrayView MakeArrayView( - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { static constexpr Index shape[] = {N0, N1}; static constexpr Index byte_strides[] = {N1 * sizeof(Element), sizeof(Element)}; @@ -1240,7 +1240,7 @@ ArrayView MakeArrayView( } template ArrayView MakeArrayView( - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { static constexpr Index shape[] = {N0, N1}; static constexpr Index byte_strides[] = {N1 * sizeof(Element), sizeof(Element)}; @@ -1302,7 +1302,7 @@ SharedArray MakeArray(const Element (&array)[N0][N1]) { template ArrayView MakeOffsetArrayView( tensorstore::span origin, - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0]) { static constexpr Index shape[] = {N0}; static constexpr Index byte_strides[] = {sizeof(Element)}; StridedLayoutView<1, offset_origin> layout(origin, shape, byte_strides); @@ -1313,7 +1313,7 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0]) { + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0]) { static constexpr Index shape[] = {N0}; static constexpr Index byte_strides[] = {sizeof(Element)}; StridedLayoutView<1, offset_origin> layout(origin, shape, byte_strides); @@ -1324,7 +1324,7 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { static constexpr Index shape[] = {N0, N1}; static constexpr Index byte_strides[] = {N1 * sizeof(Element), sizeof(Element)}; @@ -1336,7 +1336,7 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { static constexpr Index shape[] = {N0, N1}; static constexpr Index byte_strides[] = {N1 * sizeof(Element), sizeof(Element)}; @@ -1383,8 +1383,8 @@ SharedArray MakeOffsetArray( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0]) { static_assert(OriginRank == 1, "Origin vector must have length 1."); static constexpr Index shape[] = {N0}; static constexpr Index byte_strides[] = {sizeof(Element)}; @@ -1395,8 +1395,8 @@ ArrayView MakeOffsetArrayView( } template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0]) { static_assert(OriginRank == 1, "Origin vector must have length 1."); static constexpr Index shape[] = {N0}; static constexpr Index byte_strides[] = {sizeof(Element)}; @@ -1408,8 +1408,8 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { static_assert(OriginRank == 2, "Origin vector must have length 2."); static constexpr Index shape[] = {N0, N1}; static constexpr Index byte_strides[] = {N1 * sizeof(Element), @@ -1421,8 +1421,8 @@ ArrayView MakeOffsetArrayView( } template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1]) { static_assert(OriginRank == 2, "Origin vector must have length 2."); static constexpr Index shape[] = {N0, N1}; static constexpr Index byte_strides[] = {N1 * sizeof(Element), diff --git a/tensorstore/box.h b/tensorstore/box.h index d44e8d826..b3af8d5e3 100644 --- a/tensorstore/box.h +++ b/tensorstore/box.h @@ -26,10 +26,10 @@ #include #include -#include "absl/base/attributes.h" #include "absl/meta/type_traits.h" #include "tensorstore/index.h" #include "tensorstore/index_interval.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/internal/gdb_scripting.h" #include "tensorstore/internal/multi_vector.h" #include "tensorstore/internal/multi_vector_view.h" @@ -439,8 +439,8 @@ Box(const Index (&shape)[Rank]) -> Box; template && IsIndexConvertibleVector)>* = nullptr> -Box(const Origin& origin, - const Shape& shape) -> Box::value>; +Box(const Origin& origin, const Shape& shape) + -> Box::value>; template Box(const Index (&origin)[Rank], const Index (&shape)[Rank]) -> Box; @@ -512,7 +512,7 @@ class BoxView : public internal_box::BoxViewStorage { template > explicit BoxView(tensorstore::span shape - ABSL_ATTRIBUTE_LIFETIME_BOUND) { + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) { const auto rank = GetStaticOrDynamicExtent(shape); Access::Assign(this, rank, GetConstantVector(rank).data(), shape.data()); @@ -520,7 +520,7 @@ class BoxView : public internal_box::BoxViewStorage { template > - explicit BoxView(IndexType (&shape ABSL_ATTRIBUTE_LIFETIME_BOUND)[N]) { + explicit BoxView(IndexType (&shape TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N]) { const auto rank = std::integral_constant{}; Access::Assign(this, rank, GetConstantVector(rank).data(), shape); } @@ -535,8 +535,8 @@ class BoxView : public internal_box::BoxViewStorage { } template > - explicit BoxView(IndexType (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[N], - IndexType (&shape ABSL_ATTRIBUTE_LIFETIME_BOUND)[N]) { + explicit BoxView(IndexType (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N], + IndexType (&shape TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N]) { const auto rank = std::integral_constant{}; Access::Assign(this, rank, origin, shape); } @@ -557,11 +557,12 @@ class BoxView : public internal_box::BoxViewStorage { /// \requires If `Mutable == true`, `BoxType` must be a mutable Box-like type /// (such as a non-const `Box` reference or a `MutableBoxView`). /// \id convert - template && (!Mutable || IsMutableBoxLike) && - RankConstraint::Implies( - absl::remove_cvref_t::static_rank, Rank))>> + template < + typename BoxType, + typename = std::enable_if_t< + (IsBoxLike && + (!Mutable || IsMutableBoxLike)&&RankConstraint::Implies( + absl::remove_cvref_t::static_rank, Rank))>> // NONITPICK: std::remove_cvref_t::static_rank BoxView(BoxType&& other) : BoxView(other.rank(), other.origin().data(), other.shape().data()) {} @@ -586,7 +587,7 @@ class BoxView : public internal_box::BoxViewStorage { typename BoxType, std::enable_if_t< (IsBoxLike> && - (!Mutable || IsMutableBoxLike>) && + (!Mutable || IsMutableBoxLike>)&& RankConstraint::Implies(absl::remove_cvref_t::static_rank, Rank))>* = nullptr> @@ -666,7 +667,7 @@ class BoxView : public internal_box::BoxViewStorage { return ApplyIndexTransform(*this, std::forward(transformable)); } -}; +}; // namespace tensorstore BoxView(DimensionIndex rank) -> BoxView<>; @@ -703,8 +704,8 @@ BoxView(Origin&& origin, Shape&& shape) (IsMutableIndexVector && IsMutableIndexVector)>; template -BoxView(const Index (&origin)[Rank], - const Index (&shape)[Rank]) -> BoxView; +BoxView(const Index (&origin)[Rank], const Index (&shape)[Rank]) + -> BoxView; template struct StaticCastTraits> diff --git a/tensorstore/generate_make_array_overloads.py b/tensorstore/generate_make_array_overloads.py index 73b748e42..24593baa0 100755 --- a/tensorstore/generate_make_array_overloads.py +++ b/tensorstore/generate_make_array_overloads.py @@ -109,7 +109,8 @@ def output_make_array( elif origin_type == 'array': if is_view: origin_parameter = ( - 'const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], ' + 'const Index (&origin' + ' TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], ' ) else: origin_parameter = 'const Index (&origin)[OriginRank], ' @@ -138,7 +139,7 @@ def output_make_array( out.write( 'ArrayView<{element}, {rank}{origin_kind_parameter}>' ' Make{function_name}View({origin_parameter}{element} (&array' - ' ABSL_ATTRIBUTE_LIFETIME_BOUND)'.format( + ' TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)'.format( rank=rank, element=maybe_const_element, origin_parameter=origin_parameter, diff --git a/tensorstore/internal/attributes.h b/tensorstore/internal/attributes.h index ed539c379..951335d53 100644 --- a/tensorstore/internal/attributes.h +++ b/tensorstore/internal/attributes.h @@ -17,6 +17,14 @@ #include "absl/base/attributes.h" +#ifndef TENSORSTORE_CPP_DOC_GENERATION +#define TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND ABSL_ATTRIBUTE_LIFETIME_BOUND +#else +// Expand to nothing to avoid cluttering the documentation and because the +// Sphinx C++ parser chokes on it. +#define TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND +#endif + // When defining a conditionally-explicit constructor, this may be used on the // explicit overload to wrap the portion of the `enable_if` conditions that // differ from the implicit overload. diff --git a/tensorstore/make_array.inc b/tensorstore/make_array.inc index c8db0f0b5..6d9c399b5 100644 --- a/tensorstore/make_array.inc +++ b/tensorstore/make_array.inc @@ -11,7 +11,7 @@ template ArrayView MakeArrayView( - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { static constexpr Index shape[] = {N0, N1, N2}; static constexpr Index byte_strides[] = { N1 * N2 * sizeof(Element), N2 * sizeof(Element), sizeof(Element)}; @@ -20,7 +20,7 @@ ArrayView MakeArrayView( } template ArrayView MakeArrayView( - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { static constexpr Index shape[] = {N0, N1, N2}; static constexpr Index byte_strides[] = { N1 * N2 * sizeof(Element), N2 * sizeof(Element), sizeof(Element)}; @@ -30,7 +30,7 @@ ArrayView MakeArrayView( template ArrayView MakeArrayView( - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { static constexpr Index shape[] = {N0, N1, N2, N3}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * sizeof(Element), N2 * N3 * sizeof(Element), @@ -39,8 +39,8 @@ ArrayView MakeArrayView( return {&array[0][0][0][0], layout}; } template -ArrayView MakeArrayView( - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { +ArrayView MakeArrayView(const Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { static constexpr Index shape[] = {N0, N1, N2, N3}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * sizeof(Element), N2 * N3 * sizeof(Element), @@ -51,7 +51,7 @@ ArrayView MakeArrayView( template ArrayView MakeArrayView( - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * sizeof(Element), N2 * N3 * N4 * sizeof(Element), @@ -60,8 +60,8 @@ ArrayView MakeArrayView( return {&array[0][0][0][0][0], layout}; } template -ArrayView MakeArrayView( - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { +ArrayView MakeArrayView(const Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * sizeof(Element), N2 * N3 * N4 * sizeof(Element), @@ -72,8 +72,8 @@ ArrayView MakeArrayView( template -ArrayView MakeArrayView( - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { +ArrayView MakeArrayView(Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4, N5}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * N5 * sizeof(Element), @@ -88,7 +88,7 @@ ArrayView MakeArrayView( template ArrayView MakeArrayView(const Element ( - &array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4, N5}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * N5 * sizeof(Element), @@ -143,7 +143,7 @@ SharedArray MakeArray( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { static constexpr Index shape[] = {N0, N1, N2}; static constexpr Index byte_strides[] = { N1 * N2 * sizeof(Element), N2 * sizeof(Element), sizeof(Element)}; @@ -155,7 +155,7 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { static constexpr Index shape[] = {N0, N1, N2}; static constexpr Index byte_strides[] = { N1 * N2 * sizeof(Element), N2 * sizeof(Element), sizeof(Element)}; @@ -168,7 +168,7 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { static constexpr Index shape[] = {N0, N1, N2, N3}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * sizeof(Element), N2 * N3 * sizeof(Element), @@ -181,7 +181,8 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { + const Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { static constexpr Index shape[] = {N0, N1, N2, N3}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * sizeof(Element), N2 * N3 * sizeof(Element), @@ -195,7 +196,7 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * sizeof(Element), N2 * N3 * N4 * sizeof(Element), @@ -208,7 +209,8 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( tensorstore::span origin, - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { + const Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * sizeof(Element), N2 * N3 * N4 * sizeof(Element), @@ -223,7 +225,8 @@ template ArrayView MakeOffsetArrayView( tensorstore::span origin, - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { + Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4, N5}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * N5 * sizeof(Element), @@ -242,7 +245,7 @@ template MakeOffsetArrayView( tensorstore::span origin, const Element ( - &array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { static constexpr Index shape[] = {N0, N1, N2, N3, N4, N5}; static constexpr Index byte_strides[] = { N1 * N2 * N3 * N4 * N5 * sizeof(Element), @@ -312,8 +315,8 @@ SharedArray MakeOffsetArray( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { static_assert(OriginRank == 3, "Origin vector must have length 3."); static constexpr Index shape[] = {N0, N1, N2}; static constexpr Index byte_strides[] = { @@ -325,8 +328,8 @@ ArrayView MakeOffsetArrayView( } template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + const Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2]) { static_assert(OriginRank == 3, "Origin vector must have length 3."); static constexpr Index shape[] = {N0, N1, N2}; static constexpr Index byte_strides[] = { @@ -340,8 +343,8 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { static_assert(OriginRank == 4, "Origin vector must have length 4."); static constexpr Index shape[] = {N0, N1, N2, N3}; static constexpr Index byte_strides[] = { @@ -355,8 +358,9 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + const Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3]) { static_assert(OriginRank == 4, "Origin vector must have length 4."); static constexpr Index shape[] = {N0, N1, N2, N3}; static constexpr Index byte_strides[] = { @@ -371,8 +375,8 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + Element (&array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { static_assert(OriginRank == 5, "Origin vector must have length 5."); static constexpr Index shape[] = {N0, N1, N2, N3, N4}; static constexpr Index byte_strides[] = { @@ -386,8 +390,9 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - const Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + const Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4]) { static_assert(OriginRank == 5, "Origin vector must have length 5."); static constexpr Index shape[] = {N0, N1, N2, N3, N4}; static constexpr Index byte_strides[] = { @@ -402,8 +407,9 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], - Element (&array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + Element ( + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { static_assert(OriginRank == 6, "Origin vector must have length 6."); static constexpr Index shape[] = {N0, N1, N2, N3, N4, N5}; static constexpr Index byte_strides[] = { @@ -421,9 +427,9 @@ ArrayView MakeOffsetArrayView( template ArrayView MakeOffsetArrayView( - const Index (&origin ABSL_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], + const Index (&origin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[OriginRank], const Element ( - &array ABSL_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { + &array TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N0][N1][N2][N3][N4][N5]) { static_assert(OriginRank == 6, "Origin vector must have length 6."); static constexpr Index shape[] = {N0, N1, N2, N3, N4, N5}; static constexpr Index byte_strides[] = { diff --git a/tensorstore/util/BUILD b/tensorstore/util/BUILD index 04d6d4aa5..d628ee66c 100644 --- a/tensorstore/util/BUILD +++ b/tensorstore/util/BUILD @@ -11,6 +11,7 @@ tensorstore_cc_library( deps = [ ":small_bit_set", ":span", + "//tensorstore/internal:attributes", "@com_google_absl//absl/base:core_headers", ], ) @@ -158,8 +159,8 @@ tensorstore_cc_library( name = "small_bit_set", hdrs = ["small_bit_set.h"], deps = [ + "//tensorstore/internal:attributes", "//tensorstore/internal:integer_types", - "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/numeric:bits", ], ) @@ -323,6 +324,7 @@ tensorstore_cc_library( ":executor", ":result", ":span", + "//tensorstore/internal:attributes", "//tensorstore/internal:integer_sequence", "//tensorstore/internal:intrusive_ptr", "//tensorstore/internal:tagged_ptr", @@ -495,6 +497,7 @@ tensorstore_cc_library( ], deps = [ ":status", + "//tensorstore/internal:attributes", "//tensorstore/internal:type_traits", "//tensorstore/internal/preprocessor:cat", "//tensorstore/internal/preprocessor:expand", @@ -537,6 +540,7 @@ tensorstore_cc_library( name = "span", hdrs = ["span.h"], deps = [ + "//tensorstore/internal:attributes", "//tensorstore/internal:gdb_scripting", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/log:absl_log", diff --git a/tensorstore/util/bit_span.h b/tensorstore/util/bit_span.h index bbfdfc7b7..f18a3cf1f 100644 --- a/tensorstore/util/bit_span.h +++ b/tensorstore/util/bit_span.h @@ -28,6 +28,7 @@ #include #include "absl/base/attributes.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/util/small_bit_set.h" #include "tensorstore/util/span.h" @@ -118,7 +119,7 @@ class BitSpan { /// \dchecks `offset >= 0`. /// \dchecks `size >= 0`. /// \dchecks `Extent == dynamic_extent || Extent == size`. - constexpr BitSpan(T* base ABSL_ATTRIBUTE_LIFETIME_BOUND, + constexpr BitSpan(T* base TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND, std::ptrdiff_t offset, std::ptrdiff_t size) : BitSpan(BitIterator(base, offset), size) {} diff --git a/tensorstore/util/future.h b/tensorstore/util/future.h index bb44220ff..c4f0082fc 100644 --- a/tensorstore/util/future.h +++ b/tensorstore/util/future.h @@ -29,10 +29,10 @@ #include #include -#include "absl/base/attributes.h" #include "absl/meta/type_traits.h" #include "absl/status/status.h" #include "absl/time/time.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/internal/intrusive_ptr.h" #include "tensorstore/internal/type_traits.h" #include "tensorstore/util/executor.h" @@ -463,7 +463,8 @@ class AnyFuture { /// (when a value is present) or a copy of result.status(). /// /// \dchecks `!null()` - const absl::Status& status() const& noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + const absl::Status& status() const& noexcept + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { Wait(); return rep().status(); } @@ -811,13 +812,14 @@ class Future : public AnyFuture { /// /// \dchecks `!null()` std::add_lvalue_reference_t result() const - ABSL_ATTRIBUTE_LIFETIME_BOUND { + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { this->Wait(); return rep().result; } /// Equivalent to `result().value()`. - std::add_lvalue_reference_t value() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + std::add_lvalue_reference_t value() const + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { return result().value(); } diff --git a/tensorstore/util/result.h b/tensorstore/util/result.h index 22d478b8d..3b6baf3b3 100644 --- a/tensorstore/util/result.h +++ b/tensorstore/util/result.h @@ -19,12 +19,12 @@ #include #include -#include "absl/base/attributes.h" #include "absl/base/optimization.h" #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/meta/type_traits.h" #include "absl/status/status.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/internal/preprocessor/cat.h" #include "tensorstore/internal/preprocessor/expand.h" #include "tensorstore/internal/type_traits.h" @@ -380,14 +380,14 @@ class Result : private internal_result::ResultStorage, /// opt.emplace(arg1,arg2,arg3); // Constructs Foo(arg1,arg2,arg3) /// template - T& emplace(Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { + T& emplace(Args&&... args) TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { static_assert(sizeof...(Args) == 0 || !std::is_void_v); this->emplace_value(std::forward(args)...); return this->value_; } template T& emplace(std::initializer_list il, - Args&&... args) ABSL_ATTRIBUTE_LIFETIME_BOUND { + Args&&... args) TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { this->emplace_value(il, std::forward(args)...); return this->value_; } @@ -412,25 +412,26 @@ class Result : private internal_result::ResultStorage, /// Terminates the process if `*this` represents a failure state. /// /// \pre `has_value() == true` - const T& value() const& noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + const T& value() const& noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { if (!has_value()) TENSORSTORE_CHECK_OK(status()); return this->value_; } - T& value() & noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + T& value() & noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { if (!has_value()) TENSORSTORE_CHECK_OK(status()); return this->value_; } - const T&& value() const&& noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + const T&& value() const&& noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { if (!has_value()) TENSORSTORE_CHECK_OK(status()); return std::move(this->value_); } - T&& value() && noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + T&& value() && noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { if (!has_value()) TENSORSTORE_CHECK_OK(status()); return std::move(this->value_); } /// Returns the error status. - const absl::Status& status() const& noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + const absl::Status& status() const& noexcept + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { return status_; } absl::Status status() && noexcept { @@ -442,30 +443,32 @@ class Result : private internal_result::ResultStorage, /// Returns a pointer to the contained value. /// /// \pre has_value() == true - constexpr const T* operator->() const noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr const T* operator->() const noexcept + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert_has_value(); return &this->value_; } - constexpr T* operator->() noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr T* operator->() noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert_has_value(); return &this->value_; } /// Returns a reference to the contained value. - constexpr const T& operator*() const& noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr const T& operator*() const& noexcept + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert_has_value(); return this->value_; } - constexpr T& operator*() & noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr T& operator*() & noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert_has_value(); return this->value_; } constexpr const T&& operator*() const&& noexcept - ABSL_ATTRIBUTE_LIFETIME_BOUND { + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert_has_value(); return std::move(this->value_); } - constexpr T&& operator*() && noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr T&& operator*() && noexcept TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert_has_value(); return std::move(this->value_); } @@ -668,7 +671,8 @@ class Result { void value() const { TENSORSTORE_CHECK_OK(status()); } - const absl::Status& status() const& noexcept ABSL_ATTRIBUTE_LIFETIME_BOUND { + const absl::Status& status() const& noexcept + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { return status_; } diff --git a/tensorstore/util/small_bit_set.h b/tensorstore/util/small_bit_set.h index 9a1871e88..83ef00fbc 100644 --- a/tensorstore/util/small_bit_set.h +++ b/tensorstore/util/small_bit_set.h @@ -22,8 +22,8 @@ #include #include -#include "absl/base/attributes.h" #include "absl/numeric/bits.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/internal/integer_types.h" namespace tensorstore { @@ -56,7 +56,8 @@ class BitRef { constexpr static ptrdiff_t kBitsPerBlock = sizeof(T) * 8; /// Binds to bit `offset % kBitsPerBlock` of `*block`. - constexpr BitRef(T* block ABSL_ATTRIBUTE_LIFETIME_BOUND, ptrdiff_t offset) + constexpr BitRef(T* block TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND, + ptrdiff_t offset) : block_(block), mask_(static_cast(1) << (offset % kBitsPerBlock)) { assert(offset >= 0); } @@ -168,7 +169,8 @@ class BitIterator { /// Constructs from a base pointer and offset. /// /// \id base, offset - constexpr BitIterator(T* base ABSL_ATTRIBUTE_LIFETIME_BOUND, ptrdiff_t offset) + constexpr BitIterator(T* base TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND, + ptrdiff_t offset) : base_(base), offset_(offset) {} /// Converts from a non-``const`` iterator. @@ -488,13 +490,14 @@ class SmallBitSet { /// Mutable view of SmallBitSet bits. using BoolsView = bitset_impl::BoolsView, N>; - constexpr BoolsView bools_view() ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr BoolsView bools_view() TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { return BoolsView(BitIterator(&bits_, 0)); } /// Immutable view of SmallBitSet bits. using ConstBoolsView = bitset_impl::BoolsView, N>; - constexpr ConstBoolsView bools_view() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr ConstBoolsView bools_view() const + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { return ConstBoolsView(BitIterator(&bits_, 0)); } @@ -561,7 +564,8 @@ class SmallBitSet { /// Returns a reference to an individual bit. /// /// \dchecks `offset >= 0 && offset < N` - constexpr reference operator[](size_t offset) ABSL_ATTRIBUTE_LIFETIME_BOUND { + constexpr reference operator[](size_t offset) + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND { assert(offset >= 0 && offset < N); return reference(&bits_, offset); } diff --git a/tensorstore/util/span.h b/tensorstore/util/span.h index c16bb1c80..d60ee17e3 100644 --- a/tensorstore/util/span.h +++ b/tensorstore/util/span.h @@ -27,6 +27,7 @@ #include "absl/base/attributes.h" #include "absl/base/optimization.h" #include "absl/log/absl_log.h" +#include "tensorstore/internal/attributes.h" #include "tensorstore/internal/gdb_scripting.h" TENSORSTORE_GDB_AUTO_SCRIPT("span_gdb.py") @@ -194,7 +195,7 @@ class span { /// /// \dchecks `Extent == dynamic_extent || count == Extent` /// \id pointer, count - constexpr span(pointer ptr ABSL_ATTRIBUTE_LIFETIME_BOUND, + constexpr span(pointer ptr TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND, index_type count) noexcept : data_(ptr), size_{} { if constexpr (Extent == dynamic_extent) { @@ -216,8 +217,8 @@ class span { // // See https://github.com/Microsoft/GSL/issues/541. typename = void> - constexpr span(pointer begin ABSL_ATTRIBUTE_LIFETIME_BOUND, - pointer end ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept + constexpr span(pointer begin TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND, + pointer end TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) noexcept : span(begin, end - begin) {} /// Constructs from an array or `std::array`. @@ -225,19 +226,19 @@ class span { /// \id array template > - constexpr span(T (&arr ABSL_ATTRIBUTE_LIFETIME_BOUND)[N]) noexcept + constexpr span(T (&arr TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N]) noexcept : span(arr, N) {} template > - constexpr span( - std::array& arr ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept + constexpr span(std::array& arr + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) noexcept : span(arr.data(), N) {} template < size_t N, typename U = T, typename = std::enable_if_t && (Extent == dynamic_extent || Extent == N)>> constexpr span(const std::array& arr - ABSL_ATTRIBUTE_LIFETIME_BOUND) noexcept + TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) noexcept : span(arr.data(), N) {} /// Constructs from a container with ``data`` and ``size`` methods. @@ -245,12 +246,12 @@ class span { /// \id container template > - constexpr span(Container& cont ABSL_ATTRIBUTE_LIFETIME_BOUND) + constexpr span(Container& cont TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) : span(cont.data(), cont.size()) {} template < typename Container, typename = internal_span::EnableIfCompatibleContainer> - constexpr span(const Container& cont ABSL_ATTRIBUTE_LIFETIME_BOUND) + constexpr span(const Container& cont TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) : span(cont.data(), cont.size()) {} /// Converts from a compatible span type.