Skip to content

Commit 2eb36e4

Browse files
committed
Introduce special name for destructors
This name is not used yet
1 parent 1b9d19a commit 2eb36e4

File tree

10 files changed

+42
-3
lines changed

10 files changed

+42
-3
lines changed

include/swift/AST/Identifier.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ class DeclBaseName {
214214
public:
215215
enum class Kind: uint8_t {
216216
Normal,
217-
Subscript
217+
Subscript,
218+
Destructor
218219
};
219220

220221
private:
@@ -223,6 +224,8 @@ class DeclBaseName {
223224
/// This is an implementation detail that should never leak outside of
224225
/// DeclName.
225226
static void *SubscriptIdentifierData;
227+
/// As above, for special destructor DeclNames.
228+
static void *DestructorIdentifierData;
226229

227230
Identifier Ident;
228231

@@ -235,9 +238,15 @@ class DeclBaseName {
235238
return DeclBaseName(Identifier((const char *)SubscriptIdentifierData));
236239
}
237240

241+
static DeclBaseName createDestructor() {
242+
return DeclBaseName(Identifier((const char *)DestructorIdentifierData));
243+
}
244+
238245
Kind getKind() const {
239246
if (Ident.get() == SubscriptIdentifierData) {
240247
return Kind::Subscript;
248+
} else if (Ident.get() == DestructorIdentifierData) {
249+
return Kind::Destructor;
241250
} else {
242251
return Kind::Normal;
243252
}
@@ -273,6 +282,8 @@ class DeclBaseName {
273282
return getIdentifier().str();
274283
case Kind::Subscript:
275284
return "subscript";
285+
case Kind::Destructor:
286+
return "deinit";
276287
}
277288
}
278289

include/swift/Serialization/ModuleFormat.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 353; // Last change: count inherited conformances
57+
const uint16_t VERSION_MINOR = 354; // Last change: special destructor names
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -345,7 +345,8 @@ using OptionalTypeKindField = BCFixed<2>;
345345
// VERSION_MAJOR.
346346
enum class DeclNameKind: uint8_t {
347347
Normal,
348-
Subscript
348+
Subscript,
349+
Destructor
349350
};
350351

351352
// These IDs must \em not be renumbered or reordered without incrementing
@@ -359,6 +360,8 @@ enum SpecialIdentifierID : uint8_t {
359360
OBJC_HEADER_MODULE_ID,
360361
/// Special value for the special subscript name
361362
SUBSCRIPT_ID,
363+
/// Special value for the special destructor name
364+
DESTRUCTOR_ID,
362365

363366
/// The number of special Identifier IDs. This value should never be encoded;
364367
/// it should only be used to count the number of names above. As such, it

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
548548
case DeclBaseName::Kind::Subscript:
549549
appendIdentifier("subscript");
550550
break;
551+
case DeclBaseName::Kind::Destructor:
552+
llvm_unreachable("Destructors are not mangled using appendDeclName");
551553
}
552554
} else {
553555
assert(AllowNamelessEntities && "attempt to mangle unnamed decl");

lib/AST/Identifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ using namespace swift;
2222

2323
void *DeclBaseName::SubscriptIdentifierData =
2424
&DeclBaseName::SubscriptIdentifierData;
25+
void *DeclBaseName::DestructorIdentifierData =
26+
&DeclBaseName::DestructorIdentifierData;
2527

2628
raw_ostream &llvm::operator<<(raw_ostream &OS, Identifier I) {
2729
if (I.get() == nullptr)

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ DeclBaseName SerializedSwiftName::toDeclBaseName(ASTContext &Context) const {
211211
return Context.getIdentifier(Name);
212212
case DeclBaseName::Kind::Subscript:
213213
return DeclBaseName::createSubscript();
214+
case DeclBaseName::Kind::Destructor:
215+
return DeclBaseName::createDestructor();
214216
}
215217
}
216218

@@ -829,6 +831,9 @@ void SwiftLookupTable::dump() const {
829831
case DeclBaseName::Kind::Subscript:
830832
llvm::errs() << " subscript:\n";
831833
break;
834+
case DeclBaseName::Kind::Destructor:
835+
llvm::errs() << " deinit:\n";
836+
break;
832837
}
833838
const auto &entries = LookupTable.find(baseName)->second;
834839
for (const auto &entry : entries) {

lib/ClangImporter/SwiftLookupTable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ struct SerializedSwiftName {
8282
return Name;
8383
case DeclBaseName::Kind::Subscript:
8484
return "subscript";
85+
case DeclBaseName::Kind::Destructor:
86+
return "deinit";
8587
}
8688
}
8789

lib/SIL/SILFunctionType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,8 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
16211621
return getSelectorFamily(declName.getIdentifier());
16221622
case DeclBaseName::Kind::Subscript:
16231623
return SelectorFamily::None;
1624+
case DeclBaseName::Kind::Destructor:
1625+
return SelectorFamily::None;
16241626
}
16251627
}
16261628
return SelectorFamily::None;

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,8 @@ DeclBaseName ModuleFile::getDeclBaseName(IdentifierID IID) {
16231623
llvm_unreachable("Cannot get DeclBaseName of special module id");
16241624
case SUBSCRIPT_ID:
16251625
return DeclBaseName::createSubscript();
1626+
case serialization::DESTRUCTOR_ID:
1627+
return DeclBaseName::createDestructor();
16261628
case NUM_SPECIAL_IDS:
16271629
llvm_unreachable("implementation detail only");
16281630
}
@@ -1805,6 +1807,7 @@ ModuleDecl *ModuleFile::getModule(ModuleID MID) {
18051807
return clangImporter->getImportedHeaderModule();
18061808
}
18071809
case SUBSCRIPT_ID:
1810+
case DESTRUCTOR_ID:
18081811
llvm_unreachable("Modules cannot be named with special names");
18091812
case NUM_SPECIAL_IDS:
18101813
llvm_unreachable("implementation detail only");

lib/Serialization/ModuleFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ class ModuleFile::DeclTableInfo {
341341
}
342342
case static_cast<uint8_t>(DeclNameKind::Subscript):
343343
return {DeclBaseName::Kind::Subscript, StringRef()};
344+
case static_cast<uint8_t>(DeclNameKind::Destructor):
345+
return {DeclBaseName::Kind::Destructor, StringRef()};
344346
default:
345347
llvm_unreachable("Unknown DeclNameKind");
346348
}

lib/Serialization/Serialization.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ namespace {
9191
return llvm::HashString(key.getIdentifier().str());
9292
case DeclBaseName::Kind::Subscript:
9393
return static_cast<uint8_t>(DeclNameKind::Subscript);
94+
case DeclBaseName::Kind::Destructor:
95+
return static_cast<uint8_t>(DeclNameKind::Destructor);
9496
}
9597
}
9698

@@ -119,6 +121,9 @@ namespace {
119121
case DeclBaseName::Kind::Subscript:
120122
writer.write<uint8_t>(static_cast<uint8_t>(DeclNameKind::Subscript));
121123
break;
124+
case DeclBaseName::Kind::Destructor:
125+
writer.write<uint8_t>(static_cast<uint8_t>(DeclNameKind::Destructor));
126+
break;
122127
}
123128
}
124129

@@ -509,6 +514,8 @@ IdentifierID Serializer::addDeclBaseNameRef(DeclBaseName ident) {
509514
}
510515
case DeclBaseName::Kind::Subscript:
511516
return SUBSCRIPT_ID;
517+
case DeclBaseName::Kind::Destructor:
518+
return DESTRUCTOR_ID;
512519
}
513520
}
514521

0 commit comments

Comments
 (0)