mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user