Skip to content

Commit

Permalink
Rename {ABSL->TENSORSTORE}_ATTRIBUTE_LIFETIME_BOUND for API documenta…
Browse files Browse the repository at this point in the history
…tion

This permits the definition to be overridden when generating the C++ API
documentation.

PiperOrigin-RevId: 688800852
Change-Id: I0543738f3bcdeb48cad9bd5828c773718f7714d7
  • Loading branch information
jbms authored and copybara-github committed Oct 23, 2024
1 parent b52f8a6 commit fef32ae
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 108 deletions.
4 changes: 2 additions & 2 deletions tensorstore/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
],
Expand Down
34 changes: 17 additions & 17 deletions tensorstore/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <type_traits>
#include <utility>

#include "absl/base/attributes.h"
#include "absl/log/absl_check.h"
#include "absl/meta/type_traits.h"
#include "absl/status/status.h"
Expand All @@ -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"
Expand Down Expand Up @@ -1215,23 +1215,23 @@ Array<typename internal::SpanType<Source>::element_type, 1> MakeArrayView(
/// \id array
template <typename Element, Index N0>
ArrayView<Element, 1> 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);
return {&array[0], layout};
}
template <typename Element, Index N0>
ArrayView<const Element, 1> 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);
return {&array[0], layout};
}
template <typename Element, Index N0, Index N1>
ArrayView<Element, 2> 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)};
Expand All @@ -1240,7 +1240,7 @@ ArrayView<Element, 2> MakeArrayView(
}
template <typename Element, Index N0, Index N1>
ArrayView<const Element, 2> 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)};
Expand Down Expand Up @@ -1302,7 +1302,7 @@ SharedArray<Element, 2> MakeArray(const Element (&array)[N0][N1]) {
template <typename Element, Index N0>
ArrayView<Element, 1, offset_origin> MakeOffsetArrayView(
tensorstore::span<const Index, 1> 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);
Expand All @@ -1313,7 +1313,7 @@ ArrayView<Element, 1, offset_origin> MakeOffsetArrayView(
template <typename Element, Index N0>
ArrayView<const Element, 1, offset_origin> MakeOffsetArrayView(
tensorstore::span<const Index, 1> 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);
Expand All @@ -1324,7 +1324,7 @@ ArrayView<const Element, 1, offset_origin> MakeOffsetArrayView(
template <typename Element, Index N0, Index N1>
ArrayView<Element, 2, offset_origin> MakeOffsetArrayView(
tensorstore::span<const Index, 2> 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)};
Expand All @@ -1336,7 +1336,7 @@ ArrayView<Element, 2, offset_origin> MakeOffsetArrayView(
template <typename Element, Index N0, Index N1>
ArrayView<const Element, 2, offset_origin> MakeOffsetArrayView(
tensorstore::span<const Index, 2> 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)};
Expand Down Expand Up @@ -1383,8 +1383,8 @@ SharedArray<Element, 2, offset_origin> MakeOffsetArray(

template <typename Element, Index N0, ptrdiff_t OriginRank>
ArrayView<Element, 1, offset_origin> 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)};
Expand All @@ -1395,8 +1395,8 @@ ArrayView<Element, 1, offset_origin> MakeOffsetArrayView(
}
template <typename Element, Index N0, ptrdiff_t OriginRank>
ArrayView<const Element, 1, offset_origin> 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)};
Expand All @@ -1408,8 +1408,8 @@ ArrayView<const Element, 1, offset_origin> MakeOffsetArrayView(

template <typename Element, Index N0, Index N1, ptrdiff_t OriginRank>
ArrayView<Element, 2, offset_origin> 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),
Expand All @@ -1421,8 +1421,8 @@ ArrayView<Element, 2, offset_origin> MakeOffsetArrayView(
}
template <typename Element, Index N0, Index N1, ptrdiff_t OriginRank>
ArrayView<const Element, 2, offset_origin> 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),
Expand Down
33 changes: 17 additions & 16 deletions tensorstore/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include <string>
#include <type_traits>

#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"
Expand Down Expand Up @@ -439,8 +439,8 @@ Box(const Index (&shape)[Rank]) -> Box<Rank>;
template <typename Origin, typename Shape,
std::enable_if_t<(IsIndexConvertibleVector<Origin> &&
IsIndexConvertibleVector<Shape>)>* = nullptr>
Box(const Origin& origin,
const Shape& shape) -> Box<SpanStaticExtent<Origin, Shape>::value>;
Box(const Origin& origin, const Shape& shape)
-> Box<SpanStaticExtent<Origin, Shape>::value>;

