Skip to content

Commit e4ea167

Browse files
committed
Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
1 parent 40122df commit e4ea167

34 files changed

+238
-217
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,6 @@ class ASTContext final {
756756
// Builtin type and simple types that are used frequently.
757757
const CanType TheErrorType; /// This is the ErrorType singleton.
758758
const CanType TheUnresolvedType; /// This is the UnresolvedType singleton.
759-
const CanType ThePlaceholderType;
760759
const CanType TheEmptyTupleType; /// This is '()', aka Void
761760
const CanType TheAnyType; /// This is 'Any', the empty protocol composition
762761
#define SINGLETON_TYPE(SHORT_ID, ID) \

include/swift/AST/TypeNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
TYPE(Error, Type)
9999
UNCHECKED_TYPE(Unresolved, Type)
100100
UNCHECKED_TYPE(Placeholder, Type)
101-
UNCHECKED_TYPE(Hole, Type)
102101
ABSTRACT_TYPE(Builtin, Type)
103102
ABSTRACT_TYPE(AnyBuiltinInteger, BuiltinType)
104103
BUILTIN_TYPE(BuiltinInteger, AnyBuiltinIntegerType)

include/swift/AST/Types.h

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Identifier;
6767
class InOutType;
6868
class OpaqueTypeDecl;
6969
class OpenedArchetypeType;
70+
class PlaceholderTypeRepr;
7071
enum class ReferenceCounting : uint8_t;
7172
enum class ResilienceExpansion : unsigned;
7273
class SILModule;
@@ -126,7 +127,7 @@ class RecursiveTypeProperties {
126127

127128
/// This type expression contains an UnresolvedType.
128129
HasUnresolvedType = 0x08,
129-
130+
130131
/// Whether this type expression contains an unbound generic type.
131132
HasUnboundGeneric = 0x10,
132133

@@ -145,15 +146,12 @@ class RecursiveTypeProperties {
145146

146147
/// This type contains a DependentMemberType.
147148
HasDependentMember = 0x200,
148-
149+
149150
/// This type contains an OpaqueTypeArchetype.
150151
HasOpaqueArchetype = 0x400,
151152

152-
/// This type contains a type hole.
153-
HasTypeHole = 0x800,
154-
155-
/// This type contains a placeholder.
156-
HasPlaceholder = 0x1000,
153+
/// This type contains a type placeholder.
154+
HasPlaceholder = 0x800,
157155

158156
Last_Property = HasPlaceholder
159157
};
@@ -210,10 +208,6 @@ class RecursiveTypeProperties {
210208
/// generic type?
211209
bool hasUnboundGeneric() const { return Bits & HasUnboundGeneric; }
212210

213-
/// Does a type with these properties structurally contain a
214-
/// type hole?
215-
bool hasTypeHole() const { return Bits & HasTypeHole; }
216-
217211
/// Does a type with these properties structurally contain a placeholder?
218212
bool hasPlaceholder() const { return Bits & HasPlaceholder; }
219213

@@ -552,7 +546,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
552546
/// Is this the 'Any' type?
553547
bool isAny();
554548

555-
bool isHole();
549+
bool isPlaceholder();
556550

557551
/// Does the type have outer parenthesis?
558552
bool hasParenSugar() const { return getKind() == TypeKind::Paren; }
@@ -591,9 +585,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
591585
return getRecursiveProperties().hasPlaceholder();
592586
}
593587

594-
/// Determine whether this type involves a hole.
595-
bool hasHole() const { return getRecursiveProperties().hasTypeHole(); }
596-
597588
/// Determine whether the type involves a context-dependent archetype.
598589
bool hasArchetype() const {
599590
return getRecursiveProperties().hasArchetype();
@@ -1362,20 +1353,6 @@ class UnresolvedType : public TypeBase {
13621353
};
13631354
DEFINE_EMPTY_CAN_TYPE_WRAPPER(UnresolvedType, Type)
13641355

1365-
class PlaceholderType : public TypeBase {
1366-
friend class ASTContext;
1367-
// The Placeholder type is always canonical.
1368-
PlaceholderType(ASTContext &C)
1369-
: TypeBase(TypeKind::Placeholder, &C,
1370-
RecursiveTypeProperties(RecursiveTypeProperties::HasPlaceholder)) { }
1371-
public:
1372-
// Implement isa/cast/dyncast/etc.
1373-
static bool classof(const TypeBase *T) {
1374-
return T->getKind() == TypeKind::Placeholder;
1375-
}
1376-
};
1377-
DEFINE_EMPTY_CAN_TYPE_WRAPPER(PlaceholderType, Type)
1378-
13791356

13801357
/// BuiltinType - An abstract class for all the builtin types.
13811358
class BuiltinType : public TypeBase {
@@ -5834,31 +5811,31 @@ TypeVariableType : public TypeBase {
58345811
};
58355812
DEFINE_EMPTY_CAN_TYPE_WRAPPER(TypeVariableType, Type)
58365813

5837-
/// HoleType - This represents a placeholder type for a type variable
5814+
/// PlaceholderType - This represents a placeholder type for a type variable
58385815
/// or dependent member type that cannot be resolved to a concrete type
58395816
/// because the expression is ambiguous. This type is only used by the
58405817
/// constraint solver and transformed into UnresolvedType to be used in AST.
5841-
class HoleType : public TypeBase {
5842-
using Originator = llvm::PointerUnion<TypeVariableType *,
5843-
DependentMemberType *, VarDecl *,
5844-
ErrorExpr *>;
5818+
class PlaceholderType : public TypeBase {
5819+
using Originator =
5820+
llvm::PointerUnion<TypeVariableType *, DependentMemberType *, VarDecl *,
5821+
ErrorExpr *, PlaceholderTypeRepr *>;
58455822

58465823
Originator O;
58475824

5848-
HoleType(ASTContext &C, Originator originator,
5849-
RecursiveTypeProperties properties)
5850-
: TypeBase(TypeKind::Hole, &C, properties), O(originator) {}
5825+
PlaceholderType(ASTContext &C, Originator originator,
5826+
RecursiveTypeProperties properties)
5827+
: TypeBase(TypeKind::Placeholder, &C, properties), O(originator) {}
58515828

58525829
public:
58535830
static Type get(ASTContext &ctx, Originator originator);
58545831

58555832
Originator getOriginator() const { return O; }
58565833

58575834
static bool classof(const TypeBase *T) {
5858-
return T->getKind() == TypeKind::Hole;
5835+
return T->getKind() == TypeKind::Placeholder;
58595836
}
58605837
};
5861-
DEFINE_EMPTY_CAN_TYPE_WRAPPER(HoleType, Type)
5838+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(PlaceholderType, Type)
58625839

58635840
inline bool TypeBase::isTypeVariableOrMember() {
58645841
if (is<TypeVariableType>())

include/swift/Sema/CSBindings.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct PotentialBinding {
138138

139139
static PotentialBinding forHole(TypeVariableType *typeVar,
140140
ConstraintLocator *locator) {
141-
return {HoleType::get(typeVar->getASTContext(), typeVar),
141+
return {PlaceholderType::get(typeVar->getASTContext(), typeVar),
142142
AllowedBindingKind::Exact,
143143
/*source=*/locator};
144144
}
@@ -279,9 +279,9 @@ struct PotentialBindings {
279279
bool isPotentiallyIncomplete() const;
280280

281281
/// If this type variable doesn't have any viable bindings, or
282-
/// if there is only one binding and it's a hole type, consider
282+
/// if there is only one binding and it's a placeholder type, consider
283283
/// this type variable to be a hole in a constraint system
284-
/// regardless of where hole type originated.
284+
/// regardless of where the placeholder type originated.
285285
bool isHole() const {
286286
if (isDirectHole())
287287
return true;
@@ -290,14 +290,14 @@ struct PotentialBindings {
290290
return false;
291291

292292
const auto &binding = Bindings.front();
293-
return binding.BindingType->is<HoleType>();
293+
return binding.BindingType->is<PlaceholderType>();
294294
}
295295

296296
/// Determines whether the only possible binding for this type variable
297-
/// would be a hole type. This is different from `isHole` method because
298-
/// type variable could also acquire a hole type transitively if one
299-
/// of the type variables in its subtype/equivalence chain has been
300-
/// bound to a hole type.
297+
/// would be a placeholder type. This is different from `isHole` method
298+
/// because type variable could also acquire a placeholder type transitively
299+
/// if one of the type variables in its subtype/equivalence chain has been
300+
/// bound to a placeholder type.
301301
bool isDirectHole() const;
302302

303303
/// Determine if the bindings only constrain the type variable from above

include/swift/Sema/ConstraintLocator.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,20 @@ class LocatorPathElt::ConformanceRequirement final
781781
}
782782
};
783783

784+
class LocatorPathElt::PlaceholderType final
785+
: public StoredPointerElement<PlaceholderTypeRepr> {
786+
public:
787+
PlaceholderType(PlaceholderTypeRepr *placeholderRepr)
788+
: StoredPointerElement(PathElementKind::PlaceholderType,
789+
placeholderRepr) {}
790+
791+
PlaceholderTypeRepr *getPlaceholderRepr() const { return getStoredPointer(); }
792+
793+
static bool classof(const LocatorPathElt *elt) {
794+
return elt->getKind() == ConstraintLocator::PlaceholderType;
795+
}
796+
};
797+
784798
namespace details {
785799
template <typename CustomPathElement>
786800
class PathElement {

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ SIMPLE_LOCATOR_PATH_ELT(UnresolvedMemberChainResult)
198198
/// The conformance requirement associated with a type.
199199
CUSTOM_LOCATOR_PATH_ELT(ConformanceRequirement)
200200

201+
/// A source-specified placeholder.
202+
CUSTOM_LOCATOR_PATH_ELT(PlaceholderType)
203+
201204
#undef LOCATOR_PATH_ELT
202205
#undef CUSTOM_LOCATOR_PATH_ELT
203206
#undef SIMPLE_LOCATOR_PATH_ELT

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ enum TypeVariableOptions {
255255
/// Whether the type variable can be bound to a non-escaping type or not.
256256
TVO_CanBindToNoEscape = 0x04,
257257

258-
/// Whether the type variable can be bound to a hole type or not.
258+
/// Whether the type variable can be bound to a hole or not.
259259
TVO_CanBindToHole = 0x08,
260260

261261
/// Whether a more specific deduction for this type variable implies a
@@ -327,7 +327,7 @@ class TypeVariableType::Implementation {
327327
/// Whether this type variable can bind to an inout type.
328328
bool canBindToNoEscape() const { return getRawOptions() & TVO_CanBindToNoEscape; }
329329

330-
/// Whether this type variable can bind to a hole type.
330+
/// Whether this type variable can bind to a hole.
331331
bool canBindToHole() const { return getRawOptions() & TVO_CanBindToHole; }
332332

333333
/// Whether this type variable prefers a subtype binding over a supertype
@@ -5033,10 +5033,12 @@ class HandlePlaceholderType {
50335033
const ConstraintLocatorBuilder &locator)
50345034
: cs(cs), locator(locator) {}
50355035

5036-
Type operator()() const {
5036+
Type operator()(PlaceholderTypeRepr *placeholderRepr) const {
50375037
return cs.createTypeVariable(
5038-
cs.getConstraintLocator(locator),
5039-
TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding | TVO_CanBindToHole);
5038+
cs.getConstraintLocator(
5039+
locator, LocatorPathElt::PlaceholderType(placeholderRepr)),
5040+
TVO_CanBindToNoEscape | TVO_PrefersSubtypeBinding |
5041+
TVO_CanBindToHole);
50405042
}
50415043
};
50425044

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,6 @@ ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typeckOpts,
595595
ErrorType(*this, Type(), RecursiveTypeProperties::HasError)),
596596
TheUnresolvedType(new (*this, AllocationArena::Permanent)
597597
UnresolvedType(*this)),
598-
ThePlaceholderType(new (*this, AllocationArena::Permanent)
599-
PlaceholderType(*this)),
600598
TheEmptyTupleType(TupleType::get(ArrayRef<TupleTypeElt>(), *this)),
601599
TheAnyType(ProtocolCompositionType::get(*this, ArrayRef<Type>(),
602600
/*HasExplicitAnyObject=*/false)),
@@ -1519,9 +1517,8 @@ bool ASTContext::hadError() const {
15191517
/// Retrieve the arena from which we should allocate storage for a type.
15201518
static AllocationArena getArena(RecursiveTypeProperties properties) {
15211519
bool hasTypeVariable = properties.hasTypeVariable();
1522-
bool hasHole = properties.hasTypeHole();
1523-
return hasTypeVariable || hasHole ? AllocationArena::ConstraintSolver
1524-
: AllocationArena::Permanent;
1520+
return hasTypeVariable ? AllocationArena::ConstraintSolver
1521+
: AllocationArena::Permanent;
15251522
}
15261523

15271524
void ASTContext::addSearchPath(StringRef searchPath, bool isFramework,
@@ -2497,11 +2494,10 @@ Type ErrorType::get(Type originalType) {
24972494
return entry = new (mem) ErrorType(ctx, originalType, properties);
24982495
}
24992496

2500-
Type HoleType::get(ASTContext &ctx, Originator originator) {
2497+
Type PlaceholderType::get(ASTContext &ctx, Originator originator) {
25012498
assert(originator);
2502-
auto arena = getArena(RecursiveTypeProperties::HasTypeHole);
2503-
return new (ctx, arena)
2504-
HoleType(ctx, originator, RecursiveTypeProperties::HasTypeHole);
2499+
return new (ctx, AllocationArena::Permanent)
2500+
PlaceholderType(ctx, originator, RecursiveTypeProperties::HasPlaceholder);
25052501
}
25062502

25072503
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,
@@ -2945,7 +2941,7 @@ ReferenceStorageType *ReferenceStorageType::get(Type T,
29452941
ReferenceOwnership ownership,
29462942
const ASTContext &C) {
29472943
assert(!T->hasTypeVariable()); // not meaningful in type-checker
2948-
assert(!T->hasHole());
2944+
assert(!T->hasPlaceholder());
29492945
switch (optionalityOf(ownership)) {
29502946
case ReferenceOwnershipOptionality::Disallowed:
29512947
assert(!T->getOptionalObjectType() && "optional type is disallowed");
@@ -3104,7 +3100,7 @@ isFunctionTypeCanonical(ArrayRef<AnyFunctionType::Param> params,
31043100
static RecursiveTypeProperties
31053101
getGenericFunctionRecursiveProperties(ArrayRef<AnyFunctionType::Param> params,
31063102
Type result) {
3107-
static_assert(RecursiveTypeProperties::BitWidth == 13,
3103+
static_assert(RecursiveTypeProperties::BitWidth == 12,
31083104
"revisit this if you add new recursive type properties");
31093105
RecursiveTypeProperties properties;
31103106

@@ -3332,7 +3328,7 @@ GenericFunctionType *GenericFunctionType::get(GenericSignature sig,
33323328
ExtInfo info) {
33333329
assert(sig && "no generic signature for generic function type?!");
33343330
assert(!result->hasTypeVariable());
3335-
assert(!result->hasHole());
3331+
assert(!result->hasPlaceholder());
33363332

33373333
llvm::FoldingSetNodeID id;
33383334
GenericFunctionType::Profile(id, sig, params, result, info);
@@ -3678,7 +3674,7 @@ CanSILFunctionType SILFunctionType::get(
36783674
void *mem = ctx.Allocate(bytes, alignof(SILFunctionType));
36793675

36803676
RecursiveTypeProperties properties;
3681-
static_assert(RecursiveTypeProperties::BitWidth == 13,
3677+
static_assert(RecursiveTypeProperties::BitWidth == 12,
36823678
"revisit this if you add new recursive type properties");
36833679
for (auto &param : params)
36843680
properties |= param.getInterfaceType()->getRecursiveProperties();

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,20 +3535,19 @@ namespace {
35353535

35363536
TRIVIAL_TYPE_PRINTER(Unresolved, unresolved)
35373537

3538-
TRIVIAL_TYPE_PRINTER(Placeholder, placeholder)
3539-
3540-
void visitHoleType(HoleType *T, StringRef label) {
3541-
printCommon(label, "hole_type");
3538+
void visitPlaceholderType(PlaceholderType *T, StringRef label) {
3539+
printCommon(label, "placeholder_type");
35423540
auto originator = T->getOriginator();
35433541
if (auto *typeVar = originator.dyn_cast<TypeVariableType *>()) {
35443542
printRec("type_variable", typeVar);
35453543
} else if (auto *VD = originator.dyn_cast<VarDecl *>()) {
35463544
VD->dumpRef(PrintWithColorRAII(OS, DeclColor).getOS());
35473545
} else if (auto *EE = originator.dyn_cast<ErrorExpr *>()) {
35483546
printFlag("error_expr");
3547+
} else if (auto *DMT = originator.dyn_cast<DependentMemberType *>()) {
3548+
printRec("dependent_member_type", DMT);
35493549
} else {
3550-
printRec("dependent_member_type",
3551-
originator.get<DependentMemberType *>());
3550+
printFlag("placeholder_type_repr");
35523551
}
35533552
PrintWithColorRAII(OS, ParenthesisColor) << ')';
35543553
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,15 +958,14 @@ void ASTMangler::appendType(Type type, const ValueDecl *forDecl) {
958958
TypeBase *tybase = type.getPointer();
959959
switch (type->getKind()) {
960960
case TypeKind::TypeVariable:
961-
case TypeKind::Hole:
961+
case TypeKind::Placeholder:
962962
llvm_unreachable("mangling type variable");
963963

964964
case TypeKind::Module:
965965
llvm_unreachable("Cannot mangle module type yet");
966966

967967
case TypeKind::Error:
968968
case TypeKind::Unresolved:
969-
case TypeKind::Placeholder:
970969
appendOperator("Xe");
971970
return;
972971

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,15 +4169,8 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41694169
}
41704170

41714171
void visitPlaceholderType(PlaceholderType *T) {
4172-
if (Options.PrintTypesForDebugging)
4173-
Printer << "<<placeholdertype>>";
4174-
else
4175-
Printer << "_";
4176-
}
4177-
4178-
void visitHoleType(HoleType *T) {
41794172
if (Options.PrintTypesForDebugging) {
4180-
Printer << "<<hole for ";
4173+
Printer << "<<placeholder for ";
41814174
auto originator = T->getOriginator();
41824175
if (auto *typeVar = originator.dyn_cast<TypeVariableType *>()) {
41834176
visit(typeVar);
@@ -4186,8 +4179,10 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41864179
Printer << VD->getName();
41874180
} else if (auto *EE = originator.dyn_cast<ErrorExpr *>()) {
41884181
Printer << "error_expr";
4182+
} else if (auto *DMT = originator.dyn_cast<DependentMemberType *>()) {
4183+
visit(DMT);
41894184
} else {
4190-
visit(originator.get<DependentMemberType *>());
4185+
Printer << "placeholder_type_repr";
41914186
}
41924187
Printer << ">>";
41934188
} else {

0 commit comments

Comments
 (0)