Skip to content

Commit 54033af

Browse files
committed
Sema: Clean up TypeChecker::computeCaptures(), NFC
Just a cleanup for now, but actually has correctness implications when combined with upcoming patches.
1 parent d67c730 commit 54033af

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

lib/Sema/TypeCheckExpr.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,30 +1064,16 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
10641064
}
10651065
}
10661066

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.
10711070
//
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())) {
10911077
AFR.getCaptureInfo().setGenericParamCaptures(GenericParamCaptures);
10921078
}
10931079

0 commit comments

Comments
 (0)