mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: Lower captures to boxes with an appropriate generic context.
Officially kick SILBoxType over to be "nominal" in its layout, with generic layouts structurally parameterized only by formal types. Change SIL to lower a capture to a nongeneric box when possible, or a box capturing the enclosing generic context when necessary.
This commit is contained in:
@@ -335,7 +335,11 @@ void SILGenFunction::emitCaptures(SILLocation loc,
|
||||
// since we could conceivably forward the copied value into the
|
||||
// closure context and pass it down to the partially applied function
|
||||
// in-place.
|
||||
auto boxTy = SILBoxType::get(vl.value->getType().getSwiftRValueType());
|
||||
// TODO: Use immutable box for immutable captures.
|
||||
auto boxTy = SGM.Types.getContextBoxTypeForCapture(vd,
|
||||
vl.value->getType().getSwiftRValueType(),
|
||||
F.getGenericEnvironment(),
|
||||
/*mutable*/ true);
|
||||
|
||||
AllocBoxInst *allocBox = B.createAllocBox(loc, boxTy);
|
||||
ProjectBoxInst *boxAddress = B.createProjectBox(loc, allocBox, 0);
|
||||
@@ -708,13 +712,14 @@ static void forwardCaptureArgs(SILGenFunction &gen,
|
||||
}
|
||||
|
||||
case CaptureKind::Box: {
|
||||
auto *var = dyn_cast<VarDecl>(vd);
|
||||
SILType ty = gen.getLoweredType(var->getType()->getRValueType())
|
||||
.getAddressType();
|
||||
// Forward the captured owning box.
|
||||
SILType boxTy = SILType::getPrimitiveObjectType(
|
||||
SILBoxType::get(ty.getSwiftRValueType()));
|
||||
addSILArgument(boxTy, vd);
|
||||
auto *var = cast<VarDecl>(vd);
|
||||
auto boxTy = gen.SGM.Types
|
||||
.getInterfaceBoxTypeForCapture(vd,
|
||||
gen.getLoweredType(var->getType())
|
||||
.getSwiftRValueType(),
|
||||
/*mutable*/ true);
|
||||
addSILArgument(SILType::getPrimitiveObjectType(boxTy), vd);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user