Skip to content

Commit 4be67a6

Browse files
committed
[NFC] Further simplify ModuleFile::associateWithFileContext
1 parent cce0411 commit 4be67a6

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,17 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
187187
continue;
188188
}
189189

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");
197194
}
198195

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);
208201
if (!module || module->failedToLoad()) {
209202
// If we're missing the module we're an overlay for, treat that specially.
210203
if (modulePath.size() == 1 &&
@@ -219,16 +212,7 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc) {
219212
continue;
220213
}
221214

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};
232216

233217
// SPI
234218
StringRef spisStr = dependency.Core.RawSPIs;

0 commit comments

Comments
 (0)