Skip to content

Commit 0cdc476

Browse files
slavapestovjtbandes
authored andcommitted
Sema: Clarify @escaping code based on code review feedback, NFC
1 parent 9193abf commit 0cdc476

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,9 +1410,9 @@ static bool isDefaultNoEscapeContext(const DeclContext *DC) {
14101410
}
14111411

14121412
// Hack to apply context-specific @escaping to an AST function type.
1413-
static Type adjustFunctionExtInfo(DeclContext *DC,
1414-
Type ty,
1415-
TypeResolutionOptions options) {
1413+
static Type applyNonEscapingFromContext(DeclContext *DC,
1414+
Type ty,
1415+
TypeResolutionOptions options) {
14161416
// Remember whether this is a function parameter.
14171417
bool isFunctionParam =
14181418
options.contains(TR_FunctionInput) ||
@@ -1426,7 +1426,11 @@ static Type adjustFunctionExtInfo(DeclContext *DC,
14261426
if (defaultNoEscape && !extInfo.isNoEscape()) {
14271427
extInfo = extInfo.withNoEscape();
14281428

1429-
// We lost the sugar to flip the isNoEscape bit
1429+
// We lost the sugar to flip the isNoEscape bit.
1430+
//
1431+
// FIXME: It would be better to add a new AttributedType sugared type,
1432+
// which would wrap the NameAliasType or ParenType, and apply the
1433+
// isNoEscape bit when de-sugaring.
14301434
return FunctionType::get(funcTy->getInput(), funcTy->getResult(), extInfo);
14311435
}
14321436

@@ -1467,7 +1471,7 @@ Type TypeChecker::resolveIdentifierType(
14671471
// Hack to apply context-specific @escaping to a typealias with an underlying
14681472
// function type.
14691473
if (result->is<FunctionType>())
1470-
result = adjustFunctionExtInfo(DC, result, options);
1474+
result = applyNonEscapingFromContext(DC, result, options);
14711475

14721476
// We allow a type to conform to a protocol that is less available than
14731477
// the type itself. This enables a type to retroactively model or directly
@@ -1716,7 +1720,7 @@ Type TypeResolver::resolveType(TypeRepr *repr, TypeResolutionOptions options) {
17161720
// Default non-escaping for closure parameters
17171721
auto result = resolveASTFunctionType(cast<FunctionTypeRepr>(repr), options);
17181722
if (result && result->is<FunctionType>())
1719-
return adjustFunctionExtInfo(DC, result, options);
1723+
return applyNonEscapingFromContext(DC, result, options);
17201724
return result;
17211725
}
17221726
return resolveSILFunctionType(cast<FunctionTypeRepr>(repr), options);
@@ -1973,10 +1977,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
19731977
.fixItReplace(resultRange, "Never");
19741978
}
19751979

1976-
if (attrs.has(TAK_noescape)) {
1977-
// FIXME: diagnostic to tell user this is redundant and drop it
1978-
}
1979-
19801980
// Resolve the function type directly with these attributes.
19811981
FunctionType::ExtInfo extInfo(rep,
19821982
attrs.has(TAK_autoclosure),
@@ -2016,7 +2016,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20162016
attrs.clearAttribute(TAK_escaping);
20172017
} else {
20182018
// No attribute; set the isNoEscape bit if we're in parameter context.
2019-
ty = adjustFunctionExtInfo(DC, ty, options);
2019+
ty = applyNonEscapingFromContext(DC, ty, options);
20202020
}
20212021
}
20222022

@@ -2034,6 +2034,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20342034
}
20352035
}
20362036
} else if (hasFunctionAttr && fnRepr) {
2037+
// Remove the function attributes from the set so that we don't diagnose.
20372038
for (auto i : FunctionAttrs)
20382039
attrs.clearAttribute(i);
20392040
attrs.convention = None;
@@ -2484,6 +2485,11 @@ Type TypeResolver::resolveTupleType(TupleTypeRepr *repr,
24842485

24852486
// If this is the top level of a function input list, peel off the
24862487
// ImmediateFunctionInput marker and install a FunctionInput one instead.
2488+
//
2489+
// If we have a single ParenType though, don't clear these bits; we
2490+
// still want to parse the type contained therein as if it were in
2491+
// parameter position, meaning function types are not @escaping by
2492+
// default.
24872493
auto elementOptions = options;
24882494
if (!repr->isParenType()) {
24892495
elementOptions = withoutContext(elementOptions);

0 commit comments

Comments
 (0)