, , . , , .
-, , , ( Swift, Objective-C ).
-, :
protocol Foo { }
struct Bar: Foo { }
var fooArray = [Foo]()
fooArray.append(Bar())
fooArray.append(Bar())
fooArray.append(Bar())
let arrayElement = fooArray[0]
print(arrayElement)
... LLVM IR, swiftc -emit-ir unveil.swift > unveil.ir, IR, fooArray.append(Bar()):
%15 = getelementptr inbounds %P6unveil3Foo_* %3, i32 0, i32 1
store %swift.type* bitcast (i64* getelementptr inbounds ({ i8**, i64, { i64, i8*, i32, i32, i8*, %swift.type** (%swift.type*)*, %swift.type_pattern*, i32, i32, i32 }*, %swift.type* }* @_TMfV6unveil3Bar, i32 0, i32 1) to %swift.type*), %swift.type** %15, align 8
%16 = getelementptr inbounds %P6unveil3Foo_* %3, i32 0, i32 2
store i8** getelementptr inbounds ([0 x i8*]* @_TWPV6unveil3BarS_3FooS_, i32 0, i32 0), i8*** %16, align 8
%17 = getelementptr inbounds %P6unveil3Foo_* %3, i32 0, i32 0
call void @_TFV6unveil3BarCfMS0_FT_S0_()
%18 = bitcast %P6unveil3Foo_* %3 to %swift.opaque*
call void @_TFSa6appendurfRGSaq__Fq_T_(%swift.opaque* noalias nocapture %18, %swift.type* %14, %Sa* nocapture dereferenceable(8) @_Tv6unveil8fooArrayGSaPS_3Foo__)
LLVM IR, , Swift - .
, IR, Swift, :
leaq __TWPV6unveil3BarS_3FooS_(%rip), %rax
leaq __TMfV6unveil3Bar(%rip), %rcx
addq $8, %rcx
movq %rcx, -56(%rbp)
movq %rax, -48(%rbp)
callq __TFV6unveil3BarCfMS0_FT_S0_
leaq __Tv6unveil8fooArrayGSaPS_3Foo__(%rip), %rdx
leaq -80(%rbp), %rax
movq %rax, %rdi
movq -160(%rbp), %rsi
callq __TFSa6appendurfRGSaq__Fq_T_
... , , .
, , SIL SILWitnessTable.h SILWitnessVisitor.h swift.org, swift/include/swift/SIL/, .
, ( , -, , , ), (, struct s) (read class es) . , , .