Merge pull request #15111 from davidungar/fix-OFM-parser
Fix bug on OutputFileMap parser when parsing beyond JSON.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55317a8..ab911cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -114,17 +114,19 @@
recursive constraints. For example, the `SubSequence` associated type of
`Sequence` follows the enclosing protocol:
- protocol Sequence {
- associatedtype Element
- associatedtype SubSequence: Sequence
- where SubSequence.Element == Element,
- SubSequence.SubSequence == SubSequence
- // ...
- }
+ ```swift
+ protocol Sequence {
+ associatedtype Element
+ associatedtype SubSequence: Sequence
+ where SubSequence.Element == Element,
+ SubSequence.SubSequence == SubSequence
+ // ...
+ }
- protocol Collection: Sequence where Self.SubSequence: Collection {
- // ...
- }
+ protocol Collection: Sequence where Self.SubSequence: Collection {
+ // ...
+ }
+ ```
As a result, a number of new constraints have been introduced into the
standard library protocols:
diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp
index bf5e21b..53ead97 100644
--- a/lib/SILGen/SILGenExpr.cpp
+++ b/lib/SILGen/SILGenExpr.cpp
@@ -2412,10 +2412,28 @@
return RValue::forInContext();
}
}
-
+
+ llvm::SmallVector<RValue, 8> tupleElts;
+ bool hasAtleastOnePlusOneValue = false;
+ for (Expr *elt : E->getElements()) {
+ RValue RV = SGF.emitRValue(elt);
+ hasAtleastOnePlusOneValue |= RV.isPlusOne(SGF);
+ tupleElts.emplace_back(std::move(RV));
+ }
+
+ // Once we have found if we have any plus one arguments, add each element of
+ // tuple elts into result, making sure each value is at plus 1.
RValue result(type);
- for (Expr *elt : E->getElements())
- result.addElement(SGF.emitRValue(elt));
+ if (hasAtleastOnePlusOneValue) {
+ for (unsigned i : indices(tupleElts)) {
+ result.addElement(std::move(tupleElts[i]).ensurePlusOne(SGF, E));
+ }
+ } else {
+ for (unsigned i : indices(tupleElts)) {
+ result.addElement(std::move(tupleElts[i]));
+ }
+ }
+
return result;
}
@@ -2756,7 +2774,7 @@
shuffleIndex != TupleShuffleExpr::Variadic &&
"Only argument tuples can have default initializers & varargs");
- result.addElement(std::move(elements[shuffleIndex]));
+ result.addElement(std::move(elements[shuffleIndex]).ensurePlusOne(SGF, E));
return result;
}
@@ -2777,7 +2795,8 @@
// separately.
if (shuffleIndex != TupleShuffleExpr::Variadic) {
// Map from a different tuple element.
- result.addElement(std::move(elements[shuffleIndex]));
+ result.addElement(
+ std::move(elements[shuffleIndex]).ensurePlusOne(SGF, E));
continue;
}
@@ -2799,8 +2818,9 @@
ManagedValue varargs = emitVarargs(SGF, E, field.getVarargBaseTy(),
variadicValues,
E->getVarargsArrayType());
- result.addElement(RValue(SGF, E, field.getType()->getCanonicalType(),
- varargs));
+ result.addElement(
+ RValue(SGF, E, field.getType()->getCanonicalType(), varargs)
+ .ensurePlusOne(SGF, E));
break;
}