@@ -187,24 +187,17 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
187
187
continue ;
188
188
}
189
189
190
- StringRef modulePathStr = dependency.Core .RawPath ;
191
- StringRef scopePath;
192
- if (dependency.isScoped ()) {
193
- auto splitPoint = modulePathStr.find_last_of (' \0 ' );
194
- assert (splitPoint != StringRef::npos);
195
- scopePath = modulePathStr.substr (splitPoint+1 );
196
- modulePathStr = modulePathStr.slice (0 , splitPoint);
190
+ ImportPath::Builder builder (ctx, dependency.Core .RawPath ,
191
+ /* separator=*/ ' \0 ' );
192
+ for (const auto &elem : builder) {
193
+ assert (!elem.Item .empty () && " invalid import path name" );
197
194
}
198
195
199
- // TODO: Further simplification is possible by unifying scopePath above with
200
- // this.
201
- ImportPath::Module::Builder modulePath (ctx, modulePathStr,
202
- /* separator=*/ ' \0 ' );
203
- for (const auto &elem : modulePath) {
204
- assert (!elem.Item .empty () &&
205
- " invalid module name (submodules not yet supported)" );
206
- }
207
- auto module = getModule (modulePath.get (), /* allowLoading*/ true );
196
+ auto importPath = builder.copyTo (ctx);
197
+ auto modulePath = importPath.getModulePath (dependency.isScoped ());
198
+ auto accessPath = importPath.getAccessPath (dependency.isScoped ());
199
+
200
+ auto module = getModule (modulePath, /* allowLoading*/ true );
208
201
if (!module || module ->failedToLoad ()) {
209
202
// If we're missing the module we're an overlay for, treat that specially.
210
203
if (modulePath.size () == 1 &&
@@ -219,16 +212,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
219
212
continue ;
220
213
}
221
214
222
- if (scopePath.empty ()) {
223
- dependency.Import =
224
- ModuleDecl::ImportedModule{ImportPath::Access (), module };
225
- } else {
226
- auto scopeID = ctx.getIdentifier (scopePath);
227
- assert (!scopeID.empty () &&
228
- " invalid decl name (non-top-level decls not supported)" );
229
- dependency.Import = ModuleDecl::ImportedModule{
230
- ImportPath::Access::Builder (scopeID).copyTo (ctx), module };
231
- }
215
+ dependency.Import = ModuleDecl::ImportedModule{accessPath, module };
232
216
233
217
// SPI
234
218
StringRef spisStr = dependency.Core .RawSPIs ;
0 commit comments