Skip to content

Commit 019d8ad

Browse files
committed
Attempt to unify the async sequence features together
1 parent e8c4cd0 commit 019d8ad

18 files changed

+55
-40
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,9 @@ namespace {
820820
if (isAsyncCall(outerCall)) {
821821
// This call is a partial application within an async call.
822822
// If the partial application take a value inout, it is bad.
823-
if (InOutExpr *inoutArg = dyn_cast<InOutExpr>(
824-
call->getArg()->getSemanticsProvidingExpr()))
825-
diagnoseInOutArg(outerCall, inoutArg, true);
823+
// if (InOutExpr *inoutArg = dyn_cast<InOutExpr>(
824+
// call->getArg()->getSemanticsProvidingExpr()))
825+
// diagnoseInOutArg(outerCall, inoutArg, true);
826826
}
827827
}
828828

@@ -958,6 +958,7 @@ namespace {
958958
/// \returns true if we diagnosed the entity, \c false otherwise.
959959
bool diagnoseInOutArg(const ApplyExpr *call, const InOutExpr *arg,
960960
bool isPartialApply) {
961+
961962
// check that the call is actually async
962963
if (!isAsyncCall(call))
963964
return false;

lib/Sema/TypeCheckDecl.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -829,23 +829,26 @@ FunctionRethrowingKind
829829
FunctionRethrowingKindRequest::evaluate(Evaluator &evaluator,
830830
AbstractFunctionDecl *decl) const {
831831
if (decl->hasThrows()) {
832-
if (auto proto = dyn_cast<ProtocolDecl>(decl->getDeclContext())) {
833-
if (proto->isRethrowingProtocol()) {
834-
GenericSignature genericSig = decl->getGenericSignature();
835-
FunctionRethrowingKind kind = getParameterThrowingKind(decl, genericSig);
836-
// since we have checked all arguments, if we still havent found anything
837-
// check the self parameter
838-
if (kind == FunctionRethrowingKind::Invalid &&
839-
decl->hasImplicitSelfDecl()) {
840-
auto selfParam = decl->getImplicitSelfDecl();
841-
if (selfParam) {
842-
auto interfaceTy = selfParam->getInterfaceType();
843-
kind = getTypeThrowingKind(interfaceTy, genericSig);
844-
}
832+
auto proto = dyn_cast<ProtocolDecl>(decl->getDeclContext());
833+
bool fromRethrow = proto != nullptr ? proto->isRethrowingProtocol() : false;
834+
bool markedRethrows = decl->getAttrs().hasAttribute<RethrowsAttr>();
835+
if (fromRethrow && !markedRethrows) {
836+
return FunctionRethrowingKind::ByConformance;
837+
}
838+
if (markedRethrows) {
839+
GenericSignature genericSig = decl->getGenericSignature();
840+
FunctionRethrowingKind kind = getParameterThrowingKind(decl, genericSig);
841+
// since we have checked all arguments, if we still havent found anything
842+
// check the self parameter
843+
if (kind == FunctionRethrowingKind::Invalid &&
844+
decl->hasImplicitSelfDecl()) {
845+
auto selfParam = decl->getImplicitSelfDecl();
846+
if (selfParam) {
847+
auto interfaceTy = selfParam->getInterfaceType();
848+
kind = getTypeThrowingKind(interfaceTy, genericSig);
845849
}
846-
847-
return kind;
848850
}
851+
return kind;
849852
}
850853
return FunctionRethrowingKind::Throws;
851854
}

lib/Sema/TypeCheckEffects.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,13 @@ class ApplyClassifier {
578578
return Classification::forRethrowingOnly(
579579
PotentialThrowReason::forThrowingApply(), isAsync);
580580
}
581+
} else if (fnRef.isBodyRethrows() &&
582+
fnRef.getRethrowingKind() == FunctionRethrowingKind::Throws) {
583+
return Classification::forThrow(PotentialThrowReason::forThrowingApply(),
584+
isAsync);
585+
} else if (fnRef.isBodyRethrows() &&
586+
fnRef.getRethrowingKind() == FunctionRethrowingKind::None) {
587+
return isAsync ? Classification::forAsync() : Classification();
581588
}
582589

583590
// If the function doesn't throw at all, we're done here.
@@ -1072,7 +1079,8 @@ class Context {
10721079
if (!fn)
10731080
return false;
10741081

1075-
return fn->getAttrs().hasAttribute<RethrowsAttr>();
1082+
1083+
return fn->getRethrowingKind() == FunctionRethrowingKind::ByClosure;
10761084
}
10771085

10781086
/// Whether this is an autoclosure.
@@ -2074,6 +2082,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
20742082

20752083
ShouldRecurse_t checkTry(TryExpr *E) {
20762084

2085+
20772086
// Walk the operand.
20782087
ContextScope scope(*this, None);
20792088
scope.enterTry();

stdlib/public/Concurrency/AllSatisfy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414

1515
extension AsyncSequence {
16-
public func allSatisfy(_ predicate: (Element) async throws -> Bool) async throws /*rethrows*/ -> Bool {
16+
public func allSatisfy(_ predicate: (Element) async throws -> Bool) async rethrows -> Bool {
1717
var it = makeAsyncIterator()
1818
while let element = await try it.next() {
1919
if !(await try predicate(element)) {

stdlib/public/Concurrency/AsyncCompactMapSequence.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct AsyncCompactMapSequence<Upstream, ElementOfResult>: AsyncSequence
3535
self.transform = transform
3636
}
3737

38-
public mutating func next() async throws /*rethrows*/ -> ElementOfResult? {
38+
public mutating func next() async rethrows -> ElementOfResult? {
3939
while true {
4040
guard let item = await try upstreamIterator?.next() else {
4141
return nil
@@ -78,7 +78,7 @@ public struct AsyncTryCompactMapSequence<Upstream, ElementOfResult>: AsyncSequen
7878
self.transform = transform
7979
}
8080

81-
public mutating func next() async throws /*rethrows*/ -> ElementOfResult? {
81+
public mutating func next() async throws -> ElementOfResult? {
8282
while true {
8383
guard let item = await try upstreamIterator?.next() else {
8484
return nil

stdlib/public/Concurrency/AsyncConcatSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct AsyncConcatSequence<Prefix, Suffix>: AsyncSequence where Prefix: A
3535
self.suffixIterator = suffixIterator
3636
}
3737

38-
public mutating func next() async throws /*rethrows*/ -> Prefix.Element? {
38+
public mutating func next() async rethrows -> Prefix.Element? {
3939
if let item = await try prefixIterator?.next() {
4040
return item
4141
}

stdlib/public/Concurrency/AsyncDropWhileSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct AsyncDropWhileSequence<Upstream>: AsyncSequence where Upstream: As
3535
self.predicate = predicate
3636
}
3737

38-
public mutating func next() async throws /*rethrows*/ -> Upstream.Element? {
38+
public mutating func next() async rethrows -> Upstream.Element? {
3939
while true {
4040
guard let item = await try upstreamIterator?.next() else {
4141
return nil

stdlib/public/Concurrency/AsyncFilterSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public struct AsyncFilterSequence<Upstream>: AsyncSequence where Upstream: Async
4040
self.predicate = predicate
4141
}
4242

43-
public mutating func next() async throws /*rethrows*/ -> Upstream.Element? {
43+
public mutating func next() async rethrows -> Upstream.Element? {
4444
guard let item = await try upstreamIterator?.next() else {
4545
return nil
4646
}

stdlib/public/Concurrency/AsyncFlatMapSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct AsyncFlatMapSequence<Upstream, SegmentOfResult: AsyncSequence>: As
3636
self.transform = transform
3737
}
3838

39-
public mutating func next() async throws /*rethrows*/ -> SegmentOfResult.Element? {
39+
public mutating func next() async rethrows -> SegmentOfResult.Element? {
4040
if let item = await try currentIterator?.next() {
4141
return item
4242
} else {

stdlib/public/Concurrency/AsyncIteratorProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Swift
1414

15+
@rethrows
1516
public protocol AsyncIteratorProtocol {
1617
associatedtype Element
1718
mutating func next() async throws -> Element?

stdlib/public/Concurrency/AsyncMapSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public struct AsyncMapSequence<Upstream, Transformed>: AsyncSequence where Upstr
3737
self.transform = transform
3838
}
3939

40-
public mutating func next() async throws /*rethrows*/ -> Transformed? {
40+
public mutating func next() async rethrows -> Transformed? {
4141
guard let item = await try upstreamIterator?.next() else {
4242
return nil
4343
}

stdlib/public/Concurrency/AsyncPrefixWhileSequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct AsyncPrefixWhileSequence<Upstream>: AsyncSequence where Upstream:
3535
self.predicate = predicate
3636
}
3737

38-
public mutating func next() async throws /*rethrows*/ -> Element? {
38+
public mutating func next() async rethrows -> Element? {
3939
guard let item = await try upstreamIterator?.next() else {
4040
return nil
4141
}

stdlib/public/Concurrency/AsyncSequence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Swift
1414

15+
@rethrows
1516
public protocol AsyncSequence {
1617
associatedtype AsyncIterator: AsyncIteratorProtocol where AsyncIterator.Element == Element
1718
associatedtype Element

stdlib/public/Concurrency/Contains.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414

1515
extension AsyncSequence {
16-
public func contains(where predicate: (Element) async throws -> Bool) async throws /*rethrows*/ -> Bool {
16+
public func contains(where predicate: (Element) async throws -> Bool) async rethrows -> Bool {
1717
var it = makeAsyncIterator()
1818
while let e = await try it.next() {
1919
if await try predicate(e) {
@@ -25,7 +25,7 @@ extension AsyncSequence {
2525
}
2626

2727
extension AsyncSequence where Element: Equatable {
28-
public func contains(_ element: Element) async throws /*rethrows*/ -> Bool {
29-
return await try contains { $0 == element }
28+
public func contains(_ element: Element) async rethrows -> Bool {
29+
return await contains { $0 == element }
3030
}
3131
}

stdlib/public/Concurrency/Count.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414

1515
extension AsyncSequence {
16-
public func count() async throws /*rethrows*/ -> Int {
16+
public func count() async rethrows -> Int {
1717
var count = 0
1818
var it = makeAsyncIterator()
1919
while await try it.next() != nil {

stdlib/public/Concurrency/First.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414

1515
extension AsyncSequence {
16-
public func first(where predicate: (Element) async throws -> Bool) async throws /*rethrows*/ -> Element? {
16+
public func first(where predicate: (Element) async throws -> Bool) async rethrows -> Element? {
1717
var it = makeAsyncIterator()
1818
while let element = await try it.next() {
1919
if await try predicate(element) {
@@ -23,7 +23,7 @@ extension AsyncSequence {
2323
return nil
2424
}
2525

26-
public func first() async throws /*rethrows*/ -> Element? {
26+
public func first() async rethrows -> Element? {
2727
var it = makeAsyncIterator()
2828
return await try it.next()
2929
}

stdlib/public/Concurrency/MinMax.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414

1515
extension AsyncSequence {
16-
public func min(by areInIncreasingOrder: (Element, Element) async throws -> Bool) async throws /*rethrows*/ -> Element? {
16+
public func min(by areInIncreasingOrder: (Element, Element) async throws -> Bool) async rethrows -> Element? {
1717
var it = makeAsyncIterator()
1818
guard var result = await try it.next() else { return nil }
1919
while let e = await try it.next() {
@@ -22,7 +22,7 @@ extension AsyncSequence {
2222
return result
2323
}
2424

25-
public func max(by areInIncreasingOrder: (Element, Element) async throws -> Bool) async throws /*rethrows*/ -> Element? {
25+
public func max(by areInIncreasingOrder: (Element, Element) async throws -> Bool) async rethrows -> Element? {
2626
var it = makeAsyncIterator()
2727
guard var result = await try it.next() else { return nil }
2828
while let e = await try it.next() {
@@ -33,11 +33,11 @@ extension AsyncSequence {
3333
}
3434

3535
extension AsyncSequence where Element: Comparable {
36-
public func min() async throws /*rethrows*/ -> Element? {
36+
public func min() async rethrows -> Element? {
3737
return await try min(by: <)
3838
}
3939

40-
public func max() async throws /*rethrows*/ -> Element? {
40+
public func max() async rethrows -> Element? {
4141
return await try max(by: <)
4242
}
4343
}

stdlib/public/Concurrency/Reduce.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Swift
1414

1515
extension AsyncSequence {
16-
public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (_ partialResult: Result, Element) async throws -> Result) async throws /*rethrows*/ -> Result {
16+
public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (_ partialResult: Result, Element) async throws -> Result) async rethrows -> Result {
1717
var accumulator = initialResult
1818
var it = makeAsyncIterator()
1919
while let element = await try it.next() {
@@ -22,7 +22,7 @@ extension AsyncSequence {
2222
return accumulator
2323
}
2424

25-
public func reduce<Result>(into initialResult: __owned Result, _ updateAccumulatingResult: (_ partialResult: inout Result, Element) async throws -> Void) async throws /*rethrows*/ -> Result {
25+
public func reduce<Result>(into initialResult: __owned Result, _ updateAccumulatingResult: (_ partialResult: inout Result, Element) async throws -> Void) async rethrows -> Result {
2626
var accumulator = initialResult
2727
var it = makeAsyncIterator()
2828
while let element = await try it.next() {

0 commit comments

Comments
 (0)