Skip to content

Commit 1772f02

Browse files
authored
Merge pull request #75193 from jckarter/reabstract-before-abi-safe-lvalue-conversion
SILGen: Reabstract subexpr lvalue before ABISafeConversion.
2 parents 0ebe45d + 4da65df commit 1772f02

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

4570-
auto OrigType = e->getSubExpr()->getType();
4571-
4572-
lval.add<UncheckedConversionComponent>(typeData, OrigType);
4581+
lval.add<UncheckedConversionComponent>(typeData, subExprType);
45734582

45744583
return lval;
45754584
}
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)