Skip to content

Commit 7eff49c

Browse files
authored
[cxx-interop] [nfc] Remove swift namespace from SwiftShims in C++ mode. (#32715)
Most SwiftShims were put in the swift namespace in C++ mode which broke certain things when importing them in a swift file in C++ mode. This was OK when they were only imported as part of the swift runtime but, now they are used in C++ mode both in the swift runtime and when C++ interop is enabled. This broke when C++ interop was enabled because the `Swift` module contains references to symbols in the SwiftShims headers which are built without C++ interop enabled (no "swift" namespace). But, when C++ interop is enabled, the SwiftShims headers would put everything in the swift namespace meaning the symbols couldn't be found in the global namespace. Then, the compiler would error when trying to deserialize the Swift module.
1 parent f558eb3 commit 7eff49c

18 files changed

+87
-87
lines changed

stdlib/public/SwiftShims/AssertionReporting.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#endif
2222

2323
#ifdef __cplusplus
24-
namespace swift { extern "C" {
24+
extern "C" {
2525
#endif
2626

2727
/// Report a fatal error to system console, stderr, and crash logs.
@@ -69,7 +69,7 @@ void _swift_stdlib_reportUnimplementedInitializer(
6969
__swift_uint32_t flags);
7070

7171
#ifdef __cplusplus
72-
}} // extern "C", namespace swift
72+
} // extern "C"
7373
#endif
7474

7575
#if __has_feature(nullability)

stdlib/public/SwiftShims/CoreFoundationShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "Visibility.h"
2424

2525
#ifdef __cplusplus
26-
namespace swift { extern "C" {
26+
extern "C" {
2727
#endif
2828

2929
#ifdef __OBJC2__
@@ -78,7 +78,7 @@ _swift_stdlib_dyld_is_objc_constant_string(const void * _Nonnull addr);
7878
#endif // __OBJC2__
7979

8080
#ifdef __cplusplus
81-
}} // extern "C", namespace swift
81+
} // extern "C"
8282
#endif
8383

8484
#endif // SWIFT_STDLIB_SHIMS_COREFOUNDATIONSHIMS_H

stdlib/public/SwiftShims/DispatchOverlayShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#pragma clang assume_nonnull begin
3333

3434
#ifdef __cplusplus
35-
namespace swift { extern "C" {
35+
extern "C" {
3636
#endif
3737

3838
typedef void (^__swift_shims_dispatch_block_t)(void);
@@ -251,7 +251,7 @@ static inline void _swift_dispatch_release(dispatch_object_t object) {
251251
}
252252

253253
#ifdef __cplusplus
254-
}} // extern "C", namespace swift
254+
} // extern "C"
255255
#endif
256256

257257
#pragma clang assume_nonnull end

stdlib/public/SwiftShims/FoundationShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "SwiftStdint.h"
3131

3232
#ifdef __cplusplus
33-
namespace swift { extern "C" {
33+
extern "C" {
3434
#endif
3535

3636
typedef struct {
@@ -58,7 +58,7 @@ SWIFT_RUNTIME_STDLIB_API
5858
_SwiftNSOperatingSystemVersion _swift_stdlib_operatingSystemVersion() __attribute__((const));
5959

6060
#ifdef __cplusplus
61-
}} // extern "C", namespace swift
61+
} // extern "C"
6262
#endif
6363

6464
#endif // SWIFT_STDLIB_SHIMS_FOUNDATIONSHIMS_H

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#endif
3030

3131
#ifdef __cplusplus
32-
namespace swift { extern "C" {
32+
extern "C" {
3333
#endif
3434

3535
// This declaration might not be universally correct.
@@ -184,7 +184,7 @@ long double lgammal_r(long double x, int *psigngam);
184184
#endif // defined(__APPLE__)
185185

186186
#ifdef __cplusplus
187-
}} // extern "C", namespace swift
187+
} // extern "C"
188188
#endif
189189

190190
#if __has_feature(nullability)

stdlib/public/SwiftShims/Random.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
#endif
2626

2727
#ifdef __cplusplus
28-
namespace swift { extern "C" {
28+
extern "C" {
2929
#endif
3030

3131
SWIFT_RUNTIME_STDLIB_API
3232
void swift_stdlib_random(void *buf, __swift_size_t nbytes);
3333

3434
#ifdef __cplusplus
35-
}} // extern "C", namespace swift
35+
} // extern "C"
3636
#endif
3737

3838
#if __has_feature(nullability)

stdlib/public/SwiftShims/RuntimeShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "Visibility.h"
2424

2525
#ifdef __cplusplus
26-
namespace swift { extern "C" {
26+
extern "C" {
2727
#endif
2828

2929
/// Return an NSString to be used as the Mirror summary of the object
@@ -85,7 +85,7 @@ __swift_size_t _swift_stdlib_getHardwareConcurrency(void);
8585
#define _swift_MinAllocationAlignment (__swift_size_t) 16
8686

8787
#ifdef __cplusplus
88-
}} // extern "C", namespace swift
88+
} // extern "C"
8989
#endif
9090

9191
#endif // SWIFT_STDLIB_SHIMS_RUNTIMESHIMS_H

stdlib/public/SwiftShims/RuntimeStubs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "LibcShims.h"
2323

2424
#ifdef __cplusplus
25-
namespace swift { extern "C" {
25+
extern "C" {
2626
#endif
2727

2828
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
@@ -42,7 +42,7 @@ _swift_stdlib_overrideUnsafeArgvArgc(char * _Nullable * _Nonnull argv, int argc)
4242
SWIFT_END_NULLABILITY_ANNOTATIONS
4343

4444
#ifdef __cplusplus
45-
}} // extern "C", namespace swift
45+
} // extern "C"
4646
#endif
4747

4848
#endif // SWIFT_STDLIB_SHIMS_RUNTIMESTUBS_H_

stdlib/public/SwiftShims/UnicodeShims.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif
2727

2828
#ifdef __cplusplus
29-
namespace swift { extern "C" {
29+
extern "C" {
3030
#endif
3131

3232
SWIFT_RUNTIME_STDLIB_API
@@ -554,7 +554,7 @@ double __swift_stdlib_u_getNumericValue(__swift_stdlib_UChar32 c);
554554

555555

556556
#ifdef __cplusplus
557-
}} // extern "C", namespace swift
557+
} // extern "C"
558558
#endif
559559

560560
#if __has_feature(nullability)

stdlib/public/runtime/BackDeployment.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _swift_classIsSwiftMask = computeIsSwiftMask();
3030
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
3131
#endif // SWIFT_CLASS_IS_SWIFT_MASK_GLOBAL_VARIABLE
3232

33-
static swift::_SwiftNSOperatingSystemVersion swiftInOSVersion = {
33+
static _SwiftNSOperatingSystemVersion swiftInOSVersion = {
3434
#if __MAC_OS_X_VERSION_MIN_REQUIRED
3535
10, 14, 4
3636
// WatchOS also pretends to be iOS, so check it first.
@@ -43,8 +43,8 @@ static swift::_SwiftNSOperatingSystemVersion swiftInOSVersion = {
4343
#endif
4444
};
4545

46-
static bool versionLessThan(swift::_SwiftNSOperatingSystemVersion lhs,
47-
swift::_SwiftNSOperatingSystemVersion rhs) {
46+
static bool versionLessThan(_SwiftNSOperatingSystemVersion lhs,
47+
_SwiftNSOperatingSystemVersion rhs) {
4848
if (lhs.majorVersion < rhs.majorVersion) return true;
4949
if (lhs.majorVersion > rhs.majorVersion) return false;
5050

@@ -58,7 +58,7 @@ static bool versionLessThan(swift::_SwiftNSOperatingSystemVersion lhs,
5858

5959
SWIFT_RUNTIME_STDLIB_INTERNAL
6060
int _swift_isBackDeploying() {
61-
auto version = swift::_swift_stdlib_operatingSystemVersion();
61+
auto version = _swift_stdlib_operatingSystemVersion();
6262
return versionLessThan(version, swiftInOSVersion);
6363
}
6464
#endif

0 commit comments

Comments
 (0)