Skip to content

Commit 4a01904

Browse files
cyyeverpytorchmergebot
authored andcommitted
Enable nested namespace check in clang-tidy (pytorch#118506)
It is time to enable nested namespaces in the code. Pull Request resolved: pytorch#118506 Approved by: https://github.com/albanD
1 parent 1b03423 commit 4a01904

33 files changed

+65
-142
lines changed

.clang-tidy

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ misc-*,
4242
-misc-non-private-member-variables-in-classes,
4343
-misc-confusable-identifiers,
4444
modernize-*,
45-
-modernize-concat-nested-namespaces,
4645
-modernize-macro-to-enum,
4746
-modernize-return-braced-init-list,
4847
-modernize-use-auto,

c10/core/WrapDimMinimal.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <c10/core/WrapDimMinimal.h>
22

3-
namespace c10 {
4-
namespace detail {
3+
namespace c10::detail {
54

65
template <typename T>
76
T maybe_wrap_dim_slow(T dim, T dim_post_expr, bool wrap_scalar) {
@@ -40,5 +39,4 @@ maybe_wrap_dim_slow(int64_t dim, int64_t dim_post_expr, bool wrap_scalar);
4039
template C10_API SymInt
4140
maybe_wrap_dim_slow(SymInt dim, SymInt dim_post_expr, bool wrap_scalar);
4241

43-
} // namespace detail
44-
} // namespace c10
42+
} // namespace c10::detail

c10/core/impl/DeviceGuardImplInterface.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <c10/core/impl/DeviceGuardImplInterface.h>
22

3-
namespace c10 {
4-
namespace impl {
3+
namespace c10::impl {
54

65
// NOLINTNEXTLINE(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
76
std::atomic<const DeviceGuardImplInterface*>
@@ -14,5 +13,4 @@ DeviceGuardImplRegistrar::DeviceGuardImplRegistrar(
1413
device_guard_impl_registry[static_cast<size_t>(type)].store(impl);
1514
}
1615

17-
} // namespace impl
18-
} // namespace c10
16+
} // namespace c10::impl

c10/core/impl/FakeGuardImpl.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
#include <array>
66

7-
namespace c10 {
8-
namespace impl {
7+
namespace c10::impl {
98

109
// FakeGuardImpl is hardcoded to have eight devices. Not for
1110
// any good reason, just to simplify code.
@@ -100,5 +99,4 @@ template <DeviceType T>
10099
thread_local std::array<StreamId, kFakeGuardImplMaxDevices>
101100
FakeGuardImpl<T>::current_streams_ = {0, 0, 0, 0, 0, 0, 0, 0};
102101

103-
} // namespace impl
104-
} // namespace c10
102+
} // namespace c10::impl

c10/core/impl/GPUTrace.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <c10/core/impl/GPUTrace.h>
22
#include <c10/util/CallOnce.h>
33

4-
namespace c10 {
5-
namespace impl {
4+
namespace c10::impl {
65

76
std::atomic<const PyInterpreter*> GPUTrace::gpuTraceState{nullptr};
87

@@ -16,5 +15,4 @@ void GPUTrace::set_trace(const PyInterpreter* trace) {
1615
});
1716
}
1817

19-
} // namespace impl
20-
} // namespace c10
18+
} // namespace c10::impl

c10/core/impl/GPUTrace.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
#include <c10/core/impl/PyInterpreter.h>
44

5-
namespace c10 {
6-
namespace impl {
5+
namespace c10::impl {
76

87
struct C10_API GPUTrace {
98
// On the x86 architecture the atomic operations are lock-less.
@@ -26,5 +25,4 @@ struct C10_API GPUTrace {
2625
}
2726
};
2827

29-
} // namespace impl
30-
} // namespace c10
28+
} // namespace c10::impl

c10/core/impl/HermeticPyObjectTLS.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <c10/core/impl/HermeticPyObjectTLS.h>
22

3-
namespace c10 {
4-
namespace impl {
3+
namespace c10::impl {
54

65
thread_local std::atomic<bool> hermeticPyObjectState{false};
76

@@ -19,5 +18,4 @@ void HermeticPyObjectTLS::init_state() {
1918
haveState_ = true;
2019
}
2120

22-
} // namespace impl
23-
} // namespace c10
21+
} // namespace c10::impl

c10/core/impl/LocalDispatchKeySet.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <c10/core/impl/LocalDispatchKeySet.h>
22

