Merge remote-tracking branch 'origin/main' into 20230929-merge-rebranch

Conflicts:
  - `CMakeLists.txt` caused by the extra `-D` added in rebranch to
    reduce the number of deprecation warnings.
  - `lib/Frontend/PrintingDiagnosticConsumer.cpp` caused by the removal
    of one of the `#if SWIFT_SWIFT_PARSER` on rebranch (probably should
    have been done on main).
This commit is contained in:
Ben Barham
2023-09-29 09:50:50 -07:00
42 changed files with 314 additions and 486 deletions

View File

@@ -1197,9 +1197,8 @@ llvm::Optional<Type> ConstraintSystem::isSetType(Type type) {
return llvm::None;
}
Type ConstraintSystem::getFixedTypeRecursive(Type type,
TypeMatchOptions &flags,
bool wantRValue) const {
Type ConstraintSystem::getFixedTypeRecursive(Type type, TypeMatchOptions &flags,
bool wantRValue) {
if (wantRValue)
type = type->getRValueType();
@@ -3827,7 +3826,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
namespace {
struct TypeSimplifier {
const ConstraintSystem &CS;
ConstraintSystem &CS;
llvm::function_ref<Type(TypeVariableType *)> GetFixedTypeFn;
struct ActivePackExpansion {
@@ -3836,7 +3835,7 @@ struct TypeSimplifier {
};
SmallVector<ActivePackExpansion, 4> ActivePackExpansions;
TypeSimplifier(const ConstraintSystem &CS,
TypeSimplifier(ConstraintSystem &CS,
llvm::function_ref<Type(TypeVariableType *)> getFixedTypeFn)
: CS(CS), GetFixedTypeFn(getFixedTypeFn) {}
@@ -3984,8 +3983,7 @@ struct TypeSimplifier {
if (lookupBaseType->mayHaveMembers() ||
lookupBaseType->is<PackType>()) {
auto *proto = assocType->getProtocol();
auto conformance = CS.DC->getParentModule()->lookupConformance(
lookupBaseType, proto);
auto conformance = CS.lookupConformance(lookupBaseType, proto);
if (!conformance) {
// If the base type doesn't conform to the associatedtype's protocol,
// there will be a missing conformance fix applied in diagnostic mode,
@@ -4016,11 +4014,11 @@ struct TypeSimplifier {
} // end anonymous namespace
Type ConstraintSystem::simplifyTypeImpl(Type type,
llvm::function_ref<Type(TypeVariableType *)> getFixedTypeFn) const {
llvm::function_ref<Type(TypeVariableType *)> getFixedTypeFn) {
return type.transform(TypeSimplifier(*this, getFixedTypeFn));
}
Type ConstraintSystem::simplifyType(Type type) const {
Type ConstraintSystem::simplifyType(Type type) {
if (!type->hasTypeVariable())
return type;
@@ -6103,15 +6101,12 @@ bool constraints::hasAppliedSelf(const OverloadChoice &choice,
/// Check whether given type conforms to `RawRepresentable` protocol
/// and return the witness type.
Type constraints::isRawRepresentable(ConstraintSystem &cs, Type type) {
auto *DC = cs.DC;
auto rawReprType = TypeChecker::getProtocol(
cs.getASTContext(), SourceLoc(), KnownProtocolKind::RawRepresentable);
if (!rawReprType)
return Type();
auto conformance = TypeChecker::conformsToProtocol(type, rawReprType,
DC->getParentModule());
auto conformance = cs.lookupConformance(type, rawReprType);
if (conformance.isInvalid())
return Type();
@@ -7347,6 +7342,21 @@ bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const {
return true;
}
ProtocolConformanceRef
ConstraintSystem::lookupConformance(Type type, ProtocolDecl *protocol) {
auto cacheKey = std::make_pair(type.getPointer(), protocol);
auto cachedConformance = Conformances.find(cacheKey);
if (cachedConformance != Conformances.end())
return cachedConformance->second;
auto conformance =
DC->getParentModule()->lookupConformance(type, protocol,
/*allowMissing=*/true);
Conformances[cacheKey] = conformance;
return conformance;
}
TypeVarBindingProducer::TypeVarBindingProducer(BindingSet &bindings)
: BindingProducer(bindings.getConstraintSystem(),
bindings.getTypeVariable()->getImpl().getLocator()),
@@ -7479,7 +7489,7 @@ bool TypeVarBindingProducer::requiresOptionalAdjustment(
auto *proto = CS.getASTContext().getProtocol(
KnownProtocolKind::ExpressibleByNilLiteral);
return !proto->getParentModule()->lookupConformance(type, proto);
return !CS.lookupConformance(type, proto);
} else if (binding.isDefaultableBinding() && binding.BindingType->isAny()) {
return true;
}