Sema: Simpler materializeForSet return type, NFC

The function pointer is a thin function and possibly polymorphic,
so it does not really have an AST type. Instead of pretending it has
an AST type, just return a RawPointer and remove some casts in the
process.
This commit is contained in:
Slava Pestov
2016-03-08 16:02:54 -08:00
parent cfebe49e90
commit bc1fc73b2a
14 changed files with 103 additions and 182 deletions

View File

@@ -457,23 +457,12 @@ void MaterializeForSetEmitter::emit(SILGenFunction &gen) {
// Form the callback.
SILValue callback;
if (callbackFn) {
// Make a reference to the function.
// Make a reference to the callback.
callback = gen.B.createFunctionRef(loc, callbackFn);
// If it's polymorphic, cast to RawPointer and then back to the
// right monomorphic type. The safety of this cast relies on some
// assumptions about what exactly IRGen can reconstruct from the
// callback's thick type argument.
if (callbackFn->getLoweredFunctionType()->isPolymorphic()) {
callback = gen.B.createThinFunctionToPointer(loc, callback, rawPointerTy);
OptionalTypeKind optKind;
auto callbackTy = optCallbackTy.getAnyOptionalObjectType(SGM.M, optKind);
callback = gen.B.createPointerToThinFunction(loc, callback, callbackTy);
}
callback = gen.B.createThinFunctionToPointer(loc, callback, rawPointerTy);
callback = gen.B.createOptionalSome(loc, callback, optCallbackTy);
} else {
// There is no callback.
callback = gen.B.createOptionalNone(loc, optCallbackTy);
}
@@ -548,7 +537,8 @@ collectIndicesFromParameters(SILGenFunction &gen, SILLocation loc,
return result;
}
SILFunction *MaterializeForSetEmitter::createCallback(SILFunction &F, GeneratorFn generator) {
SILFunction *MaterializeForSetEmitter::createCallback(SILFunction &F,
GeneratorFn generator) {
auto callbackType =
SGM.Types.getMaterializeForSetCallbackType(WitnessStorage,
GenericSig,