mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[cxx-interop][SwiftCompilerSources] Do not use SWIFT_IMPORT_UNSAFE with BridgedOwnedString
`SWIFT_IMPORT_UNSAFE` is an escape hatch that can be used to make the Swift compiler ignore its usual safety heuristics for C++ types. `BridgedOwnedString` fits into the definition of a self-contained C++ type in Swift: it manages the lifetimes of its own fields. This removes the usages of `SWIFT_IMPORT_UNSAFE` for C++ functions that return `BridgedOwnedString`, and annotates `BridgedOwnedString` as a self-contained type.
This commit is contained in:
@@ -234,7 +234,7 @@ public:
|
||||
#endif
|
||||
|
||||
void destroy() const;
|
||||
};
|
||||
} SWIFT_SELF_CONTAINED;
|
||||
|
||||
SWIFT_NAME("getter:BridgedOwnedString.data(self:)")
|
||||
BRIDGED_INLINE
|
||||
|
||||
@@ -90,6 +90,13 @@
|
||||
#define SWIFT_IMPORT_UNSAFE
|
||||
#endif
|
||||
|
||||
/// Same as `SWIFT_SELF_CONTAINED` in <swift/bridging>.
|
||||
#if __has_attribute(swift_attr)
|
||||
#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned")))
|
||||
#else
|
||||
#define SWIFT_SELF_CONTAINED
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define SWIFT_ATTRIBUTE_NORETURN __attribute__((noreturn))
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
@@ -267,7 +267,7 @@ struct BridgedLifetimeDependenceInfo {
|
||||
BRIDGED_INLINE bool checkScope(SwiftInt index) const;
|
||||
BRIDGED_INLINE SwiftInt getTargetIndex() const;
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
|
||||
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
|
||||
};
|
||||
|
||||
struct BridgedLifetimeDependenceInfoArray {
|
||||
@@ -313,7 +313,7 @@ struct BridgedASTType {
|
||||
}
|
||||
#endif
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
|
||||
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
|
||||
|
||||
BRIDGED_INLINE bool hasTypeParameter() const;
|
||||
|
||||
@@ -394,7 +394,7 @@ struct BridgedType {
|
||||
}
|
||||
#endif
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
|
||||
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
|
||||
BRIDGED_INLINE bool isNull() const;
|
||||
BRIDGED_INLINE bool isAddress() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getAddressType() const;
|
||||
@@ -486,7 +486,7 @@ struct BridgedValue {
|
||||
|
||||
Kind getKind() const;
|
||||
BRIDGED_INLINE swift::ValueBase * _Nonnull getSILValue() const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedOperand getFirstUse() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getType() const;
|
||||
BRIDGED_INLINE Ownership getOwnership() const;
|
||||
@@ -582,7 +582,7 @@ struct BridgedLocation {
|
||||
}
|
||||
#endif
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getAutogeneratedLocation() const;
|
||||
BRIDGED_INLINE bool hasValidLineNumber() const;
|
||||
BRIDGED_INLINE bool isAutoGenerated() const;
|
||||
@@ -638,7 +638,7 @@ struct BridgedFunction {
|
||||
SWIFT_IMPORT_UNSAFE BridgedFunction() {}
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SILFunction * _Nonnull getFunction() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
|
||||
BRIDGED_INLINE bool hasOwnership() const;
|
||||
BRIDGED_INLINE bool hasLoweredAddresses() const;
|
||||
@@ -732,7 +732,7 @@ struct BridgedGlobalVar {
|
||||
BridgedGlobalVar(SwiftObject obj) : obj(obj) {}
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SILGlobalVariable * _Nonnull getGlobal() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNullableVarDecl getDecl() const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
|
||||
BRIDGED_INLINE bool isLet() const;
|
||||
BRIDGED_INLINE void setLet(bool value) const;
|
||||
@@ -849,7 +849,7 @@ struct BridgedInstruction {
|
||||
#endif
|
||||
|
||||
BridgedInstruction(SwiftObject obj) : obj(obj) {}
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedInstruction getNext() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedInstruction getPrevious() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock getParent() const;
|
||||
@@ -1111,7 +1111,7 @@ struct BridgedBasicBlock {
|
||||
}
|
||||
#endif
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getNext() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getPrevious() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction getFunction() const;
|
||||
@@ -1151,7 +1151,7 @@ struct BridgedSuccessorArray {
|
||||
struct BridgedVTableEntry {
|
||||
const swift::SILVTableEntry * _Nonnull entry;
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction getImplementation() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedVTableEntry advanceBy(SwiftInt index) const;
|
||||
};
|
||||
@@ -1164,7 +1164,7 @@ struct BridgedVTableEntryArray {
|
||||
struct BridgedVTable {
|
||||
const swift::SILVTable * _Nonnull vTable;
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedVTableEntryArray getEntries() const;
|
||||
};
|
||||
|
||||
@@ -1185,7 +1185,7 @@ struct BridgedWitnessTableEntry {
|
||||
}
|
||||
#endif
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
BRIDGED_INLINE Kind getKind() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedFunction getMethodFunction() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedWitnessTableEntry advanceBy(SwiftInt index) const;
|
||||
@@ -1199,7 +1199,7 @@ struct BridgedWitnessTableEntryArray {
|
||||
struct BridgedWitnessTable {
|
||||
const swift::SILWitnessTable * _Nonnull table;
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedWitnessTableEntryArray getEntries() const;
|
||||
};
|
||||
|
||||
@@ -1210,7 +1210,7 @@ struct OptionalBridgedWitnessTable {
|
||||
struct BridgedDefaultWitnessTable {
|
||||
const swift::SILDefaultWitnessTable * _Nonnull table;
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
|
||||
BridgedOwnedString getDebugDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedWitnessTableEntryArray getEntries() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ struct BridgedPassContext {
|
||||
Lowered
|
||||
};
|
||||
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString getModuleDescription() const;
|
||||
BridgedOwnedString getModuleDescription() const;
|
||||
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedChangeNotificationHandler asNotificationHandler() const;
|
||||
BRIDGED_INLINE void notifyDependencyOnBodyOf(BridgedFunction otherFunction) const;
|
||||
BRIDGED_INLINE SILStage getSILStage() const;
|
||||
@@ -251,12 +251,12 @@ struct BridgedPassContext {
|
||||
BridgedFunction function) const;
|
||||
bool specializeClassMethodInst(BridgedInstruction cm) const;
|
||||
bool specializeAppliesInFunction(BridgedFunction function, bool isMandatory) const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleOutlinedVariable(BridgedFunction function) const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleAsyncRemoved(BridgedFunction function) const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleWithDeadArgs(const SwiftInt * _Nullable deadArgs,
|
||||
BridgedOwnedString mangleOutlinedVariable(BridgedFunction function) const;
|
||||
BridgedOwnedString mangleAsyncRemoved(BridgedFunction function) const;
|
||||
BridgedOwnedString mangleWithDeadArgs(const SwiftInt * _Nullable deadArgs,
|
||||
SwiftInt numDeadArgs,
|
||||
BridgedFunction function) const;
|
||||
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleWithClosureArgs(BridgedValueArray closureArgs,
|
||||
BridgedOwnedString mangleWithClosureArgs(BridgedValueArray closureArgs,
|
||||
BridgedArrayRef closureArgIndices,
|
||||
BridgedFunction applySiteCallee) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user