mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Reimplement most of the logic in Swift as an Instruction simplification and remove the old code from SILCombine
* support more cases of existential archetype replacements:
For example:
```
%0 = alloc_stack $any P
%1 = init_existential_addr %0, $T
use %1
```
is transformed to
```
%0 = alloc_stack $T
use %0
```
Also, if the alloc_stack is already an opened existential and the concrete type is known,
replace it as well:
```
%0 = metatype $@thick T.Type
%1 = init_existential_metatype %0, $@thick any P.Type
%2 = open_existential_metatype %1 : $@thick any P.Type to $@thick (@opened("X", P) Self).Type
...
%3 = alloc_stack $@opened("X", any P) Self
use %3
```
is transformed to
```
...
%3 = alloc_stack $T
use %3
```
59 lines
1.5 KiB
Swift
59 lines
1.5 KiB
Swift
// RUN: %target-swift-frontend -module-name main -O -emit-sil -primary-file %s | %FileCheck %s
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
|
|
protocol P {
|
|
func foo()
|
|
}
|
|
|
|
class C {}
|
|
|
|
public struct Inner {
|
|
var x: C
|
|
var y: Int
|
|
}
|
|
|
|
public struct S : P {
|
|
var i: Inner
|
|
|
|
func foo() {
|
|
print(i.x)
|
|
}
|
|
}
|
|
|
|
@_silgen_name("barrier")
|
|
func barrier()
|
|
|
|
// The specializations should be @_eagerMove.
|
|
|
|
// CHECK-LABEL: sil {{.*}}@$s4main27callee_guaranteed_eagerMoveyyAA1P_pFTf4e_n : {{.*}}{
|
|
// CHECK: {{bb[0-9]+}}({{%[^,]+}} : @_eagerMove $
|
|
// CHECK-LABEL: } // end sil function '$s4main27callee_guaranteed_eagerMoveyyAA1P_pFTf4e_n'
|
|
|
|
// CHECK-LABEL: sil {{.*}}@$s4main27callee_guaranteed_eagerMoveyyAA1P_pFTf4e_nAA1SV_Tg5Tf4x_n : {{.*}}{
|
|
// CHECK: {{bb[0-9]+}}({{%[^,]+}} : @_eagerMove
|
|
// CHECK-LABEL: } // end sil function '$s4main27callee_guaranteed_eagerMoveyyAA1P_pFTf4e_nAA1SV_Tg5Tf4x_n'
|
|
@inline(never)
|
|
func callee_guaranteed_eagerMove(@_eagerMove _ p: P) {
|
|
p.foo()
|
|
barrier()
|
|
}
|
|
|
|
public func caller_guaranteed_eagerMove(s: S) {
|
|
callee_guaranteed_eagerMove(s)
|
|
}
|
|
|
|
// TODO: update the test. Some exitential->generic specialization is happening, too.
|
|
// xCHECK-LABEL: sil {{.*}}@$s4main22callee_owned_eagerMoveyyAA1P_pnFTf4e_nTf4g_n : {{.*}}{
|
|
// xCHECK: {{bb[0-9]+}}({{%[^,]+}} : @_eagerMove $
|
|
// xCHECK-LABEL: } // end sil function '$s4main22callee_owned_eagerMoveyyAA1P_pnFTf4e_nTf4g_n'
|
|
@inline(never)
|
|
func callee_owned_eagerMove(@_eagerMove _ p: __owned P) {
|
|
p.foo()
|
|
barrier()
|
|
}
|
|
|
|
public func caller_owned_eagerMove(s: S) {
|
|
callee_owned_eagerMove(s)
|
|
}
|