Skip to content

SILBridging: remove some #ifdef USED_IN_CPP_SOURCE #76675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 22 additions & 194 deletions include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace swift {
class ValueBase;
class Operand;
class ForwardingInstruction;
class SILType;
class SILFunction;
class SILBasicBlock;
class SILSuccessor;
Expand All @@ -58,13 +59,19 @@ class SILVTableEntry;
class SILVTable;
class SILWitnessTable;
class SILDefaultWitnessTable;
class SILDebugLocation;
class NominalTypeDecl;
class VarDecl;
class Type;
class TypeBase;
class SubstitutionMap;
class SwiftPassInvocation;
class GenericSpecializationInformation;
class LifetimeDependenceInfo;
class IndexSubset;
enum class ResultConvention : uint8_t;
class SILResultInfo;
class SILParameterInfo;
}

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

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedResultInfo() {}

#ifdef USED_IN_CPP_SOURCE
inline static BridgedResultConvention
castToResultConvention(swift::ResultConvention convention) {
return static_cast<BridgedResultConvention>(convention);
}

BridgedResultInfo(swift::SILResultInfo resultInfo):
type(resultInfo.getInterfaceType().getPointer()),
convention(castToResultConvention(resultInfo.getConvention()))
{}
#endif
BRIDGED_INLINE static BridgedResultConvention castToResultConvention(swift::ResultConvention convention);
BRIDGED_INLINE BridgedResultInfo(swift::SILResultInfo resultInfo);
};

struct OptionalBridgedResultInfo {
swift::TypeBase * _Nullable type = nullptr;
BridgedResultConvention convention = BridgedResultConvention::Indirect;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
OptionalBridgedResultInfo() {}

#ifdef USED_IN_CPP_SOURCE
OptionalBridgedResultInfo(std::optional<swift::SILResultInfo> resultInfo) {
if (resultInfo) {
type = resultInfo->getInterfaceType().getPointer();
convention =
BridgedResultInfo::castToResultConvention(resultInfo->getConvention());
}
}
#endif
swift::TypeBase * _Nullable type;
BridgedResultConvention convention;
};

