mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Serialization|NFC] Extract logic loading dependencies out of associateWithFileContext
This commit is contained in:
@@ -123,53 +123,13 @@ bool ModuleFile::allowCompilerErrors() const {
|
|||||||
return getContext().LangOpts.AllowModuleWithCompilerErrors;
|
return getContext().LangOpts.AllowModuleWithCompilerErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
Status
|
||||||
bool recoverFromIncompatibility) {
|
ModuleFile::loadDependenciesForFileContext(const FileUnit *file,
|
||||||
PrettyStackTraceModuleFile stackEntry(*this);
|
SourceLoc diagLoc,
|
||||||
|
bool forTestable) {
|
||||||
assert(!hasError() && "error already detected; should not call this");
|
|
||||||
assert(!FileContext && "already associated with an AST module");
|
|
||||||
FileContext = file;
|
|
||||||
Status status = Status::Valid;
|
|
||||||
|
|
||||||
ModuleDecl *M = file->getParentModule();
|
|
||||||
// The real (on-disk) name of the module should be checked here as that's the
|
|
||||||
// actually loaded module. In case module aliasing is used when building the main
|
|
||||||
// module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
|
|
||||||
// that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
|
|
||||||
// modules only), which is retrieved via M->getRealName(). If no module aliasing is
|
|
||||||
// used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
|
|
||||||
if (M->getRealName().str() != Core->Name) {
|
|
||||||
return error(Status::NameMismatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
ASTContext &ctx = getContext();
|
ASTContext &ctx = getContext();
|
||||||
|
|
||||||
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
|
|
||||||
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
|
|
||||||
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
|
|
||||||
status = Status::TargetIncompatible;
|
|
||||||
if (!recoverFromIncompatibility)
|
|
||||||
return error(status);
|
|
||||||
} else if (ctx.LangOpts.EnableTargetOSChecking && !M->isResilient() &&
|
|
||||||
isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
|
|
||||||
status = Status::TargetTooNew;
|
|
||||||
if (!recoverFromIncompatibility)
|
|
||||||
return error(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
|
|
||||||
if (SDKPath.empty() ||
|
|
||||||
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
|
|
||||||
for (const auto &searchPath : Core->SearchPaths) {
|
|
||||||
ctx.addSearchPath(
|
|
||||||
ctx.SearchPathOpts.SearchPathRemapper.remapPath(searchPath.Path),
|
|
||||||
searchPath.IsFramework,
|
|
||||||
searchPath.IsSystem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto clangImporter = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
|
auto clangImporter = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
|
||||||
|
ModuleDecl *M = file->getParentModule();
|
||||||
|
|
||||||
bool missingDependency = false;
|
bool missingDependency = false;
|
||||||
for (auto &dependency : Dependencies) {
|
for (auto &dependency : Dependencies) {
|
||||||
@@ -259,6 +219,59 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
|||||||
return error(Status::MissingDependency);
|
return error(Status::MissingDependency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Status::Valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
||||||
|
bool recoverFromIncompatibility) {
|
||||||
|
PrettyStackTraceModuleFile stackEntry(*this);
|
||||||
|
|
||||||
|
assert(!hasError() && "error already detected; should not call this");
|
||||||
|
assert(!FileContext && "already associated with an AST module");
|
||||||
|
FileContext = file;
|
||||||
|
Status status = Status::Valid;
|
||||||
|
|
||||||
|
ModuleDecl *M = file->getParentModule();
|
||||||
|
// The real (on-disk) name of the module should be checked here as that's the
|
||||||
|
// actually loaded module. In case module aliasing is used when building the main
|
||||||
|
// module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
|
||||||
|
// that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
|
||||||
|
// modules only), which is retrieved via M->getRealName(). If no module aliasing is
|
||||||
|
// used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
|
||||||
|
if (M->getRealName().str() != Core->Name) {
|
||||||
|
return error(Status::NameMismatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
ASTContext &ctx = getContext();
|
||||||
|
|
||||||
|
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
|
||||||
|
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
|
||||||
|
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
|
||||||
|
status = Status::TargetIncompatible;
|
||||||
|
if (!recoverFromIncompatibility)
|
||||||
|
return error(status);
|
||||||
|
} else if (ctx.LangOpts.EnableTargetOSChecking && !M->isResilient() &&
|
||||||
|
isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
|
||||||
|
status = Status::TargetTooNew;
|
||||||
|
if (!recoverFromIncompatibility)
|
||||||
|
return error(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
|
||||||
|
if (SDKPath.empty() ||
|
||||||
|
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
|
||||||
|
for (const auto &searchPath : Core->SearchPaths) {
|
||||||
|
ctx.addSearchPath(
|
||||||
|
ctx.SearchPathOpts.SearchPathRemapper.remapPath(searchPath.Path),
|
||||||
|
searchPath.IsFramework,
|
||||||
|
searchPath.IsSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Status res = loadDependenciesForFileContext(file, diagLoc,
|
||||||
|
/*forTestable=*/false);
|
||||||
|
if (res != Status::Valid) return res;
|
||||||
|
|
||||||
if (Core->Bits.HasEntryPoint) {
|
if (Core->Bits.HasEntryPoint) {
|
||||||
FileContext->getParentModule()->registerEntryPointFile(FileContext,
|
FileContext->getParentModule()->registerEntryPointFile(FileContext,
|
||||||
SourceLoc(),
|
SourceLoc(),
|
||||||
|
|||||||
@@ -649,6 +649,19 @@ public:
|
|||||||
Status associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
Status associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
||||||
bool recoverFromIncompatibility);
|
bool recoverFromIncompatibility);
|
||||||
|
|
||||||
|
/// Load dependencies of this module.
|
||||||
|
///
|
||||||
|
/// \param file The FileUnit that represents this file's place in the AST.
|
||||||
|
/// \param diagLoc A location used for diagnostics that occur during loading.
|
||||||
|
/// This does not include diagnostics about \e this file failing to load,
|
||||||
|
/// but rather other things that might be imported as part of bringing the
|
||||||
|
/// file into the AST.
|
||||||
|
///
|
||||||
|
/// \returns any error that occurred during loading dependencies.
|
||||||
|
Status
|
||||||
|
loadDependenciesForFileContext(const FileUnit *file, SourceLoc diagLoc,
|
||||||
|
bool forTestable);
|
||||||
|
|
||||||
/// How should \p dependency be loaded for a transitive import via \c this?
|
/// How should \p dependency be loaded for a transitive import via \c this?
|
||||||
ModuleLoadingBehavior
|
ModuleLoadingBehavior
|
||||||
getTransitiveLoadingBehavior(const Dependency &dependency) const;
|
getTransitiveLoadingBehavior(const Dependency &dependency) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user