@@ -1064,30 +1064,16 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
1064
1064
}
1065
1065
}
1066
1066
1067
- // We don't distinguish inner from outer generic parameters yet, but also
1068
- // nested generics are not really supported by the rest of the compiler.
1069
- // There are three cases where getGenericSignatureOfContext() returns a
1070
- // non-null value:
1067
+ // Since nested generic functions are not supported yet, the only case where
1068
+ // generic parameters can be captured is by closures and non-generic local
1069
+ // functions.
1071
1070
//
1072
- // 1) Top-level generic functions
1073
- // 2) Methods with a generic signature either on the type or the method
1074
- // 3) Local generic functions
1075
- //
1076
- // But *not*
1077
- //
1078
- // 4) Closure or non-generic local function inside a generic context
1079
- //
1080
- // In case 1) and 2), usages of generic type parameters are never formally
1081
- // "captures". In case 3), the only way a generic type parameter can be
1082
- // captured is if the local generic function is itself nested inside a generic
1083
- // context. However, SILGen does not currently support this anyway.
1084
- //
1085
- // So we only set GenericParamCaptures in case 4), to avoid confusing SILGen.
1086
- // Eventually, the computation in checkType() will be more exact and this
1087
- // conditional should be removed.
1088
- if (!(AFR.getAbstractFunctionDecl () &&
1089
- AFR.getAbstractFunctionDecl ()->hasType () &&
1090
- AFR.getAbstractFunctionDecl ()->getGenericSignatureOfContext ())) {
1071
+ // So we only set GenericParamCaptures if we have a closure, or a
1072
+ // non-generic function defined inside a local context.
1073
+ auto *AFD = AFR.getAbstractFunctionDecl ();
1074
+ if (!AFD ||
1075
+ (!AFD->getGenericParams () &&
1076
+ AFD->getDeclContext ()->isLocalContext ())) {
1091
1077
AFR.getCaptureInfo ().setGenericParamCaptures (GenericParamCaptures);
1092
1078
}
1093
1079
0 commit comments