Skip to content

Commit 5f0f3e4

Browse files
Updated existing tests to run with feature enabled
1 parent e643a97 commit 5f0f3e4

File tree

7 files changed

+89
-8
lines changed

7 files changed

+89
-8
lines changed

test/DebugInfo/WeakCapture.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature WeakLet -emit-ir -g -o - | %FileCheck %s
23
class A {
34
init(handler: (() -> ())) { }
45
}

test/DebugInfo/weak-self-capture.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature WeakLet -emit-ir -g -o - | %FileCheck %s
23
public class ClosureMaker {
34
var a : Int
45

test/Interpreter/weak.swift

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-run-simple-swift | %FileCheck %s
2+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-feature -Xfrontend WeakLet) | %FileCheck %s --check-prefixes=CHECK,CHECK-WEAK-LET
23
// REQUIRES: executable_test
34

45
protocol Protocol : class {
@@ -76,6 +77,20 @@ func testWeakInLet() {
7677

7778
testWeakInLet()
7879

80+
#if hasFeature(WeakLet)
81+
func testWeakLet() {
82+
print("testWeakLet") // CHECK-WEAK-LET-LABEL: testWeakLet
83+
84+
var obj: SwiftClassBase? = SwiftClass() // CHECK-WEAK-LET: SwiftClass Created
85+
weak let weakRef = obj
86+
printState(weakRef) // CHECK-WEAK-LET-NEXT: is present
87+
obj = nil // CHECK-WEAK-LET-NEXT: SwiftClass Destroyed
88+
printState(weakRef) // CHECK-WEAK-LET-NEXT: is nil
89+
}
90+
91+
testWeakLet()
92+
#endif
93+
7994

8095
//======================== Test Classbound Protocols ========================
8196

test/Interpreter/weak_objc.swift

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// RUN: %target-build-swift %s -Xfrontend -disable-objc-attr-requires-foundation-module -o %t-main
1+
// RUN: %target-build-swift %s -Xfrontend -disable-objc-attr-requires-foundation-module -enable-experimental-feature WeakLet -o %t-main
22
// RUN: %target-codesign %t-main
33
// RUN: %target-run %t-main | %FileCheck %s
4+
5+
// RUN: %target-build-swift %s -Xfrontend -disable-objc-attr-requires-foundation-module -enable-experimental-feature WeakLet -o %t-main-weak-let
6+
// RUN: %target-codesign %t-main-weak-let
7+
// RUN: %target-run %t-main-weak-let | %FileCheck %s --check-prefixes=CHECK,CHECK-WEAK-LET
8+
49
// REQUIRES: executable_test
510
// REQUIRES: objc_interop
611

@@ -47,3 +52,31 @@ func testObjCClass() {
4752
}
4853

4954
testObjCClass()
55+
56+
#if hasFeature(WeakLet)
57+
func testObjCWeakLet() {
58+
print("testObjCWeakLet") // CHECK-WEAK-LET: testObjCWeakLet
59+
60+
var c : ObjCClassBase = ObjCClass() // CHECK-WEAK-LET: ObjCClass Created
61+
weak let w : ObjCClassBase? = c
62+
printState(w) // CHECK-WEAK-LET-NEXT: is present
63+
c = ObjCClassBase() // CHECK-WEAK-LET-NEXT: ObjCClass Destroyed
64+
printState(w) // CHECK-WEAK-LET-NEXT: is nil
65+
}
66+
67+
testObjCWeakLet()
68+
69+
func testObjCWeakLetCapture() {
70+
print("testObjCWeakLetCapture") // CHECK-WEAK-LET: testObjCWeakLetCapture
71+
72+
var c : ObjCClassBase = ObjCClass() // CHECK-WEAK-LET: ObjCClass Created
73+
let closure: () -> ObjCClassBase? = { [weak c] in c }
74+
printState(closure()) // CHECK-WEAK-LET-NEXT: is present
75+
printState(closure()) // CHECK-WEAK-LET-NEXT: is present
76+
c = ObjCClassBase() // CHECK-WEAK-LET-NEXT: ObjCClass Destroyed
77+
printState(closure()) // CHECK-WEAK-LET-NEXT: is nil
78+
printState(closure()) // CHECK-WEAK-LET-NEXT: is nil
79+
}
80+
81+
testObjCWeakLetCapture()
82+
#endif

test/SILGen/weak.swift

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -module-name weak -Xllvm -sil-full-demangle %s | %FileCheck %s
3+
// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -module-name weak -Xllvm -sil-full-demangle %s -enable-experimental-feature WeakLet | %FileCheck %s
34

45
class C {
56
func f() -> Int { return 42 }
@@ -67,6 +68,19 @@ func testClosureOverWeak() {
6768
takeClosure { bC!.f() }
6869
}
6970

71+
#if hasFeature(WeakLet)
72+
func testClosureOverWeakLet() {
73+
weak let bC = C()
74+
takeClosure { bC!.f() }
75+
}
76+
77+
func testClosureOverWeakCapture() {
78+
let bC = C()
79+
takeClosure { [weak bC] in bC!.f() }
80+
}
81+
82+
#endif
83+
7084
class CC {
7185
weak var x: CC?
7286

test/expr/closure/closures_swift6.swift

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 6
1+
// There seems to be a minor bug in the diagnostic of the self-capture.
2+
// Diagnostic algorithm does not @lvalue DeclRefExpr wrapped into LoadExpr,
3+
// and enabling WeakLet removes the LoadExpr.
4+
// As a result, diagnostic messages change slightly.
5+
6+
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix no-weak-let-
7+
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix has-weak-let- -enable-experimental-feature WeakLet
28

39
func doStuff(_ fn : @escaping () -> Int) {}
410
func doVoidStuff(_ fn : @escaping () -> ()) {}
@@ -936,7 +942,9 @@ class TestExtensionOnOptionalSelf {
936942
extension TestExtensionOnOptionalSelf? {
937943
func foo() {
938944
_ = { [weak self] in
939-
foo() // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
945+
// expected-no-weak-let-error@+2 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
946+
// expected-has-weak-let-error@+1 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
947+
foo()
940948
}
941949

942950
_ = {
@@ -946,8 +954,11 @@ extension TestExtensionOnOptionalSelf? {
946954
}
947955

948956
_ = { [weak self] in
949-
_ = {
950-
foo() // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
957+
_ = { // expected-has-weak-let-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
958+
// expected-no-weak-let-error@+3 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
959+
// expected-has-weak-let-error@+2 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
960+
// expected-has-weak-let-note@+1 {{reference 'self.' explicitly}}
961+
foo()
951962
self.foo()
952963
self?.bar()
953964
}
@@ -967,7 +978,9 @@ extension TestExtensionOnOptionalSelf? {
967978
extension TestExtensionOnOptionalSelf {
968979
func foo() {
969980
_ = { [weak self] in
970-
foo() // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
981+
// expected-no-weak-let-error@+2 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
982+
// expected-has-weak-let-error@+1 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
983+
foo()
971984
self.foo()
972985
self?.bar()
973986
}
@@ -978,8 +991,11 @@ extension TestExtensionOnOptionalSelf {
978991
}
979992

980993
_ = { [weak self] in
981-
_ = {
982-
foo() // expected-error {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
994+
_ = { // expected-has-weak-let-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
995+
// expected-no-weak-let-error@+3 {{implicit use of 'self' in closure; use 'self.' to make capture semantics explicit}}
996+
// expected-has-weak-let-error@+2 {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
997+
// expected-has-weak-let-note@+1 {{reference 'self.' explicitly}}
998+
foo()
983999
self.foo()
9841000
}
9851001
}

test/expr/closure/implicit_weak_capture.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -swift-version 6)
2+
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -swift-version 6 -enable-experimental-feature WeakLet)
23

34
// REQUIRES: concurrency
45
// REQUIRES: executable_test

0 commit comments

Comments
 (0)