DefinitInitialization: convert begin_access instructions of initializations to a static accesses

In case of `var` initializations, SILGen creates a dynamic begin/end_access pair around the initialization store.
If it's an initialization (and not a re-assign) it's guanranteed that it's an exlusive access and we can convert the access to an `[init] [static]` access.

https://github.com/apple/swift/issues/66496
This commit is contained in:
Erik Eckstein
2023-06-13 13:20:29 +02:00
parent 6a2f3c9f84
commit 63808be395
10 changed files with 87 additions and 20 deletions

View File

@@ -2312,6 +2312,19 @@ void LifetimeChecker::handleSelfInitUse(unsigned UseID) {
}
}
// In case of `var` initializations, SILGen creates a dynamic begin/end_access
// pair around the initialization store. If it's an initialization (and not
// a re-assign) it's guaranteed that it's an exclusive access and we can
// convert the access to an `[init] [static]` access.
static void setStaticInitAccess(SILValue memoryAddress) {
if (auto *ba = dyn_cast<BeginAccessInst>(memoryAddress)) {
if (ba->getEnforcement() == SILAccessEnforcement::Dynamic) {
ba->setEnforcement(SILAccessEnforcement::Static);
if (ba->getAccessKind() == SILAccessKind::Modify)
ba->setAccessKind(SILAccessKind::Init);
}
}
}
/// updateInstructionForInitState - When an instruction being analyzed moves
/// from being InitOrAssign to some concrete state, update it for that state.
@@ -2336,6 +2349,8 @@ void LifetimeChecker::updateInstructionForInitState(unsigned UseID) {
assert(!CA->isInitializationOfDest() &&
"should not modify copy_addr that already knows it is initialized");
CA->setIsInitializationOfDest(InitKind);
if (InitKind == IsInitialization)
setStaticInitAccess(CA->getDest());
return;
}
@@ -2382,6 +2397,7 @@ void LifetimeChecker::updateInstructionForInitState(unsigned UseID) {
MarkMustCheckInst::CheckKind::InitableButNotConsumable);
}
}
setStaticInitAccess(AI->getDest());
}
return;