Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/TypeMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TupleType>()) {
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/TypeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
82 changes: 43 additions & 39 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Type *>(this + 1) = originalType;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -8124,6 +8117,17 @@ inline ASTContext &TypeBase::getASTContext() const {
return *const_cast<ASTContext*>(getCanonicalType()->Context);
}

inline bool TypeBase::isBareErrorType() const {
auto *errTy = dyn_cast<ErrorType>(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<InOutType>());
Expand Down
2 changes: 1 addition & 1 deletion include/swift/IDE/TypeCheckCompletionCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct WithSolutionSpecificVarTypesRAII {
} else {
RestoreVarTypes[var] = Type();
}
if (!ty->hasArchetype() && !ty->hasUnresolvedType()) {
if (!ty->hasArchetype()) {
setInterfaceType(const_cast<VarDecl *>(var), ty);
} else {
setInterfaceType(const_cast<VarDecl *>(var), ErrorType::get(ty));
Expand Down
11 changes: 4 additions & 7 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TupleTypeElt>(), *this)),
TheEmptyPackType(PackType::get(*this, {})),
TheAnyType(ProtocolCompositionType::theAnyType(*this)),
Expand Down Expand Up @@ -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<Type> terms) {
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6204,14 +6204,6 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
}
}

void visitUnresolvedType(UnresolvedType *T,
NonRecursivePrintOptions nrOptions) {
if (Options.PrintTypesForDebugging)
Printer << "<<unresolvedtype>>";
else
Printer << "_";
}

void visitErrorUnionType(ErrorUnionType *T,
NonRecursivePrintOptions nrOptions) {
Printer << "error_union(";
Expand Down
7 changes: 3 additions & 4 deletions lib/AST/ConformanceLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnresolvedType>() || type->is<PlaceholderType>())
// 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<PlaceholderType>())
return ProtocolConformanceRef::forAbstract(type, protocol);

// Pack types can conform to protocols.
Expand Down
5 changes: 2 additions & 3 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpaqueTypeArchetypeType>(type.getPointer()) &&
Expand Down
1 change: 0 additions & 1 deletion lib/AST/SubstitutionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ void SubstitutionMap::verify(bool allowInvalid) const {
!substType->is<PackElementType>() &&
!substType->is<ArchetypeType>() &&
!substType->isTypeVariableOrMember() &&
!substType->is<UnresolvedType>() &&
!substType->is<PlaceholderType>() &&
!substType->is<ErrorType>()) {
ABORT([&](auto &out) {
Expand Down
9 changes: 2 additions & 7 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -761,7 +760,6 @@ bool TypeBase::hasTypeRepr() const {
return !Type(const_cast<TypeBase *>(this)).findIf([](Type subTy) -> bool {
switch (subTy->getKind()) {
case TypeKind::Error:
case TypeKind::Unresolved:
case TypeKind::TypeVariable:
return true;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -2318,10 +2315,9 @@ bool TypeBase::mayBeCallable(DeclContext *dc) {
return true;

// Unresolved types that could potentially be callable.
if (isPlaceholder() || is<UnresolvedType>() ||
isTypeParameter() || isTypeVariableOrMember()) {
if (isPlaceholder() || isTypeParameter() || isTypeVariableOrMember())
return true;
}

// Callable nominal types.
if (isCallAsFunctionType(dc) || hasDynamicCallableAttribute())
return true;
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion lib/AST/TypeWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Traversal : public TypeVisitor<Traversal, bool>
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; }
Expand Down
1 change: 0 additions & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,6 @@ class GetSendableType :
return pass(ty, /*found=*/true);
}

NEVER_VISIT(UnresolvedType)
NEVER_VISIT(PlaceholderType)
NEVER_VISIT(BuiltinType)
NEVER_VISIT(BuiltinTupleType)
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/ArgumentCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
}
}
if (ExpectedCallType &&
(ExpectedCallType->hasUnresolvedType() ||
(ExpectedCallType->hasError() ||
ExpectedCallType->hasUnboundGenericType())) {
ExpectedCallType = Type();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericFunctionType>()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/ConformingMethodList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void ConformingMethodListCallbacks::readyForTypeChecking(SourceFile *SrcFile) {
Type T = Res.Ty;
WithSolutionSpecificVarTypesRAII VarType(Res.SolutionSpecificVarTypes);

if (!T || T->is<ErrorType>() || T->is<UnresolvedType>())
if (!T || T->is<ErrorType>())
return;

T = T->getRValueType();
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/PostfixCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/SelectedOverloadInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ swift::ide::getSelectedOverloadInfo(const Solution &S,
OverloadChoiceKind::KeyPathApplication) {
auto Params = Result.ValueTy->getAs<AnyFunctionType>()->getParams();
if (Params.size() == 1 &&
Params[0].getPlainType()->is<UnresolvedType>()) {
Params[0].getPlainType()->is<ErrorType>()) {
auto *KPDecl = CS.getASTContext().getKeyPathDecl();
Type KPTy =
KPDecl->mapTypeIntoContext(KPDecl->getDeclaredInterfaceType());
Expand Down
Loading