@@ -1041,7 +1041,12 @@ SILInstruction *SILCombiner::visitIndexAddrInst(IndexAddrInst *IA) {
10411041// / operation for \p value is required. This differs from a simple `isTrivial`
10421042// / check, because it treats a value_to_bridge_object instruction as "trivial".
10431043// / It can also handle non-trivial enums with trivial cases.
1044- static bool isTrivial (SILValue value, SILFunction *function) {
1044+ // /
1045+ // / TODO: Define this as a top-level SILValue API. It needs to be updated
1046+ // / whenever we refine the specification of isTrivial. For example, in the
1047+ // / future we will check for the existence of a user-defined deinitializer and
1048+ // / handle C++ types specially.
1049+ static bool isValueTrivial (SILValue value, SILFunction *function) {
10451050 SmallVector<ValueBase *, 32 > workList;
10461051 SmallPtrSet<ValueBase *, 16 > visited;
10471052 workList.push_back (value);
@@ -1051,6 +1056,11 @@ static bool isTrivial(SILValue value, SILFunction *function) {
10511056 continue ;
10521057 if (isa<ValueToBridgeObjectInst>(v))
10531058 continue ;
1059+
1060+ // MoveOnly types may have a user-defined deinit.
1061+ if (v->getType ().isPureMoveOnly ())
1062+ return false ;
1063+
10541064 if (isa<StructInst>(v) || isa<TupleInst>(v)) {
10551065 for (SILValue op : cast<SingleValueInstruction>(v)->getOperandValues ()) {
10561066 if (visited.insert (op).second )
@@ -1102,7 +1112,7 @@ SILInstruction *SILCombiner::visitReleaseValueInst(ReleaseValueInst *RVI) {
11021112 RVI->getAtomicity ());
11031113
11041114 // ReleaseValueInst of a trivial type is a no-op.
1105- if (isTrivial (Operand, RVI->getFunction ()))
1115+ if (isValueTrivial (Operand, RVI->getFunction ()))
11061116 return eraseInstFromFunction (*RVI);
11071117
11081118 // Do nothing for non-trivial non-reference types.
@@ -2523,4 +2533,4 @@ SILCombiner::visitCopyAddrInst(CopyAddrInst *CAI) {
25232533 return Builder.createCopyAddr (
25242534 CAI->getLoc (), Src->getOperand (), Dst->getOperand (),
25252535 CAI->isTakeOfSrc (), CAI->isInitializationOfDest ());
2526- }
2536+ }
0 commit comments