Skip to content

Commit 4f300bb

Browse files
committed
Update tests
1 parent 4cba763 commit 4f300bb

9 files changed

+164
-58
lines changed

test/IRGen/lazy_opaque_result_type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-implicit-dynamic -disable-availability-checking -Xllvm -sil-disable-pass=OpaqueArchetypeSpecializer -parse-as-library -module-name=test -O -primary-file %s -emit-ir > %t.ll
1+
// RUN: %target-swift-frontend -enable-implicit-dynamic -disable-availability-checking -parse-as-library -module-name=test -O -primary-file %s -emit-ir > %t.ll
22
// RUN: %FileCheck %s < %t.ll
33

44
protocol P { }

test/IRGen/opaque_result_type_debug.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -g -emit-ir -enable-anonymous-context-mangled-names %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -enable-library-evolution -disable-availability-checking -g -emit-ir -enable-anonymous-context-mangled-names %s | %FileCheck %s
22

33
public protocol P {}
44
extension Int: P {}
@@ -24,6 +24,7 @@ public var prop: some P {
2424
// CHECK: @"$s24opaque_result_type_debug3FooVQrycipQOMQ" = {{.*}}constant{{.*}} @"$s24opaque_result_type_debug3FooVQrycipMXX"
2525

2626
public struct Foo {
27+
public init() {}
2728
public subscript() -> some P {
2829
return 0
2930
}
@@ -33,6 +34,7 @@ public struct Foo {
3334

3435
@_silgen_name("use") public func use<T: P>(_: T)
3536

37+
@inlinable
3638
public func bar<T: P>(genericValue: T) {
3739
use(genericValue)
3840

test/IRGen/opaque_result_type_substitution.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -primary-file %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -enable-library-evolution -disable-availability-checking -emit-ir -primary-file %s | %FileCheck %s
22

3-
protocol E {}
3+
public protocol E {}
44

5-
struct Pair<T, V> : E {
5+
public struct Pair<T, V> : E {
66
var fst : T
77
var snd : V
88

9-
init(_ f: T, _ s: V) {
9+
public init(_ f: T, _ s: V) {
1010
self.fst = f
1111
self.snd = s
1212
}
1313

14-
func foobar() -> some E {
14+
public func foobar() -> some E {
1515
return self
1616
}
1717
}
1818

19+
@inlinable
1920
public func usePair<T, V>(_ t: T, _ v: V) {
2021
var x = Pair(t, v)
2122
let q = x.foobar()

test/IRGen/partial_apply.sil

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,14 @@ enum GenericEnum2<T> {
527527
sil public_external @generic_indirect_return2 : $@convention(thin) <T> (Int) -> @owned GenericEnum2<T>
528528

529529
// CHECK-LABEL: define{{.*}} @partial_apply_generic_indirect_return2
530-
// CHECK: insertvalue {{.*}}$s24generic_indirect_return2TA
530+
// CHECK: [[CTX:%.]] = call noalias %swift.refcounted* @swift_allocObject
531+
// CHECK: store {{.*}}$s24generic_indirect_return2TA
532+
// CHECK: store %swift.refcounted* [[CTX]]
533+
// CHECK: [[FN:%.*]] = load i8*
534+
// CHECK: [[CTX2:%.*]] = load %swift.refcounted*
535+
// CHECK: [[R1:%.]] = insertvalue { i8*, %swift.refcounted* } undef, i8* [[FN]], 0
536+
// CHECK: [[R2:%.*]] = insertvalue { i8*, %swift.refcounted* } [[R1]], %swift.refcounted* [[CTX2]], 1
537+
// CHECK: ret { i8*, %swift.refcounted* } [[R2]]
531538

532539
// CHECK-LABEL: define internal swiftcc void @"$s24generic_indirect_return2TA"(%T13partial_apply12GenericEnum2OySiG* noalias nocapture sret, %swift.refcounted* swiftself)
533540
// CHECK: [[CASTED_ADDR:%.*]] = bitcast %T13partial_apply12GenericEnum2OySiG* %0 to %T13partial_apply12GenericEnum2O*

test/SIL/Serialization/opaque_return_type_serialize.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -disable-availability-checking -emit-module -emit-module-path %t/OpaqueReturnTypeExporter.swiftmodule -module-name OpaqueReturnTypeExporter %S/Inputs/OpaqueReturnTypeExporter.swift
2+
// RUN: %target-swift-frontend -disable-availability-checking -enable-library-evolution -emit-module -emit-module-path %t/OpaqueReturnTypeExporter.swiftmodule -module-name OpaqueReturnTypeExporter %S/Inputs/OpaqueReturnTypeExporter.swift
33
// RUN: %target-sil-opt -I %t %s -emit-sib -module-name test -o %t/test.sib
44
// RUN: %target-swift-frontend -disable-availability-checking -I %t -emit-ir %t/test.sib
55

@@ -12,7 +12,7 @@ typealias SomeButt2 = @_opaqueReturnTypeOf("$sSi24OpaqueReturnTypeExporterE8some
1212
sil @$s24OpaqueReturnTypeExporter07exportsaB0QryF : $@convention(thin) () -> @out SomeButt
1313
sil @$sSi24OpaqueReturnTypeExporterE8someButtQryF : $@convention(thin) (Int) -> @out SomeButt2
1414

15-
sil @use_opaque_type : $@convention(thin) (Int) -> () {
15+
sil [serialized] @use_opaque_type : $@convention(thin) (Int) -> () {
1616
entry(%a : $Int):
1717
%f = function_ref @$s24OpaqueReturnTypeExporter07exportsaB0QryF : $@convention(thin) () -> @out SomeButt
1818
%x = alloc_stack $SomeButt

test/SILGen/opaque_result_type.swift

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s | %FileCheck %s
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
3+
// RUN: %target-swift-frontend -I %t -disable-availability-checking -emit-silgen %s | %FileCheck %s
4+
5+
import resilient_struct
26

37
protocol P {}
48
protocol Q: AnyObject {}
@@ -10,39 +14,138 @@ class C: Q {}
1014

1115
// CHECK-LABEL: sil hidden {{.*}}11valueToAddr1xQr
1216
func valueToAddr(x: String) -> some P {
13-
// CHECK: [[UNDERLYING:%.*]] = unchecked_addr_cast %0
14-
// CHECK: [[VALUE_COPY:%.*]] = copy_value %1
15-
// CHECK: store [[VALUE_COPY]] to [init] [[UNDERLYING]]
17+
// CHECK: bb0([[ARG0:%.*]] : $*String, [[ARG1:%.*]] : @guaranteed $String):
18+
// CHECK: [[VALUE_COPY:%.*]] = copy_value [[ARG1]]
19+
// CHECK: store [[VALUE_COPY]] to [init] [[ARG0]]
1620
return x
1721
}
1822

1923
// CHECK-LABEL: sil hidden {{.*}}10addrToAddr1xQr
2024
func addrToAddr(x: AddrOnly) -> some P {
21-
// CHECK: [[UNDERLYING:%.*]] = unchecked_addr_cast %0
22-
// CHECK: copy_addr %1 to [initialization] [[UNDERLYING]]
25+
// CHECK: bb0([[ARG0:%.*]] : $*AddrOnly, [[ARG1:%.*]] : $*AddrOnly):
26+
// CHECK: copy_addr [[ARG1]] to [initialization] [[ARG0]]
2327
return x
2428
}
2529

2630
// CHECK-LABEL: sil hidden {{.*}}13genericAddrToE01xQr
2731
func genericAddrToAddr<T: P>(x: T) -> some P {
28-
// CHECK: [[UNDERLYING:%.*]] = unchecked_addr_cast %0
29-
// CHECK: copy_addr %1 to [initialization] [[UNDERLYING]]
32+
// CHECK: bb0([[ARG0:%.*]] : $*T, [[ARG1:%.*]] : $*T):
33+
// CHECK: copy_addr [[ARG1]] to [initialization] [[ARG0]]
3034
return x
3135
}
3236

3337
// CHECK-LABEL: sil hidden {{.*}}12valueToValue1xQr
3438
func valueToValue(x: C) -> some Q {
35-
// CHECK: [[VALUE_COPY:%.*]] = copy_value %0
36-
// CHECK: [[CAST_TO_OPAQUE:%.*]] = unchecked_ref_cast [[VALUE_COPY]]
37-
// CHECK: return [[CAST_TO_OPAQUE]]
39+
// CHECK: bb0([[ARG:%.*]] : @guaranteed $C):
40+
// CHECK: [[VALUE_COPY:%.*]] = copy_value [[ARG]]
41+
// CHECK: return [[VALUE_COPY]]
3842
return x
3943
}
4044

4145
// CHECK-LABEL: sil hidden {{.*}}13reabstraction1xQr
4246
func reabstraction(x: @escaping () -> ()) -> some Any {
43-
// CHECK: [[UNDERLYING:%.*]] = unchecked_addr_cast %0 : ${{.*}} to $*@callee_guaranteed () -> @out ()
44-
// CHECK: [[VALUE_COPY:%.*]] = copy_value %1
45-
// CHECK: [[VALUE_REABSTRACT:%.*]] = partial_apply [callee_guaranteed] {{%.*}}([[VALUE_COPY]])
46-
// CHECK: store [[VALUE_REABSTRACT]] to [init] [[UNDERLYING]]
47+
// CHECK: bb0([[ARG0:%.*]] : $*@callee_guaranteed () -> @out (), [[ARG1:%.*]] : @guaranteed $@callee_guaranteed () -> ()):
48+
// CHECK: [[VALUE_COPY:%.*]] = copy_value [[ARG1]]
49+
// CHECK: [[REABSTRACT:%.*]] = function_ref @$sIeg_ytIegr_TR
50+
// CHECK: [[THUNK:%.*]] = partial_apply [callee_guaranteed] [[REABSTRACT]]([[VALUE_COPY]])
51+
// CHECK: store [[THUNK]] to [init] [[ARG0]]
4752
return x
4853
}
54+
55+
protocol X {
56+
associatedtype A
57+
func foo() -> A
58+
}
59+
60+
extension Int : P {}
61+
62+
extension ResilientInt : P {}
63+
64+
class K : P {}
65+
66+
func useClosure2(_ cl: () -> ()) {}
67+
68+
func useClosure(_ cl: @escaping () -> ()) {
69+
cl()
70+
}
71+
72+
struct S : X {
73+
74+
func foo() -> some P {
75+
return returnTrivial()
76+
}
77+
78+
func returnTrivial() -> some P {
79+
return 1
80+
}
81+
82+
func returnClass() -> some P {
83+
return K()
84+
}
85+
86+
func returnResilient() -> some P {
87+
return ResilientInt(i: 1)
88+
}
89+
90+
func testCapture() {
91+
var someP = returnTrivial()
92+
var someK = returnClass()
93+
var someR = returnResilient()
94+
useClosure {
95+
someP = self.returnTrivial()
96+
someK = self.returnClass()
97+
someR = self.returnResilient()
98+
}
99+
print(someP)
100+
print(someK)
101+
print(someR)
102+
}
103+
104+
func testCapture2() {
105+
var someP = returnTrivial()
106+
var someK = returnClass()
107+
var someR = returnResilient()
108+
useClosure2 {
109+
someP = self.returnTrivial()
110+
someK = self.returnClass()
111+
someR = self.returnResilient()
112+
}
113+
print(someP)
114+
print(someK)
115+
print(someR)
116+
}
117+
118+
func testCapture3() {
119+
let someP = returnTrivial()
120+
let someK = returnClass()
121+
let someR = returnResilient()
122+
useClosure {
123+
print(someP)
124+
print(someK)
125+
print(someR)
126+
}
127+
}
128+
129+
func testCapture4() {
130+
let someP = returnTrivial()
131+
let someK = returnClass()
132+
let someR = returnResilient()
133+
useClosure {
134+
print(someP)
135+
print(someK)
136+
print(someR)
137+
}
138+
}
139+
}
140+
141+
extension Optional : P { }
142+
143+
struct S2 : X {
144+
func foo() -> some P {
145+
let x : Optional = 1
146+
return x
147+
}
148+
func returnFunctionType() -> () -> A {
149+
return foo
150+
}
151+
}

test/SILOptimizer/cast_folding.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ public func testCastToPForOptionalFailure() -> Bool {
10721072
struct Underlying : P {
10731073
}
10741074

1075-
func returnOpaque() -> some P {
1075+
public func returnOpaque() -> some P {
10761076
return Underlying()
10771077
}
10781078

@@ -1083,6 +1083,7 @@ func returnOpaque() -> some P {
10831083
// MANDATORY: [[U:%.*]] = alloc_stack $Underlying
10841084
// MANDATORY: unconditional_checked_cast_addr @_opaqueReturnTypeOf{{.*}}in [[O]] : $*@_opaqueReturnTypeOf{{.*}}to Underlying in [[U]] : $*Underlying
10851085
// MANDATORY: load [[U]] : $*Underlying
1086+
@inlinable
10861087
public func testCastOpaqueArchetype() {
10871088
let o = returnOpaque() as! Underlying
10881089
}

0 commit comments

Comments
 (0)