Skip to content

Commit 08d71a4

Browse files
committed
Basic, SIL: Include <swift/bridging> when avaiable instead of defining our own macros
1 parent 00aa22f commit 08d71a4

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

include/swift/Basic/BasicBridging.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3939

4040
#include "swift/Basic/BridgedSwiftObject.h"
41-
#include "swift/Basic/Compiler.h"
41+
#include "swift/Basic/SwiftBridging.h"
4242

4343
#include <stddef.h>
4444
#include <stdint.h>
@@ -55,13 +55,6 @@
5555
#include <vector>
5656
#endif
5757

58-
// FIXME: We ought to be importing '<swift/bridging>' instead.
59-
#if __has_attribute(swift_name)
60-
#define SWIFT_NAME(NAME) __attribute__((swift_name(NAME)))
61-
#else
62-
#define SWIFT_NAME(NAME)
63-
#endif
64-
6558
#if __has_attribute(availability)
6659
#define SWIFT_UNAVAILABLE(msg) \
6760
__attribute__((availability(swift, unavailable, message=msg)))

include/swift/Basic/Compiler.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@
9090
#define SWIFT_IMPORT_UNSAFE
9191
#endif
9292

93-
/// Same as `SWIFT_SELF_CONTAINED` in <swift/bridging>.
94-
#if __has_attribute(swift_attr)
95-
#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned")))
96-
#else
97-
#define SWIFT_SELF_CONTAINED
98-
#endif
99-
10093
#ifdef __GNUC__
10194
#define SWIFT_ATTRIBUTE_NORETURN __attribute__((noreturn))
10295
#elif defined(_MSC_VER)

include/swift/Basic/SwiftBridging.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===--- Basic/SwiftBridging.h ----------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
///
13+
/// This is a wrapper around `<swift/bridging>` that redefines `SWIFT_NAME` to
14+
/// accept a string literal, and some other macros in case the header is
15+
/// unavailable (e.g. during bootstrapping). String literals enable us to
16+
/// properly format the long Swift declaration names that many of our bridging
17+
/// functions have.
18+
///
19+
//===----------------------------------------------------------------------===//
20+
21+
#ifndef SWIFT_BASIC_SWIFT_BRIDGING_H
22+
#define SWIFT_BASIC_SWIFT_BRIDGING_H
23+
24+
#include "swift/Basic/Compiler.h"
25+
#if __has_include(<swift/bridging>)
26+
#include <swift/bridging>
27+
#else
28+
29+
#if __has_attribute(swift_attr)
30+
31+
/// Specifies that a C++ `class` or `struct` owns and controls the lifetime of
32+
/// all of the objects it references. Such type should not reference any
33+
/// objects whose lifetime is controlled externally. This annotation allows
34+
/// Swift to import methods that return a `class` or `struct` type that is
35+
/// annotated with this macro.
36+
#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned")))
37+
38+
#else // #if __has_attribute(swift_attr)
39+
40+
#define SWIFT_SELF_CONTAINED
41+
#define SWIFT_COMPUTED_PROPERTY
42+
43+
#endif // #if __has_attribute(swift_attr)
44+
45+
#endif // #if __has_include(<swift/bridging>)
46+
47+
// Redefine SWIFT_NAME.
48+
#ifdef SWIFT_NAME
49+
#undef SWIFT_NAME
50+
#endif
51+
52+
#if __has_attribute(swift_name)
53+
/// Specifies a name that will be used in Swift for this declaration instead of
54+
/// its original name.
55+
#define SWIFT_NAME(_name) __attribute__((swift_name(_name)))
56+
#else
57+
#define SWIFT_NAME(_name)
58+
#endif
59+
60+
#endif // SWIFT_BASIC_SWIFT_BRIDGING_H
61+

include/swift/SIL/SILLocation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#ifndef SWIFT_SIL_LOCATION_H
1414
#define SWIFT_SIL_LOCATION_H
1515

16-
#include "llvm/ADT/PointerUnion.h"
1716
#include "swift/AST/ASTNode.h"
17+
#include "swift/AST/TypeAlignments.h"
1818
#include "swift/Basic/SourceLoc.h"
19+
#include "swift/Basic/SwiftBridging.h"
1920
#include "swift/SIL/SILAllocated.h"
20-
#include "swift/AST/TypeAlignments.h"
21+
#include "llvm/ADT/PointerUnion.h"
2122

2223
#include <cstddef>
2324
#include <type_traits>

0 commit comments

Comments
 (0)