Skip to content

Commit ed67e36

Browse files
committed
bridging: reduce #ifdef USED_IN_CPP_SOURCE in bridging headers
Especially avoid any constructors in `#ifdef USED_IN_CPP_SOURCE` blocks, because this breaks Windows ARM64.
1 parent 5c7509b commit ed67e36

File tree

14 files changed

+444
-419
lines changed

14 files changed

+444
-419
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 34 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,30 @@
2222
#include "swift/Basic/BasicBridging.h"
2323

2424
#ifdef USED_IN_CPP_SOURCE
25-
#include "swift/AST/ArgumentList.h"
2625
#include "swift/AST/Attr.h"
2726
#include "swift/AST/Decl.h"
28-
#include "swift/AST/DiagnosticConsumer.h"
29-
#include "swift/AST/DiagnosticEngine.h"
30-
#include "swift/AST/IfConfigClauseRangeInfo.h"
31-
#include "swift/AST/Stmt.h"
3227
#endif
3328

3429
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
3530

3631
namespace swift {
32+
class Argument;
3733
class ASTContext;
34+
struct ASTNode;
35+
class DeclAttributes;
36+
class DeclBaseName;
37+
class DeclNameLoc;
38+
class DeclNameRef;
3839
class DiagnosticArgument;
3940
class DiagnosticEngine;
41+
class Identifier;
42+
class IfConfigClauseRangeInfo;
43+
struct LabeledStmtInfo;
44+
class ProtocolConformanceRef;
4045
class Type;
4146
class CanType;
4247
class TypeBase;
48+
class StmtConditionElement;
4349
class SubstitutionMap;
4450
}
4551

@@ -62,14 +68,9 @@ class BridgedIdentifier {
6268
SWIFT_NAME("init(raw:)")
6369
BridgedIdentifier(const void *_Nullable raw) : Raw(raw) {}
6470

65-
#ifdef USED_IN_CPP_SOURCE
66-
BridgedIdentifier(swift::Identifier ident)
67-
: Raw(ident.getAsOpaquePointer()) {}
71+
BRIDGED_INLINE BridgedIdentifier(swift::Identifier ident);
6872

69-
swift::Identifier unbridged() const {
70-
return swift::Identifier::getFromOpaquePointer(Raw);
71-
}
72-
#endif
73+
BRIDGED_INLINE swift::Identifier unbridged() const;
7374
};
7475

7576
SWIFT_NAME("getter:BridgedIdentifier.raw(self:)")
@@ -89,17 +90,9 @@ class BridgedDeclBaseName {
8990
BridgedIdentifier Ident;
9091

9192
public:
92-
// Ensure that this struct value type will be indirectly returned on
93-
// Windows ARM64
94-
BridgedDeclBaseName() : Ident() {}
95-
96-
#ifdef USED_IN_CPP_SOURCE
97-
BridgedDeclBaseName(swift::DeclBaseName baseName) : Ident(baseName.Ident) {}
93+
BRIDGED_INLINE BridgedDeclBaseName(swift::DeclBaseName baseName);
9894

99-
swift::DeclBaseName unbridged() const {
100-
return swift::DeclBaseName(Ident.unbridged());
101-
}
102-
#endif
95+
BRIDGED_INLINE swift::DeclBaseName unbridged() const;
10396
};
10497

10598
SWIFT_NAME("BridgedDeclBaseName.createConstructor()")
@@ -119,17 +112,9 @@ class BridgedDeclNameRef {
119112
void *_Nonnull opaque;
120113

121114
public:
122-
// Ensure that this struct value type will be indirectly returned on
123-
// Windows ARM64
124-
BridgedDeclNameRef() : opaque() {}
115+
BRIDGED_INLINE BridgedDeclNameRef(swift::DeclNameRef name);
125116

126-
#ifdef USED_IN_CPP_SOURCE
127-
BridgedDeclNameRef(swift::DeclNameRef name) : opaque(name.getOpaqueValue()) {}
128-
129-
swift::DeclNameRef unbridged() const {
130-
return swift::DeclNameRef::getFromOpaqueValue(opaque);
131-
}
132-
#endif
117+
BRIDGED_INLINE swift::DeclNameRef unbridged() const;
133118
};
134119

135120
SWIFT_NAME("BridgedDeclNameRef.createParsed(_:baseName:argumentLabels:)")
@@ -149,15 +134,9 @@ class BridgedDeclNameLoc {
149134
public:
150135
BridgedDeclNameLoc() : LocationInfo(nullptr), NumArgumentLabels(0) {}
151136

152-
#ifdef USED_IN_CPP_SOURCE
153-
BridgedDeclNameLoc(swift::DeclNameLoc loc)
154-
: LocationInfo(loc.LocationInfo),
155-
NumArgumentLabels(loc.NumArgumentLabels) {}
137+
BRIDGED_INLINE BridgedDeclNameLoc(swift::DeclNameLoc loc);
156138

157-
swift::DeclNameLoc unbridged() const {
158-
return swift::DeclNameLoc(LocationInfo, NumArgumentLabels);
159-
}
160-
#endif
139+
BRIDGED_INLINE swift::DeclNameLoc unbridged() const;
161140
};
162141

