@@ -35,12 +35,6 @@ using namespace Lowering;
35
35
// Helper Routines
36
36
// ===----------------------------------------------------------------------===//
37
37
38
- static unsigned getTupleSize (CanType t) {
39
- if (auto tt = dyn_cast<TupleType>(t))
40
- return tt->getNumElements ();
41
- return 1 ;
42
- }
43
-
44
38
unsigned RValue::getRValueSize (AbstractionPattern pattern, CanType formalType) {
45
39
if (pattern.isTuple ()) {
46
40
if (pattern.doesTupleContainPackExpansionType ())
@@ -483,7 +477,7 @@ RValue::RValue(SILGenFunction &SGF, Expr *expr, ManagedValue v)
483
477
}
484
478
485
479
RValue::RValue (CanType type)
486
- : type(type), elementsToBeAdded(getTupleSize (type)) {
480
+ : type(type), elementsToBeAdded(getRValueSize (type)) {
487
481
}
488
482
489
483
RValue::RValue (AbstractionPattern pattern, CanType type)
@@ -493,12 +487,14 @@ RValue::RValue(AbstractionPattern pattern, CanType type)
493
487
void RValue::addElement (RValue &&element) & {
494
488
assert (!element.isUsed () && " adding consumed value to r-value" );
495
489
assert (!element.isInSpecialState () && " adding special value to r-value" );
496
- assert (!isComplete () && " rvalue already complete" );
497
- assert (!isInSpecialState () && " cannot add elements to a special r-value" );
498
- --elementsToBeAdded;
499
- values.insert (values.end (),
500
- element.values .begin (), element.values .end ());
501
- element.makeUsed ();
490
+ assert (elementsToBeAdded >= element.values .size () && " rvalue too full" );
491
+ if (!element.values .empty ()) {
492
+ assert (!isInSpecialState () && " cannot add elements to a special r-value" );
493
+ elementsToBeAdded -= element.values .size ();
494
+ values.insert (values.end (),
495
+ element.values .begin (), element.values .end ());
496
+ element.makeUsed ();
497
+ }
502
498
503
499
assert (!isComplete () || values.size () == getRValueSize (type));
504
500
// Call into the verifier helper directly without an SGF since we know that
0 commit comments