Skip to content

Commit 586ac09

Browse files
authored
Merge pull request #76408 from swiftlang/egorzhdan/scs-owned-string
[cxx-interop][SwiftCompilerSources] Do not use `SWIFT_IMPORT_UNSAFE` with `BridgedOwnedString`
2 parents 58c6a2f + 35263ef commit 586ac09

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

include/swift/Basic/BasicBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class BridgedOwnedString {
234234
#endif
235235

236236
void destroy() const;
237-
};
237+
} SWIFT_SELF_CONTAINED;
238238

239239
SWIFT_NAME("getter:BridgedOwnedString.data(self:)")
240240
BRIDGED_INLINE

include/swift/Basic/Compiler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@
9090
#define SWIFT_IMPORT_UNSAFE
9191
#endif
9292

93+
/// Same as `SWIFT_SELF_CONTAINED` in <swift/bridging>.
94+
#if __has_attribute(swift_attr)
95+
#define SWIFT_SELF_CONTAINED __attribute__((swift_attr("import_owned")))
96+
#else
97+
#define SWIFT_SELF_CONTAINED
98+
#endif
99+
93100
#ifdef __GNUC__
94101
#define SWIFT_ATTRIBUTE_NORETURN __attribute__((noreturn))
95102
#elif defined(_MSC_VER)

include/swift/SIL/SILBridging.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ struct BridgedLifetimeDependenceInfo {
267267
BRIDGED_INLINE bool checkScope(SwiftInt index) const;
268268
BRIDGED_INLINE SwiftInt getTargetIndex() const;
269269

270-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
270+
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
271271
};
272272

