Skip to content

Commit 2c1a6dd

Browse files
authored
Merge pull request #85749 from eeckstein/fix-embedded-cpp-classes-6.3
[6.3] embedded: don't try to specialize vtables of C++ imported reference-counted classes
2 parents b05fae7 + 7a21e46 commit 2c1a6dd

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ final public class ClassDecl: NominalTypeDecl {
7272
final public var destructor: DestructorDecl {
7373
bridged.Class_getDestructor().getAs(DestructorDecl.self)
7474
}
75+
76+
public var isForeign: Bool { bridged.Class_isForeign() }
7577
}
7678

7779
final public class ProtocolDecl: NominalTypeDecl {

SwiftCompilerSources/Sources/Optimizer/Utilities/GenericSpecialization.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ private struct VTableSpecializer {
4848
}
4949

5050
let classDecl = classType.nominal! as! ClassDecl
51+
if classDecl.isForeign {
52+
return
53+
}
5154
guard let origVTable = context.lookupVTable(for: classDecl) else {
5255
if context.enableWMORequiredDiagnostics {
5356
context.diagnosticEngine.diagnose(.cannot_specialize_class, classType, at: errorLocation)

include/swift/AST/ASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ struct BridgedDeclObj {
334334
BRIDGED_INLINE bool Struct_hasUnreferenceableStorage() const;
335335
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType Class_getSuperclass() const;
336336
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj Class_getDestructor() const;
337+
BRIDGED_INLINE bool Class_isForeign() const;
337338
BRIDGED_INLINE bool ProtocolDecl_requiresClass() const;
338339
BRIDGED_INLINE bool AbstractFunction_isOverridden() const;
339340
BRIDGED_INLINE bool Destructor_isIsolated() const;

include/swift/AST/ASTBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ BridgedDeclObj BridgedDeclObj::Class_getDestructor() const {
218218
return {getAs<swift::ClassDecl>()->getDestructor()};
219219
}
220220

221+
bool BridgedDeclObj::Class_isForeign() const {
222+
return getAs<swift::ClassDecl>()->isForeign();
223+
}
224+
221225
bool BridgedDeclObj::ProtocolDecl_requiresClass() const {
222226
return getAs<swift::ProtocolDecl>()->requiresClass();
223227
}

test/embedded/cxx-import-reference.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ public func test()
4040
let c = C.create()
4141
c.foo()
4242
}
43+
44+
public func cast<S,D>(_ s:S, to type:D.Type) -> D {
45+
return unsafeBitCast(s, to: type.self)
46+
}
47+
48+
public func testcast(_ provider: AnyObject) -> C {
49+
return cast (provider, to: C.self)
50+
}
51+

0 commit comments

Comments
 (0)