Record Objective-C method lookup tables in Swift modules.

Include a mapping from Objective-C selectors to the @objc methods that
produce Objective-c methods with those selectors. Use this to lazily
populate the Objective-C method lookup tables in each class. This makes
@objc override checking work across Swift modules, which is part of
rdar://problem/18391046.

Note that we use a single, unified selector table, both because it is
simpler and because it makes global queries ("is there any method with
the given selector?") easier.

Swift SVN r23214
This commit is contained in:
Doug Gregor
2014-11-11 00:19:03 +00:00
parent 3910c25da1
commit b27e88b70b
16 changed files with 426 additions and 18 deletions

View File

@@ -252,6 +252,12 @@ private:
std::unique_ptr<SerializedDeclTable> ClassMembersByName;
std::unique_ptr<SerializedDeclTable> OperatorMethodDecls;
class ObjCMethodTableInfo;
using SerializedObjCMethodTable =
llvm::OnDiskIterableChainedHashTable<ObjCMethodTableInfo>;
std::unique_ptr<SerializedObjCMethodTable> ObjCMethods;
llvm::DenseMap<const ValueDecl *, Identifier> PrivateDiscriminatorsByValue;
TinyPtrVector<Decl *> ImportDecls;
@@ -323,6 +329,11 @@ private:
std::unique_ptr<SerializedDeclTable>
readDeclTable(ArrayRef<uint64_t> fields, StringRef blobData);
/// Read an on-disk Objective-C method table stored in
/// index_block::ObjCMethodTableLayout format.
std::unique_ptr<ModuleFile::SerializedObjCMethodTable>
readObjCMethodTable(ArrayRef<uint64_t> fields, StringRef blobData);
/// Reads the index block, which contains global tables.
///
/// Returns false if there was an error.
@@ -450,6 +461,25 @@ public:
/// Note that this may cause other decls to load as well.
void loadExtensions(NominalTypeDecl *nominal);
/// \brief Load the methods within the given class that that produce
/// Objective-C class or instance methods with the given selector.
///
/// \param classDecl The class in which we are searching for @objc methods.
/// The search only considers this class and its extensions; not any
/// superclasses.
///
/// \param selector The selector to search for.
///
/// \param isInstanceMethod Whether we are looking for an instance method
/// (vs. a class method).
///
/// \param methods The list of @objc methods in this class that have this
/// selector and are instance/class methods as requested.
void loadObjCMethods(ClassDecl *classDecl,
ObjCSelector selector,
bool isInstanceMethod,
llvm::TinyPtrVector<AbstractFunctionDecl *> &methods);
/// Reports all class members in the module to the given consumer.
///
/// This is intended for use with id-style lookup and code completion.