@@ -3099,6 +3099,15 @@ static bool isDeclaredInModule(const ClangModuleUnit *ModuleFilter,
3099
3099
if (VD->getModuleContext ()->getName ().str () == CLANG_HEADER_MODULE_NAME) {
3100
3100
return true ;
3101
3101
}
3102
+ // Because the ClangModuleUnit saved as a decl context will be saved as the top-level module, but
3103
+ // the ModuleFilter we're given might be a submodule (if a submodule was passed to
3104
+ // getTopLevelDecls, for example), we should compare the underlying Clang modules to determine
3105
+ // module membership.
3106
+ if (auto ClangNode = VD->getClangNode ()) {
3107
+ if (auto *ClangModule = ClangNode.getOwningClangModule ()) {
3108
+ return ModuleFilter->getClangModule () == ClangModule;
3109
+ }
3110
+ }
3102
3111
auto ContainingUnit = VD->getDeclContext ()->getModuleScopeContext ();
3103
3112
return ModuleFilter == ContainingUnit;
3104
3113
}
@@ -3271,7 +3280,7 @@ class FilteringDeclaredDeclConsumer : public swift::VisibleDeclConsumer {
3271
3280
FilteringDeclaredDeclConsumer (swift::VisibleDeclConsumer &consumer,
3272
3281
const ClangModuleUnit *CMU)
3273
3282
: NextConsumer(consumer), ModuleFilter(CMU) {
3274
- assert (CMU && CMU-> isTopLevel () && " Only top-level modules supported " );
3283
+ assert (CMU);
3275
3284
}
3276
3285
3277
3286
void foundDecl (ValueDecl *VD, DeclVisibilityKind Reason,
@@ -3622,9 +3631,6 @@ class VectorDeclPtrConsumer : public swift::VisibleDeclConsumer {
3622
3631
};
3623
3632
} // unnamed namespace
3624
3633
3625
- // FIXME(https://github.com/apple/swift-docc/issues/190): Should submodules still be crawled for the symbol graph?
3626
- bool ClangModuleUnit::shouldCollectDisplayDecls () const { return isTopLevel (); }
3627
-
3628
3634
void ClangModuleUnit::getTopLevelDecls (SmallVectorImpl<Decl*> &results) const {
3629
3635
VectorDeclPtrConsumer consumer (results);
3630
3636
FilteringDeclaredDeclConsumer filterConsumer (consumer, this );
@@ -3645,10 +3651,12 @@ void ClangModuleUnit::getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {
3645
3651
3646
3652
// Add the extensions produced by importing categories.
3647
3653
for (auto category : lookupTable->categories ()) {
3648
- if (auto extension = cast_or_null<ExtensionDecl>(
3649
- owner.importDecl (category, owner.CurrentVersion ,
3650
- /* UseCanonical*/ false ))) {
3651
- results.push_back (extension);
3654
+ if (category->getOwningModule () == clangModule) {
3655
+ if (auto extension = cast_or_null<ExtensionDecl>(
3656
+ owner.importDecl (category, owner.CurrentVersion ,
3657
+ /* UseCanonical*/ false ))) {
3658
+ results.push_back (extension);
3659
+ }
3652
3660
}
3653
3661
}
3654
3662
@@ -3663,11 +3671,11 @@ void ClangModuleUnit::getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {
3663
3671
};
3664
3672
// Retrieve all of the globals that will be mapped to members.
3665
3673
3666
- // FIXME: Since we don't represent Clang submodules as Swift
3667
- // modules, we're getting everything.
3668
3674
llvm::SmallPtrSet<ExtensionDecl *, 8 > knownExtensions;
3669
3675
for (auto entry : lookupTable->allGlobalsAsMembers ()) {
3670
3676
auto decl = entry.get <clang::NamedDecl *>();
3677
+ if (decl->getOwningModule () != clangModule) continue ;
3678
+
3671
3679
Decl *importedDecl = owner.importDecl (decl, owner.CurrentVersion );
3672
3680
if (!importedDecl) continue ;
3673
3681
0 commit comments