AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance()

This commit is contained in:
Slava Pestov
2024-01-16 15:18:44 -05:00
parent 1e950b1725
commit 14d1fcb51a
35 changed files with 151 additions and 193 deletions

View File

@@ -83,8 +83,8 @@ getStoredPropertiesForDifferentiation(
if (vd->getInterfaceType()->hasError())
continue;
auto varType = DC->mapTypeIntoContext(vd->getValueInterfaceType());
auto conformance = TypeChecker::conformsToProtocol(
varType, diffableProto, DC->getParentModule());
auto conformance = DC->getParentModule()->checkConformance(
varType, diffableProto);
if (!conformance)
continue;
// Skip `let` stored properties with a mutating `move(by:)` if requested.
@@ -117,8 +117,7 @@ static Type getTangentVectorInterfaceType(Type contextualType,
auto *diffableProto = C.getProtocol(KnownProtocolKind::Differentiable);
assert(diffableProto && "`Differentiable` protocol not found");
auto conf =
TypeChecker::conformsToProtocol(contextualType, diffableProto,
DC->getParentModule());
DC->getParentModule()->checkConformance(contextualType, diffableProto);
assert(conf && "Contextual type must conform to `Differentiable`");
if (!conf)
return nullptr;
@@ -140,8 +139,7 @@ static bool canDeriveTangentVectorAsSelf(NominalTypeDecl *nominal,
auto *diffableProto = C.getProtocol(KnownProtocolKind::Differentiable);
auto *addArithProto = C.getProtocol(KnownProtocolKind::AdditiveArithmetic);
// `Self` must conform to `AdditiveArithmetic`.
if (!TypeChecker::conformsToProtocol(nominalTypeInContext, addArithProto,
DC->getParentModule()))
if (!DC->getParentModule()->checkConformance(nominalTypeInContext, addArithProto))
return false;
for (auto *field : nominal->getStoredProperties()) {
// `Self` must not have any `@noDerivative` stored properties.
@@ -149,8 +147,7 @@ static bool canDeriveTangentVectorAsSelf(NominalTypeDecl *nominal,
return false;
// `Self` must have all stored properties satisfy `Self == TangentVector`.
auto fieldType = DC->mapTypeIntoContext(field->getValueInterfaceType());
auto conf = TypeChecker::conformsToProtocol(fieldType, diffableProto,
DC->getParentModule());
auto conf = DC->getParentModule()->checkConformance(fieldType, diffableProto);
if (!conf)
return false;
auto tangentType = conf.getTypeWitnessByName(fieldType, C.Id_TangentVector);
@@ -213,8 +210,7 @@ bool DerivedConformance::canDeriveDifferentiable(NominalTypeDecl *nominal,
if (v->getInterfaceType()->hasError())
return false;
auto varType = DC->mapTypeIntoContext(v->getValueInterfaceType());
return (bool)TypeChecker::conformsToProtocol(varType, diffableProto,
DC->getParentModule());
return (bool) DC->getParentModule()->checkConformance(varType, diffableProto);
});
}
@@ -556,8 +552,7 @@ static void checkAndDiagnoseImplicitNoDerivative(ASTContext &Context,
// Check whether to diagnose stored property.
auto varType = DC->mapTypeIntoContext(vd->getValueInterfaceType());
auto diffableConformance =
TypeChecker::conformsToProtocol(varType, diffableProto,
DC->getParentModule());
DC->getParentModule()->checkConformance(varType, diffableProto);
// If stored property should not be diagnosed, continue.
if (diffableConformance &&
canInvokeMoveByOnProperty(vd, diffableConformance))