SIL: Canonicalize capture types with the AST function's generic signature.

When lowering closures, we avoid capturing the enclosing generic context when possible. However, the generic context may still be necessary to canonicalize types mentioned inside the closure, such as when an associated type is referred to that is same-typed to a concrete type. Fixes rdar://problem/30254048.
This commit is contained in:
Joe Groff
2017-02-03 12:07:28 -08:00
parent 93b7cbfa65
commit a7f23f5019
5 changed files with 51 additions and 6 deletions

View File

@@ -346,7 +346,9 @@ void SILGenFunction::bindParametersForForwarding(const ParameterList *params,
}
}
static void emitCaptureArguments(SILGenFunction &gen, CapturedValue capture,
static void emitCaptureArguments(SILGenFunction &gen,
AnyFunctionRef closure,
CapturedValue capture,
unsigned ArgNo) {
auto *VD = capture.getDecl();
@@ -359,7 +361,12 @@ static void emitCaptureArguments(SILGenFunction &gen, CapturedValue capture,
auto interfaceType = cast<VarDecl>(VD)->getInterfaceType();
if (!interfaceType->hasTypeParameter()) return interfaceType;
auto genericEnv = gen.F.getGenericEnvironment();
// NB: The generic signature may be elided from the lowered function type
// if the function is in a fully-specialized context, but we still need to
// canonicalize references to the generic parameters that may appear in
// non-canonical types in that context. We need the original generic
// environment from the AST for that.
auto genericEnv = closure.getGenericEnvironment();
return genericEnv->mapTypeIntoContext(gen.F.getModule().getSwiftModule(),
interfaceType);
};
@@ -448,7 +455,7 @@ void SILGenFunction::emitProlog(AnyFunctionRef TheClosure,
return;
}
emitCaptureArguments(*this, capture, ++ArgNo);
emitCaptureArguments(*this, TheClosure, capture, ++ArgNo);
}
}