static void replaceDestroy(DestroyAddrInst *DAI, SILValue NewValue) { SILFunction *F = DAI->getFunction(); assert(DAI->getOperand()->getType().isLoadable(*F) && "Unexpected promotion of address-only type!"); assert(NewValue && "Expected a value to release!"); SILBuilderWithScope Builder(DAI); auto Ty = DAI->getOperand()->getType(); auto &TL = F->getTypeLowering(Ty); bool expand = shouldExpand(DAI->getModule(), DAI->getOperand()->getType().getObjectType()); using TypeExpansionKind = Lowering::TypeLowering::TypeExpansionKind; auto expansionKind = expand ? TypeExpansionKind::MostDerivedDescendents : TypeExpansionKind::None; TL.emitLoweredDestroyValue(Builder, DAI->getLoc(), NewValue, expansionKind); DAI->eraseFromParent(); }