Skip to content

Commit 8f750a2

Browse files
committed
[Concurrency] Teach Type::stripConcurrency to handle tuples
1 parent 66effa4 commit 8f750a2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/AST/Type.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,23 @@ Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {
11281128
: Type(this);
11291129
}
11301130

1131+
if (auto *tuple = getAs<TupleType>()) {
1132+
if (!recurse)
1133+
return Type(this);
1134+
1135+
bool anyChanged = false;
1136+
SmallVector<TupleTypeElt, 2> elts;
1137+
llvm::transform(
1138+
tuple->getElements(), std::back_inserter(elts), [&](const auto &elt) {
1139+
auto eltTy = elt.getType();
1140+
auto strippedTy = eltTy->stripConcurrency(recurse, dropGlobalActor);
1141+
anyChanged |= !strippedTy->isEqual(eltTy);
1142+
return elt.getWithType(strippedTy);
1143+
});
1144+
1145+
return anyChanged ? TupleType::get(elts, getASTContext()) : Type(this);
1146+
}
1147+
11311148
return Type(this);
11321149
}
11331150

test/Concurrency/sendable_preconcurrency_erasure.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ do {
1111
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure4testL_yyAA1SL_VyypGF
1212
@preconcurrency func test(_: S<Array<@Sendable () -> Void>>) {}
1313
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure4testL0_yyAA1SL_VySayyycGGF
14+
@preconcurrency func test(_: Array<(any Sendable, @Sendable () -> Void)>) {}
15+
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure4testL1_yySayyp_yyctGF
16+
}
17+
18+
public struct Data {
19+
@preconcurrency var test: (any Sendable, Array<(Int, any Sendable)>)? = nil
20+
// CHECK-LABEL: sil [transparent] [ossa] @$s31sendable_preconcurrency_erasure4DataV4testyp_SaySi_yptGtSgvpfi
1421
}

0 commit comments

Comments
 (0)