@@ -1934,11 +1934,7 @@ void updateResultTypeForForeignInfo(
1934
1934
llvm_unreachable (" unhandled kind" );
1935
1935
}
1936
1936
1937
- // / Lower any/all capture context parameters.
1938
- // /
1939
- // / *NOTE* Currently default arg generators can not capture anything.
1940
- // / If we ever add that ability, it will be a different capture list
1941
- // / from the function to which the argument is attached.
1937
+ // / Captured values become SIL function parameters in this function.
1942
1938
static void
1943
1939
lowerCaptureContextParameters (TypeConverter &TC, SILDeclRef function,
1944
1940
CanGenericSignature genericSig,
@@ -1962,28 +1958,38 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
1962
1958
// signature from the AST for that.
1963
1959
auto origGenericSig = function.getAnyFunctionRef ()->getGenericSignature ();
1964
1960
auto loweredCaptures = TC.getLoweredLocalCaptures (function);
1961
+ auto capturedEnvs = loweredCaptures.getGenericEnvironments ();
1965
1962
auto *isolatedParam = loweredCaptures.getIsolatedParamCapture ();
1966
1963
1964
+ auto mapTypeOutOfContext = [&](Type t) -> CanType {
1965
+ LLVM_DEBUG (llvm::dbgs () << " -- capture with contextual type " << t << " \n " );
1966
+
1967
+ t = t.subst (MapLocalArchetypesOutOfContext (origGenericSig, capturedEnvs),
1968
+ MakeAbstractConformanceForGenericType (),
1969
+ SubstFlags::PreservePackExpansionLevel);
1970
+
1971
+ LLVM_DEBUG (llvm::dbgs () << " -- maps to " << t->getCanonicalType () << " \n " );
1972
+ return t->getCanonicalType ();
1973
+ };
1974
+
1967
1975
for (auto capture : loweredCaptures.getCaptures ()) {
1968
1976
if (capture.isDynamicSelfMetadata ()) {
1969
1977
ParameterConvention convention = ParameterConvention::Direct_Unowned;
1970
1978
auto dynamicSelfInterfaceType =
1971
- loweredCaptures.getDynamicSelfType ()-> mapTypeOutOfContext ( );
1979
+ mapTypeOutOfContext ( loweredCaptures.getDynamicSelfType ());
1972
1980
1973
- auto selfMetatype = MetatypeType ::get (dynamicSelfInterfaceType,
1974
- MetatypeRepresentation::Thick);
1981
+ auto selfMetatype = CanMetatypeType ::get (dynamicSelfInterfaceType,
1982
+ MetatypeRepresentation::Thick);
1975
1983
1976
- auto canSelfMetatype = selfMetatype->getReducedType (origGenericSig);
1977
- SILParameterInfo param (canSelfMetatype, convention);
1984
+ SILParameterInfo param (selfMetatype, convention);
1978
1985
inputs.push_back (param);
1979
1986
1980
1987
continue ;
1981
1988
}
1982
1989
1983
1990
if (capture.isOpaqueValue ()) {
1984
1991
OpaqueValueExpr *opaqueValue = capture.getOpaqueValue ();
1985
- auto canType = opaqueValue->getType ()->mapTypeOutOfContext ()
1986
- ->getReducedType (origGenericSig);
1992
+ auto canType = mapTypeOutOfContext (opaqueValue->getType ());
1987
1993
auto &loweredTL =
1988
1994
TC.getTypeLowering (AbstractionPattern (genericSig, canType),
1989
1995
canType, expansion);
@@ -2001,9 +2007,16 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
2001
2007
continue ;
2002
2008
}
2003
2009
2004
- auto *varDecl = capture.getDecl ();
2005
- auto type = varDecl->getInterfaceType ();
2006
- auto canType = type->getReducedType (origGenericSig);
2010
+ auto *varDecl = cast<VarDecl>(capture.getDecl ());
2011
+
2012
+ auto type = varDecl->getTypeInContext ();
2013
+ assert (!type->hasLocalArchetype () ||
2014
+ (genericSig && origGenericSig &&
2015
+ !genericSig->isEqual (origGenericSig)));
2016
+ type = mapTypeOutOfContext (type);
2017
+
2018
+ auto canType = type->getReducedType (
2019
+ genericSig ? genericSig : origGenericSig);
2007
2020
2008
2021
auto options = SILParameterInfo::Options ();
2009
2022
if (isolatedParam == varDecl) {
0 commit comments