remove dependence on system parameter in SILGen/DefiniteInit

This commit is contained in:
Kavon Farvardin
2022-03-08 17:03:02 -07:00
parent 01a5fafa7c
commit 6c0cfac69a
5 changed files with 118 additions and 54 deletions

View File

@@ -787,6 +787,42 @@ static bool isDistributedActorCtor(SILFunction &F) {
return false;
}
//static SILValue emitActorPropertyReference(
// SILGenFunction &SGF, SILLocation loc, SILValue actorSelf,
// VarDecl *property) {
// Type formalType = SGF.F.mapTypeIntoContext(property->getInterfaceType());
// SILType loweredType = SGF.getLoweredType(formalType).getAddressType();
// return SGF.B.createRefElementAddr(loc, actorSelf, property, loweredType);
//}
/// Creates a reference to the distributed actor's \p actorSystem
/// stored property.
static SILValue refDistributedActorSystem(SILLocation loc,
SILBuilder &b,
SILValue actorInstance,
SILFunction &F) {
ClassDecl *clsDecl = F.getDeclContext()->getSelfClassDecl();
assert(clsDecl->isDistributedActor());
// get the VarDecl corresponding to the actorSystem.
auto refs = clsDecl->lookupDirect(clsDecl->getASTContext().Id_actorSystem);
assert(refs.size() == 1);
VarDecl *actorSystemVar = dyn_cast<VarDecl>(refs.front());
return b.createRefElementAddr(loc, actorInstance, actorSystemVar);
}
static void loadCopyWithCleanups(SILLocation loc, SILBuilder& b, SILValue ref,
llvm::function_ref<void(SILValue)> scope) {
auto copy = b.createLoad(loc, ref, LoadOwnershipQualifier::Copy);
auto borrow = b.createBeginBorrow(loc, copy);
scope(borrow);
b.createEndBorrow(loc, borrow);
b.createDestroyValue(loc, copy);
}
/// Injects a hop_to_executor instruction after the specified insertion point.
static void injectHopToExecutorAfter(SILLocation loc,
SILBasicBlock::iterator insertPt,
@@ -806,29 +842,32 @@ static void injectHopToExecutorAfter(SILLocation loc,
LLVM_DEBUG(llvm::dbgs() << "hop-injector: injecting after " << *insertPt);
SILBuilderWithScope::insertAfter(insertPt, [&](SILBuilder &b) {
SILLocation genLoc = loc.asAutoGenerated();
const bool delegating = !TheMemory.isNonDelegatingInit();
SILValue val = TheMemory.getUninitializedValue();
// delegating inits always have an alloc we need to load it from.
if (delegating)
val = b.createLoad(loc.asAutoGenerated(), val,
LoadOwnershipQualifier::Copy);
val = b.createLoad(genLoc, val, LoadOwnershipQualifier::Copy);
SILValue actor = b.createBeginBorrow(loc.asAutoGenerated(), val);
SILValue actor = b.createBeginBorrow(genLoc, val);
b.createHopToExecutor(loc.asAutoGenerated(), actor, /*mandatory=*/false);
// Distributed actors also need to notify their transport immediately
// after performing the hop.
if (!delegating && isDistributedActorCtor(b.getFunction())) {
auto transport = findFirstDistributedActorSystemArg(b.getFunction());
emitActorReadyCall(b, loc.asAutoGenerated(), actor, transport);
SILValue systemRef = refDistributedActorSystem(loc.asAutoGenerated(),
b, actor, b.getFunction());
loadCopyWithCleanups(genLoc, b, systemRef, [&](SILValue systemVal) {
emitActorReadyCall(b, genLoc, actor, systemVal);
});
}
b.createEndBorrow(loc.asAutoGenerated(), actor);
b.createEndBorrow(genLoc, actor);
if (delegating)
b.createDestroyValue(loc.asAutoGenerated(), val);
b.createDestroyValue(genLoc, val);
});
};