Skip to content

Commit 2ac0860

Browse files
committed
[AST] Remove BridgedVarDecl + BridgedNominalTypeDecl duplicates
These are now stamped out by the ASTBridgingWrappers.
1 parent 6afde8a commit 2ac0860

File tree

5 files changed

+18
-57
lines changed

5 files changed

+18
-57
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ public struct VarDecl {
358358
var bridged: BridgedVarDecl
359359

360360
public init?(bridged: BridgedNullableVarDecl) {
361-
guard let decl = bridged.get() else { return nil }
362-
self.bridged = BridgedVarDecl(decl: decl)
361+
guard let decl = bridged.raw else { return nil }
362+
self.bridged = BridgedVarDecl(raw: decl)
363363
}
364364

365365
public var userFacingName: String { String(bridged.getUserFacingName()) }

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ public struct NominalTypeDecl : Equatable, Hashable {
216216
public var name: StringRef { StringRef(bridged: bridged.getName()) }
217217

218218
public static func ==(lhs: NominalTypeDecl, rhs: NominalTypeDecl) -> Bool {
219-
lhs.bridged.decl == rhs.bridged.decl
219+
lhs.bridged.raw == rhs.bridged.raw
220220
}
221221

222222
public func hash(into hasher: inout Hasher) {
223-
hasher.combine(bridged.decl)
223+
hasher.combine(bridged.raw)
224224
}
225225

226226
public var isStructWithUnreferenceableStorage: Bool {

include/swift/AST/ASTBridging.h

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
2828
namespace swift {
2929
class DiagnosticArgument;
3030
class DiagnosticEngine;
31-
class NominalTypeDecl;
32-
class VarDecl;
3331
}
3432

3533
//===----------------------------------------------------------------------===//
@@ -60,22 +58,19 @@ bool ASTContext_langOptsHasFeature(BridgedASTContext cContext,
6058
// AST nodes
6159
//===----------------------------------------------------------------------===//
6260

61+
// Forward declare the underlying AST node type for each wrapper.
62+
namespace swift {
63+
#define AST_BRIDGING_WRAPPER(Name) class Name;
64+
#include "swift/AST/ASTBridgingWrappers.def"
65+
} // end namespace swift
66+
6367
// Define the bridging wrappers for each AST node.
64-
#define AST_BRIDGING_WRAPPER_NONNULL(Name) \
65-
typedef struct { \
66-
void *_Nonnull raw; \
67-
} Bridged##Name;
68-
69-
// For nullable nodes, define both a nullable and non-null variant.
70-
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) \
71-
typedef struct { \
72-
void *_Nullable raw; \
73-
} BridgedNullable##Name; \
74-
\
75-
typedef struct { \
76-
void *_Nonnull raw; \
77-
} Bridged##Name;
68+
#define AST_BRIDGING_WRAPPER(Name) BRIDGING_WRAPPER_NONNULL(Name)
69+
#include "swift/AST/ASTBridgingWrappers.def"
7870

71+
// For nullable nodes, also define a nullable variant.
72+
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) BRIDGING_WRAPPER_NULLABLE(Name)
73+
#define AST_BRIDGING_WRAPPER_NONNULL(Name)
7974
#include "swift/AST/ASTBridgingWrappers.def"
8075

8176
// Declare `.asDecl` on each BridgedXXXDecl type, which upcasts a wrapper for
@@ -219,17 +214,6 @@ void Diagnostic_finish(BridgedDiagnostic cDiag);
219214
// NominalTypeDecl
220215
//===----------------------------------------------------------------------===//
221216

222-
class BridgedNominalTypeDecl {
223-
swift::NominalTypeDecl * _Nonnull Ptr;
224-
225-
public:
226-
#ifdef USED_IN_CPP_SOURCE
227-
BridgedNominalTypeDecl(swift::NominalTypeDecl * _Nonnull ptr) : Ptr(ptr) {}
228-
229-
swift::NominalTypeDecl * _Nonnull get() const { return Ptr; }
230-
#endif
231-
};
232-
233217
SWIFT_NAME("BridgedNominalTypeDecl.getName(self:)")
234218
BRIDGED_INLINE
235219
BridgedStringRef BridgedNominalTypeDecl_getName(BridgedNominalTypeDecl decl);
@@ -250,32 +234,10 @@ void NominalTypeDecl_setParsedMembers(BridgedNominalTypeDecl decl,
250234
// VarDecl
251235
//===----------------------------------------------------------------------===//
252236

253-
class BridgedVarDecl {
254-
swift::VarDecl * _Nonnull Ptr;
255-
256-
public:
257-
#ifdef USED_IN_CPP_SOURCE
258-
BridgedVarDecl(swift::VarDecl * _Nonnull ptr) : Ptr(ptr) {}
259-
260-
swift::VarDecl * _Nonnull get() const { return Ptr; }
261-
#endif
262-
};
263-
264237
SWIFT_NAME("BridgedVarDecl.getUserFacingName(self:)")
265238
BRIDGED_INLINE
266239
BridgedStringRef BridgedVarDecl_getUserFacingName(BridgedVarDecl decl);
267240

268-
class BridgedNullableVarDecl {
269-
swift::VarDecl * _Nullable Ptr;
270-
271-
public:
272-
#ifdef USED_IN_CPP_SOURCE
273-
BridgedNullableVarDecl(swift::VarDecl * _Nullable ptr) : Ptr(ptr) {}
274-
275-
swift::VarDecl * _Nullable get() const { return Ptr; }
276-
#endif
277-
};
278-
279241
//===----------------------------------------------------------------------===//
280242
// Misc
281243
//===----------------------------------------------------------------------===//

include/swift/AST/ASTBridgingWrappers.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
#define AST_BRIDGING_WRAPPER_NONNULL(Name) AST_BRIDGING_WRAPPER(Name)
3232
#endif
3333

34-
// Each AST node subclass stores a non-null raw value.
3534
#ifndef DECL
36-
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Decl)
35+
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NULLABLE(Id##Decl)
3736
#endif
3837
#define ABSTRACT_DECL(Id, Parent) DECL(Id, Parent)
3938
#include "swift/AST/DeclNodes.def"

lib/AST/ASTBridging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ bool BridgedNominalTypeDecl_isStructWithUnreferenceableStorage(
150150
// Define `unbridged` overloads for each AST node.
151151
#define AST_BRIDGING_WRAPPER(Name) \
152152
[[maybe_unused]] static Name *unbridged(Bridged##Name bridged) { \
153-
return static_cast<Name *>(bridged.raw); \
153+
return bridged.get(); \
154154
}
155155
#include "swift/AST/ASTBridgingWrappers.def"
156156

157157
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) \
158158
[[maybe_unused]] static Name *unbridged(BridgedNullable##Name bridged) { \
159-
return static_cast<Name *>(bridged.raw); \
159+
return bridged.get(); \
160160
}
161161
#define AST_BRIDGING_WRAPPER_NONNULL(Name)
162162
#include "swift/AST/ASTBridgingWrappers.def"

0 commit comments

Comments
 (0)