@@ -449,7 +449,7 @@ namespace {
449449 RValue visitKeyPathApplicationExpr (KeyPathApplicationExpr *E, SGFContext C);
450450 RValue visitDynamicSubscriptExpr (DynamicSubscriptExpr *E,
451451 SGFContext C);
452- RValue visitTupleShuffleExpr (TupleShuffleExpr *E, SGFContext C);
452+ RValue visitDestructureTupleExpr (DestructureTupleExpr *E, SGFContext C);
453453 RValue visitArgumentShuffleExpr (ArgumentShuffleExpr *E, SGFContext C);
454454 RValue visitDynamicTypeExpr (DynamicTypeExpr *E, SGFContext C);
455455 RValue visitCaptureListExpr (CaptureListExpr *E, SGFContext C);
@@ -2151,81 +2151,34 @@ RValue SILGenFunction::emitApplyOfStoredPropertyInitializer(
21512151 subs, {}, calleeTypeInfo, ApplyOptions::None, C);
21522152}
21532153
2154- static void emitTupleShuffleExprInto (RValueEmitter &emitter,
2155- TupleShuffleExpr *E,
2156- Initialization *outerTupleInit) {
2157- CanTupleType outerTuple = cast<TupleType>(E->getType ()->getCanonicalType ());
2158- auto outerFields = outerTuple->getElements ();
2159- (void ) outerFields;
2160-
2161- // Decompose the initialization.
2162- SmallVector<InitializationPtr, 4 > outerInitsBuffer;
2163- auto outerInits =
2164- outerTupleInit->splitIntoTupleElements (emitter.SGF , RegularLocation (E),
2165- outerTuple, outerInitsBuffer);
2166- assert (outerInits.size () == outerFields.size () &&
2167- " initialization size does not match tuple size?!" );
2168-
2169- // Map outer initializations into a tuple of inner initializations:
2170- // - fill out the initialization elements with null
2171- TupleInitialization innerTupleInit;
2172-
2173- CanTupleType innerTuple =
2174- cast<TupleType>(E->getSubExpr ()->getType ()->getCanonicalType ());
2175- innerTupleInit.SubInitializations .resize (innerTuple->getNumElements ());
2154+ RValue RValueEmitter::visitDestructureTupleExpr (DestructureTupleExpr *E,
2155+ SGFContext C) {
2156+ // Emit the sub-expression tuple and destructure it into elements.
2157+ SmallVector<RValue, 4 > elements;
2158+ visit (E->getSubExpr ()).extractElements (elements);
21762159
2177- // Map all the outer initializations to their appropriate targets.
2178- for ( unsigned outerIndex = 0 ; outerIndex != outerInits. size (); outerIndex++) {
2179- auto innerMapping = E->getElementMapping ()[outerIndex] ;
2180- innerTupleInit. SubInitializations [innerMapping] =
2181- std::move (outerInits[outerIndex]) ;
2182- }
2160+ // Bind each element of the input tuple to its corresponding
2161+ // opaque value.
2162+ for ( unsigned i = 0 , e = E->getDestructuredElements (). size () ;
2163+ i != e; ++i) {
2164+ auto *opaqueElt = E-> getDestructuredElements ()[i] ;
2165+ assert (!SGF. OpaqueValues . count (opaqueElt));
21832166
2184- #ifndef NDEBUG
2185- for (auto &innerInit : innerTupleInit.SubInitializations ) {
2186- assert (innerInit != nullptr && " didn't map all inner elements" );
2167+ auto opaqueMV = std::move (elements[i]).getAsSingleValue (SGF, E);
2168+ SGF.OpaqueValues [opaqueElt] = opaqueMV;
21872169 }
2188- #endif
2189-
2190- // Emit the sub-expression into the tuple initialization we just built.
2191- emitter.SGF .emitExprInto (E->getSubExpr (), &innerTupleInit);
21922170
2193- outerTupleInit->finishInitialization (emitter.SGF );
2194- }
2171+ // Emit the result expression written in terms of the above
2172+ // opaque values.
2173+ auto result = visit (E->getResultExpr (), C);
21952174
2196- RValue RValueEmitter::visitTupleShuffleExpr (TupleShuffleExpr *E,
2197- SGFContext C) {
2198- // If we're emitting into an initialization, we can try shuffling the
2199- // elements of the initialization.
2200- if (Initialization *I = C.getEmitInto ()) {
2201- if (I->canSplitIntoTupleElements ()) {
2202- emitTupleShuffleExprInto (*this , E, I);
2203- return RValue::forInContext ();
2204- }
2175+ // Clean up.
2176+ for (unsigned i = 0 , e = E->getDestructuredElements ().size ();
2177+ i != e; ++i) {
2178+ auto *opaqueElt = E->getDestructuredElements ()[i];
2179+ SGF.OpaqueValues .erase (opaqueElt);
22052180 }
22062181
2207- // Emit the sub-expression tuple and destructure it into elements.
2208- SmallVector<RValue, 4 > elements;
2209- visit (E->getSubExpr ()).extractElements (elements);
2210-
2211- // Prepare a new tuple to hold the shuffled result.
2212- RValue result (E->getType ()->getCanonicalType ());
2213-
2214- auto outerFields = E->getType ()->castTo <TupleType>()->getElements ();
2215- auto shuffleIndexIterator = E->getElementMapping ().begin ();
2216- auto shuffleIndexEnd = E->getElementMapping ().end ();
2217- (void )shuffleIndexEnd;
2218- for (auto &field : outerFields) {
2219- (void ) field;
2220- assert (shuffleIndexIterator != shuffleIndexEnd &&
2221- " ran out of shuffle indexes before running out of fields?!" );
2222- int shuffleIndex = *shuffleIndexIterator++;
2223-
2224- // Map from a different tuple element.
2225- result.addElement (
2226- std::move (elements[shuffleIndex]).ensurePlusOne (SGF, E));
2227- }
2228-
22292182 return result;
22302183}
22312184
0 commit comments