Skip to content

[Dependency Scanning] Remove obsolete placeholder module concept #82031

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 2 additions & 2 deletions include/swift-c/DependencyScan/DependencyScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef enum {
// SwiftInterface and SwiftSource.
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2,
SWIFTSCAN_DEPENDENCY_INFO_CLANG = 3
} swiftscan_dependency_info_kind_t;

Expand Down Expand Up @@ -273,7 +272,8 @@ swiftscan_swift_binary_detail_get_module_cache_key(
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_binary_detail_get_user_module_version(
swiftscan_module_details_t details);
//=== Swift Placeholder Module Details query APIs -------------------------===//

//=== Swift Placeholder Module Details query APIs - DEPRECATED -----------===//

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_placeholder_detail_get_compiled_module_path(
Expand Down
8 changes: 0 additions & 8 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,6 @@ ERROR(explicit_swift_module_map_corrupted,none,
"explicit Swift module map from %0 is malformed",
(StringRef))

ERROR(placeholder_dependency_module_map_missing,none,
"cannot open Swift placeholder dependency module map from %0",
(StringRef))

ERROR(placeholder_dependency_module_map_corrupted,none,
"Swift placeholder dependency module map from %0 is malformed",
(StringRef))

ERROR(const_extract_protocol_list_input_file_missing,none,
"cannot open constant extraction protocol list input file from %0",
(StringRef))
Expand Down
77 changes: 2 additions & 75 deletions include/swift/AST/ModuleDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,7 @@ enum class ModuleDependencyKind : int8_t {
Clang,
// Used to model the translation unit's source module
SwiftSource,
// Placeholder dependencies are a kind of dependencies used only by the
// dependency scanner. They are swift modules that the scanner will not be
// able to locate in its search paths and which are the responsibility of the
// scanner's client to ensure are provided.
//
// Placeholder dependencies will be specified in the scanner's output
// dependency graph where it is the responsibility of the scanner's client to
// ensure required post-processing takes place to "resolve" them. In order to
// do so, the client (swift driver, or any other client build system) is
// expected to have access to a full dependency graph of all placeholder
// dependencies and be able to replace placeholder nodes in the dependency
// graph with their full dependency trees, `uniquing` common dependency module
// nodes in the process.
//
// One example where placeholder dependencies are employed is when using
// SwiftPM in Explicit Module Build mode. SwiftPM constructs a build plan for
// all targets ahead-of-time. When planning a build for a target that depends
// on other targets, the dependency scanning action is not able to locate
// dependency target modules, because they have not yet been built. Instead,
// the build system treats them as placeholder dependencies and resolves them
// with `actual` dependencies in a post-processing step once dependency graphs
// of all targets, individually, have been computed.
SwiftPlaceholder,
LastKind = SwiftPlaceholder + 1
LastKind = SwiftSource + 1
};

/// This is used to idenfity a specific macro plugin dependency.
Expand Down Expand Up @@ -537,39 +514,6 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
}
};

/// Describes an placeholder Swift module dependency module stub.
///
/// This class is mostly an implementation detail for \c ModuleDependencyInfo.

class SwiftPlaceholderModuleDependencyStorage
: public ModuleDependencyInfoStorageBase {
public:
SwiftPlaceholderModuleDependencyStorage(StringRef compiledModulePath,
StringRef moduleDocPath,
StringRef sourceInfoPath)
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftPlaceholder, {}, {},
{}),
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
sourceInfoPath(sourceInfoPath) {}

ModuleDependencyInfoStorageBase *clone() const override {
return new SwiftPlaceholderModuleDependencyStorage(*this);
}

/// The path to the .swiftmodule file.
const std::string compiledModulePath;

/// The path to the .swiftModuleDoc file.
const std::string moduleDocPath;

/// The path to the .swiftSourceInfo file.
const std::string sourceInfoPath;

static bool classof(const ModuleDependencyInfoStorageBase *base) {
return base->dependencyKind == ModuleDependencyKind::SwiftPlaceholder;
}
};

// MARK: Module Dependency Info
/// Describes the dependencies of a given module.
///
Expand Down Expand Up @@ -670,16 +614,6 @@ class ModuleDependencyInfo {
CASFileSystemRootID, clangIncludeTreeRoot, moduleCacheKey, IsSystem));
}

/// Describe a placeholder dependency swift module.
static ModuleDependencyInfo
forPlaceholderSwiftModuleStub(StringRef compiledModulePath,
StringRef moduleDocPath,
StringRef sourceInfoPath) {
return ModuleDependencyInfo(
std::make_unique<SwiftPlaceholderModuleDependencyStorage>(
compiledModulePath, moduleDocPath, sourceInfoPath));
}

