@@ -116,14 +116,34 @@ bool ModuleDependencyInfo::isTestableImport(StringRef moduleName) const {
116116}
117117
118118void ModuleDependencyInfo::addOptionalModuleImport (
119- StringRef module , bool isExported, llvm::StringSet<> *alreadyAddedModules) {
120- if (!alreadyAddedModules || alreadyAddedModules->insert (module ).second )
121- storage->optionalModuleImports .push_back ({module .str (), isExported});
119+ StringRef module , bool isExported, AccessLevel accessLevel,
120+ llvm::StringSet<> *alreadyAddedModules) {
121+
122+ if (alreadyAddedModules && alreadyAddedModules->contains (module )) {
123+ // Find a prior import of this module and add import location
124+ // and adjust whether or not this module is ever imported as exported
125+ // as well as the access level
126+ for (auto &existingImport : storage->optionalModuleImports ) {
127+ if (existingImport.importIdentifier == module ) {
128+ existingImport.isExported |= isExported;
129+ existingImport.accessLevel = std::max (existingImport.accessLevel ,
130+ accessLevel);
131+ break ;
132+ }
133+ }
134+ } else {
135+ if (alreadyAddedModules)
136+ alreadyAddedModules->insert (module );
137+
138+ storage->optionalModuleImports .push_back (
139+ {module .str (), isExported, accessLevel});
140+ }
122141}
123142
124143void ModuleDependencyInfo::addModuleImport (
125- StringRef module , bool isExported, llvm::StringSet<> *alreadyAddedModules,
126- const SourceManager *sourceManager, SourceLoc sourceLocation) {
144+ StringRef module , bool isExported, AccessLevel accessLevel,
145+ llvm::StringSet<> *alreadyAddedModules, const SourceManager *sourceManager,
146+ SourceLoc sourceLocation) {
127147 auto scannerImportLocToDiagnosticLocInfo =
128148 [&sourceManager](SourceLoc sourceLocation) {
129149 auto lineAndColumnNumbers =
@@ -138,13 +158,16 @@ void ModuleDependencyInfo::addModuleImport(
138158 if (alreadyAddedModules && alreadyAddedModules->contains (module )) {
139159 // Find a prior import of this module and add import location
140160 // and adjust whether or not this module is ever imported as exported
161+ // as well as the access level
141162 for (auto &existingImport : storage->moduleImports ) {
142163 if (existingImport.importIdentifier == module ) {
143164 if (validSourceLocation) {
144165 existingImport.addImportLocation (
145- scannerImportLocToDiagnosticLocInfo (sourceLocation));
166+ scannerImportLocToDiagnosticLocInfo (sourceLocation));
146167 }
147168 existingImport.isExported |= isExported;
169+ existingImport.accessLevel = std::max (existingImport.accessLevel ,
170+ accessLevel);
148171 break ;
149172 }
150173 }
@@ -154,16 +177,18 @@ void ModuleDependencyInfo::addModuleImport(
154177
155178 if (validSourceLocation)
156179 storage->moduleImports .push_back (ScannerImportStatementInfo (
157- module .str (), isExported, scannerImportLocToDiagnosticLocInfo (sourceLocation)));
180+ module .str (), isExported, accessLevel,
181+ scannerImportLocToDiagnosticLocInfo (sourceLocation)));
158182 else
159183 storage->moduleImports .push_back (
160- ScannerImportStatementInfo (module .str (), isExported));
184+ ScannerImportStatementInfo (module .str (), isExported, accessLevel ));
161185 }
162186}
163187
164188void ModuleDependencyInfo::addModuleImport (
165- ImportPath::Module module , bool isExported, llvm::StringSet<> *alreadyAddedModules,
166- const SourceManager *sourceManager, SourceLoc sourceLocation) {
189+ ImportPath::Module module , bool isExported, AccessLevel accessLevel,
190+ llvm::StringSet<> *alreadyAddedModules, const SourceManager *sourceManager,
191+ SourceLoc sourceLocation) {
167192 std::string ImportedModuleName = module .front ().Item .str ().str ();
168193 auto submodulePath = module .getSubmodulePath ();
169194 if (submodulePath.size () > 0 && !submodulePath[0 ].Item .empty ()) {
@@ -172,11 +197,12 @@ void ModuleDependencyInfo::addModuleImport(
172197 // module named "Foo_Private". ClangImporter has special support for this.
173198 if (submoduleComponent.Item .str () == " Private" )
174199 addOptionalModuleImport (ImportedModuleName + " _Private" ,
200+ isExported, accessLevel,
175201 alreadyAddedModules);
176202 }
177203
178- addModuleImport (ImportedModuleName, isExported, alreadyAddedModules ,
179- sourceManager, sourceLocation);
204+ addModuleImport (ImportedModuleName, isExported, accessLevel ,
205+ alreadyAddedModules, sourceManager, sourceLocation);
180206}
181207
182208void ModuleDependencyInfo::addModuleImports (
@@ -205,6 +231,7 @@ void ModuleDependencyInfo::addModuleImports(
205231 continue ;
206232
207233 addModuleImport (realPath, importDecl->isExported (),
234+ importDecl->getAccessLevel (),
208235 &alreadyAddedModules, sourceManager,
209236 importDecl->getLoc ());
210237
0 commit comments