Files
Saleem Abdulrasool 32eaacfb01 IRGen: recover native Swift identity in scalar COM casts
Use the general dynamic-cast entry point for COM sources as well as COM
destinations. A source interface can expose ISwiftObject and recover a
native object whose address and reference count differ from the interface.

Initialize the entire destination storage before querying the runtime so
that failed casts also produce a nil result for native class-bound
existentials, which carry witness tables alongside the object pointer.
2026-10-01 18:29:07 -07:00

53 lines
2.3 KiB
Plaintext

sil_stage canonical
import Swift
import M
sil [ossa] @com_native_conditional : $@convention(thin) (@owned any ISource) -> @owned Optional<NativeBase> {
bb0(%source : @owned $any ISource):
checked_cast_br any ISource in %source : $any ISource to NativeBase, bb1, bb2
bb1(%target : @owned $NativeBase):
%some = enum $Optional<NativeBase>, #Optional.some!enumelt, %target : $NativeBase
br bb3(%some : $Optional<NativeBase>)
bb2(%failed : @owned $any ISource):
destroy_value %failed : $any ISource
%none = enum $Optional<NativeBase>, #Optional.none!enumelt
br bb3(%none : $Optional<NativeBase>)
bb3(%result : @owned $Optional<NativeBase>):
return %result : $Optional<NativeBase>
}
sil [ossa] @com_native_forced : $@convention(thin) (@owned any ISource) -> @owned NativeBase {
bb0(%source : @owned $any ISource):
%target = unconditional_checked_cast %source : $any ISource to NativeBase
return %target : $NativeBase
}
sil [ossa] @com_native_optional : $@convention(thin) (@owned Optional<any ISource>) -> @owned Optional<NativeBase> {
bb0(%source : @owned $Optional<any ISource>):
checked_cast_br Optional<any ISource> in %source : $Optional<any ISource> to NativeBase, bb1, bb2
bb1(%target : @owned $NativeBase):
%some = enum $Optional<NativeBase>, #Optional.some!enumelt, %target : $NativeBase
br bb3(%some : $Optional<NativeBase>)
bb2(%failed : @owned $Optional<any ISource>):
destroy_value %failed : $Optional<any ISource>
%none = enum $Optional<NativeBase>, #Optional.none!enumelt
br bb3(%none : $Optional<NativeBase>)
bb3(%result : @owned $Optional<NativeBase>):
return %result : $Optional<NativeBase>
}
sil [ossa] @com_native_protocol : $@convention(thin) (@owned any ISource) -> @owned Optional<any NativeMarker> {
bb0(%source : @owned $any ISource):
checked_cast_br any ISource in %source : $any ISource to any NativeMarker, bb1, bb2
bb1(%target : @owned $any NativeMarker):
%some = enum $Optional<any NativeMarker>, #Optional.some!enumelt, %target : $any NativeMarker
br bb3(%some : $Optional<any NativeMarker>)
bb2(%failed : @owned $any ISource):
destroy_value %failed : $any ISource
%none = enum $Optional<any NativeMarker>, #Optional.none!enumelt
br bb3(%none : $Optional<any NativeMarker>)
bb3(%result : @owned $Optional<any NativeMarker>):
return %result : $Optional<any NativeMarker>
}