Introduce special name for destructors

This name is not used yet
This commit is contained in:
Alex Hoppen
2017-07-12 17:50:13 +02:00
committed by Alex Hoppen
parent 1b9d19a353
commit 2eb36e41f5
10 changed files with 42 additions and 3 deletions

View File

@@ -214,7 +214,8 @@ class DeclBaseName {
public: public:
enum class Kind: uint8_t { enum class Kind: uint8_t {
Normal, Normal,
Subscript Subscript,
Destructor
}; };
private: private:
@@ -223,6 +224,8 @@ private:
/// This is an implementation detail that should never leak outside of /// This is an implementation detail that should never leak outside of
/// DeclName. /// DeclName.
static void *SubscriptIdentifierData; static void *SubscriptIdentifierData;
/// As above, for special destructor DeclNames.
static void *DestructorIdentifierData;
Identifier Ident; Identifier Ident;
@@ -235,9 +238,15 @@ public:
return DeclBaseName(Identifier((const char *)SubscriptIdentifierData)); return DeclBaseName(Identifier((const char *)SubscriptIdentifierData));
} }
static DeclBaseName createDestructor() {
return DeclBaseName(Identifier((const char *)DestructorIdentifierData));
}
Kind getKind() const { Kind getKind() const {
if (Ident.get() == SubscriptIdentifierData) { if (Ident.get() == SubscriptIdentifierData) {
return Kind::Subscript; return Kind::Subscript;
} else if (Ident.get() == DestructorIdentifierData) {
return Kind::Destructor;
} else { } else {
return Kind::Normal; return Kind::Normal;
} }
@@ -273,6 +282,8 @@ public:
return getIdentifier().str(); return getIdentifier().str();
case Kind::Subscript: case Kind::Subscript:
return "subscript"; return "subscript";
case Kind::Destructor:
return "deinit";
} }
} }

View File

@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
/// in source control, you should also update the comment to briefly /// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important; /// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format. /// it just ensures a conflict if two people change the module format.
const uint16_t VERSION_MINOR = 353; // Last change: count inherited conformances const uint16_t VERSION_MINOR = 354; // Last change: special destructor names
using DeclID = PointerEmbeddedInt<unsigned, 31>; using DeclID = PointerEmbeddedInt<unsigned, 31>;
using DeclIDField = BCFixed<31>; using DeclIDField = BCFixed<31>;
@@ -345,7 +345,8 @@ using OptionalTypeKindField = BCFixed<2>;
// VERSION_MAJOR. // VERSION_MAJOR.
enum class DeclNameKind: uint8_t { enum class DeclNameKind: uint8_t {
Normal, Normal,
Subscript Subscript,
Destructor
}; };
// These IDs must \em not be renumbered or reordered without incrementing // These IDs must \em not be renumbered or reordered without incrementing
@@ -359,6 +360,8 @@ enum SpecialIdentifierID : uint8_t {
OBJC_HEADER_MODULE_ID, OBJC_HEADER_MODULE_ID,
/// Special value for the special subscript name /// Special value for the special subscript name
SUBSCRIPT_ID, SUBSCRIPT_ID,
/// Special value for the special destructor name
DESTRUCTOR_ID,
/// The number of special Identifier IDs. This value should never be encoded; /// The number of special Identifier IDs. This value should never be encoded;
/// it should only be used to count the number of names above. As such, it /// it should only be used to count the number of names above. As such, it

View File

@@ -548,6 +548,8 @@ void ASTMangler::appendDeclName(const ValueDecl *decl) {
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
appendIdentifier("subscript"); appendIdentifier("subscript");
break; break;
case DeclBaseName::Kind::Destructor:
llvm_unreachable("Destructors are not mangled using appendDeclName");
} }
} else { } else {
assert(AllowNamelessEntities && "attempt to mangle unnamed decl"); assert(AllowNamelessEntities && "attempt to mangle unnamed decl");

View File

@@ -22,6 +22,8 @@ using namespace swift;
void *DeclBaseName::SubscriptIdentifierData = void *DeclBaseName::SubscriptIdentifierData =
&DeclBaseName::SubscriptIdentifierData; &DeclBaseName::SubscriptIdentifierData;
void *DeclBaseName::DestructorIdentifierData =
&DeclBaseName::DestructorIdentifierData;
raw_ostream &llvm::operator<<(raw_ostream &OS, Identifier I) { raw_ostream &llvm::operator<<(raw_ostream &OS, Identifier I) {
if (I.get() == nullptr) if (I.get() == nullptr)

View File

@@ -211,6 +211,8 @@ DeclBaseName SerializedSwiftName::toDeclBaseName(ASTContext &Context) const {
return Context.getIdentifier(Name); return Context.getIdentifier(Name);
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
return DeclBaseName::createSubscript(); return DeclBaseName::createSubscript();
case DeclBaseName::Kind::Destructor:
return DeclBaseName::createDestructor();
} }
} }
@@ -829,6 +831,9 @@ void SwiftLookupTable::dump() const {
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
llvm::errs() << " subscript:\n"; llvm::errs() << " subscript:\n";
break; break;
case DeclBaseName::Kind::Destructor:
llvm::errs() << " deinit:\n";
break;
} }
const auto &entries = LookupTable.find(baseName)->second; const auto &entries = LookupTable.find(baseName)->second;
for (const auto &entry : entries) { for (const auto &entry : entries) {

View File

@@ -82,6 +82,8 @@ struct SerializedSwiftName {
return Name; return Name;
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
return "subscript"; return "subscript";
case DeclBaseName::Kind::Destructor:
return "deinit";
} }
} }

