Skip to content

Commit 69dc77f

Browse files
committed
[NFC] Refactor resolveASTFunctionTypeParams
Directly return the parameter vector, and handle missing types the same way we handle error types.
1 parent 26ee5d5 commit 69dc77f

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,12 +1725,9 @@ namespace {
17251725
= nullptr,
17261726
DifferentiabilityKind diffKind
17271727
= DifferentiabilityKind::NonDifferentiable);
1728-
bool
1729-
resolveASTFunctionTypeParams(TupleTypeRepr *inputRepr,
1730-
TypeResolutionOptions options,
1731-
bool requiresMappingOut,
1732-
DifferentiabilityKind diffKind,
1733-
SmallVectorImpl<AnyFunctionType::Param> &ps);
1728+
SmallVector<AnyFunctionType::Param, 8> resolveASTFunctionTypeParams(
1729+
TupleTypeRepr *inputRepr, TypeResolutionOptions options,
1730+
bool requiresMappingOut, DifferentiabilityKind diffKind);
17341731

17351732
Type resolveSILFunctionType(FunctionTypeRepr *repr,
17361733
TypeResolutionOptions options,
@@ -2453,10 +2450,12 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
24532450
return ty;
24542451
}
24552452

2456-
bool TypeResolver::resolveASTFunctionTypeParams(
2457-
TupleTypeRepr *inputRepr, TypeResolutionOptions options,
2458-
bool requiresMappingOut, DifferentiabilityKind diffKind,
2459-
SmallVectorImpl<AnyFunctionType::Param> &elements) {
2453+
SmallVector<AnyFunctionType::Param, 8>
2454+
TypeResolver::resolveASTFunctionTypeParams(TupleTypeRepr *inputRepr,
2455+
TypeResolutionOptions options,
2456+
bool requiresMappingOut,
2457+
DifferentiabilityKind diffKind) {
2458+
SmallVector<AnyFunctionType::Param, 8> elements;
24602459
elements.reserve(inputRepr->getNumElements());
24612460

24622461
auto elementOptions = options.withoutContext(true);
@@ -2477,9 +2476,7 @@ bool TypeResolver::resolveASTFunctionTypeParams(
24772476
}
24782477

24792478
Type ty = resolveType(eltTypeRepr, thisElementOptions);
2480-
if (!ty) return true;
2481-
2482-
if (ty->hasError()) {
2479+
if (!ty || ty->hasError()) {
24832480
elements.emplace_back(ErrorType::get(Context));
24842481
continue;
24852482
}
@@ -2573,7 +2570,7 @@ bool TypeResolver::resolveASTFunctionTypeParams(
25732570
}
25742571
}
25752572

2576-
return false;
2573+
return elements;
25772574
}
25782575

25792576
Type TypeResolver::resolveOpaqueReturnType(TypeRepr *repr,
@@ -2626,18 +2623,16 @@ Type TypeResolver::resolveASTFunctionType(
26262623

26272624
TypeResolutionOptions options = None;
26282625
options |= parentOptions.withoutContext().getFlags();
2629-
2630-
SmallVector<AnyFunctionType::Param, 8> params;
2631-
if (resolveASTFunctionTypeParams(repr->getArgsTypeRepr(), options,
2632-
repr->getGenericEnvironment() != nullptr,
2633-
diffKind, params)) {
2634-
return Type();
2635-
}
2626+
auto params = resolveASTFunctionTypeParams(
2627+
repr->getArgsTypeRepr(), options,
2628+
repr->getGenericEnvironment() != nullptr, diffKind);
26362629

26372630
auto resultOptions = options.withoutContext();
26382631
resultOptions.setContext(TypeResolverContext::FunctionResult);
26392632
Type outputTy = resolveType(repr->getResultTypeRepr(), resultOptions);
2640-
if (!outputTy || outputTy->hasError()) return outputTy;
2633+
if (!outputTy || outputTy->hasError()) {
2634+
return ErrorType::get(Context);
2635+
}
26412636

26422637
// If this is a function type without parens around the parameter list,
26432638
// diagnose this and produce a fixit to add them.

0 commit comments

Comments
 (0)