Skip to content

Commit bbd182b

Browse files
committed
[Concurrency] Teach Type::stripConcurrency to handle sugared array and dictionary types
1 parent 8f750a2 commit bbd182b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/AST/Type.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,25 @@ Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {
11451145
return anyChanged ? TupleType::get(elts, getASTContext()) : Type(this);
11461146
}
11471147

1148+
if (auto *arrayTy = dyn_cast<ArraySliceType>(this)) {
1149+
auto newBaseTy =
1150+
arrayTy->getBaseType()->stripConcurrency(recurse, dropGlobalActor);
1151+
return newBaseTy->isEqual(arrayTy->getBaseType())
1152+
? Type(this)
1153+
: ArraySliceType::get(newBaseTy);
1154+
}
1155+
1156+
if (auto *dictTy = dyn_cast<DictionaryType>(this)) {
1157+
auto keyTy = dictTy->getKeyType();
1158+
auto strippedKeyTy = keyTy->stripConcurrency(recurse, dropGlobalActor);
1159+
auto valueTy = dictTy->getValueType();
1160+
auto strippedValueTy = valueTy->stripConcurrency(recurse, dropGlobalActor);
1161+
1162+
return keyTy->isEqual(strippedKeyTy) && valueTy->isEqual(strippedValueTy)
1163+
? Type(this)
1164+
: DictionaryType::get(strippedKeyTy, strippedValueTy);
1165+
}
1166+
11481167
return Type(this);
11491168
}
11501169

test/Concurrency/sendable_preconcurrency_erasure.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ do {
1515
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure4testL1_yySayyp_yyctGF
1616
}
1717

18+
// Test erase in sugared types
19+
do {
20+
@preconcurrency func testArray1(_: [any Sendable]) {}
21+
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure10testArray1L2_yySayypGF
22+
@preconcurrency func testArray2(_: [@Sendable () -> Void]) {}
23+
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure10testArray2L2_yySayyycGF
24+
25+
@preconcurrency func testDictionary(_: [Int: (any Sendable, (String, @Sendable (any Sendable) -> Void))]) {}
26+
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure14testDictionaryL2_yySDySiyp_SS_yypcttGF
27+
28+
@preconcurrency func testDesugaredDict(_: Dictionary<Int, (any Sendable, (String, @Sendable (any Sendable) -> Void))>) {}
29+
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure17testDesugaredDictL2_yySDySiyp_SS_yypcttGF
30+
31+
@preconcurrency func testVariadic(_: (any Sendable)...) {}
32+
// CHECK-LABEL: sil private [ossa] @$s31sendable_preconcurrency_erasure12testVariadicL2_yyypd_tF
33+
}
34+
1835
public struct Data {
1936
@preconcurrency var test: (any Sendable, Array<(Int, any Sendable)>)? = nil
2037
// CHECK-LABEL: sil [transparent] [ossa] @$s31sendable_preconcurrency_erasure4DataV4testyp_SaySi_yptGtSgvpfi

0 commit comments

Comments
 (0)