Skip to content

Commit c8b5df5

Browse files
authored
Merge pull request #85647 from eeckstein/fix-embedded-cpp-classes
embedded: don't try to specialize vtables of C++ imported reference-counted classes
2 parents e18ba6d + fa3bfa3 commit c8b5df5

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
@@ -128,6 +128,8 @@ final public class ClassDecl: NominalTypeDecl {
128128
final public var destructor: DestructorDecl {
129129
bridged.Class_getDestructor().getAs(DestructorDecl.self)
130130
}
131+
132+
public var isForeign: Bool { bridged.Class_isForeign() }
131133
}
132134

133135
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
@@ -346,6 +346,7 @@ struct BridgedDeclObj {
346346
BRIDGED_INLINE bool Struct_hasUnreferenceableStorage() const;
347347
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedASTType Class_getSuperclass() const;
348348
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclObj Class_getDestructor() const;
349+
BRIDGED_INLINE bool Class_isForeign() const;
349350
BRIDGED_INLINE bool ProtocolDecl_requiresClass() const;
350351
BRIDGED_INLINE bool AbstractFunction_isOverridden() const;
351352
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
@@ -256,6 +256,10 @@ BridgedDeclObj BridgedDeclObj::Class_getDestructor() const {
256256
return {getAs<swift::ClassDecl>()->getDestructor()};
257257
}
258258

259+
bool BridgedDeclObj::Class_isForeign() const {
260+
return getAs<swift::ClassDecl>()->isForeign();
261+
}
262+
259263
bool BridgedDeclObj::ProtocolDecl_requiresClass() const {
260264
return getAs<swift::ProtocolDecl>()->requiresClass();
261265
}

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)