Derive conformances of Equatable and Hashable for simple enums.

If an enum has no cases with payloads, make it implicitly Equatable and Hashable, and derive default implementations of '==' and 'hashValue'. Insert the derived '==' into module context wrapped in a new DerivedFileUnit kind, and arrange for it to be codegenned with the deriving EnumDecl by adding a 'DerivedOperatorDecls' array to NominalTypeDecls that gets visited at SILGen time.

Swift SVN r14471
This commit is contained in:
Joe Groff
2014-02-27 20:28:38 +00:00
parent 1753c0cf64
commit 8e6b353542
21 changed files with 839 additions and 61 deletions

View File

@@ -313,6 +313,25 @@ void BuiltinUnit::lookupValue(Module::AccessPathTy accessPath, Identifier name,
getCache().lookupValue(name, lookupKind, *this, result);
}
void DerivedFileUnit::lookupValue(Module::AccessPathTy accessPath,
Identifier name,
NLKind lookupKind,
SmallVectorImpl<ValueDecl*> &result) const {
if (name == DerivedDecl->getName())
result.push_back(DerivedDecl);
}
void DerivedFileUnit::lookupVisibleDecls(Module::AccessPathTy accessPath,
VisibleDeclConsumer &consumer,
NLKind lookupKind) const {
consumer.foundDecl(DerivedDecl, DeclVisibilityKind::VisibleAtTopLevel);
}
void DerivedFileUnit::getTopLevelDecls(SmallVectorImpl<swift::Decl *> &results)
const {
results.push_back(DerivedDecl);
}
void SourceFile::lookupValue(Module::AccessPathTy accessPath, Identifier name,
NLKind lookupKind,
SmallVectorImpl<ValueDecl*> &result) const {
@@ -795,7 +814,8 @@ lookupOperatorDeclForName(const FileUnit &File, SourceLoc Loc, Identifier Name,
{
switch (File.getKind()) {
case FileUnitKind::Builtin:
// The Builtin module declares no operators.
case FileUnitKind::Derived:
// The Builtin module declares no operators, nor do derived units.
return nullptr;
case FileUnitKind::Source:
break;