Skip to content

[6.0] SILGen: Reabstract subexpr lvalue before ABISafeConversion. #75194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/SILGen/SILGenLValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4570,10 +4570,19 @@ LValue SILGenLValue::visitABISafeConversionExpr(ABISafeConversionExpr *e,
LValueOptions options) {
LValue lval = visitRec(e->getSubExpr(), accessKind, options);
auto typeData = getValueTypeData(SGF, accessKind, e);
auto subExprType = e->getSubExpr()->getType()->getRValueType();
auto loweredSubExprType = SGF.getLoweredType(subExprType);

// Ensure the lvalue is re-abstracted to the substituted type, since that's
// the type with which we have ABI compatibility.
if (lval.getTypeOfRValue().getASTType() != loweredSubExprType.getASTType()) {
// Logical components always re-abstract back to the substituted
// type.
assert(lval.isLastComponentPhysical());
lval.addOrigToSubstComponent(loweredSubExprType);
}

auto OrigType = e->getSubExpr()->getType();

lval.add<UncheckedConversionComponent>(typeData, OrigType);
lval.add<UncheckedConversionComponent>(typeData, subExprType);

return lval;
}
Expand Down
25 changes: 25 additions & 0 deletions test/SILGen/preconcurrency-abi-safe-conversions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %target-swift-emit-silgen -swift-version 5 -verify %s
// RUN: %target-swift-emit-silgen -swift-version 6 -verify %s

struct Text {
init<S>(_: S) where S: StringProtocol {}
}

// In Swift 5, we introduce an implicit @Sendable on the closures here.
// Make sure that doing so doesn't disrupt SILGen's lvalue emission.
// rdar://130016855
public struct Header<TitleContent> {
@preconcurrency
private let titleContent: @MainActor () -> TitleContent

init(title: String) where TitleContent == Text {
self.titleContent = {
Text(title)
}
}

func testGet() -> @MainActor () -> Text
where TitleContent == Text {
return titleContent // expected-warning * {{}}
}
}