Skip to content

Commit 3912ead

Browse files
authored
Merge pull request #76675 from hjyamauchi/issue74866-4
SILBridging: remove some #ifdef USED_IN_CPP_SOURCE
2 parents 762fd4a + 89a7dff commit 3912ead

File tree

2 files changed

+134
-211
lines changed

2 files changed

+134
-211
lines changed

include/swift/SIL/SILBridging.h

+22-194
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace swift {
4747
class ValueBase;
4848
class Operand;
4949
class ForwardingInstruction;
50+
class SILType;
5051
class SILFunction;
5152
class SILBasicBlock;
5253
class SILSuccessor;
@@ -58,13 +59,19 @@ class SILVTableEntry;
5859
class SILVTable;
5960
class SILWitnessTable;
6061
class SILDefaultWitnessTable;
62+
class SILDebugLocation;
6163
class NominalTypeDecl;
6264
class VarDecl;
65+
class Type;
6366
class TypeBase;
67+
class SubstitutionMap;
6468
class SwiftPassInvocation;
6569
class GenericSpecializationInformation;
6670
class LifetimeDependenceInfo;
6771
class IndexSubset;
72+
enum class ResultConvention : uint8_t;
73+
class SILResultInfo;
74+
class SILParameterInfo;
6875
}
6976

7077
bool swiftModulesInitialized();
@@ -83,58 +90,18 @@ struct BridgedResultInfo {
8390
swift::TypeBase * _Nonnull type;
8491
BridgedResultConvention convention;
8592

86-
// Ensure that this struct value type will be indirectly returned on
87-
// Windows ARM64
88-
BridgedResultInfo() {}
89-
90-
#ifdef USED_IN_CPP_SOURCE
91-
inline static BridgedResultConvention
92-
castToResultConvention(swift::ResultConvention convention) {
93-
return static_cast<BridgedResultConvention>(convention);
94-
}
95-
96-
BridgedResultInfo(swift::SILResultInfo resultInfo):
97-
type(resultInfo.getInterfaceType().getPointer()),
98-
convention(castToResultConvention(resultInfo.getConvention()))
99-
{}
100-
#endif
93+
BRIDGED_INLINE static BridgedResultConvention castToResultConvention(swift::ResultConvention convention);
94+
BRIDGED_INLINE BridgedResultInfo(swift::SILResultInfo resultInfo);
10195
};
10296

10397
struct OptionalBridgedResultInfo {
104-
swift::TypeBase * _Nullable type = nullptr;
105-
BridgedResultConvention convention = BridgedResultConvention::Indirect;
106-
107-
// Ensure that this struct value type will be indirectly returned on
108-
// Windows ARM64
109-
OptionalBridgedResultInfo() {}
110-
111-
#ifdef USED_IN_CPP_SOURCE
112-
OptionalBridgedResultInfo(std::optional<swift::SILResultInfo> resultInfo) {
113-
if (resultInfo) {
114-
type = resultInfo->getInterfaceType().getPointer();
115-
convention =
116-
BridgedResultInfo::castToResultConvention(resultInfo->getConvention());
117-
}
118-
}
119-
#endif
98+
swift::TypeBase * _Nullable type;
99+
BridgedResultConvention convention;
120100
};
121101

