mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SILGen: Add a new RValue(AbstractionPattern, CanType) constructor
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "Initialization.h"
|
||||
#include "RValue.h"
|
||||
#include "swift/SIL/AbstractionPattern.h"
|
||||
#include "swift/SIL/SILArgument.h"
|
||||
#include "swift/AST/CanTypeVisitor.h"
|
||||
#include "swift/Basic/Fallthrough.h"
|
||||
@@ -33,6 +34,20 @@ static unsigned getTupleSize(CanType t) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static unsigned getRValueSize(AbstractionPattern pattern, CanType formalType) {
|
||||
if (pattern.isTuple()) {
|
||||
unsigned count = 0;
|
||||
auto formalTupleType = cast<TupleType>(formalType);
|
||||
for (auto i : indices(formalTupleType.getElementTypes())) {
|
||||
count += getRValueSize(pattern.getTupleElementType(i),
|
||||
formalTupleType.getElementType(i));
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// Return the number of rvalue elements in the given canonical type.
|
||||
static unsigned getRValueSize(CanType type) {
|
||||
if (auto tupleType = dyn_cast<TupleType>(type)) {
|
||||
@@ -393,6 +408,10 @@ RValue::RValue(CanType type)
|
||||
: type(type), elementsToBeAdded(getTupleSize(type)) {
|
||||
}
|
||||
|
||||
RValue::RValue(AbstractionPattern pattern, CanType type)
|
||||
: type(type), elementsToBeAdded(getRValueSize(pattern, type)) {
|
||||
}
|
||||
|
||||
void RValue::addElement(RValue &&element) & {
|
||||
assert(!element.isUsed() && "adding consumed value to r-value");
|
||||
assert(!isComplete() && "rvalue already complete");
|
||||
|
||||
Reference in New Issue
Block a user