Skip to content

Commit be20c7a

Browse files
[Revert][Sema] Revert ApplyClassifier changes and add regression test
1 parent 1f6f969 commit be20c7a

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,6 @@ class ApplyClassifier {
724724
DeclContext *RethrowsDC = nullptr;
725725
DeclContext *ReasyncDC = nullptr;
726726

727-
// Indicates if `classifyApply` will attempt to classify SelfApplyExpr
728-
// because that should be done only in certain contexts like when infering
729-
// if "async let" implicit auto closure wrapping initialize expression can
730-
// throw.
731-
bool ClassifySelfApplyExpr = false;
732-
733727
DeclContext *getPolymorphicEffectDeclContext(EffectKind kind) const {
734728
switch (kind) {
735729
case EffectKind::Throws: return RethrowsDC;
@@ -758,19 +752,6 @@ class ApplyClassifier {
758752

759753
if (auto *SAE = dyn_cast<SelfApplyExpr>(E)) {
760754
assert(!E->isImplicitlyAsync());
761-
762-
if (ClassifySelfApplyExpr) {
763-
// Do not consider throw properties in SelfAssignExpr with an implicit
764-
// conversion base.
765-
if (isa<ImplicitConversionExpr>(SAE->getBase()))
766-
return Classification();
767-
768-
auto fnType = E->getType()->getAs<AnyFunctionType>();
769-
if (fnType && fnType->isThrowing()) {
770-
return Classification::forUnconditional(
771-
EffectKind::Throws, PotentialEffectReason::forApply());
772-
}
773-
}
774755
return Classification();
775756
}
776757

@@ -2983,7 +2964,6 @@ void TypeChecker::checkPropertyWrapperEffects(
29832964

29842965
bool TypeChecker::canThrow(Expr *expr) {
29852966
ApplyClassifier classifier;
2986-
classifier.ClassifySelfApplyExpr = true;
29872967
return (classifier.classifyExpr(expr, EffectKind::Throws) ==
29882968
ConditionalEffectKind::Always);
29892969
}

test/Concurrency/sr15049.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking -strict-concurrency=targeted
22
// REQUIRES: concurrency
33

4+
// FIXME: Those cases should compile, but currently ApplyClassifier doesn't handle throws/no-throws properly.
5+
46
func testAsyncSequenceTypedPatternSendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable {
5-
async let result: Int = seq.reduce(0) { $0 + $1 } // OK
7+
async let result: Int = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
68
// expected-warning@-1{{immutable value 'result' was never used; consider replacing with '_' or removing it}}
79
}
810

911
func testAsyncSequenceTypedPattern1Sendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable {
10-
async let _: Int = seq.reduce(0) { $0 + $1 } // OK
12+
async let _: Int = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
1113
}
1214

1315
func testAsyncSequenceSendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable {
14-
async let result = seq.reduce(0) { $0 + $1 } // OK
16+
async let result = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
1517
// expected-warning@-1{{initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it}}
1618
}
1719

1820
func testAsyncSequence1Sendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable {
19-
async let _ = seq.reduce(0) { $0 + $1 } // OK
21+
async let _ = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
2022
}
2123

2224
func testAsyncSequenceTypedPattern<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-note{{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{54-54=, Sendable}}
23-
async let result: Int = seq.reduce(0) { $0 + $1 } // OK
25+
async let result: Int = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
2426
// expected-warning@-1{{immutable value 'result' was never used; consider replacing with '_' or removing it}}
2527
// expected-warning@-2{{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
2628
}
2729

2830
func testAsyncSequenceTypedPattern1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-note{{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{55-55=, Sendable}}
29-
async let _: Int = seq.reduce(0) { $0 + $1 } // OK
31+
async let _: Int = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
3032
// expected-warning@-1{{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
3133
}
3234

3335
func testAsyncSequence<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-note{{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{42-42=, Sendable}}
34-
async let result = seq.reduce(0) { $0 + $1 } // OK
36+
async let result = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
3537
// expected-warning@-1{{initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it}}
3638
// expected-warning@-2{{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
3739
}
3840

3941
func testAsyncSequence1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int { // expected-note{{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{43-43=, Sendable}}
40-
async let _ = seq.reduce(0) { $0 + $1 } // OK
42+
async let _ = seq.reduce(0) { $0 + $1 } // expected-error{{call can throw, but it is executed in a non-throwing autoclosure}} expected-note{{call is to 'rethrows' function, but a conformance has a throwing witness}}
4143
// expected-warning@-1{{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
4244
}
4345

@@ -49,3 +51,8 @@ func testAsyncSequence3<Seq>(_ seq: Seq) async throws where Seq: AsyncSequence,
4951
func testAsyncSequence4<Seq>(_ seq: Seq) async throws where Seq: AsyncSequence, Seq.Element == Int { // expected-note{{consider making generic parameter 'Seq' conform to the 'Sendable' protocol}} {{28-28=: Sendable}}
5052
async let _ = seq // expected-warning{{capture of 'seq' with non-sendable type 'Seq' in 'async let' binding}}
5153
}
54+
55+
func search(query: String, entities: [String]) async throws -> [String] {
56+
async let r = entities.filter { $0.contains(query) }.map { String($0) }
57+
return await r // OK
58+
}

0 commit comments

Comments
 (0)