/// Retrieve the module-level imports.
ArrayRef<ScannerImportStatementInfo> getModuleImports() const {
return storage->moduleImports;
Expand Down Expand Up @@ -898,7 +832,7 @@ class ModuleDependencyInfo {
bool isTestableImport(StringRef moduleName) const;

/// Whether the dependencies are for a Swift module: either Textual, Source,
/// Binary, or Placeholder.
/// or Binary
bool isSwiftModule() const;

/// Whether the dependencies are for a textual interface Swift module or a
Expand All @@ -914,9 +848,6 @@ class ModuleDependencyInfo {
/// Whether the dependencies are for a binary Swift module.
bool isSwiftBinaryModule() const;

/// Whether this represents a placeholder module stub
bool isSwiftPlaceholderModule() const;

/// Whether the dependencies are for a Clang module.
bool isClangModule() const;

Expand All @@ -935,10 +866,6 @@ class ModuleDependencyInfo {
/// Retrieve the dependencies for a Clang module.
const ClangModuleDependencyStorage *getAsClangModule() const;

/// Retrieve the dependencies for a placeholder dependency module stub.
const SwiftPlaceholderModuleDependencyStorage *
getAsPlaceholderDependencyModule() const;

/// Add a dependency on the given module, if it was not already in the set.
void
addOptionalModuleImport(StringRef module, bool isExported,
Expand Down
15 changes: 0 additions & 15 deletions include/swift/DependencyScan/DependencyScanImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct swiftscan_dependency_info_s {
/// "swiftInterface"
/// "swiftSource"
/// "swiftBinary"
/// "swiftPlaceholder"
/// "clang""
swiftscan_string_ref_t module_name;

Expand Down Expand Up @@ -183,19 +182,6 @@ typedef struct {
swiftscan_string_ref_t user_module_version;
} swiftscan_swift_binary_details_t;

/// Swift placeholder modules carry additional details that specify their
/// module doc path and source info paths.
typedef struct {
/// The path to the pre-compiled binary module
swiftscan_string_ref_t compiled_module_path;

/// The path to the .swiftModuleDoc file.
swiftscan_string_ref_t module_doc_path;

/// The path to the .swiftSourceInfo file.
swiftscan_string_ref_t module_source_info_path;
} swiftscan_swift_placeholder_details_t;

/// Clang modules are built from a module map file.
typedef struct {
/// The path to the module map used to build this module.
Expand All @@ -222,7 +208,6 @@ struct swiftscan_module_details_s {
union {
swiftscan_swift_textual_details_t swift_textual_details;
swiftscan_swift_binary_details_t swift_binary_details;
swiftscan_swift_placeholder_details_t swift_placeholder_details;
swiftscan_clang_details_t clang_details;
};
};
Expand Down
4 changes: 1 addition & 3 deletions include/swift/DependencyScan/DependencyScanningTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ class DependencyScanningTool {
/// Construct a dependency scanning tool.
DependencyScanningTool();

/// Collect the full module dependency graph for the input, ignoring any
/// placeholder modules.
/// Collect the full module dependency graph for the input.
///
/// \returns a \c StringError with the diagnostic output if errors
/// occurred, \c swiftscan_dependency_result_t otherwise.
llvm::ErrorOr<swiftscan_dependency_graph_t>
getDependencies(ArrayRef<const char *> Command,
const llvm::StringSet<> &PlaceholderModules,
StringRef WorkingDirectory);

/// Collect the set of imports for the input module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using llvm::BCVBR;

/// Every .moddepcache file begins with these 4 bytes, for easy identification.
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 9;
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR = 10;
/// Increment this on every change.
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 3;

Expand Down Expand Up @@ -109,7 +109,6 @@ enum {
OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE,
SWIFT_INTERFACE_MODULE_DETAILS_NODE,
SWIFT_SOURCE_MODULE_DETAILS_NODE,
SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE,
SWIFT_BINARY_MODULE_DETAILS_NODE,
CLANG_MODULE_DETAILS_NODE,
IDENTIFIER_NODE,
Expand Down Expand Up @@ -204,7 +203,6 @@ using OptionalImportStatementArrayLayout =
// - SwiftInterfaceModuleDetails
// - SwiftSourceModuleDetails
// - SwiftBinaryModuleDetails
// - SwiftPlaceholderModuleDetails
// - ClangModuleDetails
using ModuleInfoLayout =
BCRecordLayout<MODULE_NODE, // ID
Expand Down Expand Up @@ -269,13 +267,6 @@ using SwiftBinaryModuleDetailsLayout =
IdentifierIDField // UserModuleVersion
>;

using SwiftPlaceholderModuleDetailsLayout =
BCRecordLayout<SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE, // ID
FileIDField, // compiledModulePath
FileIDField, // moduleDocPath
FileIDField // moduleSourceInfoPath
>;

using ClangModuleDetailsLayout =
BCRecordLayout<CLANG_MODULE_DETAILS_NODE, // ID
FileIDField, // pcmOutputPath
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ def const_gather_protocols_file
: Separate<["-"], "const-gather-protocols-file">, MetaVarName<"<path>">,
HelpText<"Specify a list of protocols for extraction of conformances' const values'">;

def placeholder_dependency_module_map
: Separate<["-"], "placeholder-dependency-module-map-file">, MetaVarName<"<path>">,
HelpText<"Specify a JSON file containing information of external Swift module dependencies">;

def import_prescan : Flag<["-"], "import-prescan">,
HelpText<"When performing a dependency scan, only identify all imports of the main Swift module sources">;

Expand Down
45 changes: 0 additions & 45 deletions include/swift/Serialization/ScanningLoaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,6 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
return MDS->getKind() == MDS_plain;
}
};

/// A ModuleLoader that loads placeholder dependency module stubs specified in
/// -placeholder-dependency-module-map-file
/// This loader is used only in dependency scanning to inform the scanner that a
/// set of modules constitute placeholder dependencies that are not visible to
/// the scanner but will nevertheless be provided by the scanner's clients. This
/// "loader" will not attempt to load any module files.
class PlaceholderSwiftModuleScanner : public SwiftModuleScanner {
/// Scan the given placeholder module map
void parsePlaceholderModuleMap(StringRef fileName);

llvm::StringMap<ExplicitSwiftModuleInputInfo> PlaceholderDependencyModuleMap;
llvm::BumpPtrAllocator Allocator;

public:
PlaceholderSwiftModuleScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
Identifier moduleName,
StringRef PlaceholderDependencyModuleMap,
InterfaceSubContextDelegate &astDelegate,
StringRef moduleOutputPath,
StringRef sdkModuleOutputPath)
: SwiftModuleScanner(ctx, LoadMode, moduleName, astDelegate,
moduleOutputPath, sdkModuleOutputPath, {},
MDS_placeholder) {
// FIXME: Find a better place for this map to live, to avoid
// doing the parsing on every module.
if (!PlaceholderDependencyModuleMap.empty()) {
parsePlaceholderModuleMap(PlaceholderDependencyModuleMap);
}
}

virtual bool
findModule(ImportPath::Element moduleID,
SmallVectorImpl<char> *moduleInterfacePath,
SmallVectorImpl<char> *moduleInterfaceSourcePath,
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
bool skipBuildingInterface, bool isTestableDependencyLookup,
bool &isFramework, bool &isSystemModule) override;

static bool classof(const SwiftModuleScanner *MDS) {
return MDS->getKind() == MDS_placeholder;
}
};
} // namespace swift

#endif // SWIFT_SCANNINGLOADERS_H
19 changes: 1 addition & 18 deletions lib/AST/ModuleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ModuleDependencyInfoStorageBase::~ModuleDependencyInfoStorageBase() {}

bool ModuleDependencyInfo::isSwiftModule() const {
return isSwiftInterfaceModule() || isSwiftSourceModule() ||
isSwiftBinaryModule() || isSwiftPlaceholderModule();
isSwiftBinaryModule();
}

bool ModuleDependencyInfo::isTextualSwiftModule() const {
Expand Down Expand Up @@ -66,10 +66,6 @@ bool ModuleDependencyInfo::isSwiftBinaryModule() const {
return isa<SwiftBinaryModuleDependencyStorage>(storage.get());
}

bool ModuleDependencyInfo::isSwiftPlaceholderModule() const {
return isa<SwiftPlaceholderModuleDependencyStorage>(storage.get());
}

bool ModuleDependencyInfo::isClangModule() const {
return isa<ClangModuleDependencyStorage>(storage.get());
}
Expand Down Expand Up @@ -97,12 +93,6 @@ ModuleDependencyInfo::getAsClangModule() const {
return dyn_cast<ClangModuleDependencyStorage>(storage.get());
}

/// Retrieve the dependencies for a placeholder dependency module stub.
const SwiftPlaceholderModuleDependencyStorage *
ModuleDependencyInfo::getAsPlaceholderDependencyModule() const {
return dyn_cast<SwiftPlaceholderModuleDependencyStorage>(storage.get());
}

void ModuleDependencyInfo::addTestableImport(ImportPath::Module module) {
assert(getAsSwiftSourceModule() && "Expected source module for addTestableImport.");
dyn_cast<SwiftSourceModuleDependenciesStorage>(storage.get())->addTestableImport(module);
Expand Down Expand Up @@ -361,11 +351,6 @@ std::string ModuleDependencyInfo::getModuleOutputPath() const {
cast<SwiftBinaryModuleDependencyStorage>(storage.get());
return swiftBinaryStorage->compiledModulePath;
}
case swift::ModuleDependencyKind::SwiftPlaceholder: {
auto swiftPlaceholderStorage =
cast<SwiftPlaceholderModuleDependencyStorage>(storage.get());
return swiftPlaceholderStorage->compiledModulePath;
}
default:
llvm_unreachable("Unexpected dependency kind");
}
Expand Down Expand Up @@ -849,8 +834,6 @@ ModuleDependenciesCache::findSwiftDependency(StringRef moduleName) const {
return found;
if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftSource))
return found;
if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftPlaceholder))
return found;
return std::nullopt;
}

Expand Down
3 changes: 0 additions & 3 deletions lib/AST/ModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(
case swift::ModuleDependencyKind::SwiftSource: {
return result;
}
case swift::ModuleDependencyKind::SwiftPlaceholder: {
return result;
}
case swift::ModuleDependencyKind::LastKind:
llvm_unreachable("Unhandled dependency kind.");
}
Expand Down
Loading