[NFC] Adopt new ImportPath types and terminology

# Conflicts:
#	lib/IDE/CodeCompletion.cpp
This commit is contained in:
Brent Royal-Gordon
2020-09-10 19:05:40 -07:00
parent 1ed3caece6
commit cff4ddf13a
52 changed files with 375 additions and 361 deletions

View File

@@ -70,13 +70,13 @@ struct UnboundImport {
/// The module names being imported. There will usually be just one for the
/// top-level module, but a submodule import will have more.
ModuleDecl::AccessPathTy modulePath;
ImportPath::Module modulePath;
/// If this is a scoped import, the names of the declaration being imported;
/// otherwise empty. (Currently the compiler doesn't support nested scoped
/// imports, so there should always be zero or one elements, but
/// \c AccessPathTy is the common currency type for this.)
ModuleDecl::AccessPathTy declPath;
ImportPath::Access declPath;
// Names of explicitly imported SPI groups via @_spi.
ArrayRef<Identifier> spiGroups;
@@ -202,7 +202,7 @@ public:
for (auto &import : SF.getParentModule()->getImplicitImports()) {
assert(!(SF.Kind == SourceFileKind::SIL &&
import.Module->isStdlibModule()));
ImportedModule importedMod{ModuleDecl::AccessPathTy(), import.Module};
ImportedModule importedMod{ImportPath::Access(), import.Module};
boundImports.emplace_back(importedMod, import.Options);
}
}
@@ -260,7 +260,7 @@ private:
/// Load a module referenced by an import statement.
///
/// Returns null if no module can be loaded.
ModuleDecl *getModule(ArrayRef<Located<Identifier>> ModuleID);
ModuleDecl *getModule(ImportPath::Module ModuleID);
};
} // end anonymous namespace
@@ -368,7 +368,7 @@ void ImportResolver::addImport(const UnboundImport &I, ModuleDecl *M) {
//===----------------------------------------------------------------------===//
ModuleDecl *
ImportResolver::getModule(ArrayRef<Located<Identifier>> modulePath) {
ImportResolver::getModule(ImportPath::Module modulePath) {
assert(!modulePath.empty());
auto moduleID = modulePath[0];
@@ -447,7 +447,8 @@ ModuleImplicitImportsRequest::evaluate(Evaluator &evaluator,
// Add any modules we were asked to implicitly import.
for (auto moduleName : importInfo.ModuleNames) {
auto *importModule = ctx.getModule({{moduleName, SourceLoc()}});
auto *importModule = ctx.getModule(
ImportPath::Module::Builder(moduleName).get());
if (!importModule) {
ctx.Diags.diagnose(SourceLoc(), diag::sema_no_import, moduleName.str());
if (ctx.SearchPathOpts.SDKPath.empty() &&
@@ -481,7 +482,7 @@ ModuleImplicitImportsRequest::evaluate(Evaluator &evaluator,
// Implicitly import the underlying Clang half of this module if needed.
if (importInfo.ShouldImportUnderlyingModule) {
auto *underlyingMod = clangImporter->loadModule(
SourceLoc(), {Located<Identifier>(module->getName(), SourceLoc())});
SourceLoc(), ImportPath::Module::Builder(module->getName()).get());
if (underlyingMod) {
imports.emplace_back(underlyingMod, ImportFlags::Exported);
} else {
@@ -558,10 +559,10 @@ bool UnboundImport::checkModuleLoaded(ModuleDecl *M, SourceFile &SF) {
ASTContext &ctx = SF.getASTContext();
SmallString<64> modulePathStr;
interleave(modulePath, [&](ImportDecl::AccessPathElement elem) {
modulePathStr += elem.Item.str();
},
[&] { modulePathStr += "."; });
llvm::interleave(modulePath, [&](ImportPath::Element elem) {
modulePathStr += elem.Item.str();
},
[&] { modulePathStr += "."; });
auto diagKind = diag::sema_no_import;
if (ctx.LangOpts.DebuggerSupport)
@@ -866,9 +867,9 @@ ScopedImportLookupRequest::evaluate(Evaluator &evaluator,
auto importLoc = import->getLoc();
if (decls.empty()) {
ctx.Diags.diagnose(importLoc, diag::decl_does_not_exist_in_module,
static_cast<unsigned>(importKind), declPath.front().Item,
modulePath.front().Item)
.highlight(SourceRange(declPath.front().Loc, declPath.back().Loc));
static_cast<unsigned>(importKind),
declPath.front().Item, modulePath.front().Item)
.highlight(declPath.getSourceRange());
return ArrayRef<ValueDecl *>();
}
@@ -897,8 +898,9 @@ ScopedImportLookupRequest::evaluate(Evaluator &evaluator,
getImportKindString(importKind)));
} else {
emittedDiag.emplace(ctx.Diags.diagnose(
importLoc, diag::imported_decl_is_wrong_kind, declPath.front().Item,
getImportKindString(importKind), static_cast<unsigned>(*actualKind)));
importLoc, diag::imported_decl_is_wrong_kind,
declPath.front().Item, getImportKindString(importKind),
static_cast<unsigned>(*actualKind)));
}
emittedDiag->fixItReplace(SourceRange(import->getKindLoc()),
@@ -931,14 +933,16 @@ UnboundImport::UnboundImport(ASTContext &ctx, const UnboundImport &base,
const ImportedModuleDesc &declaringImport,
const ImportedModuleDesc &bystandingImport)
: importLoc(base.importLoc), options(), privateImportFileName(),
modulePath(),
// Cross-imports are not backed by an ImportDecl, so we need to provide
// our own storage for their module paths.
modulePath(
ImportPath::Module::Builder(overlayName, base.modulePath[0].Loc)
.copyTo(ctx)),
// If the declaring import was scoped, inherit that scope in the
// overlay's import.
declPath(declaringImport.module.accessPath),
importOrUnderlyingModuleDecl(declaringImport.module.importedModule) {
modulePath = ctx.AllocateCopy(
ModuleDecl::AccessPathTy( { overlayName, base.modulePath[0].Loc }));
importOrUnderlyingModuleDecl(declaringImport.module.importedModule)
{
// A cross-import is never private or testable, and never comes from a private
// or testable import.
assert(canCrossImport(declaringImport));
@@ -1136,8 +1140,7 @@ void ImportResolver::addCrossImportableModules(ImportedModuleDesc importDesc) {
// cannot possibly expose anything new. Skip it.
if (!importDesc.module.accessPath.empty() &&
!nextImport.accessPath.empty() &&
!ModuleDecl::isSameAccessPath(importDesc.module.accessPath,
nextImport.accessPath))
!importDesc.module.accessPath.isSameAs(nextImport.accessPath))
continue;
// If we are importing a submodule, treat it as though we imported its