163142
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:baseNameLoc:lParenLoc:"
@@ -179,17 +158,11 @@ class BridgedASTContext {
179158
swift::ASTContext * _Nonnull Ctx;
180159

181160
public:
182-
// Ensure that this struct value type will be indirectly returned on
183-
// Windows ARM64
184-
BridgedASTContext() : Ctx() {}
185-
186-
#ifdef USED_IN_CPP_SOURCE
187161
SWIFT_UNAVAILABLE("Use init(raw:) instead")
188-
BridgedASTContext(swift::ASTContext &ctx) : Ctx(&ctx) {}
162+
BRIDGED_INLINE BridgedASTContext(swift::ASTContext &ctx);
189163

190164
SWIFT_UNAVAILABLE("Use '.raw' instead")
191-
swift::ASTContext &unbridged() const { return *Ctx; }
192-
#endif
165+
BRIDGED_INLINE swift::ASTContext &unbridged() const;
193166
};
194167

195168
SWIFT_NAME("getter:BridgedASTContext.raw(self:)")
@@ -343,18 +316,7 @@ struct BridgedASTNode {
343316
SWIFT_NAME("kind")
344317
ASTNodeKind Kind;
345318

346-
#ifdef USED_IN_CPP_SOURCE
347-
swift::ASTNode unbridged() const {
348-
switch (Kind) {
349-
case ASTNodeKindExpr:
350-
return swift::ASTNode(static_cast<swift::Expr *>(Raw));
351-
case ASTNodeKindStmt:
352-
return swift::ASTNode(static_cast<swift::Stmt *>(Raw));
353-
case ASTNodeKindDecl:
354-
return swift::ASTNode(static_cast<swift::Decl *>(Raw));
355-
}
356-
}
357-
#endif
319+
BRIDGED_INLINE swift::ASTNode unbridged() const;
358320
};
359321

360322
// Forward declare the underlying AST node type for each wrapper.
@@ -453,39 +415,16 @@ class BridgedDiagnosticArgument {
453415
int64_t storage[3];
454416

455417
public:
456-
// Ensure that this struct value type will be indirectly returned on
457-
// Windows ARM64
458-
BridgedDiagnosticArgument() {}
459-
460-
#ifdef USED_IN_CPP_SOURCE
461-
BridgedDiagnosticArgument(const swift::DiagnosticArgument &arg) {
462-
*reinterpret_cast<swift::DiagnosticArgument *>(&storage) = arg;
463-
}
464-
const swift::DiagnosticArgument &unbridged() const {
465-
return *reinterpret_cast<const swift::DiagnosticArgument *>(&storage);
466-
}
467-
#endif
418+
BRIDGED_INLINE BridgedDiagnosticArgument(const swift::DiagnosticArgument &arg);
419+
BRIDGED_INLINE const swift::DiagnosticArgument &unbridged() const;
468420

469421
BridgedDiagnosticArgument(SwiftInt i);
470422
BridgedDiagnosticArgument(BridgedStringRef s);
471423
};
472424

473425
class BridgedDiagnosticFixIt {
474-
int64_t storage[7];
475-
476426
public:
477-
// Ensure that this struct value type will be indirectly returned on
478-
// Windows ARM64
479-
BridgedDiagnosticFixIt() {}
480-
481-
#ifdef USED_IN_CPP_SOURCE
482-
BridgedDiagnosticFixIt(const swift::DiagnosticInfo::FixIt &fixit){
483-
*reinterpret_cast<swift::DiagnosticInfo::FixIt *>(&storage) = fixit;
484-
}
485-
const swift::DiagnosticInfo::FixIt &unbridged() const {
486-
return *reinterpret_cast<const swift::DiagnosticInfo::FixIt *>(&storage);
487-
}
488-
#endif
427+
int64_t storage[7];
489428

490429
BridgedDiagnosticFixIt(BridgedSourceLoc start, uint32_t length, BridgedStringRef text);
491430
};
@@ -585,16 +524,9 @@ struct BridgedDeclAttributes {
585524

586525
BridgedDeclAttributes() : chain(nullptr){};
587526

588-
#ifdef USED_IN_CPP_SOURCE
589-
BridgedDeclAttributes(swift::DeclAttributes attrs)
590-
: chain(attrs.getRawAttributeChain()) {}
527+
BRIDGED_INLINE BridgedDeclAttributes(swift::DeclAttributes attrs);
591528

592-
swift::DeclAttributes unbridged() const {
593-
swift::DeclAttributes attrs;
594-
attrs.setRawAttributeChain(chain.unbridged());
595-
return attrs;
596-
}
597-
#endif
529+
BRIDGED_INLINE swift::DeclAttributes unbridged() const;
598530
};
599531

