Skip to content

Expose a ImportPrivateDependencies LangOpt for LLDB (NFC). #75658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ namespace swift {
/// Enable features useful for running in the debugger.
bool DebuggerSupport = false;

/// Used only by the debugger. When set, the module loader will try to
/// import non-public transitive dependencies.
bool ImportNonPublicDependencies = false;

/// Enable the MemoryBufferSerializedModuleImporter.
/// Only used by lldb-moduleimport-test.
bool EnableMemoryBufferImporter = false;
Expand Down
8 changes: 3 additions & 5 deletions lib/Serialization/ModuleFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,9 @@ ModuleFile::getTransitiveLoadingBehavior(const Dependency &dependency,
// as a partial module.
auto isPartialModule = mod->isMainModule();

return Core->getTransitiveLoadingBehavior(dependency.Core,
ctx.LangOpts.DebuggerSupport,
isPartialModule,
ctx.LangOpts.PackageName,
forTestable);
return Core->getTransitiveLoadingBehavior(
dependency.Core, ctx.LangOpts.ImportNonPublicDependencies,
isPartialModule, ctx.LangOpts.PackageName, forTestable);
}

bool ModuleFile::mayHaveDiagnosticsPointingAtBuffer() const {
Expand Down
8 changes: 4 additions & 4 deletions lib/Serialization/ModuleFileSharedCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ std::string ModuleFileSharedCore::resolveModuleDefiningFilePath(const StringRef
ModuleLoadingBehavior
ModuleFileSharedCore::getTransitiveLoadingBehavior(
const Dependency &dependency,
bool debuggerMode,
bool importNonPublicDependencies,
bool isPartialModule,
StringRef packageName,
bool forTestable) const {
Expand All @@ -1805,7 +1805,7 @@ ModuleFileSharedCore::getTransitiveLoadingBehavior(
if (dependency.isImplementationOnly()) {
// Implementation-only dependencies are not usually loaded from
// transitive imports.
if (debuggerMode || forTestable) {
if (importNonPublicDependencies || forTestable) {
// In the debugger, try to load the module if possible.
// Same in the case of a testable import, try to load the dependency
// but don't fail if it's missing as this could be source breaking.
Expand All @@ -1823,7 +1823,7 @@ ModuleFileSharedCore::getTransitiveLoadingBehavior(
// on testable imports.
if (forTestable || !moduleIsResilient) {
return ModuleLoadingBehavior::Required;
} else if (debuggerMode) {
} else if (importNonPublicDependencies) {
return ModuleLoadingBehavior::Optional;
} else {
return ModuleLoadingBehavior::Ignored;
Expand All @@ -1837,7 +1837,7 @@ ModuleFileSharedCore::getTransitiveLoadingBehavior(
forTestable ||
!moduleIsResilient) {
return ModuleLoadingBehavior::Required;
} else if (debuggerMode) {
} else if (importNonPublicDependencies) {
return ModuleLoadingBehavior::Optional;
} else {
return ModuleLoadingBehavior::Ignored;
Expand Down
13 changes: 5 additions & 8 deletions lib/Serialization/ModuleFileSharedCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ class ModuleFileSharedCore {

/// How should \p dependency be loaded for a transitive import via \c this?
///
/// If \p debuggerMode, more transitive dependencies should try to be loaded
/// as they can be useful in debugging.
/// If \p importNonPublicDependencies, more transitive dependencies
/// should try to be loaded as they can be useful in debugging.
///
/// If \p isPartialModule, transitive dependencies should be loaded as we're
/// in merge-module mode.
Expand All @@ -637,12 +637,9 @@ class ModuleFileSharedCore {
/// import. Reports non-public dependencies as required for a testable
/// client so it can access internal details, which in turn can reference
/// those non-public dependencies.
ModuleLoadingBehavior
getTransitiveLoadingBehavior(const Dependency &dependency,
bool debuggerMode,
bool isPartialModule,
StringRef packageName,
bool forTestable) const;
ModuleLoadingBehavior getTransitiveLoadingBehavior(
const Dependency &dependency, bool importNonPublicDependencies,
bool isPartialModule, StringRef packageName, bool forTestable) const;
};

template <typename T, typename RawData>
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ SerializedModuleLoaderBase::getImportsOfModule(
ModuleLoadingBehavior dependencyTransitiveBehavior =
loadedModuleFile.getTransitiveLoadingBehavior(
dependency,
/*debuggerMode*/ false,
/*importPrivateDependencies*/ false,
/*isPartialModule*/ false, packageName, isTestableImport);
if (dependencyTransitiveBehavior > transitiveBehavior)
continue;
Expand Down