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

@@ -113,8 +113,8 @@ Solution::computeSubstitutions(GenericSignature sig,
}
// FIXME: Retrieve the conformance from the solution itself.
return TypeChecker::conformsToProtocol(replacement, protoType,
getConstraintSystem().DC->getParentModule());
return getConstraintSystem().DC->getParentModule()->checkConformance(
replacement, protoType);
};
return SubstitutionMap::get(sig,
@@ -565,7 +565,7 @@ namespace {
// the protocol requirement with Self == the concrete type, and SILGen
// (or later) can devirtualize as appropriate.
auto conformance =
TypeChecker::conformsToProtocol(baseTy, proto, dc->getParentModule());
dc->getParentModule()->checkConformance(baseTy, proto);
if (conformance.isConcrete()) {
if (auto witness = conformance.getConcrete()->getWitnessDecl(decl)) {
bool isMemberOperator = witness->getDeclContext()->isTypeContext();
@@ -2459,9 +2459,7 @@ namespace {
// Try to find the conformance of the value type to _BridgedToObjectiveC.
auto bridgedToObjectiveCConformance
= TypeChecker::conformsToProtocol(valueType,
bridgedProto,
dc->getParentModule());
= dc->getParentModule()->checkConformance(valueType, bridgedProto);
FuncDecl *fn = nullptr;
@@ -2722,7 +2720,7 @@ namespace {
ProtocolDecl *protocol = TypeChecker::getProtocol(
ctx, expr->getLoc(), KnownProtocolKind::ExpressibleByStringLiteral);
if (!TypeChecker::conformsToProtocol(type, protocol, dc->getParentModule())) {
if (!dc->getParentModule()->checkConformance(type, protocol)) {
// If the type does not conform to ExpressibleByStringLiteral, it should
// be ExpressibleByExtendedGraphemeClusterLiteral.
protocol = TypeChecker::getProtocol(
@@ -2731,7 +2729,7 @@ namespace {
isStringLiteral = false;
isGraphemeClusterLiteral = true;
}
if (!TypeChecker::conformsToProtocol(type, protocol, dc->getParentModule())) {
if (!dc->getParentModule()->checkConformance(type, protocol)) {
// ... or it should be ExpressibleByUnicodeScalarLiteral.
protocol = TypeChecker::getProtocol(
cs.getASTContext(), expr->getLoc(),
@@ -2846,7 +2844,7 @@ namespace {
assert(proto && "Missing string interpolation protocol?");
auto conformance =
TypeChecker::conformsToProtocol(type, proto, dc->getParentModule());
dc->getParentModule()->checkConformance(type, proto);
assert(conformance && "string interpolation type conforms to protocol");
DeclName constrName(ctx, DeclBaseName::createConstructor(), argLabels);
@@ -2987,8 +2985,7 @@ namespace {
auto proto = TypeChecker::getLiteralProtocol(ctx, expr);
assert(proto && "Missing object literal protocol?");
auto conformance =
TypeChecker::conformsToProtocol(conformingType, proto,
dc->getParentModule());
dc->getParentModule()->checkConformance(conformingType, proto);
assert(conformance && "object literal type conforms to protocol");
auto constrName = TypeChecker::getObjectLiteralConstructorName(ctx, expr);
@@ -3686,8 +3683,7 @@ namespace {
assert(arrayProto && "type-checked array literal w/o protocol?!");
auto conformance =
TypeChecker::conformsToProtocol(arrayTy, arrayProto,
dc->getParentModule());
dc->getParentModule()->checkConformance(arrayTy, arrayProto);
assert(conformance && "Type does not conform to protocol?");
DeclName name(ctx, DeclBaseName::createConstructor(),
@@ -3733,8 +3729,7 @@ namespace {
KnownProtocolKind::ExpressibleByDictionaryLiteral);
auto conformance =
TypeChecker::conformsToProtocol(dictionaryTy, dictionaryProto,
dc->getParentModule());
dc->getParentModule()->checkConformance(dictionaryTy, dictionaryProto);
if (conformance.isInvalid())
return nullptr;
@@ -5345,8 +5340,7 @@ namespace {
// verified by the solver, we just need to get it again
// with all of the generic parameters resolved.
auto hashableConformance =
TypeChecker::conformsToProtocol(indexType, hashable,
dc->getParentModule());
dc->getParentModule()->checkConformance(indexType, hashable);
assert(hashableConformance);
conformances.push_back(hashableConformance);
@@ -6905,8 +6899,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
// Find the conformance of the source type to Hashable.
auto hashable = ctx.getProtocol(KnownProtocolKind::Hashable);
auto conformance =
TypeChecker::conformsToProtocol(
cs.getType(expr), hashable, dc->getParentModule());
dc->getParentModule()->checkConformance(
cs.getType(expr), hashable);
assert(conformance && "must conform to Hashable");
return cs.cacheType(
@@ -7692,8 +7686,8 @@ Expr *ExprRewriter::convertLiteralInPlace(
// Check whether this literal type conforms to the builtin protocol. If so,
// initialize via the builtin protocol.
if (builtinProtocol) {
auto builtinConformance = TypeChecker::conformsToProtocol(
type, builtinProtocol, dc->getParentModule());
auto builtinConformance = dc->getParentModule()->checkConformance(
type, builtinProtocol);
if (builtinConformance) {
// Find the witness that we'll use to initialize the type via a builtin
// literal.
@@ -7716,8 +7710,7 @@ Expr *ExprRewriter::convertLiteralInPlace(
// This literal type must conform to the (non-builtin) protocol.
assert(protocol && "requirements should have stopped recursion");
auto conformance = TypeChecker::conformsToProtocol(type, protocol,
dc->getParentModule());
auto conformance = dc->getParentModule()->checkConformance(type, protocol);
assert(conformance && "must conform to literal protocol");
// Dig out the literal type and perform a builtin literal conversion to it.
@@ -7841,8 +7834,7 @@ std::pair<Expr *, ArgumentList *> ExprRewriter::buildDynamicCallable(
auto dictLitProto =
ctx.getProtocol(KnownProtocolKind::ExpressibleByDictionaryLiteral);
auto conformance =
TypeChecker::conformsToProtocol(argumentType, dictLitProto,
dc->getParentModule());
dc->getParentModule()->checkConformance(argumentType, dictLitProto);
auto keyType = conformance.getTypeWitnessByName(argumentType, ctx.Id_Key);
auto valueType =
conformance.getTypeWitnessByName(argumentType, ctx.Id_Value);
@@ -9192,8 +9184,8 @@ static llvm::Optional<SequenceIterationInfo> applySolutionToForEachStmt(
parsedSequence, LocatorPathElt::ContextualType(CTP_ForEachSequence));
type = Type(solution.OpenedExistentialTypes[contextualLoc]);
}
auto sequenceConformance = TypeChecker::conformsToProtocol(
type, sequenceProto, dc->getParentModule());
auto sequenceConformance = dc->getParentModule()->checkConformance(
type, sequenceProto);
assert(!sequenceConformance.isInvalid() &&
"Couldn't find sequence conformance");
stmt->setSequenceConformance(sequenceConformance);