122102
struct BridgedResultInfoArray {
123103
BridgedArrayRef resultInfoArray;
124104

125-
// Ensure that this struct value type will be indirectly returned on
126-
// Windows ARM64
127-
BridgedResultInfoArray() {}
128-
129-
#ifdef USED_IN_CPP_SOURCE
130-
BridgedResultInfoArray(llvm::ArrayRef<swift::SILResultInfo> results)
131-
: resultInfoArray(results) {}
132-
133-
llvm::ArrayRef<swift::SILResultInfo> unbridged() const {
134-
return resultInfoArray.unbridged<swift::SILResultInfo>();
135-
}
136-
#endif
137-
138105
BRIDGED_INLINE SwiftInt count() const;
139106

140107
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
@@ -160,44 +127,6 @@ enum class BridgedArgumentConvention {
160127
Pack_Out
161128
};
162129

163-
#ifdef USED_IN_CPP_SOURCE
164-
inline swift::ParameterConvention getParameterConvention(BridgedArgumentConvention convention) {
165-
switch (convention) {
166-
case BridgedArgumentConvention::Indirect_In: return swift::ParameterConvention::Indirect_In;
167-
case BridgedArgumentConvention::Indirect_In_Guaranteed: return swift::ParameterConvention::Indirect_In_Guaranteed;
168-
case BridgedArgumentConvention::Indirect_Inout: return swift::ParameterConvention::Indirect_Inout;
169-
case BridgedArgumentConvention::Indirect_InoutAliasable: return swift::ParameterConvention::Indirect_InoutAliasable;
170-
case BridgedArgumentConvention::Indirect_In_CXX: return swift::ParameterConvention::Indirect_In_CXX;
171-
case BridgedArgumentConvention::Indirect_Out: break;
172-
case BridgedArgumentConvention::Direct_Owned: return swift::ParameterConvention::Direct_Owned;
173-
case BridgedArgumentConvention::Direct_Unowned: return swift::ParameterConvention::Direct_Unowned;
174-
case BridgedArgumentConvention::Direct_Guaranteed: return swift::ParameterConvention::Direct_Guaranteed;
175-
case BridgedArgumentConvention::Pack_Owned: return swift::ParameterConvention::Pack_Owned;
176-
case BridgedArgumentConvention::Pack_Inout: return swift::ParameterConvention::Pack_Inout;
177-
case BridgedArgumentConvention::Pack_Guaranteed: return swift::ParameterConvention::Pack_Guaranteed;
178-
case BridgedArgumentConvention::Pack_Out: break;
179-
}
180-
llvm_unreachable("invalid parameter convention");
181-
}
182-
183-
inline BridgedArgumentConvention getArgumentConvention(swift::ParameterConvention convention) {
184-
switch (convention) {
185-
case swift::ParameterConvention::Indirect_In: return BridgedArgumentConvention::Indirect_In;
186-
case swift::ParameterConvention::Indirect_In_Guaranteed: return BridgedArgumentConvention::Indirect_In_Guaranteed;
187-
case swift::ParameterConvention::Indirect_Inout: return BridgedArgumentConvention::Indirect_Inout;
188-
case swift::ParameterConvention::Indirect_InoutAliasable: return BridgedArgumentConvention::Indirect_InoutAliasable;
189-
case swift::ParameterConvention::Indirect_In_CXX: return BridgedArgumentConvention::Indirect_In_CXX;
190-
case swift::ParameterConvention::Direct_Owned: return BridgedArgumentConvention::Direct_Owned;
191-
case swift::ParameterConvention::Direct_Unowned: return BridgedArgumentConvention::Direct_Unowned;
192-
case swift::ParameterConvention::Direct_Guaranteed: return BridgedArgumentConvention::Direct_Guaranteed;
193-
case swift::ParameterConvention::Pack_Owned: return BridgedArgumentConvention::Pack_Owned;
194-
case swift::ParameterConvention::Pack_Inout: return BridgedArgumentConvention::Pack_Inout;
195-
case swift::ParameterConvention::Pack_Guaranteed: return BridgedArgumentConvention::Pack_Guaranteed;
196-
}
197-
llvm_unreachable("invalid parameter convention");
198-
}
199-
#endif
200-
201130
struct BridgedParameterInfo {
202131
swift::TypeBase * _Nonnull type;
203132
BridgedArgumentConvention convention;
@@ -206,42 +135,13 @@ struct BridgedParameterInfo {
206135
BridgedParameterInfo(swift::TypeBase * _Nonnull type, BridgedArgumentConvention convention, uint8_t options) :
207136
type(type), convention(convention), options(options) {}
208137

209-
#ifdef USED_IN_CPP_SOURCE
210-
inline static BridgedArgumentConvention
211-
castToArgumentConvention(swift::ParameterConvention convention) {
212-
return static_cast<BridgedArgumentConvention>(
213-
swift::SILArgumentConvention(convention).Value);
214-
}
215-
216-
BridgedParameterInfo(swift::SILParameterInfo parameterInfo):
217-
type(parameterInfo.getInterfaceType().getPointer()),
218-
convention(castToArgumentConvention(parameterInfo.getConvention())),
219-
options(parameterInfo.getOptions().toRaw())
220-
{}
221-
222-
swift::SILParameterInfo unbridged() const {
223-
return swift::SILParameterInfo(swift::CanType(type), getParameterConvention(convention),
224-
swift::SILParameterInfo::Options(options));
225-
}
226-
#endif
138+
BRIDGED_INLINE BridgedParameterInfo(swift::SILParameterInfo parameterInfo);
139+
BRIDGED_INLINE swift::SILParameterInfo unbridged() const;
227140
};
228141

229142
struct BridgedParameterInfoArray {
230143
BridgedArrayRef parameterInfoArray;
231144

232-
// Ensure that this struct value type will be indirectly returned on
233-
// Windows ARM64
234-
BridgedParameterInfoArray() {}
235-
236-
#ifdef USED_IN_CPP_SOURCE
237-
BridgedParameterInfoArray(llvm::ArrayRef<swift::SILParameterInfo> parameters)
238-
: parameterInfoArray(parameters) {}
239-
240-
llvm::ArrayRef<swift::SILParameterInfo> unbridged() const {
241-
return parameterInfoArray.unbridged<swift::SILParameterInfo>();
242-
}
243-
#endif
244-
245145
BRIDGED_INLINE SwiftInt count() const;
246146

247147
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
@@ -251,19 +151,6 @@ struct BridgedParameterInfoArray {
251151
struct BridgedYieldInfoArray {
252152
BridgedArrayRef yieldInfoArray;
253153

254-
// Ensure that this struct value type will be indirectly returned on
255-
// Windows ARM64
256-
BridgedYieldInfoArray() {}
257-
258-
#ifdef USED_IN_CPP_SOURCE
259-
BridgedYieldInfoArray(llvm::ArrayRef<swift::SILYieldInfo> yields)
260-
: yieldInfoArray(yields) {}
261-
262-
llvm::ArrayRef<swift::SILYieldInfo> unbridged() const {
263-
return yieldInfoArray.unbridged<swift::SILYieldInfo>();
264-
}
265-
#endif
266-
267154
BRIDGED_INLINE SwiftInt count() const;
268155

269156
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
@@ -275,16 +162,7 @@ struct BridgedLifetimeDependenceInfo {
275162
SwiftUInt targetIndex;
276163
bool immortal;
277164

278-
// Ensure that this struct value type will be indirectly returned on
279-
// Windows ARM64
280-
BridgedLifetimeDependenceInfo() {}
281-
282-
#ifdef USED_IN_CPP_SOURCE
283-
BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info)
284-
: inheritLifetimeParamIndices(info.getInheritIndices()),
285-
scopeLifetimeParamIndices(info.getScopeIndices()),
286-
targetIndex(info.getTargetIndex()), immortal(info.isImmortal()) {}
287-
#endif
165+
BRIDGED_INLINE BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info);
288166

289167
BRIDGED_INLINE bool empty() const;
290168
BRIDGED_INLINE bool checkInherit(SwiftInt index) const;
@@ -297,21 +175,6 @@ struct BridgedLifetimeDependenceInfo {
297175
struct BridgedLifetimeDependenceInfoArray {
298176
BridgedArrayRef lifetimeDependenceInfoArray;
299177

300-
// Ensure that this struct value type will be indirectly returned on
301-
// Windows ARM64
302-
BridgedLifetimeDependenceInfoArray() {}
303-
304-
#ifdef USED_IN_CPP_SOURCE
305-
BridgedLifetimeDependenceInfoArray(
306-
llvm::ArrayRef<swift::LifetimeDependenceInfo> lifetimeDependenceInfo)
307-
: lifetimeDependenceInfoArray(lifetimeDependenceInfo) {}
308-
309-
llvm::ArrayRef<swift::LifetimeDependenceInfo> unbridged() const {
310-
return lifetimeDependenceInfoArray
311-
.unbridged<swift::LifetimeDependenceInfo>();
312-
}
313-
#endif
314-
315178
BRIDGED_INLINE SwiftInt count() const;
316179

317180
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLifetimeDependenceInfo
@@ -335,11 +198,7 @@ enum class BridgedLinkage {
335198
struct BridgedASTType {
336199
swift::TypeBase * _Nullable type;
337200

338-
#ifdef USED_IN_CPP_SOURCE
339-
swift::Type unbridged() const {
340-
return type;
341-
}
342-
#endif
201+
BRIDGED_INLINE swift::Type unbridged() const;
343202

344203
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
345204

@@ -418,17 +277,8 @@ struct BridgedType {
418277
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE EnumElementIterator getNext() const;
419278
};
420279

421-
// Ensure that this struct value type will be indirectly returned on
422-
// Windows ARM64
423-
BridgedType() {}
424-
425-
#ifdef USED_IN_CPP_SOURCE
426-
BridgedType(swift::SILType t) : opaqueValue(t.getOpaqueValue()) {}
427-
428-
swift::SILType unbridged() const {
429-
return swift::SILType::getFromOpaqueValue(opaqueValue);
430-
}
431-
#endif
280+
BRIDGED_INLINE BridgedType(swift::SILType t);
281+
BRIDGED_INLINE swift::SILType unbridged() const;
432282

433283
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
434284
BRIDGED_INLINE bool isNull() const;
@@ -609,18 +459,8 @@ enum class BridgedMemoryBehavior {
609459
struct BridgedLocation {
610460
uint64_t storage[3];
611461

612-
// Ensure that this struct value type will be indirectly returned on
613-
// Windows ARM64
614-
BridgedLocation() {}
615-
616-
#ifdef USED_IN_CPP_SOURCE
617-
BridgedLocation(const swift::SILDebugLocation &loc) {
618-
*reinterpret_cast<swift::SILDebugLocation *>(&storage) = loc;
619-
}
620-
const swift::SILDebugLocation &getLoc() const {
621-
return *reinterpret_cast<const swift::SILDebugLocation *>(&storage);
622-
}
623-
#endif
462+
BRIDGED_INLINE BridgedLocation(const swift::SILDebugLocation &loc);
463+
BRIDGED_INLINE const swift::SILDebugLocation &getLoc() const;
624464

625465
BridgedOwnedString getDebugDescription() const;
626466
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getAutogeneratedLocation() const;
@@ -790,28 +630,16 @@ struct OptionalBridgedGlobalVar {
790630
struct BridgedMultiValueResult {
791631
SwiftObject obj;
792632

793-
#ifdef USED_IN_CPP_SOURCE
794-
swift::MultipleValueInstructionResult * _Nonnull unbridged() const {
795-
return static_cast<swift::MultipleValueInstructionResult *>(obj);
796-
}
797-
#endif
798-
633+
BRIDGED_INLINE swift::MultipleValueInstructionResult * _Nonnull unbridged() const;
799634
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction getParent() const;
800635
BRIDGED_INLINE SwiftInt getIndex() const;
801636
};
802637

803638
struct BridgedSubstitutionMap {
804639
uint64_t storage[1];
805640

806-
#ifdef USED_IN_CPP_SOURCE
807-
BridgedSubstitutionMap(swift::SubstitutionMap map) {
808-
*reinterpret_cast<swift::SubstitutionMap *>(&storage) = map;
809-
}
810-
swift::SubstitutionMap unbridged() const {
811-
return *reinterpret_cast<const swift::SubstitutionMap *>(&storage);
812-
}
813-
#endif
814-
641+
BRIDGED_INLINE BridgedSubstitutionMap(swift::SubstitutionMap map);
642+
BRIDGED_INLINE swift::SubstitutionMap unbridged() const;
815643
BRIDGED_INLINE BridgedSubstitutionMap();
816644
BRIDGED_INLINE bool isEmpty() const;
817645
BRIDGED_INLINE bool hasAnySubstitutableParams() const;

0 commit comments

Comments
 (0)