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:
Joe Groff
2016-12-13 17:48:30 -08:00
parent 464a47430d
commit 4444d83756
72 changed files with 668 additions and 554 deletions

View File

@@ -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;
}