Skip to content

[MoveOnly] Call borrowing methods on existentials. #73857

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
merged 3 commits into from
May 24, 2024
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
6 changes: 6 additions & 0 deletions lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ SubElementOffset::computeForAddress(SILValue projectionDerivedFromRoot,
continue;
}

if (auto *oea =
dyn_cast<OpenExistentialAddrInst>(projectionDerivedFromRoot)) {
projectionDerivedFromRoot = oea->getOperand();
continue;
}

if (auto *teai =
dyn_cast<TupleElementAddrInst>(projectionDerivedFromRoot)) {
SILType tupleType = teai->getOperand()->getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ bool ExistentialSpecializer::canSpecializeExistentialArgsInFunction(
if (paramInfo.isIndirectMutating())
continue;

// The ExistentialSpecializerCloner copies the incoming generic argument
// into an existential if it is non-consuming (if it's consuming, it's
// moved into the existential via `copy_addr [take]`). Introducing a copy
// of a move-only value isn't legal.
if (!paramInfo.isConsumed() &&
paramInfo.getSILStorageInterfaceType().isMoveOnly())
continue;

ETAD.AccessType = paramInfo.isConsumed()
? OpenedExistentialAccess::Mutable
: OpenedExistentialAccess::Immutable;
Expand Down
21 changes: 21 additions & 0 deletions test/Interpreter/rdar125864434.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/bin
// RUN: %target-codesign %t/bin
// RUN: %target-run %t/bin | %FileCheck %s

// REQUIRES: executable_test

protocol Boopable: ~Copyable {
func boop()
}

struct S: ~Copyable, Boopable {
func boop() { print("boop") }
}

func check(_ b: borrowing any Boopable & ~Copyable) {
b.boop()
}

// CHECK: boop
check(S())