600532
SWIFT_NAME("BridgedDeclAttributes.add(self:_:)")
@@ -1209,12 +1141,7 @@ struct BridgedCallArgument {
12091141
BridgedIdentifier label;
12101142
BridgedExpr argExpr;
12111143

1212-
#ifdef USED_IN_CPP_SOURCE
1213-
swift::Argument unbridged() const {
1214-
return swift::Argument(labelLoc.unbridged(), label.unbridged(),
1215-
argExpr.unbridged());
1216-
}
1217-
#endif
1144+
BRIDGED_INLINE swift::Argument unbridged() const;
12181145
};
12191146

12201147
SWIFT_NAME("BridgedArgumentList.createImplicitUnlabeled(_:exprs:)")
@@ -1528,29 +1455,16 @@ struct BridgedLabeledStmtInfo {
15281455
SWIFT_NAME("loc")
15291456
BridgedSourceLoc Loc;
15301457

1531-
#ifdef USED_IN_CPP_SOURCE
1532-
swift::LabeledStmtInfo unbridged() const {
1533-
return {Name.unbridged(), Loc.unbridged()};
1534-
}
1535-
#endif
1458+
BRIDGED_INLINE swift::LabeledStmtInfo unbridged() const;
15361459
};
15371460

15381461
class BridgedStmtConditionElement {
15391462
void *_Nonnull Raw;
15401463

15411464
public:
1542-
// Ensure that this struct value type will be indirectly returned on
1543-
// Windows ARM64
1544-
BridgedStmtConditionElement() {}
1545-
1546-
#ifdef USED_IN_CPP_SOURCE
1547-
BridgedStmtConditionElement(swift::StmtConditionElement elem)
1548-
: Raw(elem.getOpaqueValue()) {}
1465+
BRIDGED_INLINE BridgedStmtConditionElement(swift::StmtConditionElement elem);
15491466

1550-
swift::StmtConditionElement unbridged() const {
1551-
return swift::StmtConditionElement::fromOpaqueValue(Raw);
1552-
}
1553-
#endif
1467+
BRIDGED_INLINE swift::StmtConditionElement unbridged() const;
15541468
};
15551469

15561470
SWIFT_NAME("BridgedStmtConditionElement.createBoolean(expr:)")
@@ -2099,14 +2013,8 @@ class BridgedCanType {
20992013
struct BridgedConformance {
21002014
void * _Nullable opaqueValue;
21012015

2102-
#ifdef USED_IN_CPP_SOURCE
2103-
BridgedConformance(swift::ProtocolConformanceRef conformance)
2104-
: opaqueValue(conformance.getOpaqueValue()) {}
2105-
2106-
swift::ProtocolConformanceRef unbridged() const {
2107-
return swift::ProtocolConformanceRef::getFromOpaqueValue(opaqueValue);
2108-
}
2109-
#endif
2016+
BRIDGED_INLINE BridgedConformance(swift::ProtocolConformanceRef conformance);
2017+
BRIDGED_INLINE swift::ProtocolConformanceRef unbridged() const;
21102018

21112019
BridgedOwnedString getDebugDescription() const;
21122020
BRIDGED_INLINE bool isConcrete() const;
@@ -2122,15 +2030,6 @@ struct BridgedConformance {
21222030
struct BridgedConformanceArray {
21232031
BridgedArrayRef pcArray;
21242032

2125-
#ifdef USED_IN_CPP_SOURCE
2126-
BridgedConformanceArray(llvm::ArrayRef<swift::ProtocolConformanceRef> conformances)
2127-
: pcArray(conformances) {}
2128-
2129-
llvm::ArrayRef<swift::ProtocolConformanceRef> unbridged() const {
2130-
return pcArray.unbridged<swift::ProtocolConformanceRef>();
2131-
}
2132-
#endif
2133-
21342033
SwiftInt getCount() const { return SwiftInt(pcArray.Length); }
21352034

21362035
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
@@ -2168,29 +2067,7 @@ struct BridgedIfConfigClauseRangeInfo {
21682067
BridgedSourceLoc endLoc;
21692068
BridgedIfConfigClauseKind kind;
21702069

2171-
#ifdef USED_IN_CPP_SOURCE
2172-
swift::IfConfigClauseRangeInfo unbridged() const {
2173-
swift::IfConfigClauseRangeInfo::ClauseKind clauseKind;
2174-
switch (kind) {
2175-
case IfConfigActive:
2176-
clauseKind = swift::IfConfigClauseRangeInfo::ActiveClause;
2177-
break;
2178-
2179-
case IfConfigInactive:
2180-
clauseKind = swift::IfConfigClauseRangeInfo::InactiveClause;
2181-
break;
2182-
2183-
case IfConfigEnd:
2184-
clauseKind = swift::IfConfigClauseRangeInfo::EndDirective;
2185-
break;
2186-
}
2187-
2188-
return swift::IfConfigClauseRangeInfo(directiveLoc.unbridged(),
2189-
bodyLoc.unbridged(),
2190-
endLoc.unbridged(),
2191-
clauseKind);
2192-
}
2193-
#endif
2070+
BRIDGED_INLINE swift::IfConfigClauseRangeInfo unbridged() const;
21942071
};
21952072

21962073
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)