Skip to content

Commit 7bd92f8

Browse files
committed
Merge branch 'trunk' into test-call-returning-facet-value
2 parents afc3467 + b1b79c1 commit 7bd92f8

File tree

663 files changed

+41691
-29636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

663 files changed

+41691
-29636
lines changed

.clang-format

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ SpaceBeforeParens: ControlStatementsExceptControlMacros
1717
IfMacros:
1818
[
1919
'CARBON_DEFINE_RAW_ENUM_CLASS',
20-
'CARBON_DEFINE_RAW_ENUM_CLASS_NO_NAMES',
20+
'CARBON_DEFINE_ENUM_CLASS_NAMES',
21+
'CARBON_DEFINE_RAW_ENUM_MASK',
22+
'CARBON_DEFINE_ENUM_MASK_NAMES',
2123
'CARBON_KIND_SWITCH',
2224
]
2325
StatementMacros: ['ABSTRACT']

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Checks:
2222
- '-misc-const-correctness'
2323
- '-misc-include-cleaner'
2424
- '-misc-use-anonymous-namespace'
25+
- '-modernize-deprecated-headers'
2526
- '-modernize-return-braced-init-list'
2627
- '-modernize-use-default-member-init'
2728
- '-modernize-use-integer-sign-comparison'

.github/workflows/clang_tidy.yaml

Lines changed: 0 additions & 80 deletions
This file was deleted.

.github/workflows/clangd_tidy.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ on:
88
push:
99
branches: [trunk, action-test]
1010
pull_request:
11-
# TODO: Don't run in merge_group until we're ready to replace clang-tidy.
12-
# merge_group:
11+
merge_group:
1312

1413
permissions:
1514
contents: read # For actions/checkout.

common/BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,27 @@ cc_test(
159159
],
160160
)
161161

162+
cc_library(
163+
name = "enum_mask_base",
164+
hdrs = ["enum_mask_base.h"],
165+
deps = [
166+
":enum_base",
167+
"@llvm-project//llvm:Support",
168+
],
169+
)
170+
171+
cc_test(
172+
name = "enum_mask_base_test",
173+
size = "small",
174+
srcs = ["enum_mask_base_test.cpp"],
175+
deps = [
176+
":enum_mask_base",
177+
":raw_string_ostream",
178+
"//testing/base:gtest_main",
179+
"@googletest//:gtest",
180+
],
181+
)
182+
162183
cc_library(
163184
name = "error",
164185
hdrs = ["error.h"],

common/enum_base.h

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef CARBON_COMMON_ENUM_BASE_H_
66
#define CARBON_COMMON_ENUM_BASE_H_
77

8+
#include <compare>
89
#include <type_traits>
910

1011
#include "common/ostream.h"
@@ -53,7 +54,7 @@ namespace Carbon::Internal {
5354
//
5455
// In `my_kind.cpp`:
5556
// ```
56-
// CARBON_DEFINE_ENUM_CLASS_NAMES(MyKind) = {
57+
// CARBON_DEFINE_ENUM_CLASS_NAMES(MyKind) {
5758
// #define CARBON_MY_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
5859
// #include ".../my_kind.def"
5960
// };
@@ -122,22 +123,26 @@ class EnumBase : public Printable<DerivedT> {
122123
// function.
123124
//
124125
// NOLINTNEXTLINE(google-explicit-constructor)
125-
constexpr operator RawEnumType() const { return value_; }
126+
explicit(false) constexpr operator RawEnumType() const { return value_; }
126127

127128
// Conversion to bool is deleted to prevent direct use in an `if` condition
128129
// instead of comparing with another value.
129130
explicit operator bool() const = delete;
130131

131132
// Returns the name of this value.
132-
//
133-
// This method will be automatically defined using the static `names` string
134-
// table in the base class, which is in turn will be populated for each
135-
// derived type using the macro helpers in this file.
136133
auto name() const -> llvm::StringRef { return Names[AsInt()]; }
137134

138135
// Prints this value using its name.
139136
auto Print(llvm::raw_ostream& out) const -> void { out << name(); }
140137

138+
// Don't support comparison of enums by default.
139+
friend auto operator<(DerivedT lhs, DerivedT rhs) -> bool = delete;
140+
friend auto operator<=(DerivedT lhs, DerivedT rhs) -> bool = delete;
141+
friend auto operator>(DerivedT lhs, DerivedT rhs) -> bool = delete;
142+
friend auto operator>=(DerivedT lhs, DerivedT rhs) -> bool = delete;
143+
friend auto operator<=>(DerivedT lhs, DerivedT rhs)
144+
-> std::partial_ordering = delete;
145+
141146
protected:
142147
// The default constructor is explicitly defaulted (and constexpr) as a
143148
// protected constructor to allow derived classes to be constructed but not
@@ -165,42 +170,38 @@ class EnumBase : public Printable<DerivedT> {
165170
}
166171

167172
private:
173+
template <typename MaskDerivedT, typename MaskEnumT,
174+
const llvm::StringLiteral MaskNames[]>
175+
friend class EnumMaskBase;
176+
168177
RawEnumType value_;
169178
};
170179

171180
} // namespace Carbon::Internal
172181

173-
// For use when multiple enums use the same list of names.
174-
#define CARBON_DEFINE_RAW_ENUM_CLASS_NO_NAMES(EnumClassName, UnderlyingType) \
175-
namespace Internal { \
176-
enum class EnumClassName##RawEnum : UnderlyingType; \
177-
} \
178-
enum class Internal::EnumClassName##RawEnum : UnderlyingType
179-
180182
// Use this before defining a class that derives from `EnumBase` to begin the
181183
// definition of the raw `enum class`. It should be followed by the body of that
182184
// raw enum class.
183185
#define CARBON_DEFINE_RAW_ENUM_CLASS(EnumClassName, UnderlyingType) \
184186
namespace Internal { \
185-
extern const llvm::StringLiteral EnumClassName##Names[]; \
187+
struct EnumClassName##Data { \
188+
static const llvm::StringLiteral Names[]; \
189+
enum class RawEnum : UnderlyingType; \
190+
}; \
186191
} \
187-
CARBON_DEFINE_RAW_ENUM_CLASS_NO_NAMES(EnumClassName, UnderlyingType)
192+
enum class Internal::EnumClassName##Data::RawEnum : UnderlyingType
188193

