Skip to content

Commit 8f7bafd

Browse files
Revert "[libc] add basic lifetime annotations for support data structures (#1…"
This reverts commit c0e0a33.
1 parent e101afc commit 8f7bafd

File tree

12 files changed

+30
-155
lines changed

12 files changed

+30
-155
lines changed

libc/src/__support/CPP/algorithm.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ template <class T = void> struct bit_and {};
2424
template <class T = void> struct bit_or {};
2525
template <class T = void> struct bit_xor {};
2626

27-
template <class T>
28-
LIBC_INLINE constexpr const T &max(LIBC_LIFETIME_BOUND const T &a,
29-
LIBC_LIFETIME_BOUND const T &b) {
27+
template <class T> LIBC_INLINE constexpr const T &max(const T &a, const T &b) {
3028
return (a < b) ? b : a;
3129
}
3230

33-
template <class T>
34-
LIBC_INLINE constexpr const T &min(LIBC_LIFETIME_BOUND const T &a,
35-
LIBC_LIFETIME_BOUND const T &b) {
31+
template <class T> LIBC_INLINE constexpr const T &min(const T &a, const T &b) {
3632
return (a < b) ? a : b;
3733
}
3834

libc/src/__support/CPP/array.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ template <class T, size_t N> struct array {
3131
LIBC_INLINE constexpr T *data() { return Data; }
3232
LIBC_INLINE constexpr const T *data() const { return Data; }
3333

34-
LIBC_INLINE constexpr T &front() LIBC_LIFETIME_BOUND { return Data[0]; }
35-
LIBC_INLINE constexpr const T &front() const LIBC_LIFETIME_BOUND {
36-
return Data[0];
37-
}
34+
LIBC_INLINE constexpr T &front() { return Data[0]; }
35+
LIBC_INLINE constexpr const T &front() const { return Data[0]; }
3836

39-
LIBC_INLINE constexpr T &back() LIBC_LIFETIME_BOUND { return Data[N - 1]; }
40-
LIBC_INLINE constexpr const T &back() const LIBC_LIFETIME_BOUND {
41-
return Data[N - 1];
42-
}
37+
LIBC_INLINE constexpr T &back() { return Data[N - 1]; }
38+
LIBC_INLINE constexpr const T &back() const { return Data[N - 1]; }
4339

44-
LIBC_INLINE constexpr T &operator[](size_t Index) LIBC_LIFETIME_BOUND {
45-
return Data[Index];
46-
}
40+
LIBC_INLINE constexpr T &operator[](size_t Index) { return Data[Index]; }
4741

48-
LIBC_INLINE constexpr const T &
49-
operator[](size_t Index) const LIBC_LIFETIME_BOUND {
42+
LIBC_INLINE constexpr const T &operator[](size_t Index) const {
5043
return Data[Index];
5144
}
5245

libc/src/__support/CPP/atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ template <typename T> struct Atomic {
256256
LIBC_INLINE void set(T rhs) { val = rhs; }
257257
};
258258

259-
template <typename T> struct LIBC_GSL_POINTER AtomicRef {
259+
template <typename T> struct AtomicRef {
260260
static_assert(is_trivially_copyable_v<T> && is_copy_constructible_v<T> &&
261261
is_move_constructible_v<T> && is_copy_assignable_v<T> &&
262262
is_move_assignable_v<T>,

libc/src/__support/CPP/mutex.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_MUTEX_H
1010
#define LLVM_LIBC_SRC___SUPPORT_CPP_MUTEX_H
1111

12-
#include "src/__support/macros/attributes.h"
1312
#include "src/__support/macros/config.h"
1413

1514
namespace LIBC_NAMESPACE_DECL {
@@ -29,17 +28,14 @@ template <typename MutexType> class lock_guard {
2928

3029
public:
3130
// Calls `m.lock()` upon resource acquisition.
32-
LIBC_INLINE explicit lock_guard(LIBC_LIFETIME_BOUND MutexType &m) : mutex(m) {
33-
mutex.lock();
34-
}
31+
explicit lock_guard(MutexType &m) : mutex(m) { mutex.lock(); }
3532

3633
// Acquires ownership of the mutex object `m` without attempting to lock
3734
// it. The behavior is undefined if the current thread does not hold the
3835
// lock on `m`. Does not call `m.lock()` upon resource acquisition.
39-
LIBC_INLINE lock_guard(LIBC_LIFETIME_BOUND MutexType &m, adopt_lock_t /* t */)
40-
: mutex(m) {}
36+
lock_guard(MutexType &m, adopt_lock_t /* t */) : mutex(m) {}
4137

42-
LIBC_INLINE ~lock_guard() { mutex.unlock(); }
38+
~lock_guard() { mutex.unlock(); }
4339

4440
// non-copyable
4541
lock_guard &operator=(const lock_guard &) = delete;

libc/src/__support/CPP/optional.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ template <typename T> class optional {
108108

109109
LIBC_INLINE constexpr void reset() { storage.reset(); }
110110

111-
LIBC_INLINE constexpr const T &value() const &LIBC_LIFETIME_BOUND {
111+
LIBC_INLINE constexpr const T &value() const & {
112112
return storage.stored_value;
113113
}
114114

115-
LIBC_INLINE constexpr T &value() & LIBC_LIFETIME_BOUND {
116-
return storage.stored_value;
117-
}
115+
LIBC_INLINE constexpr T &value() & { return storage.stored_value; }
118116

119117
LIBC_INLINE constexpr explicit operator bool() const {
120118
return storage.in_use;
@@ -124,12 +122,10 @@ template <typename T> class optional {
124122
return &storage.stored_value;
125123
}
126124
LIBC_INLINE constexpr T *operator->() { return &storage.stored_value; }
127-
LIBC_INLINE constexpr const T &operator*() const &LIBC_LIFETIME_BOUND {
128-
return storage.stored_value;
129-
}
130-
LIBC_INLINE constexpr T &operator*() & LIBC_LIFETIME_BOUND {
125+
LIBC_INLINE constexpr const T &operator*() const & {
131126
return storage.stored_value;
132127
}
128+
LIBC_INLINE constexpr T &operator*() & { return storage.stored_value; }
133129

134130
LIBC_INLINE constexpr T &&value() && { return move(storage.stored_value); }
135131
LIBC_INLINE constexpr T &&operator*() && {

libc/src/__support/CPP/span.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace cpp {
2828
// - No implicit type conversion (e.g. Span<B>, initialized with As where A
2929
// inherits from B),
3030
// - No reverse iterators
31-
template <typename T> class LIBC_GSL_POINTER span {
31+
template <typename T> class span {
3232
template <typename U>
3333
LIBC_INLINE_VAR static constexpr bool is_const_view_v =
3434
!cpp::is_const_v<U> && cpp::is_const_v<T> &&
@@ -64,12 +64,11 @@ template <typename T> class LIBC_GSL_POINTER span {
6464

6565
template <typename U, size_t N,
6666
cpp::enable_if_t<is_compatible_v<U>, bool> = true>
67-
LIBC_INLINE constexpr span(LIBC_LIFETIME_BOUND U (&arr)[N])
68-
: span_data(arr), span_size(N) {}
67+
LIBC_INLINE constexpr span(U (&arr)[N]) : span_data(arr), span_size(N) {}
6968

7069
template <typename U, size_t N,
7170
cpp::enable_if_t<is_compatible_v<U>, bool> = true>
72-
LIBC_INLINE constexpr span(LIBC_LIFETIME_BOUND array<U, N> &arr)
71+
LIBC_INLINE constexpr span(array<U, N> &arr)
7372
: span_data(arr.data()), span_size(arr.size()) {}
7473

7574
template <typename U, cpp::enable_if_t<is_compatible_v<U>, bool> = true>

libc/src/__support/CPP/string.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,16 @@ class string {
106106
LIBC_INLINE constexpr const char *end() const { return data() + size_; }
107107
LIBC_INLINE char *end() { return data() + size_; }
108108

109-
LIBC_INLINE constexpr const char &front() const LIBC_LIFETIME_BOUND {
110-
return data()[0];
111-
}
112-
LIBC_INLINE char &front() LIBC_LIFETIME_BOUND { return data()[0]; }
109+
LIBC_INLINE constexpr const char &front() const { return data()[0]; }
110+
LIBC_INLINE char &front() { return data()[0]; }
113111

114-
LIBC_INLINE constexpr const char &back() const LIBC_LIFETIME_BOUND {
115-
return data()[size_ - 1];
116-
}
117-
LIBC_INLINE char &back() LIBC_LIFETIME_BOUND { return data()[size_ - 1]; }
112+
LIBC_INLINE constexpr const char &back() const { return data()[size_ - 1]; }
113+
LIBC_INLINE char &back() { return data()[size_ - 1]; }
118114

119-
LIBC_INLINE constexpr const char &
120-
operator[](size_t index) const LIBC_LIFETIME_BOUND {
121-
return data()[index];
122-
}
123-
LIBC_INLINE char &operator[](size_t index) LIBC_LIFETIME_BOUND {
115+
LIBC_INLINE constexpr const char &operator[](size_t index) const {
124116
return data()[index];
125117
}
118+
LIBC_INLINE char &operator[](size_t index) { return data()[index]; }
126119

127120
LIBC_INLINE const char *c_str() const { return data(); }
128121

libc/src/__support/CPP/string_view.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace cpp {
2323
// do the checks before invoking the methods.
2424
//
2525
// This class will be extended as needed in future.
26-
class LIBC_GSL_POINTER string_view {
26+
class string_view {
2727
private:
2828
const char *Data;
2929
size_t Len;
@@ -44,15 +44,6 @@ class LIBC_GSL_POINTER string_view {
4444
return static_cast<size_t>(End - Str);
4545
}
4646

47-
template <size_t N>
48-
LIBC_INLINE static constexpr size_t
49-
bounded_length(LIBC_LIFETIME_BOUND const char (&Str)[N]) {
50-
for (size_t i = 0; i < N; ++i)
51-
if (Str[i] == '\0')
52-
return i;
53-
return N;
54-
}
55-
5647
LIBC_INLINE bool equals(string_view Other) const {
5748
return (Len == Other.Len &&
5849
compareMemory(Data, Other.Data, Other.Len) == 0);
@@ -86,10 +77,6 @@ class LIBC_GSL_POINTER string_view {
8677
LIBC_INLINE constexpr string_view(const char *Str, size_t N)
8778
: Data(Str), Len(N) {}
8879

89-
template <size_t N>
90-
LIBC_INLINE constexpr string_view(LIBC_LIFETIME_BOUND const char (&Str)[N])
91-
: Data(Str), Len(bounded_length(Str)) {}
92-
9380
LIBC_INLINE constexpr const char *data() const { return Data; }
9481

9582
// Returns the size of the string_view.

libc/src/__support/CPP/stringstream.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ class StringStream {
4848
// null terminator was not explicitly written, then the return value
4949
// will not include one. In order to produce a string_view to a null
5050
// terminated string, write ENDS explicitly.
51-
[[nodiscard]] LIBC_INLINE string_view str() const {
52-
return string_view(data.data(), write_ptr);
53-
}
51+
string_view str() const { return string_view(data.data(), write_ptr); }
5452

5553
// Write the characters from |str| to the stream.
5654
StringStream &operator<<(string_view str) {

libc/src/__support/CPP/utility/forward.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ namespace cpp {
1818

1919
// forward
2020
template <typename T>
21-
LIBC_INLINE constexpr T &&
22-
forward(LIBC_LIFETIME_BOUND remove_reference_t<T> &value) {
21+
LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &value) {
2322
return static_cast<T &&>(value);
2423
}
2524

2625
template <typename T>
27-
LIBC_INLINE constexpr T &&
28-
forward(LIBC_LIFETIME_BOUND remove_reference_t<T> &&value) {
26+
LIBC_INLINE constexpr T &&forward(remove_reference_t<T> &&value) {
2927
static_assert(!is_lvalue_reference_v<T>,
3028
"cannot forward an rvalue as an lvalue");
3129
return static_cast<T &&>(value);

0 commit comments

Comments
 (0)