Skip to content

Commit 2f98bb1

Browse files
committed
Address review feedback
1 parent 14a3530 commit 2f98bb1

File tree

6 files changed

+25
-29
lines changed

6 files changed

+25
-29
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
10151015

10161016
GenericTypeToArchetypeResolver resolver(closure);
10171017

1018-
if (TC.typeCheckParameterList(PL, DC, options, resolver, true)) {
1018+
if (TC.typeCheckParameterList(PL, DC, options, resolver)) {
10191019
closure->setType(ErrorType::get(TC.Context));
10201020

10211021
// If we encounter an error validating the parameter list, don't bail.

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4354,8 +4354,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
43544354
TypeResolutionOptions options;
43554355
options |= TypeResolutionFlags::SubscriptParameters;
43564356

4357-
isInvalid |= TC.typeCheckParameterList(SD->getIndices(), SD, options,
4358-
resolver, false);
4357+
isInvalid |= TC.typeCheckParameterList(SD->getIndices(), SD,
4358+
options,
4359+
resolver);
43594360

43604361
if (isInvalid || SD->isInvalid()) {
43614362
SD->setInterfaceType(ErrorType::get(TC.Context));
@@ -4905,8 +4906,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
49054906
GenericTypeResolver &resolver) {
49064907
bool hadError = false;
49074908
for (auto paramList : fd->getParameterLists()) {
4908-
hadError |= TC.typeCheckParameterList(
4909-
paramList, fd, TypeResolutionOptions(), resolver, fd->hasBody());
4909+
hadError |= TC.typeCheckParameterList(paramList, fd,
4910+
TypeResolutionOptions(), resolver);
49104911
}
49114912

49124913
return hadError;

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static bool checkGenericFuncSignature(TypeChecker &tc,
506506
for (auto params : func->getParameterLists()) {
507507
// Check the pattern.
508508
if (tc.typeCheckParameterList(params, func, TypeResolutionOptions(),
509-
resolver, func->hasBody()))
509+
resolver))
510510
badType = true;
511511

512512
// Infer requirements from the pattern.
@@ -1004,8 +1004,9 @@ static bool checkGenericSubscriptSignature(TypeChecker &tc,
10041004
auto params = subscript->getIndices();
10051005
TypeResolutionOptions options = TypeResolutionFlags::SubscriptParameters;
10061006

1007-
badType |=
1008-
tc.typeCheckParameterList(params, subscript, options, resolver, false);
1007+
badType |= tc.typeCheckParameterList(params, subscript,
1008+
options,
1009+
resolver);
10091010

10101011
// Infer requirements from the pattern.
10111012
if (builder) {

lib/Sema/TypeCheckPattern.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -780,26 +780,21 @@ static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
780780
void TypeChecker::requestRequiredNominalTypeLayoutForParameters(
781781
ParameterList *PL) {
782782
for (auto param : *PL) {
783-
auto type = param->hasType() ? param->getType()->getCanonicalType()
784-
: param->getTypeLoc().getType();
785-
if (!type)
786-
continue;
787-
if (auto *generic = dyn_cast<BoundGenericType>(type.getPointer())) {
788-
// Generic types are sources for typemetadata and conformances. If a
789-
// parameter is of dependent type then the body of a function with said
790-
// parameter could potentially require the generic type's layout to
791-
// recover them.
792-
if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(generic->getDecl())) {
793-
requestNominalLayout(nominalDecl);
794-
}
783+
// Generic types are sources for typemetadata and conformances. If a
784+
// parameter is of dependent type then the body of a function with said
785+
// parameter could potentially require the generic type's layout to
786+
// recover them.
787+
if (auto *nominalDecl = dyn_cast_or_null<NominalTypeDecl>(
788+
param->getType()->getAnyGeneric())) {
789+
requestNominalLayout(nominalDecl);
795790
}
796791
}
797792
}
798793

799794
/// Type check a parameter list.
800-
bool TypeChecker::typeCheckParameterList(
801-
ParameterList *PL, DeclContext *DC, TypeResolutionOptions options,
802-
GenericTypeResolver &resolver, bool bodyCouldRequireTypeOrConformance) {
795+
bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
796+
TypeResolutionOptions options,
797+
GenericTypeResolver &resolver) {
803798
bool hadError = false;
804799

805800
for (auto param : *PL) {
@@ -844,9 +839,6 @@ bool TypeChecker::typeCheckParameterList(
844839
}
845840
}
846841
}
847-
848-
if (!hadError && bodyCouldRequireTypeOrConformance)
849-
requestRequiredNominalTypeLayoutForParameters(PL);
850842

851843
return hadError;
852844
}

lib/Sema/TypeCheckStmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,9 @@ bool TypeChecker::typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD) {
14261426
if (DebugTimeFunctionBodies || WarnLongFunctionBodies)
14271427
timer.emplace(AFD, DebugTimeFunctionBodies, WarnLongFunctionBodies);
14281428

1429+
for (auto paramList : AFD->getParameterLists())
1430+
requestRequiredNominalTypeLayoutForParameters(paramList);
1431+
14291432
if (typeCheckAbstractFunctionBodyUntil(AFD, SourceLoc()))
14301433
return true;
14311434

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,9 +1816,8 @@ class TypeChecker final : public LazyResolver {
18161816
/// Type check a parameter list.
18171817
bool typeCheckParameterList(ParameterList *PL, DeclContext *dc,
18181818
TypeResolutionOptions options,
1819-
GenericTypeResolver &resolver,
1820-
bool bodyCouldRequireTypeOrConformance);
1821-
1819+
GenericTypeResolver &resolver);
1820+
18221821
/// Coerce a pattern to the given type.
18231822
///
18241823
/// \param P The pattern, which may be modified by this coercion.

0 commit comments

Comments
 (0)