Skip to content

Commit 55a38ba

Browse files
authored
Merge pull request #84634 from hamishknight/fish-whisperer
[AST] Remove UnresolvedType
2 parents bc88160 + 954b08c commit 55a38ba

32 files changed

+95
-144
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ class ASTContext final {
10441044

10451045
// Builtin type and simple types that are used frequently.
10461046
const CanType TheErrorType; /// This is the ErrorType singleton.
1047-
const CanType TheUnresolvedType; /// This is the UnresolvedType singleton.
10481047
const CanType TheEmptyTupleType; /// This is '()', aka Void
10491048
const CanType TheEmptyPackType;
10501049
const CanType TheAnyType; /// This is 'Any', the empty protocol composition

include/swift/AST/TypeMatcher.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ class TypeMatcher {
117117
#define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type)
118118
#include "swift/AST/TypeNodes.def"
119119

120-
bool visitUnresolvedType(CanUnresolvedType firstType, Type secondType,
121-
Type sugaredFirstType) {
122-
// Unresolved types never match.
123-
return mismatch(firstType.getPointer(), secondType, sugaredFirstType);
124-
}
125-
126120
bool visitTupleType(CanTupleType firstTuple, Type secondType,
127121
Type sugaredFirstType) {
128122
if (auto secondTuple = secondType->getAs<TupleType>()) {

include/swift/AST/TypeNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
#if !defined(SINGLETON_TYPE)
124124

125125
TYPE(Error, Type)
126-
UNCHECKED_TYPE(Unresolved, Type)
127126
UNCHECKED_TYPE(Placeholder, Type)
128127
ABSTRACT_TYPE(Builtin, Type)
129128
ABSTRACT_TYPE(AnyBuiltinInteger, BuiltinType)

include/swift/AST/TypeTransform.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ case TypeKind::Id:
109109
#define TYPE(Id, Parent)
110110
#include "swift/AST/TypeNodes.def"
111111
case TypeKind::Error:
112-
case TypeKind::Unresolved:
113112
case TypeKind::TypeVariable:
114113
case TypeKind::Placeholder:
115114
case TypeKind::SILToken:

include/swift/AST/Types.h

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,24 @@ class RecursiveTypeProperties {
141141
/// This type expression contains a GenericTypeParamType.
142142
HasTypeParameter = 0x04,
143143

144-
/// This type expression contains an UnresolvedType.
145-
HasUnresolvedType = 0x08,
146-
147144
/// Whether this type expression contains an unbound generic type.
148-
HasUnboundGeneric = 0x10,
145+
HasUnboundGeneric = 0x08,
149146

150147
/// This type expression contains an LValueType other than as a
151148
/// function input, and can be loaded to convert to an rvalue.
152-
IsLValue = 0x20,
149+
IsLValue = 0x10,
153150

154151
/// This type expression contains an opened existential ArchetypeType.
155-
HasOpenedExistential = 0x40,
152+
HasOpenedExistential = 0x20,
156153

157154
/// This type expression contains a DynamicSelf type.
158-
HasDynamicSelf = 0x80,
155+
HasDynamicSelf = 0x40,
159156

160157
/// This type contains an Error type.
161-
HasError = 0x100,
158+
HasError = 0x80,
159+
160+
/// This type contains an Error type without an underlying original type.
161+
HasBareError = 0x100,
162162

163163
/// This type contains a DependentMemberType.
164164
HasDependentMember = 0x200,
@@ -225,15 +225,15 @@ class RecursiveTypeProperties {
225225
/// Does a type with these properties have a type parameter somewhere in it?
226226
bool hasTypeParameter() const { return Bits & HasTypeParameter; }
227227

228-
/// Does a type with these properties have an unresolved type somewhere in it?
229-
bool hasUnresolvedType() const { return Bits & HasUnresolvedType; }
230-
231228
/// Is a type with these properties an lvalue?
232229
bool isLValue() const { return Bits & IsLValue; }
233230

234231
/// Does this type contain an error?
235232
bool hasError() const { return Bits & HasError; }
236233

234+
/// Does this type contain an error without an original type?
235+
bool hasBareError() const { return Bits & HasBareError; }
236+
237237
/// Does this type contain a dependent member type, possibly with a
238238
/// non-type parameter base, such as a type variable or concrete type?
239239
bool hasDependentMember() const { return Bits & HasDependentMember; }
@@ -750,11 +750,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
750750
/// member root in a type variable.
751751
bool isTypeVariableOrMember();
752752

753-
/// Determine whether this type involves a UnresolvedType.
754-
bool hasUnresolvedType() const {
755-
return getRecursiveProperties().hasUnresolvedType();
756-
}
757-
758753
/// Determine whether this type involves a \c PlaceholderType.
759754
bool hasPlaceholder() const {
760755
return getRecursiveProperties().hasPlaceholder();
@@ -949,6 +944,16 @@ class alignas(1 << TypeAlignInBits) TypeBase
949944
return getRecursiveProperties().hasError();
950945
}
951946

947+
/// Determine whether this type contains an error type without an
948+
/// underlying original type, i.e prints as `_`.
949+
bool hasBareError() const {
950+
return getRecursiveProperties().hasBareError();
951+
}
952+
953+
/// Whether this is a top-level ErrorType without an underlying original
954+
/// type, i.e prints as `_`.
955+
bool isBareErrorType() const;
956+
952957
/// Does this type contain a dependent member type, possibly with a
953958
/// non-type parameter base, such as a type variable or concrete type?
954959
bool hasDependentMember() const {
@@ -1654,11 +1659,18 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(NominalOrBoundGenericNominalType, AnyGenericType)
16541659
/// have to emit further diagnostics to abort compilation.
16551660
class ErrorType final : public TypeBase {
16561661
friend class ASTContext;
1662+
1663+
static RecursiveTypeProperties getProperties(Type originalType) {
1664+
RecursiveTypeProperties props = RecursiveTypeProperties::HasError;
1665+
if (!originalType || originalType->hasBareError())
1666+
props |= RecursiveTypeProperties::HasBareError;
1667+
1668+
return props;
1669+
}
1670+
16571671
// The Error type is always canonical.
1658-
ErrorType(ASTContext &C, Type originalType,
1659-
RecursiveTypeProperties properties)
1660-
: TypeBase(TypeKind::Error, &C, properties) {
1661-
assert(properties.hasError());
1672+
ErrorType(ASTContext &C, Type originalType)
1673+
: TypeBase(TypeKind::Error, &C, getProperties(originalType)) {
16621674
if (originalType) {
16631675
Bits.ErrorType.HasOriginalType = true;
16641676
*reinterpret_cast<Type *>(this + 1) = originalType;
@@ -1689,25 +1701,6 @@ class ErrorType final : public TypeBase {
16891701
}
16901702
};
16911703
DEFINE_EMPTY_CAN_TYPE_WRAPPER(ErrorType, Type)
1692-
1693-
/// UnresolvedType - This represents a type variable that cannot be resolved to
1694-
/// a concrete type because the expression is ambiguous. This is produced when
1695-
/// parsing expressions and producing diagnostics. Any instance of this should
1696-
/// cause the entire expression to be ambiguously typed.
1697-
class UnresolvedType : public TypeBase {
1698-
friend class ASTContext;
1699-
// The Unresolved type is always canonical.
1700-
UnresolvedType(ASTContext &C)
1701-
: TypeBase(TypeKind::Unresolved, &C,
1702-
RecursiveTypeProperties(RecursiveTypeProperties::HasUnresolvedType)) { }
1703-
public:
1704-
// Implement isa/cast/dyncast/etc.
1705-
static bool classof(const TypeBase *T) {
1706-
return T->getKind() == TypeKind::Unresolved;
1707-
}
1708-
};
1709-
DEFINE_EMPTY_CAN_TYPE_WRAPPER(UnresolvedType, Type)
1710-
17111704

17121705
/// BuiltinType - An abstract class for all the builtin types.
17131706
class BuiltinType : public TypeBase {
@@ -8124,6 +8117,17 @@ inline ASTContext &TypeBase::getASTContext() const {
81248117
return *const_cast<ASTContext*>(getCanonicalType()->Context);
81258118
}
81268119

8120+
inline bool TypeBase::isBareErrorType() const {
8121+
auto *errTy = dyn_cast<ErrorType>(this);
8122+
if (!errTy)
8123+
return false;
8124+
8125+
// FIXME: We shouldn't need to check for a recursive bare error type, we can
8126+
// remove this once we flatten them.
8127+
auto originalTy = errTy->getOriginalType();
8128+
return !originalTy || originalTy->isBareErrorType();
8129+
}
8130+
81278131
// TODO: This will become redundant once InOutType is removed.
81288132
inline bool TypeBase::isMaterializable() {
81298133
return !(hasLValueType() || is<InOutType>());

include/swift/IDE/TypeCheckCompletionCallback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct WithSolutionSpecificVarTypesRAII {
9292
} else {
9393
RestoreVarTypes[var] = Type();
9494
}
95-
if (!ty->hasArchetype() && !ty->hasUnresolvedType()) {
95+
if (!ty->hasArchetype()) {
9696
setInterfaceType(const_cast<VarDecl *>(var), ty);
9797
} else {
9898
setInterfaceType(const_cast<VarDecl *>(var), ErrorType::get(ty));

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,8 @@ ASTContext::ASTContext(
808808
StdlibModuleName(getIdentifier(STDLIB_NAME)),
809809
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
810810
blockListConfig(SourceMgr),
811-
TheErrorType(new(*this, AllocationArena::Permanent) ErrorType(
812-
*this, Type(), RecursiveTypeProperties::HasError)),
813-
TheUnresolvedType(new(*this, AllocationArena::Permanent)
814-
UnresolvedType(*this)),
811+
TheErrorType(new (*this, AllocationArena::Permanent)
812+
ErrorType(*this, Type())),
815813
TheEmptyTupleType(TupleType::get(ArrayRef<TupleTypeElt>(), *this)),
816814
TheEmptyPackType(PackType::get(*this, {})),
817815
TheAnyType(ProtocolCompositionType::theAnyType(*this)),
@@ -3637,8 +3635,7 @@ Type ErrorType::get(Type originalType) {
36373635

36383636
void *mem = ctx.Allocate(sizeof(ErrorType) + sizeof(Type),
36393637
alignof(ErrorType), arena);
3640-
return entry = new (mem) ErrorType(ctx, originalType,
3641-
RecursiveTypeProperties::HasError);
3638+
return entry = new (mem) ErrorType(ctx, originalType);
36423639
}
36433640

36443641
void ErrorUnionType::Profile(llvm::FoldingSetNodeID &id, ArrayRef<Type> terms) {
@@ -5859,7 +5856,7 @@ ProtocolConformanceRef ProtocolConformanceRef::forAbstract(
58595856
case TypeKind::GenericTypeParam:
58605857
case TypeKind::TypeVariable:
58615858
case TypeKind::DependentMember:
5862-
case TypeKind::Unresolved:
5859+
case TypeKind::Error:
58635860
case TypeKind::Placeholder:
58645861
case TypeKind::PrimaryArchetype:
58655862
case TypeKind::PackArchetype:

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6062,8 +6062,6 @@ namespace {
60626062
printFoot();
60636063
}
60646064

6065-
TRIVIAL_TYPE_PRINTER(Unresolved, unresolved)
6066-
60676065
void visitPlaceholderType(PlaceholderType *T, Label label) {
60686066
printCommon("placeholder_type", label);
60696067
auto originator = T->getOriginator();

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,6 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
14171417
llvm_unreachable("Cannot mangle module type yet");
14181418

14191419
case TypeKind::Error:
1420-
case TypeKind::Unresolved:
14211420
case TypeKind::Placeholder:
14221421
appendOperator("Xe");
14231422
return;

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6204,14 +6204,6 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
62046204
}
62056205
}
62066206

6207-
void visitUnresolvedType(UnresolvedType *T,
6208-
NonRecursivePrintOptions nrOptions) {
6209-
if (Options.PrintTypesForDebugging)
6210-
Printer << "<<unresolvedtype>>";
6211-
else
6212-
Printer << "_";
6213-
}
6214-
62156207
void visitErrorUnionType(ErrorUnionType *T,
62166208
NonRecursivePrintOptions nrOptions) {
62176209
Printer << "error_union(";

0 commit comments

Comments
 (0)