273273
struct BridgedLifetimeDependenceInfoArray {
@@ -313,7 +313,7 @@ struct BridgedASTType {
313313
}
314314
#endif
315315

316-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
316+
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
317317

318318
BRIDGED_INLINE bool hasTypeParameter() const;
319319

@@ -394,7 +394,7 @@ struct BridgedType {
394394
}
395395
#endif
396396

397-
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
397+
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;
398398
BRIDGED_INLINE bool isNull() const;
399399
BRIDGED_INLINE bool isAddress() const;
400400
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getAddressType() const;
@@ -486,7 +486,7 @@ struct BridgedValue {
486486

487487
Kind getKind() const;
488488
BRIDGED_INLINE swift::ValueBase * _Nonnull getSILValue() const;
489-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
489+
BridgedOwnedString getDebugDescription() const;
490490
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedOperand getFirstUse() const;
491491
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedType getType() const;
492492
BRIDGED_INLINE Ownership getOwnership() const;
@@ -582,7 +582,7 @@ struct BridgedLocation {
582582
}
583583
#endif
584584

585-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
585+
BridgedOwnedString getDebugDescription() const;
586586
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getAutogeneratedLocation() const;
587587
BRIDGED_INLINE bool hasValidLineNumber() const;
588588
BRIDGED_INLINE bool isAutoGenerated() const;
@@ -638,7 +638,7 @@ struct BridgedFunction {
638638
SWIFT_IMPORT_UNSAFE BridgedFunction() {}
639639
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SILFunction * _Nonnull getFunction() const;
640640
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
641-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
641+
BridgedOwnedString getDebugDescription() const;
642642
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getLocation() const;
643643
BRIDGED_INLINE bool hasOwnership() const;
644644
BRIDGED_INLINE bool hasLoweredAddresses() const;
@@ -732,7 +732,7 @@ struct BridgedGlobalVar {
732732
BridgedGlobalVar(SwiftObject obj) : obj(obj) {}
733733
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE swift::SILGlobalVariable * _Nonnull getGlobal() const;
734734
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNullableVarDecl getDecl() const;
735-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
735+
BridgedOwnedString getDebugDescription() const;
736736
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedStringRef getName() const;
737737
BRIDGED_INLINE bool isLet() const;
738738
BRIDGED_INLINE void setLet(bool value) const;
@@ -853,7 +853,7 @@ struct BridgedInstruction {
853853
#endif
854854

855855
BridgedInstruction(SwiftObject obj) : obj(obj) {}
856-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
856+
BridgedOwnedString getDebugDescription() const;
857857
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedInstruction getNext() const;
858858
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedInstruction getPrevious() const;
859859
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock getParent() const;
@@ -1115,7 +1115,7 @@ struct BridgedBasicBlock {
11151115
}
11161116
#endif
11171117

1118-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
1118+
BridgedOwnedString getDebugDescription() const;
11191119
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getNext() const;
11201120
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getPrevious() const;
11211121
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction getFunction() const;
@@ -1155,7 +1155,7 @@ struct BridgedSuccessorArray {
11551155
struct BridgedVTableEntry {
11561156
const swift::SILVTableEntry * _Nonnull entry;
11571157

1158-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
1158+
BridgedOwnedString getDebugDescription() const;
11591159
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction getImplementation() const;
11601160
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedVTableEntry advanceBy(SwiftInt index) const;
11611161
};
@@ -1168,7 +1168,7 @@ struct BridgedVTableEntryArray {
11681168
struct BridgedVTable {
11691169
const swift::SILVTable * _Nonnull vTable;
11701170

1171-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
1171+
BridgedOwnedString getDebugDescription() const;
11721172
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedVTableEntryArray getEntries() const;
11731173
};
11741174

@@ -1189,7 +1189,7 @@ struct BridgedWitnessTableEntry {
11891189
}
11901190
#endif
11911191

1192-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
1192+
BridgedOwnedString getDebugDescription() const;
11931193
BRIDGED_INLINE Kind getKind() const;
11941194
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedFunction getMethodFunction() const;
11951195
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedWitnessTableEntry advanceBy(SwiftInt index) const;
@@ -1203,7 +1203,7 @@ struct BridgedWitnessTableEntryArray {
12031203
struct BridgedWitnessTable {
12041204
const swift::SILWitnessTable * _Nonnull table;
12051205

1206-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
1206+
BridgedOwnedString getDebugDescription() const;
12071207
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedWitnessTableEntryArray getEntries() const;
12081208
};
12091209

@@ -1214,7 +1214,7 @@ struct OptionalBridgedWitnessTable {
12141214
struct BridgedDefaultWitnessTable {
12151215
const swift::SILDefaultWitnessTable * _Nonnull table;
12161216

1217-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getDebugDescription() const;
1217+
BridgedOwnedString getDebugDescription() const;
12181218
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedWitnessTableEntryArray getEntries() const;
12191219
};
12201220

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct BridgedPassContext {
206206
Lowered
207207
};
208208

209-
SWIFT_IMPORT_UNSAFE BridgedOwnedString getModuleDescription() const;
209+
BridgedOwnedString getModuleDescription() const;
210210
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedChangeNotificationHandler asNotificationHandler() const;
211211
BRIDGED_INLINE void notifyDependencyOnBodyOf(BridgedFunction otherFunction) const;
212212
BRIDGED_INLINE SILStage getSILStage() const;
@@ -251,12 +251,12 @@ struct BridgedPassContext {
251251
BridgedFunction function) const;
252252
bool specializeClassMethodInst(BridgedInstruction cm) const;
253253
bool specializeAppliesInFunction(BridgedFunction function, bool isMandatory) const;
254-
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleOutlinedVariable(BridgedFunction function) const;
255-
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleAsyncRemoved(BridgedFunction function) const;
256-
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleWithDeadArgs(const SwiftInt * _Nullable deadArgs,
254+
BridgedOwnedString mangleOutlinedVariable(BridgedFunction function) const;
255+
BridgedOwnedString mangleAsyncRemoved(BridgedFunction function) const;
256+
BridgedOwnedString mangleWithDeadArgs(const SwiftInt * _Nullable deadArgs,
257257
SwiftInt numDeadArgs,
258258
BridgedFunction function) const;
259-
SWIFT_IMPORT_UNSAFE BridgedOwnedString mangleWithClosureArgs(BridgedValueArray closureArgs,
259+
BridgedOwnedString mangleWithClosureArgs(BridgedValueArray closureArgs,
260260
BridgedArrayRef closureArgIndices,
261261
BridgedFunction applySiteCallee) const;
262262

0 commit comments

Comments
 (0)