Skip to content

Commit 8e4f9e4

Browse files
authored
Merge pull request #75194 from jckarter/reabstract-before-abi-safe-lvalue-conversion-6.0
[6.0] SILGen: Reabstract subexpr lvalue before ABISafeConversion.
2 parents 4527d02 + 2b1719a commit 8e4f9e4

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
@@ -4570,10 +4570,19 @@ LValue SILGenLValue::visitABISafeConversionExpr(ABISafeConversionExpr *e,
45704570
LValueOptions options) {
45714571
LValue lval = visitRec(e->getSubExpr(), accessKind, options);
45724572
auto typeData = getValueTypeData(SGF, accessKind, e);
4573+
auto subExprType = e->getSubExpr()->getType()->getRValueType();
4574+
auto loweredSubExprType = SGF.getLoweredType(subExprType);
4575+
4576+
// Ensure the lvalue is re-abstracted to the substituted type, since that's
4577+
// the type with which we have ABI compatibility.
4578+
if (lval.getTypeOfRValue().getASTType() != loweredSubExprType.getASTType()) {
4579+
// Logical components always re-abstract back to the substituted
4580+
// type.
4581+
assert(lval.isLastComponentPhysical());
4582+
lval.addOrigToSubstComponent(loweredSubExprType);
4583+
}
45734584

4574-
auto OrigType = e->getSubExpr()->getType();
4575-
4576-
lval.add<UncheckedConversionComponent>(typeData, OrigType);
4585+
lval.add<UncheckedConversionComponent>(typeData, subExprType);
45774586

45784587
return lval;
45794588
}
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)