@@ -327,19 +327,43 @@ replaceLoad(SILInstruction *inst, SILValue newValue, AllocStackInst *asi,
327
327
}
328
328
}
329
329
330
- // / Create a tuple value for an empty tuple or a tuple of empty tuples.
331
- static SILValue createValueForEmptyTuple (SILType ty,
332
- SILInstruction *insertionPoint,
333
- SILBuilderContext &ctx) {
334
- auto tupleTy = ty.castTo <TupleType>();
335
- SmallVector<SILValue, 4 > elements;
336
- for (unsigned idx : range (tupleTy->getNumElements ())) {
337
- SILType elementTy = ty.getTupleElementType (idx);
338
- elements.push_back (
339
- createValueForEmptyTuple (elementTy, insertionPoint, ctx));
330
+ // / Instantiate the specified empty type by recursively tupling and structing
331
+ // / the empty types aggregated together at each level.
332
+ static SILValue createValueForEmptyType (SILType ty,
333
+ SILInstruction *insertionPoint,
334
+ SILBuilderContext &ctx) {
335
+ auto *function = insertionPoint->getFunction ();
336
+ assert (ty.isEmpty (*function));
337
+ if (auto tupleTy = ty.getAs <TupleType>()) {
338
+ SmallVector<SILValue, 4 > elements;
339
+ for (unsigned idx : range (tupleTy->getNumElements ())) {
340
+ SILType elementTy = ty.getTupleElementType (idx);
341
+ auto element = createValueForEmptyType (elementTy, insertionPoint, ctx);
342
+ elements.push_back (element);
343
+ }
344
+ SILBuilderWithScope builder (insertionPoint, ctx);
345
+ return builder.createTuple (insertionPoint->getLoc (), ty, elements);
346
+ } else if (auto *decl = ty.getStructOrBoundGenericStruct ()) {
347
+ TypeExpansionContext tec = *function;
348
+ auto &module = function->getModule ();
349
+ if (decl->isResilient (tec.getContext ()->getParentModule (),
350
+ tec.getResilienceExpansion ())) {
351
+ llvm::errs () << " Attempting to create value for illegal empty type:\n " ;
352
+ ty.print (llvm::errs ());
353
+ llvm::report_fatal_error (" illegal empty type: resilient struct" );
354
+ }
355
+ SmallVector<SILValue, 4 > elements;
356
+ for (auto *field : decl->getStoredProperties ()) {
357
+ auto elementTy = ty.getFieldType (field, module , tec);
358
+ auto element = createValueForEmptyType (elementTy, insertionPoint, ctx);
359
+ elements.push_back (element);
360
+ }
361
+ SILBuilderWithScope builder (insertionPoint, ctx);
362
+ return builder.createStruct (insertionPoint->getLoc (), ty, elements);
340
363
}
341
- SILBuilderWithScope builder (insertionPoint, ctx);
342
- return builder.createTuple (insertionPoint->getLoc (), ty, elements);
364
+ llvm::errs () << " Attempting to create value for illegal empty type:\n " ;
365
+ ty.print (llvm::errs ());
366
+ llvm::report_fatal_error (" illegal empty type: neither tuple nor struct." );
343
367
}
344
368
345
369
// / Whether lexical lifetimes should be added for the values stored into the
@@ -1607,11 +1631,11 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *asi) {
1607
1631
// with our running value.
1608
1632
if (isLoadFromStack (inst, asi)) {
1609
1633
if (!runningVals) {
1610
- // Loading without a previous store is only acceptable if the type is
1611
- // Void (= empty tuple) or a tuple of Voids .
1634
+ // Loading from uninitialized memory is only acceptable if the type is
1635
+ // empty--an aggregate of types without storage .
1612
1636
runningVals = {
1613
1637
LiveValues::toReplace (asi,
1614
- /* replacement=*/ createValueForEmptyTuple (
1638
+ /* replacement=*/ createValueForEmptyType (
1615
1639
asi->getElementType (), inst, ctx)),
1616
1640
/* isStorageValid=*/ true };
1617
1641
}
0 commit comments