template <DimensionIndex Rank>
Box(const Index (&origin)[Rank], const Index (&shape)[Rank]) -> Box<Rank>;
Expand Down Expand Up @@ -512,15 +512,15 @@ class BoxView : public internal_box::BoxViewStorage<Rank, Mutable> {
template <bool SfinaeM = Mutable,
typename = std::enable_if_t<SfinaeM == false>>
explicit BoxView(tensorstore::span<const Index, Rank> shape
ABSL_ATTRIBUTE_LIFETIME_BOUND) {
TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND) {
const auto rank = GetStaticOrDynamicExtent(shape);
Access::Assign(this, rank, GetConstantVector<Index, 0>(rank).data(),
shape.data());
}
template <size_t N, bool SfinaeM = Mutable,
typename = std::enable_if_t<
(RankConstraint::Implies(N, static_rank) && SfinaeM == false)>>
explicit BoxView(IndexType (&shape ABSL_ATTRIBUTE_LIFETIME_BOUND)[N]) {
explicit BoxView(IndexType (&shape TENSORSTORE_ATTRIBUTE_LIFETIME_BOUND)[N]) {
const auto rank = std::integral_constant<ptrdiff_t, N>{};
Access::Assign(this, rank, GetConstantVector<Index, 0>(rank).data(), shape);
}
Expand All @@ -535,8 +535,8 @@ class BoxView : public internal_box::BoxViewStorage<Rank, Mutable> {
}
template <size_t N, typename = std::enable_if_t<
RankConstraint::Implies(N, static_rank)>>
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<ptrdiff_t, N>{};
Access::Assign(this, rank, origin, shape);
}
Expand All @@ -557,11 +557,12 @@ class BoxView : public internal_box::BoxViewStorage<Rank, Mutable> {
/// \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 <typename BoxType,
typename = std::enable_if_t<(
IsBoxLike<BoxType> && (!Mutable || IsMutableBoxLike<BoxType>) &&
RankConstraint::Implies(
absl::remove_cvref_t<BoxType>::static_rank, Rank))>>
template <
typename BoxType,
typename = std::enable_if_t<
(IsBoxLike<BoxType> &&
(!Mutable || IsMutableBoxLike<BoxType>)&&RankConstraint::Implies(
absl::remove_cvref_t<BoxType>::static_rank, Rank))>>
// NONITPICK: std::remove_cvref_t<BoxType>::static_rank
BoxView(BoxType&& other)
: BoxView(other.rank(), other.origin().data(), other.shape().data()) {}
Expand All @@ -586,7 +587,7 @@ class BoxView : public internal_box::BoxViewStorage<Rank, Mutable> {
typename BoxType,
std::enable_if_t<
(IsBoxLike<absl::remove_cvref_t<BoxType>> &&
(!Mutable || IsMutableBoxLike<std::remove_reference_t<BoxType>>) &&
(!Mutable || IsMutableBoxLike<std::remove_reference_t<BoxType>>)&&

RankConstraint::Implies(absl::remove_cvref_t<BoxType>::static_rank,
Rank))>* = nullptr>
Expand Down Expand Up @@ -666,7 +667,7 @@ class BoxView : public internal_box::BoxViewStorage<Rank, Mutable> {
return ApplyIndexTransform(*this,
std::forward<Transformable>(transformable));
}
};
}; // namespace tensorstore

BoxView(DimensionIndex rank) -> BoxView<>;

Expand Down Expand Up @@ -703,8 +704,8 @@ BoxView(Origin&& origin, Shape&& shape)
(IsMutableIndexVector<Origin> && IsMutableIndexVector<Shape>)>;

template <DimensionIndex Rank>
BoxView(const Index (&origin)[Rank],
const Index (&shape)[Rank]) -> BoxView<Rank>;
BoxView(const Index (&origin)[Rank], const Index (&shape)[Rank])
-> BoxView<Rank>;

template <DimensionIndex Rank, bool Mutable>
struct StaticCastTraits<BoxView<Rank, Mutable>>
Expand Down
5 changes: 3 additions & 2 deletions tensorstore/generate_make_array_overloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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], '
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tensorstore/internal/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit fef32ae

Please sign in to comment.