Author: mren Date: Fri Apr 29 14:04:05 2016 New Revision: 268091 URL: http://llvm.org/viewvc/llvm-project?rev=268091&view=rev Log: Method Pool in modules: we make sure that if a module contains an entry for a selector, the entry should be complete, containing everything introduced by that module and all modules it imports.
Before writing out the method pool of a module, we sync up the out of date selectors by pulling in methods for the selectors, from all modules it imports. In ReadMethodPool, after pulling in the method pool entry for module A, this lets us skip the modules that module A imports. rdar://problem/25900131 Added: cfe/trunk/test/Modules/Inputs/MethodPoolCombined1.h cfe/trunk/test/Modules/Inputs/MethodPoolCombined2.h cfe/trunk/test/Modules/Inputs/MethodPoolString1.h cfe/trunk/test/Modules/Inputs/MethodPoolString2.h cfe/trunk/test/Modules/method_pool_write.m Modified: cfe/trunk/include/clang/Sema/ExternalSemaSource.h cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/include/clang/Serialization/ASTReader.h cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp cfe/trunk/lib/Sema/Sema.cpp cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/test/Modules/Inputs/module.map Modified: cfe/trunk/include/clang/Sema/ExternalSemaSource.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ExternalSemaSource.h?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/ExternalSemaSource.h (original) +++ cfe/trunk/include/clang/Sema/ExternalSemaSource.h Fri Apr 29 14:04:05 2016 @@ -70,6 +70,10 @@ public: /// selector. virtual void ReadMethodPool(Selector Sel); + /// Load the contents of the global method pool for a given + /// selector if necessary. + virtual void updateOutOfDateSelector(Selector Sel); + /// \brief Load the set of namespaces that are known to the external source, /// which will be used during typo correction. virtual void ReadKnownNamespaces( Modified: cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h (original) +++ cfe/trunk/include/clang/Sema/MultiplexExternalSemaSource.h Fri Apr 29 14:04:05 2016 @@ -203,6 +203,10 @@ public: /// selector. void ReadMethodPool(Selector Sel) override; + /// Load the contents of the global method pool for a given + /// selector if necessary. + void updateOutOfDateSelector(Selector Sel) override; + /// \brief Load the set of namespaces that are known to the external source, /// which will be used during typo correction. void Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Fri Apr 29 14:04:05 2016 @@ -1017,6 +1017,7 @@ public: llvm::SmallSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; void ReadMethodPool(Selector Sel); + void updateOutOfDateSelector(Selector Sel); /// Private Helper predicate to check for 'self'. bool isSelfExpr(Expr *RExpr); Modified: cfe/trunk/include/clang/Serialization/ASTReader.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/include/clang/Serialization/ASTReader.h (original) +++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Apr 29 14:04:05 2016 @@ -653,6 +653,10 @@ private: /// global method pool for this selector. llvm::DenseMap<Selector, unsigned> SelectorGeneration; + /// Whether a selector is out of date. We mark a selector as out of date + /// if we load another module after the method pool entry was pulled in. + llvm::DenseMap<Selector, bool> SelectorOutOfDate; + struct PendingMacroInfo { ModuleFile *M; uint64_t MacroDirectivesOffset; @@ -1781,6 +1785,10 @@ public: /// selector. void ReadMethodPool(Selector Sel) override; + /// Load the contents of the global method pool for a given + /// selector if necessary. + void updateOutOfDateSelector(Selector Sel) override; + /// \brief Load the set of namespaces that are known to the external source, /// which will be used during typo correction. void ReadKnownNamespaces( Modified: cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp (original) +++ cfe/trunk/lib/Sema/MultiplexExternalSemaSource.cpp Fri Apr 29 14:04:05 2016 @@ -197,6 +197,11 @@ void MultiplexExternalSemaSource::ReadMe Sources[i]->ReadMethodPool(Sel); } +void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) { + for(size_t i = 0; i < Sources.size(); ++i) + Sources[i]->updateOutOfDateSelector(Sel); +} + void MultiplexExternalSemaSource::ReadKnownNamespaces( SmallVectorImpl<NamespaceDecl*> &Namespaces){ for(size_t i = 0; i < Sources.size(); ++i) Modified: cfe/trunk/lib/Sema/Sema.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/lib/Sema/Sema.cpp (original) +++ cfe/trunk/lib/Sema/Sema.cpp Fri Apr 29 14:04:05 2016 @@ -1237,6 +1237,7 @@ void Sema::ActOnComment(SourceRange Comm ExternalSemaSource::~ExternalSemaSource() {} void ExternalSemaSource::ReadMethodPool(Selector Sel) { } +void ExternalSemaSource::updateOutOfDateSelector(Selector Sel) { } void ExternalSemaSource::ReadKnownNamespaces( SmallVectorImpl<NamespaceDecl *> &Namespaces) { Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Apr 29 14:04:05 2016 @@ -3305,6 +3305,12 @@ void Sema::ReadMethodPool(Selector Sel) ExternalSource->ReadMethodPool(Sel); } +void Sema::updateOutOfDateSelector(Selector Sel) { + if (!ExternalSource) + return; + ExternalSource->updateOutOfDateSelector(Sel); +} + void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance) { // Ignore methods of invalid containers. Modified: cfe/trunk/lib/Serialization/ASTReader.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReader.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Apr 29 14:04:05 2016 @@ -3606,6 +3606,9 @@ ASTReader::ASTReadResult ASTReader::Read Id != IdEnd; ++Id) Id->second->setOutOfDate(true); } + // Mark selectors as out of date. + for (auto Sel : SelectorGeneration) + SelectorOutOfDate[Sel.first] = true; // Resolve any unresolved module exports. for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { @@ -7139,6 +7142,7 @@ void ASTReader::ReadMethodPool(Selector unsigned &Generation = SelectorGeneration[Sel]; unsigned PriorGeneration = Generation; Generation = getGeneration(); + SelectorOutOfDate[Sel] = false; // Search for methods defined with this selector. ++NumMethodPoolLookups; @@ -7170,6 +7174,11 @@ void ASTReader::ReadMethodPool(Selector addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); } +void ASTReader::updateOutOfDateSelector(Selector Sel) { + if (SelectorOutOfDate[Sel]) + ReadMethodPool(Sel); +} + void ASTReader::ReadKnownNamespaces( SmallVectorImpl<NamespaceDecl *> &Namespaces) { Namespaces.clear(); Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Apr 29 14:04:05 2016 @@ -4387,6 +4387,19 @@ uint64_t ASTWriter::WriteASTCore(Sema &S } } + // For method pool in the module, if it contains an entry for a selector, + // the entry should be complete, containing everything introduced by that + // module and all modules it imports. It's possible that the entry is out of + // date, so we need to pull in the new content here. + + // It's possible that updateOutOfDateSelector can update SelectorIDs. To be + // safe, we copy all selectors out. + llvm::SmallVector<Selector, 256> AllSelectors; + for (auto &SelectorAndID : SelectorIDs) + AllSelectors.push_back(SelectorAndID.first); + for (auto &Selector : AllSelectors) + SemaRef.updateOutOfDateSelector(Selector); + // Form the record of special types. RecordData SpecialTypes; AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); Added: cfe/trunk/test/Modules/Inputs/MethodPoolCombined1.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/MethodPoolCombined1.h?rev=268091&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/MethodPoolCombined1.h (added) +++ cfe/trunk/test/Modules/Inputs/MethodPoolCombined1.h Fri Apr 29 14:04:05 2016 @@ -0,0 +1,6 @@ + +@import MethodPoolString1; +@interface A +- (int)stringValue; +@end + Added: cfe/trunk/test/Modules/Inputs/MethodPoolCombined2.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/MethodPoolCombined2.h?rev=268091&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/MethodPoolCombined2.h (added) +++ cfe/trunk/test/Modules/Inputs/MethodPoolCombined2.h Fri Apr 29 14:04:05 2016 @@ -0,0 +1 @@ +@import MethodPoolString2; Added: cfe/trunk/test/Modules/Inputs/MethodPoolString1.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/MethodPoolString1.h?rev=268091&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/MethodPoolString1.h (added) +++ cfe/trunk/test/Modules/Inputs/MethodPoolString1.h Fri Apr 29 14:04:05 2016 @@ -0,0 +1,4 @@ + +@interface S1 +- (int)stringValue; +@end Added: cfe/trunk/test/Modules/Inputs/MethodPoolString2.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/MethodPoolString2.h?rev=268091&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/MethodPoolString2.h (added) +++ cfe/trunk/test/Modules/Inputs/MethodPoolString2.h Fri Apr 29 14:04:05 2016 @@ -0,0 +1,4 @@ + +@interface S2 +- (int)stringValue; +@end Modified: cfe/trunk/test/Modules/Inputs/module.map URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=268091&r1=268090&r2=268091&view=diff ============================================================================== --- cfe/trunk/test/Modules/Inputs/module.map (original) +++ cfe/trunk/test/Modules/Inputs/module.map Fri Apr 29 14:04:05 2016 @@ -393,3 +393,20 @@ module ElaboratedTypeStructs { header "elaborated-type-structs.h" } } + +// We import a module, then declare a method with selector stringValue in +// MethodPoolCombined1.h. In MethodPoolCombined2.h, we import another module +// that also contains a method for selector stringValue. We make sure that +// the method pool entry for stringValue in this module is complete. +module MethodPoolCombined { + header "MethodPoolCombined1.h" + header "MethodPoolCombined2.h" +} + +module MethodPoolString1 { + header "MethodPoolString1.h" +} + +module MethodPoolString2 { + header "MethodPoolString2.h" +} Added: cfe/trunk/test/Modules/method_pool_write.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/method_pool_write.m?rev=268091&view=auto ============================================================================== --- cfe/trunk/test/Modules/method_pool_write.m (added) +++ cfe/trunk/test/Modules/method_pool_write.m Fri Apr 29 14:04:05 2016 @@ -0,0 +1,11 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fsyntax-only -I %S/Inputs %s -verify +// expected-no-diagnostics + +@import MethodPoolCombined; +@import MethodPoolString2; + +void message_kindof_object(__kindof S2 *kindof_S2) { + [kindof_S2 stringValue]; +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits