-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: support store_borrow and partial_apply in memory lifetime verification #36211
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
Changes from all commits
fa11bdf
d6736e9
e064ff3
aa16864
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2193,6 +2193,23 @@ class SILVerifier : public SILVerifierBase<SILVerifier> { | |
} | ||
} | ||
|
||
void checkStoreBorrowInst(StoreBorrowInst *SI) { | ||
require(SI->getSrc()->getType().isObject(), | ||
"Can't store from an address source"); | ||
require(!fnConv.useLoweredAddresses() | ||
|| SI->getSrc()->getType().isLoadable(*SI->getFunction()), | ||
"Can't store a non loadable type"); | ||
require(SI->getDest()->getType().isAddress(), | ||
"Must store to an address dest"); | ||
requireSameType(SI->getDest()->getType().getObjectType(), | ||
SI->getSrc()->getType(), | ||
"Store operand type and dest type mismatch"); | ||
|
||
// Note: This is the current implementation and the design is not final. | ||
require(isa<AllocStackInst>(SI->getDest()), | ||
"store_borrow destination can only be an alloc_stack"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here similar to the SIL.rst comment. I want to make sure it is clear for posterity that this is not the final design and that we want to iterate further on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
void checkAssignInst(AssignInst *AI) { | ||
SILValue Src = AI->getSrc(), Dest = AI->getDest(); | ||
require(AI->getModule().getStage() == SILStage::Raw, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
#include "swift/SIL/SILInstruction.h" | ||
#include "swift/SILOptimizer/PassManager/Passes.h" | ||
#include "swift/SILOptimizer/PassManager/Transforms.h" | ||
#include "swift/SILOptimizer/Utils/InstOptUtils.h" | ||
#include "llvm/ADT/Statistic.h" | ||
|
||
STATISTIC(numAssignRewritten, "Number of assigns rewritten"); | ||
|
@@ -177,6 +178,7 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b, | |
SILValue dest = inst->getDest(); | ||
SILLocation loc = inst->getLoc(); | ||
SILBuilderWithScope forCleanup(std::next(inst->getIterator())); | ||
SingleValueInstruction *closureToDelete = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this change made? Also can you add a test? |
||
|
||
switch (inst->getAssignDestination()) { | ||
case AssignByWrapperInst::Destination::BackingWrapper: { | ||
|
@@ -199,8 +201,7 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b, | |
b.createStore(loc, wrappedSrc, dest, StoreOwnershipQualifier::Assign); | ||
} | ||
} | ||
// TODO: remove the unused setter function, which usually is a dead | ||
// partial_apply. | ||
closureToDelete = dyn_cast<SingleValueInstruction>(inst->getSetter()); | ||
break; | ||
} | ||
case AssignByWrapperInst::Destination::WrappedValue: { | ||
|
@@ -218,12 +219,13 @@ static void lowerAssignByWrapperInstruction(SILBuilderWithScope &b, | |
// nested access violation. | ||
if (auto *BA = dyn_cast<BeginAccessInst>(dest)) | ||
accessMarkers.push_back(BA); | ||
// TODO: remove the unused init function, which usually is a dead | ||
// partial_apply. | ||
closureToDelete = dyn_cast<SingleValueInstruction>(inst->getInitializer()); | ||
break; | ||
} | ||
} | ||
inst->eraseFromParent(); | ||
if (closureToDelete) | ||
tryDeleteDeadClosure(closureToDelete); | ||
} | ||
|
||
static void deleteDeadAccessMarker(BeginAccessInst *BA) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add here that this is just the current implementation and the design is not final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done