@@ -146,6 +146,8 @@ bool swift::canOpcodeForwardOwnedValues(Operand *use) {
146146
147147void BorrowingOperandKind::print (llvm::raw_ostream &os) const {
148148 switch (value) {
149+ case Kind::Invalid:
150+ llvm_unreachable (" Using an unreachable?!" );
149151 case Kind::BeginBorrow:
150152 os << " BeginBorrow" ;
151153 return ;
@@ -190,6 +192,8 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
190192bool BorrowingOperand::visitLocalEndScopeUses (
191193 function_ref<bool (Operand *)> func) const {
192194 switch (kind) {
195+ case BorrowingOperandKind::Invalid:
196+ llvm_unreachable (" Using invalid case" );
193197 case BorrowingOperandKind::BeginBorrow:
194198 for (auto *use : cast<BeginBorrowInst>(op->getUser ())->getUses ()) {
195199 if (use->isLifetimeEnding ()) {
@@ -228,20 +232,24 @@ bool BorrowingOperand::visitLocalEndScopeUses(
228232void BorrowingOperand::visitBorrowIntroducingUserResults (
229233 function_ref<void (BorrowedValue)> visitor) const {
230234 switch (kind) {
235+ case BorrowingOperandKind::Invalid:
236+ llvm_unreachable (" Using invalid case" );
231237 case BorrowingOperandKind::Apply:
232238 case BorrowingOperandKind::TryApply:
233239 case BorrowingOperandKind::BeginApply:
234240 case BorrowingOperandKind::Yield:
235241 llvm_unreachable (" Never has borrow introducer results!" );
236242 case BorrowingOperandKind::BeginBorrow: {
237- auto value = *BorrowedValue::get (cast<BeginBorrowInst>(op->getUser ()));
243+ auto value = BorrowedValue::get (cast<BeginBorrowInst>(op->getUser ()));
244+ assert (value);
238245 return visitor (value);
239246 }
240247 case BorrowingOperandKind::Branch: {
241248 auto *bi = cast<BranchInst>(op->getUser ());
242249 for (auto *succBlock : bi->getSuccessorBlocks ()) {
243250 auto value =
244- *BorrowedValue::get (succBlock->getArgument (op->getOperandNumber ()));
251+ BorrowedValue::get (succBlock->getArgument (op->getOperandNumber ()));
252+ assert (value);
245253 visitor (value);
246254 }
247255 return ;
@@ -263,8 +271,8 @@ void BorrowingOperand::visitConsumingUsesOfBorrowIntroducingUserResults(
263271 // single guaranteed scope.
264272 value.visitLocalScopeEndingUses ([&](Operand *valueUser) {
265273 if (auto subBorrowScopeOp = BorrowingOperand::get (valueUser)) {
266- if (subBorrowScopeOp-> isReborrow ()) {
267- subBorrowScopeOp-> visitUserResultConsumingUses (func);
274+ if (subBorrowScopeOp. isReborrow ()) {
275+ subBorrowScopeOp. visitUserResultConsumingUses (func);
268276 return ;
269277 }
270278 }
@@ -315,6 +323,8 @@ void BorrowingOperand::getImplicitUses(
315323
316324void BorrowedValueKind::print (llvm::raw_ostream &os) const {
317325 switch (value) {
326+ case BorrowedValueKind::Invalid:
327+ llvm_unreachable (" Using invalid case?!" );
318328 case BorrowedValueKind::SILFunctionArgument:
319329 os << " SILFunctionArgument" ;
320330 return ;
@@ -342,6 +352,8 @@ void BorrowedValue::getLocalScopeEndingInstructions(
342352 assert (isLocalScope () && " Should only call this given a local scope" );
343353
344354 switch (kind) {
355+ case BorrowedValueKind::Invalid:
356+ llvm_unreachable (" Using invalid case?!" );
345357 case BorrowedValueKind::SILFunctionArgument:
346358 llvm_unreachable (" Should only call this with a local scope" );
347359 case BorrowedValueKind::BeginBorrow:
@@ -361,6 +373,8 @@ void BorrowedValue::visitLocalScopeEndingUses(
361373 function_ref<void (Operand *)> visitor) const {
362374 assert (isLocalScope () && " Should only call this given a local scope" );
363375 switch (kind) {
376+ case BorrowedValueKind::Invalid:
377+ llvm_unreachable (" Using invalid case?!" );
364378 case BorrowedValueKind::SILFunctionArgument:
365379 llvm_unreachable (" Should only call this with a local scope" );
366380 case BorrowedValueKind::LoadBorrow:
@@ -441,7 +455,7 @@ bool BorrowedValue::visitLocalScopeTransitiveEndingUses(
441455 continue ;
442456 }
443457
444- scopeOperand-> visitConsumingUsesOfBorrowIntroducingUserResults (
458+ scopeOperand. visitConsumingUsesOfBorrowIntroducingUserResults (
445459 [&](Operand *op) {
446460 assert (op->isLifetimeEnding () && " Expected only consuming uses" );
447461 // Make sure we haven't visited this consuming operand yet. If we
@@ -464,7 +478,7 @@ bool BorrowedValue::visitInteriorPointerOperands(
464478 auto *op = worklist.pop_back_val ();
465479
466480 if (auto interiorPointer = InteriorPointerOperand::get (op)) {
467- func (* interiorPointer);
481+ func (interiorPointer);
468482 continue ;
469483 }
470484
@@ -617,6 +631,8 @@ bool InteriorPointerOperand::getImplicitUses(
617631
618632void OwnedValueIntroducerKind::print (llvm::raw_ostream &os) const {
619633 switch (value) {
634+ case OwnedValueIntroducerKind::Invalid:
635+ llvm_unreachable (" Using invalid case?!" );
620636 case OwnedValueIntroducerKind::Apply:
621637 os << " Apply" ;
622638 return ;
@@ -677,7 +693,7 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
677693
678694 // First check if v is an introducer. If so, stash it and continue.
679695 if (auto scopeIntroducer = BorrowedValue::get (value)) {
680- out.push_back (* scopeIntroducer);
696+ out.push_back (scopeIntroducer);
681697 continue ;
682698 }
683699
@@ -716,10 +732,9 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
716732 return true ;
717733}
718734
719- Optional<BorrowedValue>
720- swift::getSingleBorrowIntroducingValue (SILValue inputValue) {
735+ BorrowedValue swift::getSingleBorrowIntroducingValue (SILValue inputValue) {
721736 if (inputValue.getOwnershipKind () != OwnershipKind::Guaranteed)
722- return None ;
737+ return {} ;
723738
724739 SILValue currentValue = inputValue;
725740 while (true ) {
@@ -738,7 +753,7 @@ swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
738753 // this.
739754 auto begin = instOps.begin ();
740755 if (std::next (begin) != instOps.end ()) {
741- return None ;
756+ return {} ;
742757 }
743758 // Otherwise, set currentOp to the single operand and continue.
744759 currentValue = *begin;
@@ -758,7 +773,7 @@ swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
758773
759774 // Otherwise, this is an introducer we do not understand. Bail and return
760775 // None.
761- return None ;
776+ return {} ;
762777 }
763778
764779 llvm_unreachable (" Should never hit this" );
@@ -777,7 +792,7 @@ bool swift::getAllOwnedValueIntroducers(
777792
778793 // First check if v is an introducer. If so, stash it and continue.
779794 if (auto introducer = OwnedValueIntroducer::get (value)) {
780- out.push_back (* introducer);
795+ out.push_back (introducer);
781796 continue ;
782797 }
783798
@@ -816,10 +831,9 @@ bool swift::getAllOwnedValueIntroducers(
816831 return true ;
817832}
818833
819- Optional<OwnedValueIntroducer>
820- swift::getSingleOwnedValueIntroducer (SILValue inputValue) {
834+ OwnedValueIntroducer swift::getSingleOwnedValueIntroducer (SILValue inputValue) {
821835 if (inputValue.getOwnershipKind () != OwnershipKind::Owned)
822- return None ;
836+ return {} ;
823837
824838 SILValue currentValue = inputValue;
825839 while (true ) {
@@ -838,7 +852,7 @@ swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
838852 // this.
839853 auto begin = instOps.begin ();
840854 if (std::next (begin) != instOps.end ()) {
841- return None ;
855+ return {} ;
842856 }
843857 // Otherwise, set currentOp to the single operand and continue.
844858 currentValue = *begin;
@@ -859,7 +873,7 @@ swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
859873
860874 // Otherwise, this is an introducer we do not understand. Bail and return
861875 // None.
862- return None ;
876+ return {} ;
863877 }
864878
865879 llvm_unreachable (" Should never hit this" );
@@ -869,12 +883,12 @@ swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
869883// Forwarding Operand
870884// ===----------------------------------------------------------------------===//
871885
872- Optional< ForwardingOperand> ForwardingOperand::get (Operand *use) {
886+ ForwardingOperand ForwardingOperand::get (Operand *use) {
873887 if (use->isTypeDependent ())
874- return None ;
888+ return nullptr ;
875889
876890 if (!OwnershipForwardingMixin::isa (use->getUser ())) {
877- return None ;
891+ return nullptr ;
878892 }
879893#ifndef NDEBUG
880894 switch (use->getOperandOwnership ()) {
0 commit comments