Skip to content

Commit caaad42

Browse files
committed
[SIL-opaque] Various SILGen fixes
1 parent 2fd4de4 commit caaad42

File tree

6 files changed

+37
-18
lines changed

6 files changed

+37
-18
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3964,7 +3964,7 @@ SILGenFunction::emitBeginApply(SILLocation loc, ManagedValue fn,
39643964
yields.push_back(ManagedValue::forLValue(value));
39653965
} else if (info.isConsumed()) {
39663966
yields.push_back(emitManagedRValueWithCleanup(value));
3967-
} else if (info.isDirectGuaranteed()) {
3967+
} else if (info.isGuaranteed()) {
39683968
yields.push_back(ManagedValue::forBorrowedRValue(value));
39693969
} else {
39703970
yields.push_back(ManagedValue::forTrivialRValue(value));

lib/SILGen/SILGenDynamicCast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ namespace {
252252
}
253253

254254
ManagedValue result;
255-
if (!origTargetTL.isAddressOnly()) {
255+
if (!origTargetTL.isAddressOnly() || !SGF.useLoweredAddresses()) {
256256
result = SGF.emitLoad(Loc, buffer, origTargetTL, ctx, IsTake);
257257
} else {
258258
result = SGF.emitManagedBufferWithCleanup(buffer, origTargetTL);
@@ -450,7 +450,7 @@ RValue Lowering::emitConditionalCheckedCast(
450450
SILValue resultObjectBuffer;
451451
Optional<TemporaryInitialization> resultObjectTemp;
452452
SGFContext resultObjectCtx;
453-
if ((resultTL.isAddressOnly())
453+
if ((resultTL.isAddressOnly() && SGF.useLoweredAddresses())
454454
|| (C.getEmitInto()
455455
&& C.getEmitInto()->canPerformInPlaceInitialization())) {
456456
SILType resultTy = resultTL.getLoweredType();

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4726,7 +4726,7 @@ ManagedValue SILGenFunction::emitBindOptional(SILLocation loc,
47264726

47274727
// If optValue was loadable, we emitted a switch_enum. In such a case, return
47284728
// the argument from hasValueBB.
4729-
if (optValue.getType().isLoadable(F)) {
4729+
if (optValue.getType().isLoadable(F) || !silConv.useLoweredAddresses()) {
47304730
return emitManagedRValueWithCleanup(hasValueBB->getArgument(0));
47314731
}
47324732

lib/SILGen/SILGenFunction.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ void SILGenFunction::emitCaptures(SILLocation loc,
271271
break;
272272
case CaptureKind::Immutable:
273273
case CaptureKind::StorageAddress:
274+
// FIXME_addrlower: only call getAddressType for M.useLoweredAddresses()
274275
capturedArgs.push_back(emitUndef(getLoweredType(type).getAddressType()));
275276
break;
276277
case CaptureKind::Box: {
@@ -290,11 +291,13 @@ void SILGenFunction::emitCaptures(SILLocation loc,
290291
// Get an address value for a SILValue if it is address only in an type
291292
// expansion context without opaque archetype substitution.
292293
auto getAddressValue = [&](SILValue entryValue) -> SILValue {
293-
if (SGM.Types.getTypeLowering(
294-
valueType,
295-
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
296-
expansion.getResilienceExpansion()))
297-
.isAddressOnly()
294+
if (SGM.M.useLoweredAddresses()
295+
&& SGM.Types
296+
.getTypeLowering(
297+
valueType,
298+
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(
299+
expansion.getResilienceExpansion()))
300+
.isAddressOnly()
298301
&& !entryValue->getType().isAddress()) {
299302

300303
auto addr = emitTemporaryAllocation(vd, entryValue->getType());
@@ -342,13 +345,15 @@ void SILGenFunction::emitCaptures(SILLocation loc,
342345
}
343346
case CaptureKind::Immutable: {
344347
if (canGuarantee) {
345-
auto entryValue = getAddressValue(Entry.value);
346348
// No-escaping stored declarations are captured as the
347349
// address of the value.
348-
assert(entryValue->getType().isAddress() && "no address for captured var!");
349-
capturedArgs.push_back(ManagedValue::forLValue(entryValue));
350+
auto entryValue = getAddressValue(Entry.value);
351+
capturedArgs.push_back(ManagedValue::forBorrowedRValue(entryValue));
350352
}
351-
else {
353+
else if (!silConv.useLoweredAddresses()) {
354+
capturedArgs.push_back(
355+
B.createCopyValue(loc, ManagedValue::forUnmanaged(Entry.value)));
356+
} else {
352357
auto entryValue = getAddressValue(Entry.value);
353358
// We cannot pass a valid SILDebugVariable while creating the temp here
354359
// See rdar://60425582

lib/SILGen/SILGenPoly.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@ namespace {
11671167
outputOrigEltType, outputEltType,
11681168
elt, loweredOutputEltTy);
11691169

1170+
// Aggregation of address-only values requires ownership.
1171+
if (loweredOutputTy.isAddressOnly(SGF.F)) {
1172+
elt = elt.ensurePlusOne(SGF, Loc);
1173+
}
11701174
elements.push_back(elt);
11711175
}
11721176

@@ -1175,7 +1179,10 @@ namespace {
11751179
forwarded.push_back(elt.forward(SGF));
11761180

11771181
auto tuple = SGF.B.createTuple(Loc, loweredOutputTy, forwarded);
1178-
return SGF.emitManagedRValueWithCleanup(tuple);
1182+
if (tuple->getOwnershipKind() == OwnershipKind::Owned)
1183+
return SGF.emitManagedRValueWithCleanup(tuple);
1184+
1185+
return ManagedValue::forUnmanaged(tuple);
11791186
}
11801187

11811188
/// Handle a tuple that has been exploded in the input but wrapped in

lib/SILGen/SILGenProlog.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,18 @@ static void emitCaptureArguments(SILGenFunction &SGF,
456456
case CaptureKind::StorageAddress: {
457457
// Non-escaping stored decls are captured as the address of the value.
458458
auto type = getVarTypeInCaptureContext();
459-
SILType ty = SGF.getLoweredType(type).getAddressType();
460-
SILValue addr = SGF.F.begin()->createFunctionArgument(ty, VD);
461-
SGF.VarLocs[VD] = SILGenFunction::VarLoc::get(addr);
459+
SILType ty = SGF.getLoweredType(type);
460+
if (SGF.SGM.M.useLoweredAddresses()) {
461+
ty = ty.getAddressType();
462+
}
463+
SILValue arg = SGF.F.begin()->createFunctionArgument(ty, VD);
464+
SGF.VarLocs[VD] = SILGenFunction::VarLoc::get(arg);
462465
SILDebugVariable DbgVar(VD->isLet(), ArgNo);
463-
SGF.B.createDebugValueAddr(Loc, addr, DbgVar);
466+
if (ty.isAddress()) {
467+
SGF.B.createDebugValueAddr(Loc, arg, DbgVar);
468+
} else {
469+
SGF.B.createDebugValue(Loc, arg, DbgVar);
470+
}
464471
break;
465472
}
466473
}

0 commit comments

Comments
 (0)