189-
// In CARBON_DEFINE_RAW_ENUM_CLASS block, use this to generate each enumerator.
194+
// In the `CARBON_DEFINE_RAW_ENUM_CLASS` block, use this to generate each
195+
// enumerator.
190196
#define CARBON_RAW_ENUM_ENUMERATOR(Name) Name,
191197

192198
// Use this to compute the `Internal::EnumBase` specialization for a Carbon enum
193199
// class. It both computes the name of the raw enum and ensures all the
194200
// namespaces are correct.
195-
#define CARBON_ENUM_BASE(EnumClassName) \
196-
CARBON_ENUM_BASE_CRTP(EnumClassName, EnumClassName, EnumClassName)
197-
// This variant handles the case where the external name for the Carbon enum is
198-
// not the same as the name by which we refer to it from this context.
199-
#define CARBON_ENUM_BASE_CRTP(EnumClassName, LocalTypeNameForEnumClass, \
200-
EnumClassNameForNames) \
201-
::Carbon::Internal::EnumBase<LocalTypeNameForEnumClass, \
202-
Internal::EnumClassName##RawEnum, \
203-
Internal::EnumClassNameForNames##Names>
201+
#define CARBON_ENUM_BASE(EnumClassName) \
202+
::Carbon::Internal::EnumBase<EnumClassName, \
203+
Internal::EnumClassName##Data::RawEnum, \
204+
Internal::EnumClassName##Data::Names>
204205

205206
// Use this within the Carbon enum class body to generate named constant
206207
// declarations for each value.
@@ -212,24 +213,14 @@ class EnumBase : public Printable<DerivedT> {
212213
constexpr EnumClassName EnumClassName::Name = \
213214
EnumClassName::Make(RawEnumType::Name);
214215

215-
// Alternatively, use this within the Carbon enum class body to declare and
216-
// define each named constant. Due to type completeness constraints, this will
217-
// only work if the enum-like class is templated.
218-
//
219-
// This requires the template to have a member named `Base` that names the
220-
// `EnumBase` base class.
221-
#define CARBON_INLINE_ENUM_CONSTANT_DEFINITION(Name) \
222-
static constexpr const typename Base::EnumType& Name = \
223-
Base::Make(Base::RawEnumType::Name);
224-
225216
// Use this in the `.cpp` file for an enum class to start the definition of the
226217
// constant names array for each enumerator. It is followed by the desired
227218
// constant initializer.
228219
//
229220
// `clang-format` has a bug with spacing around `->` returns in macros. See
230221
// https://bugs.llvm.org/show_bug.cgi?id=48320 for details.
231222
#define CARBON_DEFINE_ENUM_CLASS_NAMES(EnumClassName) \
232-
constexpr llvm::StringLiteral Internal::EnumClassName##Names[]
223+
constexpr llvm::StringLiteral Internal::EnumClassName##Data::Names[] =
233224

234225
// Use this within the names array initializer to generate a string for each
235226
// name.

common/enum_base_test.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TestKind : public CARBON_ENUM_BASE(TestKind) {
3030
CARBON_ENUM_CONSTANT_DEFINITION(TestKind, Name)
3131
#include "common/enum_base_test.def"
3232

33-
CARBON_DEFINE_ENUM_CLASS_NAMES(TestKind) = {
33+
CARBON_DEFINE_ENUM_CLASS_NAMES(TestKind) {
3434
#define CARBON_ENUM_BASE_TEST_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
3535
#include "common/enum_base_test.def"
3636
};
@@ -79,23 +79,15 @@ TEST(EnumBaseTest, Switch) {
7979
TEST(EnumBaseTest, Comparison) {
8080
TestKind kind = TestKind::Beep;
8181

82-
// Make sure all the different comparisons work, and also to work with
82+
// Make sure all the different comparisons work, and also work with
8383
// GoogleTest expectations.
8484
EXPECT_EQ(TestKind::Beep, kind);
8585
EXPECT_NE(TestKind::Boop, kind);
86-
EXPECT_LT(kind, TestKind::Boop);
87-
EXPECT_GT(TestKind::Burr, kind);
88-
EXPECT_LE(kind, TestKind::Beep);
89-
EXPECT_GE(TestKind::Beep, kind);
9086

9187
// These should also all be constexpr.
9288
constexpr TestKind Kind2 = TestKind::Beep;
9389
static_assert(Kind2 == TestKind::Beep);
9490
static_assert(Kind2 != TestKind::Boop);
95-
static_assert(Kind2 < TestKind::Boop);
96-
static_assert(!(Kind2 > TestKind::Burr));
97-
static_assert(Kind2 <= TestKind::Beep);
98-
static_assert(!(Kind2 >= TestKind::Burr));
9991
}
10092

10193
TEST(EnumBaseTest, IntConversion) {

0 commit comments

Comments
 (0)