Skip to content

Commit 9a5bbed

Browse files
committed
Basic, SIL: Include <swift/bridging> when avaiable instead of defining our own macros
1 parent c2271e2 commit 9a5bbed

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

include/swift/Basic/BasicBridging.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "swift/Basic/BridgedSwiftObject.h"
4141
#include "swift/Basic/Compiler.h"
42+
#include "swift/Basic/SwiftBridging.h"
4243

4344
#include <stddef.h>
4445
#include <stdint.h>
@@ -55,13 +56,6 @@
5556
#include <vector>
5657
#endif
5758

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-
6559
#if __has_attribute(availability)
6660
#define SWIFT_UNAVAILABLE(msg) \
6761
__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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
#if __has_attribute(swift_name)
51+
/// Specifies a name that will be used in Swift for this declaration instead of
52+
/// its original name.
53+
#define SWIFT_NAME(_name) __attribute__((swift_name(_name)))
54+
#else
55+
#define SWIFT_NAME(_name)
56+
#endif
57+
#endif // #ifdef SWIFT_NAME
58+
59+
#endif // SWIFT_BASIC_SWIFT_BRIDGING_H
60+

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)