struct BridgedResultInfoArray {
BridgedArrayRef resultInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedResultInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedResultInfoArray(llvm::ArrayRef<swift::SILResultInfo> results)
: resultInfoArray(results) {}

llvm::ArrayRef<swift::SILResultInfo> unbridged() const {
return resultInfoArray.unbridged<swift::SILResultInfo>();
}
#endif

BRIDGED_INLINE SwiftInt count() const;

SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
Expand All @@ -160,44 +127,6 @@ enum class BridgedArgumentConvention {
Pack_Out
};

#ifdef USED_IN_CPP_SOURCE
inline swift::ParameterConvention getParameterConvention(BridgedArgumentConvention convention) {
switch (convention) {
case BridgedArgumentConvention::Indirect_In: return swift::ParameterConvention::Indirect_In;
case BridgedArgumentConvention::Indirect_In_Guaranteed: return swift::ParameterConvention::Indirect_In_Guaranteed;
case BridgedArgumentConvention::Indirect_Inout: return swift::ParameterConvention::Indirect_Inout;
case BridgedArgumentConvention::Indirect_InoutAliasable: return swift::ParameterConvention::Indirect_InoutAliasable;
case BridgedArgumentConvention::Indirect_In_CXX: return swift::ParameterConvention::Indirect_In_CXX;
case BridgedArgumentConvention::Indirect_Out: break;
case BridgedArgumentConvention::Direct_Owned: return swift::ParameterConvention::Direct_Owned;
case BridgedArgumentConvention::Direct_Unowned: return swift::ParameterConvention::Direct_Unowned;
case BridgedArgumentConvention::Direct_Guaranteed: return swift::ParameterConvention::Direct_Guaranteed;
case BridgedArgumentConvention::Pack_Owned: return swift::ParameterConvention::Pack_Owned;
case BridgedArgumentConvention::Pack_Inout: return swift::ParameterConvention::Pack_Inout;
case BridgedArgumentConvention::Pack_Guaranteed: return swift::ParameterConvention::Pack_Guaranteed;
case BridgedArgumentConvention::Pack_Out: break;
}
llvm_unreachable("invalid parameter convention");
}

inline BridgedArgumentConvention getArgumentConvention(swift::ParameterConvention convention) {
switch (convention) {
case swift::ParameterConvention::Indirect_In: return BridgedArgumentConvention::Indirect_In;
case swift::ParameterConvention::Indirect_In_Guaranteed: return BridgedArgumentConvention::Indirect_In_Guaranteed;
case swift::ParameterConvention::Indirect_Inout: return BridgedArgumentConvention::Indirect_Inout;
case swift::ParameterConvention::Indirect_InoutAliasable: return BridgedArgumentConvention::Indirect_InoutAliasable;
case swift::ParameterConvention::Indirect_In_CXX: return BridgedArgumentConvention::Indirect_In_CXX;
case swift::ParameterConvention::Direct_Owned: return BridgedArgumentConvention::Direct_Owned;
case swift::ParameterConvention::Direct_Unowned: return BridgedArgumentConvention::Direct_Unowned;
case swift::ParameterConvention::Direct_Guaranteed: return BridgedArgumentConvention::Direct_Guaranteed;
case swift::ParameterConvention::Pack_Owned: return BridgedArgumentConvention::Pack_Owned;
case swift::ParameterConvention::Pack_Inout: return BridgedArgumentConvention::Pack_Inout;
case swift::ParameterConvention::Pack_Guaranteed: return BridgedArgumentConvention::Pack_Guaranteed;
}
llvm_unreachable("invalid parameter convention");
}
#endif

struct BridgedParameterInfo {
swift::TypeBase * _Nonnull type;
BridgedArgumentConvention convention;
Expand All @@ -206,42 +135,13 @@ struct BridgedParameterInfo {
BridgedParameterInfo(swift::TypeBase * _Nonnull type, BridgedArgumentConvention convention, uint8_t options) :
type(type), convention(convention), options(options) {}

#ifdef USED_IN_CPP_SOURCE
inline static BridgedArgumentConvention
castToArgumentConvention(swift::ParameterConvention convention) {
return static_cast<BridgedArgumentConvention>(
swift::SILArgumentConvention(convention).Value);
}

BridgedParameterInfo(swift::SILParameterInfo parameterInfo):
type(parameterInfo.getInterfaceType().getPointer()),
convention(castToArgumentConvention(parameterInfo.getConvention())),
options(parameterInfo.getOptions().toRaw())
{}

swift::SILParameterInfo unbridged() const {
return swift::SILParameterInfo(swift::CanType(type), getParameterConvention(convention),
swift::SILParameterInfo::Options(options));
}
#endif
BRIDGED_INLINE BridgedParameterInfo(swift::SILParameterInfo parameterInfo);
BRIDGED_INLINE swift::SILParameterInfo unbridged() const;
};

struct BridgedParameterInfoArray {
BridgedArrayRef parameterInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedParameterInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedParameterInfoArray(llvm::ArrayRef<swift::SILParameterInfo> parameters)
: parameterInfoArray(parameters) {}

llvm::ArrayRef<swift::SILParameterInfo> unbridged() const {
return parameterInfoArray.unbridged<swift::SILParameterInfo>();
}
#endif

BRIDGED_INLINE SwiftInt count() const;

SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
Expand All @@ -251,19 +151,6 @@ struct BridgedParameterInfoArray {
struct BridgedYieldInfoArray {
BridgedArrayRef yieldInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedYieldInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedYieldInfoArray(llvm::ArrayRef<swift::SILYieldInfo> yields)
: yieldInfoArray(yields) {}

llvm::ArrayRef<swift::SILYieldInfo> unbridged() const {
return yieldInfoArray.unbridged<swift::SILYieldInfo>();
}
#endif

BRIDGED_INLINE SwiftInt count() const;

SWIFT_IMPORT_UNSAFE BRIDGED_INLINE
Expand All @@ -275,16 +162,7 @@ struct BridgedLifetimeDependenceInfo {
SwiftUInt targetIndex;
bool immortal;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLifetimeDependenceInfo() {}

#ifdef USED_IN_CPP_SOURCE
BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info)
: inheritLifetimeParamIndices(info.getInheritIndices()),
scopeLifetimeParamIndices(info.getScopeIndices()),
targetIndex(info.getTargetIndex()), immortal(info.isImmortal()) {}
#endif
BRIDGED_INLINE BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info);

BRIDGED_INLINE bool empty() const;
BRIDGED_INLINE bool checkInherit(SwiftInt index) const;
Expand All @@ -297,21 +175,6 @@ struct BridgedLifetimeDependenceInfo {
struct BridgedLifetimeDependenceInfoArray {
BridgedArrayRef lifetimeDependenceInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLifetimeDependenceInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedLifetimeDependenceInfoArray(
llvm::ArrayRef<swift::LifetimeDependenceInfo> lifetimeDependenceInfo)
: lifetimeDependenceInfoArray(lifetimeDependenceInfo) {}

llvm::ArrayRef<swift::LifetimeDependenceInfo> unbridged() const {
return lifetimeDependenceInfoArray
.unbridged<swift::LifetimeDependenceInfo>();
}
#endif

BRIDGED_INLINE SwiftInt count() const;

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

#ifdef USED_IN_CPP_SOURCE
swift::Type unbridged() const {
return type;
}
#endif
BRIDGED_INLINE swift::Type unbridged() const;

BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;

Expand Down Expand Up @@ -418,17 +277,8 @@ struct BridgedType {
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE EnumElementIterator getNext() const;
};

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedType() {}

#ifdef USED_IN_CPP_SOURCE
BridgedType(swift::SILType t) : opaqueValue(t.getOpaqueValue()) {}

swift::SILType unbridged() const {
return swift::SILType::getFromOpaqueValue(opaqueValue);
}
#endif
BRIDGED_INLINE BridgedType(swift::SILType t);
BRIDGED_INLINE swift::SILType unbridged() const;

BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
BRIDGED_INLINE bool isNull() const;
Expand Down Expand Up @@ -609,18 +459,8 @@ enum class BridgedMemoryBehavior {
struct BridgedLocation {
uint64_t storage[3];

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLocation() {}

#ifdef USED_IN_CPP_SOURCE
BridgedLocation(const swift::SILDebugLocation &loc) {
*reinterpret_cast<swift::SILDebugLocation *>(&storage) = loc;
}
const swift::SILDebugLocation &getLoc() const {
return *reinterpret_cast<const swift::SILDebugLocation *>(&storage);
}
#endif
BRIDGED_INLINE BridgedLocation(const swift::SILDebugLocation &loc);
BRIDGED_INLINE const swift::SILDebugLocation &getLoc() const;

BridgedOwnedString getDebugDescription() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getAutogeneratedLocation() const;
Expand Down Expand Up @@ -790,28 +630,16 @@ struct OptionalBridgedGlobalVar {
struct BridgedMultiValueResult {
SwiftObject obj;

#ifdef USED_IN_CPP_SOURCE
swift::MultipleValueInstructionResult * _Nonnull unbridged() const {
return static_cast<swift::MultipleValueInstructionResult *>(obj);
}
#endif

BRIDGED_INLINE swift::MultipleValueInstructionResult * _Nonnull unbridged() const;
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction getParent() const;
BRIDGED_INLINE SwiftInt getIndex() const;
};

struct BridgedSubstitutionMap {
uint64_t storage[1];

#ifdef USED_IN_CPP_SOURCE
BridgedSubstitutionMap(swift::SubstitutionMap map) {
*reinterpret_cast<swift::SubstitutionMap *>(&storage) = map;
}
swift::SubstitutionMap unbridged() const {
return *reinterpret_cast<const swift::SubstitutionMap *>(&storage);
}
#endif

BRIDGED_INLINE BridgedSubstitutionMap(swift::SubstitutionMap map);
BRIDGED_INLINE swift::SubstitutionMap unbridged() const;
BRIDGED_INLINE BridgedSubstitutionMap();
BRIDGED_INLINE bool isEmpty() const;
BRIDGED_INLINE bool hasAnySubstitutableParams() const;
Expand Down
Loading