Skip to content

SILGen: Borrow any move-only or borrow-expr'ed accessor base. #71908

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 1 commit into from
Feb 27, 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: 0 additions & 6 deletions lib/SILGen/SILGenLValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3734,12 +3734,6 @@ static bool shouldEmitSelfAsRValue(AccessorDecl *fn, CanType selfType,
return false;
case SelfAccessKind::Borrowing:
case SelfAccessKind::NonMutating:
// If the accessor is a coroutine, we may want to access the projected
// value through a borrow of the base. But if it's a regular get/set then
// there isn't any real benefit to doing so.
if (!fn->isCoroutine()) {
return true;
}
// Normally we'll copy the base to minimize accesses. But if the base
// is noncopyable, or we're accessing it in a `borrow` expression, then
// we want to keep the access nested on the original base.
Expand Down
7 changes: 7 additions & 0 deletions test/SILOptimizer/moveonly_borrowing_switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,10 @@ extension ChonkyList {
}
}
}

// https://github.com/apple/swift/issues/71598
struct RangeHolder:~Copyable
{
var r:Range<Int> { fatalError() }
var y:Int { self.r.upperBound }
}