diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 6de9ab2c47e90..26b7bca21988f 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -1044,7 +1044,6 @@ class ASTContext final { // Builtin type and simple types that are used frequently. const CanType TheErrorType; /// This is the ErrorType singleton. - const CanType TheUnresolvedType; /// This is the UnresolvedType singleton. const CanType TheEmptyTupleType; /// This is '()', aka Void const CanType TheEmptyPackType; const CanType TheAnyType; /// This is 'Any', the empty protocol composition diff --git a/include/swift/AST/TypeMatcher.h b/include/swift/AST/TypeMatcher.h index ab6d90eb2190d..31ac8e6ab299d 100644 --- a/include/swift/AST/TypeMatcher.h +++ b/include/swift/AST/TypeMatcher.h @@ -117,12 +117,6 @@ class TypeMatcher { #define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type) #include "swift/AST/TypeNodes.def" - bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType, - Type sugaredFirstType) { - // Unresolved types never match. - return mismatch(firstType.getPointer(), secondType, sugaredFirstType); - } - bool visitTupleType(CanTupleType firstTuple, Type secondType, Type sugaredFirstType) { if (auto secondTuple = secondType->getAs()) { diff --git a/include/swift/AST/TypeNodes.def b/include/swift/AST/TypeNodes.def index b910f88e33e5f..ec990d09eec8b 100644 --- a/include/swift/AST/TypeNodes.def +++ b/include/swift/AST/TypeNodes.def @@ -123,7 +123,6 @@ #if !defined(SINGLETON_TYPE) TYPE(Error, Type) -UNCHECKED_TYPE(Unresolved, Type) UNCHECKED_TYPE(Placeholder, Type) ABSTRACT_TYPE(Builtin, Type) ABSTRACT_TYPE(AnyBuiltinInteger, BuiltinType) diff --git a/include/swift/AST/TypeTransform.h b/include/swift/AST/TypeTransform.h index e93f07b6b3eee..1305c2695901e 100644 --- a/include/swift/AST/TypeTransform.h +++ b/include/swift/AST/TypeTransform.h @@ -109,7 +109,6 @@ case TypeKind::Id: #define TYPE(Id, Parent) #include "swift/AST/TypeNodes.def" case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::TypeVariable: case TypeKind::Placeholder: case TypeKind::SILToken: diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index da0996d628cd6..a8c017bfc1d41 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -141,24 +141,24 @@ class RecursiveTypeProperties { /// This type expression contains a GenericTypeParamType. HasTypeParameter = 0x04, - /// This type expression contains an UnresolvedType. - HasUnresolvedType = 0x08, - /// Whether this type expression contains an unbound generic type. - HasUnboundGeneric = 0x10, + HasUnboundGeneric = 0x08, /// This type expression contains an LValueType other than as a /// function input, and can be loaded to convert to an rvalue. - IsLValue = 0x20, + IsLValue = 0x10, /// This type expression contains an opened existential ArchetypeType. - HasOpenedExistential = 0x40, + HasOpenedExistential = 0x20, /// This type expression contains a DynamicSelf type. - HasDynamicSelf = 0x80, + HasDynamicSelf = 0x40, /// This type contains an Error type. - HasError = 0x100, + HasError = 0x80, + + /// This type contains an Error type without an underlying original type. + HasBareError = 0x100, /// This type contains a DependentMemberType. HasDependentMember = 0x200, @@ -225,15 +225,15 @@ class RecursiveTypeProperties { /// Does a type with these properties have a type parameter somewhere in it? bool hasTypeParameter() const { return Bits & HasTypeParameter; } - /// Does a type with these properties have an unresolved type somewhere in it? - bool hasUnresolvedType() const { return Bits & HasUnresolvedType; } - /// Is a type with these properties an lvalue? bool isLValue() const { return Bits & IsLValue; } /// Does this type contain an error? bool hasError() const { return Bits & HasError; } + /// Does this type contain an error without an original type? + bool hasBareError() const { return Bits & HasBareError; } + /// Does this type contain a dependent member type, possibly with a /// non-type parameter base, such as a type variable or concrete type? bool hasDependentMember() const { return Bits & HasDependentMember; } @@ -750,11 +750,6 @@ class alignas(1 << TypeAlignInBits) TypeBase /// member root in a type variable. bool isTypeVariableOrMember(); - /// Determine whether this type involves a UnresolvedType. - bool hasUnresolvedType() const { - return getRecursiveProperties().hasUnresolvedType(); - } - /// Determine whether this type involves a \c PlaceholderType. bool hasPlaceholder() const { return getRecursiveProperties().hasPlaceholder(); @@ -949,6 +944,16 @@ class alignas(1 << TypeAlignInBits) TypeBase return getRecursiveProperties().hasError(); } + /// Determine whether this type contains an error type without an + /// underlying original type, i.e prints as `_`. + bool hasBareError() const { + return getRecursiveProperties().hasBareError(); + } + + /// Whether this is a top-level ErrorType without an underlying original + /// type, i.e prints as `_`. + bool isBareErrorType() const; + /// Does this type contain a dependent member type, possibly with a /// non-type parameter base, such as a type variable or concrete type? bool hasDependentMember() const { @@ -1654,11 +1659,18 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(NominalOrBoundGenericNominalType, AnyGenericType) /// have to emit further diagnostics to abort compilation. class ErrorType final : public TypeBase { friend class ASTContext; + + static RecursiveTypeProperties getProperties(Type originalType) { + RecursiveTypeProperties props = RecursiveTypeProperties::HasError; + if (!originalType || originalType->hasBareError()) + props |= RecursiveTypeProperties::HasBareError; + + return props; + } + // The Error type is always canonical. - ErrorType(ASTContext &C, Type originalType, - RecursiveTypeProperties properties) - : TypeBase(TypeKind::Error, &C, properties) { - assert(properties.hasError()); + ErrorType(ASTContext &C, Type originalType) + : TypeBase(TypeKind::Error, &C, getProperties(originalType)) { if (originalType) { Bits.ErrorType.HasOriginalType = true; *reinterpret_cast(this + 1) = originalType; @@ -1689,25 +1701,6 @@ class ErrorType final : public TypeBase { } }; DEFINE_EMPTY_CAN_TYPE_WRAPPER(ErrorType, Type) - -/// UnresolvedType - This represents a type variable that cannot be resolved to -/// a concrete type because the expression is ambiguous. This is produced when -/// parsing expressions and producing diagnostics. Any instance of this should -/// cause the entire expression to be ambiguously typed. -class UnresolvedType : public TypeBase { - friend class ASTContext; - // The Unresolved type is always canonical. - UnresolvedType(ASTContext &C) - : TypeBase(TypeKind::Unresolved, &C, - RecursiveTypeProperties(RecursiveTypeProperties::HasUnresolvedType)) { } -public: - // Implement isa/cast/dyncast/etc. - static bool classof(const TypeBase *T) { - return T->getKind() == TypeKind::Unresolved; - } -}; -DEFINE_EMPTY_CAN_TYPE_WRAPPER(UnresolvedType, Type) - /// BuiltinType - An abstract class for all the builtin types. class BuiltinType : public TypeBase { @@ -8124,6 +8117,17 @@ inline ASTContext &TypeBase::getASTContext() const { return *const_cast(getCanonicalType()->Context); } +inline bool TypeBase::isBareErrorType() const { + auto *errTy = dyn_cast(this); + if (!errTy) + return false; + + // FIXME: We shouldn't need to check for a recursive bare error type, we can + // remove this once we flatten them. + auto originalTy = errTy->getOriginalType(); + return !originalTy || originalTy->isBareErrorType(); +} + // TODO: This will become redundant once InOutType is removed. inline bool TypeBase::isMaterializable() { return !(hasLValueType() || is()); diff --git a/include/swift/IDE/TypeCheckCompletionCallback.h b/include/swift/IDE/TypeCheckCompletionCallback.h index 371c29fe907ba..8432f58afb479 100644 --- a/include/swift/IDE/TypeCheckCompletionCallback.h +++ b/include/swift/IDE/TypeCheckCompletionCallback.h @@ -92,7 +92,7 @@ struct WithSolutionSpecificVarTypesRAII { } else { RestoreVarTypes[var] = Type(); } - if (!ty->hasArchetype() && !ty->hasUnresolvedType()) { + if (!ty->hasArchetype()) { setInterfaceType(const_cast(var), ty); } else { setInterfaceType(const_cast(var), ErrorType::get(ty)); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index a3ed0a899d5c8..d75dea996642a 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -808,10 +808,8 @@ ASTContext::ASTContext( StdlibModuleName(getIdentifier(STDLIB_NAME)), SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)), blockListConfig(SourceMgr), - TheErrorType(new(*this, AllocationArena::Permanent) ErrorType( - *this, Type(), RecursiveTypeProperties::HasError)), - TheUnresolvedType(new(*this, AllocationArena::Permanent) - UnresolvedType(*this)), + TheErrorType(new (*this, AllocationArena::Permanent) + ErrorType(*this, Type())), TheEmptyTupleType(TupleType::get(ArrayRef(), *this)), TheEmptyPackType(PackType::get(*this, {})), TheAnyType(ProtocolCompositionType::theAnyType(*this)), @@ -3637,8 +3635,7 @@ Type ErrorType::get(Type originalType) { void *mem = ctx.Allocate(sizeof(ErrorType) + sizeof(Type), alignof(ErrorType), arena); - return entry = new (mem) ErrorType(ctx, originalType, - RecursiveTypeProperties::HasError); + return entry = new (mem) ErrorType(ctx, originalType); } void ErrorUnionType::Profile(llvm::FoldingSetNodeID &id, ArrayRef terms) { @@ -5859,7 +5856,7 @@ ProtocolConformanceRef ProtocolConformanceRef::forAbstract( case TypeKind::GenericTypeParam: case TypeKind::TypeVariable: case TypeKind::DependentMember: - case TypeKind::Unresolved: + case TypeKind::Error: case TypeKind::Placeholder: case TypeKind::PrimaryArchetype: case TypeKind::PackArchetype: diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 38e59fcd1618e..12b44d41a2a08 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -6062,8 +6062,6 @@ namespace { printFoot(); } - TRIVIAL_TYPE_PRINTER(Unresolved, unresolved) - void visitPlaceholderType(PlaceholderType *T, Label label) { printCommon("placeholder_type", label); auto originator = T->getOriginator(); diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index 053f9b3b15147..fd2a4ad46e26d 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -1417,7 +1417,6 @@ void ASTMangler::appendType(Type type, GenericSignature sig, llvm_unreachable("Cannot mangle module type yet"); case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::Placeholder: appendOperator("Xe"); return; diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 1d5f3af3067a9..80cacbdefbd97 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -6204,14 +6204,6 @@ class TypePrinter : public TypeVisitor>"; - else - Printer << "_"; - } - void visitErrorUnionType(ErrorUnionType *T, NonRecursivePrintOptions nrOptions) { Printer << "error_union("; diff --git a/lib/AST/ConformanceLookup.cpp b/lib/AST/ConformanceLookup.cpp index 3e323a87158a1..4a589f8cf2fda 100644 --- a/lib/AST/ConformanceLookup.cpp +++ b/lib/AST/ConformanceLookup.cpp @@ -609,10 +609,9 @@ LookupConformanceInModuleRequest::evaluate( if (type->isTypeVariableOrMember()) return ProtocolConformanceRef::forAbstract(type, protocol); - // UnresolvedType is a placeholder for an unknown type used when generating - // diagnostics. We consider it to conform to all protocols, since the - // intended type might have. Same goes for PlaceholderType. - if (type->is() || type->is()) + // PlaceholderType is a placeholder for an unknown type. We consider it to + // conform to all protocols, since the intended type might have. + if (type->is()) return ProtocolConformanceRef::forAbstract(type, protocol); // Pack types can conform to protocols. diff --git a/lib/AST/DiagnosticEngine.cpp b/lib/AST/DiagnosticEngine.cpp index 570df75c1dcaa..cf926f713ea80 100644 --- a/lib/AST/DiagnosticEngine.cpp +++ b/lib/AST/DiagnosticEngine.cpp @@ -983,11 +983,10 @@ static void formatDiagnosticArgument(StringRef Modifier, needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions); } - // If a type has an unresolved type, print it with syntax sugar removed for + // If a type has a bare error type, print it with syntax sugar removed for // clarity. For example, print `Array<_>` instead of `[_]`. - if (type->hasUnresolvedType()) { + if (type->hasBareError()) type = type->getWithoutSyntaxSugar(); - } if (needsQualification && isa(type.getPointer()) && diff --git a/lib/AST/SubstitutionMap.cpp b/lib/AST/SubstitutionMap.cpp index 8204ab20f5ad9..772f2976ea358 100644 --- a/lib/AST/SubstitutionMap.cpp +++ b/lib/AST/SubstitutionMap.cpp @@ -519,7 +519,6 @@ void SubstitutionMap::verify(bool allowInvalid) const { !substType->is() && !substType->is() && !substType->isTypeVariableOrMember() && - !substType->is() && !substType->is() && !substType->is()) { ABORT([&](auto &out) { diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 6f5ba55d4637a..1cb25e0025c7a 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -237,7 +237,6 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig, // Nothing else is statically just a class reference. case TypeKind::SILBlockStorage: case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::BuiltinInteger: case TypeKind::BuiltinIntegerLiteral: case TypeKind::BuiltinFloat: @@ -761,7 +760,6 @@ bool TypeBase::hasTypeRepr() const { return !Type(const_cast(this)).findIf([](Type subTy) -> bool { switch (subTy->getKind()) { case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::TypeVariable: return true; @@ -1768,7 +1766,6 @@ CanType TypeBase::computeCanonicalType() { #define TYPE(id, parent) #include "swift/AST/TypeNodes.def" case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::TypeVariable: case TypeKind::Placeholder: case TypeKind::BuiltinTuple: @@ -2318,10 +2315,9 @@ bool TypeBase::mayBeCallable(DeclContext *dc) { return true; // Unresolved types that could potentially be callable. - if (isPlaceholder() || is() || - isTypeParameter() || isTypeVariableOrMember()) { + if (isPlaceholder() || isTypeParameter() || isTypeVariableOrMember()) return true; - } + // Callable nominal types. if (isCallAsFunctionType(dc) || hasDynamicCallableAttribute()) return true; @@ -4568,7 +4564,6 @@ ReferenceCounting TypeBase::getReferenceCounting() { case TypeKind::SILFunction: case TypeKind::SILBlockStorage: case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::BuiltinInteger: case TypeKind::BuiltinIntegerLiteral: case TypeKind::BuiltinFloat: diff --git a/lib/AST/TypeWalker.cpp b/lib/AST/TypeWalker.cpp index 9954fab3ca653..b14330d807a2c 100644 --- a/lib/AST/TypeWalker.cpp +++ b/lib/AST/TypeWalker.cpp @@ -35,7 +35,6 @@ class Traversal : public TypeVisitor TypeWalker &Walker; bool visitErrorType(ErrorType *ty) { return false; } - bool visitUnresolvedType(UnresolvedType *ty) { return false; } bool visitPlaceholderType(PlaceholderType *ty) { return false; } bool visitBuiltinType(BuiltinType *ty) { return false; } bool visitIntegerType(IntegerType *ty) { return false; } diff --git a/lib/ClangImporter/ImportType.cpp b/lib/ClangImporter/ImportType.cpp index 037568715be21..79d469ff55808 100644 --- a/lib/ClangImporter/ImportType.cpp +++ b/lib/ClangImporter/ImportType.cpp @@ -2064,7 +2064,6 @@ class GetSendableType : return pass(ty, /*found=*/true); } - NEVER_VISIT(UnresolvedType) NEVER_VISIT(PlaceholderType) NEVER_VISIT(BuiltinType) NEVER_VISIT(BuiltinTupleType) diff --git a/lib/IDE/ArgumentCompletion.cpp b/lib/IDE/ArgumentCompletion.cpp index 44cd9a2976dbc..1b3ee86346e08 100644 --- a/lib/IDE/ArgumentCompletion.cpp +++ b/lib/IDE/ArgumentCompletion.cpp @@ -201,7 +201,7 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) { } } if (ExpectedCallType && - (ExpectedCallType->hasUnresolvedType() || + (ExpectedCallType->hasError() || ExpectedCallType->hasUnboundGenericType())) { ExpectedCallType = Type(); } diff --git a/lib/IDE/CompletionLookup.cpp b/lib/IDE/CompletionLookup.cpp index 10330fb55c46a..88658c8550869 100644 --- a/lib/IDE/CompletionLookup.cpp +++ b/lib/IDE/CompletionLookup.cpp @@ -693,7 +693,7 @@ Type CompletionLookup::getTypeOfMember(const ValueDecl *VD, Type ExprType) { // For a GenericFunctionType, we only want to substitute the // param/result types, as otherwise we might end up with a bad generic - // signature if there are UnresolvedTypes present in the base type. Note + // signature if there are ErrorTypes present in the base type. Note // we pass in DesugarMemberTypes so that we see the actual concrete type // witnesses instead of type alias types. if (auto *GFT = T->getAs()) { diff --git a/lib/IDE/ConformingMethodList.cpp b/lib/IDE/ConformingMethodList.cpp index c60852a228afd..72987b054504f 100644 --- a/lib/IDE/ConformingMethodList.cpp +++ b/lib/IDE/ConformingMethodList.cpp @@ -123,7 +123,7 @@ void ConformingMethodListCallbacks::readyForTypeChecking(SourceFile *SrcFile) { Type T = Res.Ty; WithSolutionSpecificVarTypesRAII VarType(Res.SolutionSpecificVarTypes); - if (!T || T->is() || T->is()) + if (!T || T->is()) return; T = T->getRValueType(); diff --git a/lib/IDE/PostfixCompletion.cpp b/lib/IDE/PostfixCompletion.cpp index 5f32233aa4632..b4bcd69679b25 100644 --- a/lib/IDE/PostfixCompletion.cpp +++ b/lib/IDE/PostfixCompletion.cpp @@ -420,7 +420,7 @@ void PostfixCompletionCallback::collectResults( // tuple. But that doesn’t really make sense so we shouldn't be suggesting // any operators based on `Void`. if (IncludeOperators && !Result.BaseIsStaticMetaType && - !Result.BaseTy->isVoid() && + !Result.BaseTy->isVoid() && !Result.BaseTy->hasError() && !ProcessedBaseTypes.contains(Result.BaseTy)) { addOperatorResults(Result.BaseTy, Operators, DC, Lookup); } diff --git a/lib/IDE/SelectedOverloadInfo.cpp b/lib/IDE/SelectedOverloadInfo.cpp index 2fbb1c40c04c9..a1f65adca0ae5 100644 --- a/lib/IDE/SelectedOverloadInfo.cpp +++ b/lib/IDE/SelectedOverloadInfo.cpp @@ -56,7 +56,7 @@ swift::ide::getSelectedOverloadInfo(const Solution &S, OverloadChoiceKind::KeyPathApplication) { auto Params = Result.ValueTy->getAs()->getParams(); if (Params.size() == 1 && - Params[0].getPlainType()->is()) { + Params[0].getPlainType()->is()) { auto *KPDecl = CS.getASTContext().getKeyPathDecl(); Type KPTy = KPDecl->mapTypeIntoContext(KPDecl->getDeclaredInterfaceType()); diff --git a/lib/IDE/TypeCheckCompletionCallback.cpp b/lib/IDE/TypeCheckCompletionCallback.cpp index 023b257244010..cfb6ebedd9239 100644 --- a/lib/IDE/TypeCheckCompletionCallback.cpp +++ b/lib/IDE/TypeCheckCompletionCallback.cpp @@ -27,7 +27,7 @@ Type swift::ide::getTypeForCompletion(const constraints::Solution &S, // Use the contextual type, unless it is still unresolved, in which case fall // back to getting the type from the expression. if (auto ContextualType = S.getContextualType(Node)) { - if (!ContextualType->hasUnresolvedType() && + if (!ContextualType->hasError() && !ContextualType->hasUnboundGenericType()) { return ContextualType; } @@ -46,7 +46,7 @@ Type swift::ide::getTypeForCompletion(const constraints::Solution &S, Result = S.getResolvedType(Node); } - if (Result && Result->is()) { + if (Result && Result->is()) { Result = Type(); } return Result; diff --git a/lib/IDE/TypeContextInfo.cpp b/lib/IDE/TypeContextInfo.cpp index 9dfb0fae64a2d..4dad77c2a683a 100644 --- a/lib/IDE/TypeContextInfo.cpp +++ b/lib/IDE/TypeContextInfo.cpp @@ -129,7 +129,7 @@ void ContextInfoCallbacks::readyForTypeChecking(SourceFile *SrcFile) { SmallVector results; for (auto T : TypeCheckCallback.getTypes()) { - if (T->is() || T->is()) + if (T->is()) continue; T = T->getRValueType(); diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index a79c30268bfa8..e8b4f279d1cd7 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -2320,7 +2320,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { // The following types exist primarily for internal use by the type // checker. case TypeKind::Error: - case TypeKind::Unresolved: case TypeKind::LValue: case TypeKind::TypeVariable: case TypeKind::ErrorUnion: diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index b791175be8a39..d51954866b89c 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -105,15 +105,16 @@ Solution::computeSubstitutions(NullablePtr decl, if (openedTypes == OpenedTypes.end()) return SubstitutionMap(); + auto &ctx = getConstraintSystem().getASTContext(); + SmallVector replacementTypes; for (const auto &opened : openedTypes->second) { auto type = getFixedType(opened.second); if (opened.first->isParameterPack()) { if (type->is()) { - auto &ctx = type->getASTContext(); - type = - PackType::get(ctx, {PackExpansionType::get(ctx.TheUnresolvedType, - ctx.TheUnresolvedType)}); + type = PackType::get( + ctx, + {PackExpansionType::get(ErrorType::get(ctx), ErrorType::get(ctx))}); } else if (!type->is()) type = PackType::getSingletonPackExpansion(type); } @@ -126,8 +127,11 @@ Solution::computeSubstitutions(NullablePtr decl, auto replacement = original.subst(IFS); assert(!replacement->is()); - if (replacement->hasError() || - isOpenedAnyObject(replacement) || + if (replacement->hasError()) { + return ProtocolConformanceRef::forAbstract(ErrorType::get(replacement), + protoType); + } + if (isOpenedAnyObject(replacement) || replacement->is()) { return ProtocolConformanceRef::forAbstract(replacement, protoType); } @@ -7218,7 +7222,7 @@ Expr *ConstraintSystem::addImplicitLoadExpr(Expr *expr) { Expr *ExprRewriter::coerceToType(Expr *expr, Type toType, ConstraintLocatorBuilder locator) { - ASSERT(toType && !toType->hasError() && !toType->hasUnresolvedType() && + ASSERT(toType && !toType->hasError() && !toType->hasTypeVariableOrPlaceholder()); // Diagnose conversions to invalid function types that couldn't be performed @@ -10032,8 +10036,7 @@ ConstraintSystem::applySolution(Solution &solution, // unresolved types. { auto isValidType = [&](Type ty) { - return !ty->hasUnresolvedType() && !ty->hasError() && - !ty->hasTypeVariableOrPlaceholder(); + return !ty->hasError() && !ty->hasTypeVariableOrPlaceholder(); }; for (auto &[_, type] : solution.typeBindings) { ASSERT(isValidType(type) && "type binding has invalid type"); diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp index 579e254d5304c..69c2db62c6edc 100644 --- a/lib/Sema/CSBindings.cpp +++ b/lib/Sema/CSBindings.cpp @@ -115,7 +115,6 @@ static bool isGenericParameter(TypeVariableType *TypeVar) { bool PotentialBinding::isViableForJoin() const { return Kind == AllowedBindingKind::Supertypes && !BindingType->hasLValueType() && - !BindingType->hasUnresolvedType() && !BindingType->hasTypeVariable() && !BindingType->hasPlaceholder() && !BindingType->hasUnboundGenericType() && diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index ec6ea6d6d5c68..21bf83540937f 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -100,7 +100,7 @@ Type FailureDiagnostic::resolveType(Type rawType, bool reconstituteSugar, if (auto *typeVar = type->getAs()) { auto resolvedType = S.simplifyType(typeVar); - if (!resolvedType->hasUnresolvedType()) + if (!resolvedType->hasError()) return resolvedType; // If type variable was simplified to an unresolved pack expansion @@ -117,7 +117,7 @@ Type FailureDiagnostic::resolveType(Type rawType, bool reconstituteSugar, } Type GP = typeVar->getImpl().getGenericParameter(); - return resolvedType->is() && GP + return resolvedType->is() && GP ? ErrorType::get(GP) : resolvedType; } @@ -128,7 +128,7 @@ Type FailureDiagnostic::resolveType(Type rawType, bool reconstituteSugar, } if (type->isPlaceholder()) - return Type(type->getASTContext().TheUnresolvedType); + return ErrorType::get(type->getASTContext()); return std::nullopt; }); @@ -183,7 +183,7 @@ StringRef FailureDiagnostic::getEditorPlaceholder( llvm::SmallVectorImpl &scratch) const { llvm::raw_svector_ostream OS(scratch); OS << "<#"; - if (!ty || ty->is()) { + if (!ty || ty->isBareErrorType()) { OS << description; } else { OS << "T##"; @@ -5681,7 +5681,7 @@ bool MissingArgumentsFailure::diagnoseMissingResultBuilderElement() const { auto fixIt = getEditorPlaceholder("result", paramType, scratch); auto fixItLoc = call->getStartLoc(); - if (paramType->is()) { + if (paramType->isBareErrorType()) { emitDiagnostic(diag::result_builder_missing_element, resultBuilder->getName()) .fixItInsertAfter(fixItLoc, fixIt); @@ -5804,7 +5804,7 @@ bool MissingArgumentsFailure::isMisplacedMissingArgument( auto argType = solution.simplifyType(solution.getType(unaryArg)); auto paramType = fnType->getParams()[1].getPlainType(); - if (isExpr(unaryArg) && argType->is()) { + if (isExpr(unaryArg) && argType->is()) { auto unwrappedParamTy = paramType->lookThroughAllOptionalTypes(); if (unwrappedParamTy->is() || unwrappedParamTy->isAny()) return true; @@ -5958,7 +5958,7 @@ bool ClosureParamDestructuringFailure::diagnoseAsError() { }; auto isValidType = [](Type resultType) -> bool { - return resultType && !resultType->hasUnresolvedType() && + return resultType && !resultType->hasError() && !resultType->hasTypeVariable(); }; @@ -6619,7 +6619,7 @@ bool CollectionElementContextualFailure::diagnoseAsError() { // statement it has to be diagnosed as pattern match if there are // holes present in the contextual type. if (purpose == ContextualTypePurpose::CTP_ForEachSequence && - contextualType->hasUnresolvedType()) { + contextualType->hasError()) { auto diagnostic = emitDiagnostic( (contextualType->is() && !eltType->is()) ? diag::cannot_match_expr_tuple_pattern_with_nontuple_value @@ -7490,7 +7490,7 @@ bool ArgumentMismatchFailure::diagnoseAsError() { if (argType->isKeyPath() && !paramType->isKnownKeyPathType()) { auto keyPathTy = argType->castTo(); auto rootTy = keyPathTy->getGenericArgs()[0]; - if (rootTy->is()) { + if (rootTy->isBareErrorType()) { emitDiagnostic(diag::cannot_convert_unresolved_key_path_argument_value, paramType); return true; @@ -7627,7 +7627,7 @@ bool ArgumentMismatchFailure::diagnosePatternMatchingMismatch() const { auto rhsType = getType(rhsExpr); auto diagnostic = - lhsType->is() + lhsType->isBareErrorType() ? emitDiagnostic( diag::cannot_match_unresolved_expr_pattern_with_value, rhsType) : emitDiagnostic(diag::cannot_match_expr_pattern_with_value, lhsType, @@ -8286,7 +8286,7 @@ bool UnableToInferClosureParameterType::diagnoseAsError() { if (parentExpr) { // Missing or invalid member reference in call. if (auto *AE = dyn_cast(parentExpr)) { - if (getType(AE->getFn())->is()) + if (getType(AE->getFn())->is()) return false; } diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 897f412c0364d..27675a08699d0 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -300,7 +300,6 @@ static bool backwardScanAcceptsTrailingClosure( paramTy->is() || paramTy->is() || paramTy->isTypeVariableOrMember() || - paramTy->is() || paramTy->isAny(); } @@ -7425,7 +7424,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind, #include "swift/AST/TypeNodes.def" case TypeKind::Error: - case TypeKind::Unresolved: return getTypeMatchFailure(locator); case TypeKind::BuiltinFixedArray: { @@ -8454,7 +8452,6 @@ ConstraintSystem::simplifyConstructionConstraint( case TypeKind::BuiltinTuple: llvm_unreachable("BuiltinTupleType in constraint"); - case TypeKind::Unresolved: case TypeKind::Error: case TypeKind::Placeholder: return SolutionKind::Error; @@ -10109,8 +10106,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName, MemberLookupResult result; - if (instanceTy->isTypeVariableOrMember() || - instanceTy->is()) { + if (instanceTy->isTypeVariableOrMember()) { result.OverallResult = MemberLookupResult::Unsolved; return result; } diff --git a/lib/Sema/CSSolver.cpp b/lib/Sema/CSSolver.cpp index 26c011cb256e7..44e80480e0cc1 100644 --- a/lib/Sema/CSSolver.cpp +++ b/lib/Sema/CSSolver.cpp @@ -1157,7 +1157,7 @@ void ConstraintSystem::shrink(Expr *expr) { /// /// \param collection The type of the collection container. /// - /// \returns Null type, ErrorType or UnresolvedType on failure, + /// \returns Null type or ErrorType on failure, /// properly constructed type otherwise. Type extractElementType(Type collection) { auto &ctx = CS.getASTContext(); @@ -1166,8 +1166,7 @@ void ConstraintSystem::shrink(Expr *expr) { auto base = collection.getPointer(); auto isInvalidType = [](Type type) -> bool { - return type.isNull() || type->hasUnresolvedType() || - type->hasError(); + return type.isNull() || type->hasError(); }; // Array type. @@ -1179,9 +1178,6 @@ void ConstraintSystem::shrink(Expr *expr) { // Map or Set or any other associated collection type. if (auto boundGeneric = dyn_cast(base)) { - if (boundGeneric->hasUnresolvedType()) - return boundGeneric; - // Avoid handling InlineArray, building a tuple would be wrong, and // we want to eliminate shrink. if (boundGeneric->getDecl() == ctx.getInlineArrayDecl()) @@ -1290,9 +1286,7 @@ void ConstraintSystem::shrink(Expr *expr) { auto elementType = extractElementType(contextualType); // If we couldn't deduce element type for the collection, let's // not attempt to solve it. - if (!elementType || - elementType->hasError() || - elementType->hasUnresolvedType()) + if (!elementType || elementType->hasError()) return; contextualType = elementType; diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 897de2bf547c3..dde763f41512a 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -1886,7 +1886,7 @@ Type Solution::simplifyType(Type type, bool wantInterfaceType) const { ASSERT(!(wantInterfaceType && resolvedType->hasPrimaryArchetype())); // We may have type variables and placeholders left over. These are solver - // allocated so cannot escape this function. Turn them into UnresolvedType. + // allocated so cannot escape this function. Turn them into ErrorType. // - Type variables may still be present from unresolved pack expansions where // e.g the count type is a hole, so the pattern may never become a // concrete type. @@ -1900,7 +1900,7 @@ Type Solution::simplifyType(Type type, bool wantInterfaceType) const { auto *typePtr = type.getPointer(); if (isa(typePtr) || isa(typePtr)) - return Type(ctx.TheUnresolvedType); + return ErrorType::get(ctx); return std::nullopt; }); @@ -4298,7 +4298,7 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const { // If callee couldn't be resolved due to expression // issues e.g. it's a reference to an invalid member // let's just return here. - if (simplifyType(rawFnType)->is()) + if (simplifyType(rawFnType)->is()) return std::nullopt; // A tuple construction is spelled in the AST as a function call, but diff --git a/lib/Sema/IDETypeCheckingRequests.cpp b/lib/Sema/IDETypeCheckingRequests.cpp index 901879a3141e1..e2d151c3d707e 100644 --- a/lib/Sema/IDETypeCheckingRequests.cpp +++ b/lib/Sema/IDETypeCheckingRequests.cpp @@ -143,7 +143,7 @@ static bool isExtensionAppliedInternal(const DeclContext *DC, Type BaseTy, // For check on specializable archetype see comment on // ContainsSpecializableArchetype. if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType() || - BaseTy->hasUnresolvedType() || BaseTy->hasError() || + BaseTy->hasError() || ContainsSpecializableArchetype::check(DC, BaseTy)) return true; @@ -181,7 +181,7 @@ static bool isMemberDeclAppliedInternal(const DeclContext *DC, Type BaseTy, // We can't leak type variables into another constraint system. // We can't do anything if the base type has unbound generic parameters. if (BaseTy->hasTypeVariable() || BaseTy->hasUnboundGenericType()|| - BaseTy->hasUnresolvedType() || BaseTy->hasError()) + BaseTy->hasError()) return true; if (isa(VD) && BaseTy->is()) { diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index dbfad23a9f0a2..b76da1d0234f5 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -5616,17 +5616,6 @@ class Serializer::TypeSerializer : public TypeVisitor { llvm_unreachable("should not serialize an ErrorType"); } - void visitUnresolvedType(const UnresolvedType *) { - // If for some reason we have an unresolved type while compiling with - // errors, just serialize an ErrorType and continue. - if (S.getASTContext().LangOpts.AllowModuleWithCompilerErrors) { - visitErrorType( - cast(ErrorType::get(S.getASTContext()).getPointer())); - return; - } - llvm_unreachable("should not serialize an UnresolvedType"); - } - void visitPlaceholderType(const PlaceholderType *) { // If for some reason we have a placeholder type while compiling with // errors, just serialize an ErrorType and continue.