Skip to content

Commit b781005

Browse files
committed
SILGen: Reabstract subexpr lvalue before ABISafeConversion.
Fixes rdar://130016855. When preconcurrency compatibility introduces implicit `@Sendable` conversions, the `ABISafeConversionExpr` representing that conversion indicates an ABI-neutral conversion from the substituted type of the original expression, so we need to reabstract in cases where the original property is more generic than the type we're working with.
1 parent 42c43e6 commit b781005

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,10 +4564,19 @@ LValue SILGenLValue::visitABISafeConversionExpr(ABISafeConversionExpr *e,
45644564
LValueOptions options) {
45654565
LValue lval = visitRec(e->getSubExpr(), accessKind, options);
45664566
auto typeData = getValueTypeData(SGF, accessKind, e);
4567+
auto subExprType = e->getSubExpr()->getType()->getRValueType();
4568+
auto loweredSubExprType = SGF.getLoweredType(subExprType);
4569+
4570+
// Ensure the lvalue is re-abstracted to the substituted type, since that's
4571+
// the type with which we have ABI compatibility.
4572+
if (lval.getTypeOfRValue().getASTType() != loweredSubExprType.getASTType()) {
4573+
// Logical components always re-abstract back to the substituted
4574+
// type.
4575+
assert(lval.isLastComponentPhysical());
4576+
lval.addOrigToSubstComponent(loweredSubExprType);
4577+
}
45674578

4568-
auto OrigType = e->getSubExpr()->getType();
4569-
4570-
lval.add<UncheckedConversionComponent>(typeData, OrigType);
4579+
lval.add<UncheckedConversionComponent>(typeData, subExprType);
45714580

45724581
return lval;
45734582
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-emit-silgen -swift-version 5 -verify %s
2+
// RUN: %target-swift-emit-silgen -swift-version 6 -verify %s
3+
4+
struct Text {
5+
init<S>(_: S) where S: StringProtocol {}
6+
}
7+
8+
// In Swift 5, we introduce an implicit @Sendable on the closures here.
9+
// Make sure that doing so doesn't disrupt SILGen's lvalue emission.
10+
// rdar://130016855
11+
public struct Header<TitleContent> {
12+
@preconcurrency
13+
private let titleContent: @MainActor () -> TitleContent
14+
15+
init(title: String) where TitleContent == Text {
16+
self.titleContent = {
17+
Text(title)
18+
}
19+
}
20+
21+
func testGet() -> @MainActor () -> Text
22+
where TitleContent == Text {
23+
return titleContent // expected-warning * {{}}
24+
}
25+
}

0 commit comments

Comments
 (0)