View File

@@ -1621,6 +1621,8 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
return getSelectorFamily(declName.getIdentifier()); return getSelectorFamily(declName.getIdentifier());
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
return SelectorFamily::None; return SelectorFamily::None;
case DeclBaseName::Kind::Destructor:
return SelectorFamily::None;
} }
} }
return SelectorFamily::None; return SelectorFamily::None;

View File

@@ -1623,6 +1623,8 @@ DeclBaseName ModuleFile::getDeclBaseName(IdentifierID IID) {
llvm_unreachable("Cannot get DeclBaseName of special module id"); llvm_unreachable("Cannot get DeclBaseName of special module id");
case SUBSCRIPT_ID: case SUBSCRIPT_ID:
return DeclBaseName::createSubscript(); return DeclBaseName::createSubscript();
case serialization::DESTRUCTOR_ID:
return DeclBaseName::createDestructor();
case NUM_SPECIAL_IDS: case NUM_SPECIAL_IDS:
llvm_unreachable("implementation detail only"); llvm_unreachable("implementation detail only");
} }
@@ -1805,6 +1807,7 @@ ModuleDecl *ModuleFile::getModule(ModuleID MID) {
return clangImporter->getImportedHeaderModule(); return clangImporter->getImportedHeaderModule();
} }
case SUBSCRIPT_ID: case SUBSCRIPT_ID:
case DESTRUCTOR_ID:
llvm_unreachable("Modules cannot be named with special names"); llvm_unreachable("Modules cannot be named with special names");
case NUM_SPECIAL_IDS: case NUM_SPECIAL_IDS:
llvm_unreachable("implementation detail only"); llvm_unreachable("implementation detail only");

View File

@@ -341,6 +341,8 @@ public:
} }
case static_cast<uint8_t>(DeclNameKind::Subscript): case static_cast<uint8_t>(DeclNameKind::Subscript):
return {DeclBaseName::Kind::Subscript, StringRef()}; return {DeclBaseName::Kind::Subscript, StringRef()};
case static_cast<uint8_t>(DeclNameKind::Destructor):
return {DeclBaseName::Kind::Destructor, StringRef()};
default: default:
llvm_unreachable("Unknown DeclNameKind"); llvm_unreachable("Unknown DeclNameKind");
} }

View File

@@ -91,6 +91,8 @@ namespace {
return llvm::HashString(key.getIdentifier().str()); return llvm::HashString(key.getIdentifier().str());
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
return static_cast<uint8_t>(DeclNameKind::Subscript); return static_cast<uint8_t>(DeclNameKind::Subscript);
case DeclBaseName::Kind::Destructor:
return static_cast<uint8_t>(DeclNameKind::Destructor);
} }
} }
@@ -119,6 +121,9 @@ namespace {
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
writer.write<uint8_t>(static_cast<uint8_t>(DeclNameKind::Subscript)); writer.write<uint8_t>(static_cast<uint8_t>(DeclNameKind::Subscript));
break; break;
case DeclBaseName::Kind::Destructor:
writer.write<uint8_t>(static_cast<uint8_t>(DeclNameKind::Destructor));
break;
} }
} }
@@ -509,6 +514,8 @@ IdentifierID Serializer::addDeclBaseNameRef(DeclBaseName ident) {
} }
case DeclBaseName::Kind::Subscript: case DeclBaseName::Kind::Subscript:
return SUBSCRIPT_ID; return SUBSCRIPT_ID;
case DeclBaseName::Kind::Destructor:
return DESTRUCTOR_ID;
} }
} }