Skip to content

MoveOnlyChecker: Don't follow trivial transitive uses of borrows. #80470

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
Apr 3, 2025
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
3 changes: 3 additions & 0 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,9 @@ struct CopiedLoadBorrowEliminationVisitor
// Look through borrows.
for (auto value : nextUse->getUser()->getResults()) {
for (auto *use : value->getUses()) {
if (use->get()->getType().isTrivial(*use->getFunction())) {
continue;
}
useWorklist.push_back(use);
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/SILOptimizer/moveonly_addresschecker_trivial_read.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %target-swift-frontend -emit-sil -verify %s

func use(_: Int32) {}

struct NoncopyableYieldingSubscript: ~Copyable {
subscript() -> Int16 {
_read {
yield 0
}
}
}

func foo(component: inout NoncopyableYieldingSubscript, condition: Bool) {
let extracted: Int32

switch condition {
case true:
extracted = Int32(component[])

case false:
extracted = Int32(component[])

}

use(extracted)
}