Implement helper to compute partial apply return type; insert convert_function as necessary where this type does not match the needed type

Swift SVN r8315
This commit is contained in:
Stephen Lin
2013-09-17 00:39:17 +00:00
parent 1fdb8cbf9e
commit 694f56e2a1
6 changed files with 51 additions and 22 deletions

View File

@@ -1329,10 +1329,15 @@ SILGenFunction::emitClosureValue(SILLocation loc, SILDeclRef constant,
}
}
SILType closureTy = getLoweredLoadableType(TheClosure.getType());
return emitManagedRValueWithCleanup(
B.createPartialApply(loc, functionRef, capturedArgs,
closureTy));
SILType resultTy = getLoweredLoadableType(TheClosure.getType());
SILType closureTy =
SILBuilder::getPartialApplyResultType(functionRef.getType(),
capturedArgs.size(), SGM.M);
SILInstruction *toClosure =
B.createPartialApply(loc, functionRef, capturedArgs, closureTy);
if (resultTy != closureTy)
toClosure = B.createConvertFunction(loc, toClosure, resultTy);
return emitManagedRValueWithCleanup(toClosure);
}
RValue RValueEmitter::visitPipeClosureExpr(PipeClosureExpr *e, SGFContext C) {
@@ -2170,7 +2175,13 @@ void SILGenFunction::emitCurryThunk(FuncDecl *fd,
}
// Partially apply the next uncurry level and return the result closure.
auto toClosure = B.createPartialApply(fd, toFn, curriedArgs, resultTy);
auto closureTy =
SILBuilder::getPartialApplyResultType(toFn.getType(), curriedArgs.size(),
SGM.M);
SILInstruction *toClosure =
B.createPartialApply(fd, toFn, curriedArgs, closureTy);
if (resultTy != closureTy)
toClosure = B.createConvertFunction(fd, toClosure, resultTy);
B.createReturn(fd, toClosure);
}