3-
namespace c10 {
4-
namespace impl {
3+
namespace c10::impl {
54

65
// NB: POD, must be zero initialized!
76
// Note [TLS Initialization]
@@ -115,5 +114,4 @@ bool tls_is_dispatch_keyset_excluded(DispatchKeySet ks) {
115114
bool tls_is_dispatch_keyset_included(DispatchKeySet ks) {
116115
return raw_local_dispatch_key_set.included().isSupersetOf(ks);
117116
}
118-
} // namespace impl
119-
} // namespace c10
117+
} // namespace c10::impl

c10/core/impl/PyInterpreter.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include <c10/core/TensorImpl.h>
33
#include <c10/core/impl/PyInterpreter.h>
44

5-
namespace c10 {
6-
namespace impl {
5+
namespace c10::impl {
76

87
struct NoopPyInterpreterVTable final : public PyInterpreterVTable {
98
std::string name() const override {
@@ -125,5 +124,4 @@ void PyInterpreter::disarm() noexcept {
125124
vtable_ = &noop_vtable;
126125
}
127126

128-
} // namespace impl
129-
} // namespace c10
127+
} // namespace c10::impl

c10/core/impl/PyObjectSlot.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <c10/core/impl/PyObjectSlot.h>
22

3-
namespace c10 {
4-
namespace impl {
3+
namespace c10::impl {
54

65
PyObjectSlot::PyObjectSlot() : pyobj_interpreter_(nullptr), pyobj_(nullptr) {}
76

@@ -71,5 +70,4 @@ void PyObjectSlot::set_owns_pyobj(bool b) {
7170
reinterpret_cast<uintptr_t>(_unchecked_untagged_pyobj()) | b);
7271
}
7372

74-
} // namespace impl
75-
} // namespace c10
73+
} // namespace c10::impl

c10/core/impl/PythonDispatcherTLS.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#include <c10/core/impl/LocalDispatchKeySet.h>
33
#include <c10/core/impl/PythonDispatcherTLS.h>
44

5-
namespace c10 {
6-
namespace impl {
5+
namespace c10::impl {
76

87
thread_local PyInterpreter* pythonDispatcherState;
98

@@ -27,5 +26,4 @@ void PythonDispatcherTLS::reset_state() {
2726
DispatchKey::PythonDispatcher, false);
2827
}
2928

30-
} // namespace impl
31-
} // namespace c10
29+
} // namespace c10::impl

c10/core/impl/PythonDispatcherTLS.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <c10/core/impl/PyInterpreter.h>
44
#include <c10/macros/Export.h>
55

6-
namespace c10 {
7-
namespace impl {
6+
namespace c10::impl {
87

98
struct C10_API PythonDispatcherTLS {
109
static void set_state(PyInterpreter* state);
@@ -22,5 +21,4 @@ struct C10_API DisablePythonDispatcher {
2221
PyInterpreter* old_;
2322
};
2423

25-
} // namespace impl
26-
} // namespace c10
24+
} // namespace c10::impl

c10/core/impl/SizesAndStrides.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <c10/core/impl/SizesAndStrides.h>
22

3-
namespace c10 {
4-
namespace impl {
3+
namespace c10::impl {
54

65
void SizesAndStrides::resizeSlowPath(
76
const size_t newSize,
@@ -77,5 +76,4 @@ void SizesAndStrides::resizeSlowPath(
7776
size_ = newSize;
7877
}
7978

80-
} // namespace impl
81-
} // namespace c10
79+
} // namespace c10::impl

c10/core/impl/TorchDispatchModeTLS.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include <utility>
88

9-
namespace c10 {
10-
namespace impl {
9+
namespace c10::impl {
1110

1211
thread_local TorchDispatchModeTLS torchDispatchModeState;
1312

@@ -192,5 +191,4 @@ std::string to_string(TorchDispatchModeKey mode_key) {
192191
}
193192
}
194193

195-
} // namespace impl
196-
} // namespace c10
194+
} // namespace c10::impl

c10/core/impl/TorchDispatchModeTLS.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <c10/core/SafePyObject.h>
44
#include <c10/macros/Export.h>
55

6-
namespace c10 {
7-
namespace impl {
6+
namespace c10::impl {
87

98
enum class TorchDispatchModeKey : int8_t {
109
FAKE,
@@ -61,5 +60,4 @@ C10_API bool dispatch_mode_enabled();
6160

6261
C10_API std::string to_string(TorchDispatchModeKey mode_key);
6362

64-
} // namespace impl
65-
} // namespace c10
63+
} // namespace c10::impl

c10/cuda/CUDAAllocatorConfig.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include <c10/cuda/driver_api.h>
77
#endif
88

9-
namespace c10 {
10-
namespace cuda {
11-
namespace CUDACachingAllocator {
9+
namespace c10::cuda::CUDACachingAllocator {
1210

1311
constexpr size_t kRoundUpPowerOfTwoIntervals = 16;
1412

@@ -354,6 +352,4 @@ void setAllocatorSettings(const std::string& env) {
354352
CUDACachingAllocator::CUDAAllocatorConfig::instance().parseArgs(env.c_str());
355353
}
356354

357-
} // namespace CUDACachingAllocator
358-
} // namespace cuda
359-
} // namespace c10
355+
} // namespace c10::cuda::CUDACachingAllocator

c10/cuda/CUDACachingAllocator.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ namespace c10 {
4040

4141
C10_DEFINE_REGISTRY(FreeCudaMemoryCallbacksRegistry, FreeMemoryCallback);
4242

43-
namespace cuda {
44-
namespace CUDACachingAllocator {
43+
namespace cuda::CUDACachingAllocator {
4544

4645
// Included here as this is externally used in CUDAAllocatorConfig
4746
const size_t kLargeBuffer =
@@ -3347,6 +3346,6 @@ struct BackendStaticInitializer {
33473346
std::atomic<CUDAAllocator*> allocator;
33483347
BackendStaticInitializer backend_static_initializer;
33493348

3350-
} // namespace CUDACachingAllocator
3351-
} // namespace cuda
3349+
} // namespace cuda::CUDACachingAllocator
3350+
33523351
} // namespace c10

c10/cuda/CUDADeviceAssertionHost.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
false); \
2727
} while (0)
2828

29-
namespace c10 {
30-
namespace cuda {
29+
namespace c10::cuda {
3130

3231
namespace {
3332

@@ -343,5 +342,4 @@ bool CUDAKernelLaunchRegistry::has_failed() const {
343342
return false;
344343
}
345344

346-
} // namespace cuda
347-
} // namespace c10
345+
} // namespace c10::cuda

c10/cuda/CUDAException.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include <string>
88

9-
namespace c10 {
10-
namespace cuda {
9+
namespace c10::cuda {
1110

1211
void c10_cuda_check_implementation(
1312
const int32_t err,
@@ -44,5 +43,4 @@ void c10_cuda_check_implementation(
4443
TORCH_CHECK(false, check_message);
4544
}
4645

47-
} // namespace cuda
48-
} // namespace c10
46+
} // namespace c10::cuda

c10/cuda/CUDAMallocAsyncAllocator.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
#include <unordered_set>
1010
#include <vector>
1111

12-
namespace c10 {
13-
namespace cuda {
14-
namespace CUDACachingAllocator {
15-
namespace CudaMallocAsync {
12+
namespace c10::cuda::CUDACachingAllocator::CudaMallocAsync {
1613

1714
#if CUDA_VERSION >= 11040
1815
// CUDA device allocator that uses cudaMallocAsync to implement
@@ -898,7 +895,4 @@ CUDAAllocator* allocator() {
898895

899896
#endif
900897

901-
} // namespace CudaMallocAsync
902-
} // namespace CUDACachingAllocator
903-
} // namespace cuda
904-
} // namespace c10
898+
} // namespace c10::cuda::CUDACachingAllocator::CudaMallocAsync

c10/cuda/CUDAMiscFunctions.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include <c10/cuda/CUDAMiscFunctions.h>
22
#include <stdlib.h>
33

4-
namespace c10 {
5-
namespace cuda {
4+
namespace c10::cuda {
65

76
const char* get_cuda_check_suffix() noexcept {
87
static char* device_blocking_flag = getenv("CUDA_LAUNCH_BLOCKING");
@@ -21,5 +20,4 @@ std::mutex* getFreeMutex() {
2120
return &cuda_free_mutex;
2221
}
2322

24-
} // namespace cuda
25-
} // namespace c10
23+
} // namespace c10::cuda

c10/cuda/CUDAStream.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include <mutex>
1212
#include <vector>
1313

14-
namespace c10 {
15-
namespace cuda {
14+
namespace c10::cuda {
1615

1716
namespace {
1817

@@ -339,5 +338,4 @@ std::ostream& operator<<(std::ostream& stream, const CUDAStream& s) {
339338
return stream << s.unwrap();
340339
}
341340

342-
} // namespace cuda
343-
} // namespace c10
341+
} // namespace c10::cuda

c10/cuda/driver_api.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <c10/util/Exception.h>
55
#include <dlfcn.h>
66
#include <iostream>
7-
namespace c10 {
8-
namespace cuda {
7+
8+
namespace c10::cuda {
99

1010
namespace {
1111

@@ -42,7 +42,6 @@ C10_EXPORT DriverAPI* DriverAPI::get() {
4242
return &singleton;
4343
}
4444

45-
} // namespace cuda
46-
} // namespace c10
45+
} // namespace c10::cuda
4746

4847
#endif

0 commit comments

Comments
 (0)