Skip to content

Commit a78ee29

Browse files
committed
[Dependency Scanning] Remove obsolete placeholder module concept
This was used a long time ago for a design of a scanner which could rely on the client to specify that some modules *will be* present at a given location but are not yet during the scan. We have long ago determined that the scanner must have all modules available to it at the time of scan for soundness. This code has been stale for a couple of years and it is time to simplify things a bit by deleting it.
1 parent c24bae7 commit a78ee29

25 files changed

+37
-642
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ typedef enum {
3636
// SwiftInterface and SwiftSource.
3737
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL = 0,
3838
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_BINARY = 1,
39-
SWIFTSCAN_DEPENDENCY_INFO_SWIFT_PLACEHOLDER = 2,
4039
SWIFTSCAN_DEPENDENCY_INFO_CLANG = 3
4140
} swiftscan_dependency_info_kind_t;
4241

@@ -273,7 +272,8 @@ swiftscan_swift_binary_detail_get_module_cache_key(
273272
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
274273
swiftscan_swift_binary_detail_get_user_module_version(
275274
swiftscan_module_details_t details);
276-
//=== Swift Placeholder Module Details query APIs -------------------------===//
275+
276+
//=== Swift Placeholder Module Details query APIs - DEPRECATED -----------===//
277277

278278
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
279279
swiftscan_swift_placeholder_detail_get_compiled_module_path(

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,6 @@ ERROR(explicit_swift_module_map_corrupted,none,
362362
"explicit Swift module map from %0 is malformed",
363363
(StringRef))
364364

365-
ERROR(placeholder_dependency_module_map_missing,none,
366-
"cannot open Swift placeholder dependency module map from %0",
367-
(StringRef))
368-
369-
ERROR(placeholder_dependency_module_map_corrupted,none,
370-
"Swift placeholder dependency module map from %0 is malformed",
371-
(StringRef))
372-
373365
ERROR(const_extract_protocol_list_input_file_missing,none,
374366
"cannot open constant extraction protocol list input file from %0",
375367
(StringRef))

include/swift/AST/ModuleDependencies.h

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,7 @@ enum class ModuleDependencyKind : int8_t {
6969
Clang,
7070
// Used to model the translation unit's source module
7171
SwiftSource,
72-
// Placeholder dependencies are a kind of dependencies used only by the
73-
// dependency scanner. They are swift modules that the scanner will not be
74-
// able to locate in its search paths and which are the responsibility of the
75-
// scanner's client to ensure are provided.
76-
//
77-
// Placeholder dependencies will be specified in the scanner's output
78-
// dependency graph where it is the responsibility of the scanner's client to
79-
// ensure required post-processing takes place to "resolve" them. In order to
80-
// do so, the client (swift driver, or any other client build system) is
81-
// expected to have access to a full dependency graph of all placeholder
82-
// dependencies and be able to replace placeholder nodes in the dependency
83-
// graph with their full dependency trees, `uniquing` common dependency module
84-
// nodes in the process.
85-
//
86-
// One example where placeholder dependencies are employed is when using
87-
// SwiftPM in Explicit Module Build mode. SwiftPM constructs a build plan for
88-
// all targets ahead-of-time. When planning a build for a target that depends
89-
// on other targets, the dependency scanning action is not able to locate
90-
// dependency target modules, because they have not yet been built. Instead,
91-
// the build system treats them as placeholder dependencies and resolves them
92-
// with `actual` dependencies in a post-processing step once dependency graphs
93-
// of all targets, individually, have been computed.
94-
SwiftPlaceholder,
95-
LastKind = SwiftPlaceholder + 1
72+
LastKind = SwiftSource + 1
9673
};
9774

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

540-
/// Describes an placeholder Swift module dependency module stub.
541-
///
542-
/// This class is mostly an implementation detail for \c ModuleDependencyInfo.
543-
544-
class SwiftPlaceholderModuleDependencyStorage
545-
: public ModuleDependencyInfoStorageBase {
546-
public:
547-
SwiftPlaceholderModuleDependencyStorage(StringRef compiledModulePath,
548-
StringRef moduleDocPath,
549-
StringRef sourceInfoPath)
550-
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftPlaceholder, {}, {},
551-
{}),
552-
compiledModulePath(compiledModulePath), moduleDocPath(moduleDocPath),
553-
sourceInfoPath(sourceInfoPath) {}
554-
555-
ModuleDependencyInfoStorageBase *clone() const override {
556-
return new SwiftPlaceholderModuleDependencyStorage(*this);
557-
}
558-
559-
/// The path to the .swiftmodule file.
560-
const std::string compiledModulePath;
561-
562-
/// The path to the .swiftModuleDoc file.
563-
const std::string moduleDocPath;
564-
565-
/// The path to the .swiftSourceInfo file.
566-
const std::string sourceInfoPath;
567-
568-
static bool classof(const ModuleDependencyInfoStorageBase *base) {
569-
return base->dependencyKind == ModuleDependencyKind::SwiftPlaceholder;
570-
}
571-
};
572-
573517
// MARK: Module Dependency Info
574518
/// Describes the dependencies of a given module.
575519
///
@@ -670,16 +614,6 @@ class ModuleDependencyInfo {
670614
CASFileSystemRootID, clangIncludeTreeRoot, moduleCacheKey, IsSystem));
671615
}
672616

673-
/// Describe a placeholder dependency swift module.
674-
static ModuleDependencyInfo
675-
forPlaceholderSwiftModuleStub(StringRef compiledModulePath,
676-
StringRef moduleDocPath,
677-
StringRef sourceInfoPath) {
678-
return ModuleDependencyInfo(
679-
std::make_unique<SwiftPlaceholderModuleDependencyStorage>(
680-
compiledModulePath, moduleDocPath, sourceInfoPath));
681-
}
682-
683617
/// Retrieve the module-level imports.
684618
ArrayRef<ScannerImportStatementInfo> getModuleImports() const {
685619
return storage->moduleImports;
@@ -898,7 +832,7 @@ class ModuleDependencyInfo {
898832
bool isTestableImport(StringRef moduleName) const;
899833

900834
/// Whether the dependencies are for a Swift module: either Textual, Source,
901-
/// Binary, or Placeholder.
835+
/// or Binary
902836
bool isSwiftModule() const;
903837

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

917-
/// Whether this represents a placeholder module stub
918-
bool isSwiftPlaceholderModule() const;
919-
920851
/// Whether the dependencies are for a Clang module.
921852
bool isClangModule() const;
922853

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

938-
/// Retrieve the dependencies for a placeholder dependency module stub.
939-
const SwiftPlaceholderModuleDependencyStorage *
940-
getAsPlaceholderDependencyModule() const;
941-
942869
/// Add a dependency on the given module, if it was not already in the set.
943870
void
944871
addOptionalModuleImport(StringRef module, bool isExported,

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct swiftscan_dependency_info_s {
4343
/// "swiftInterface"
4444
/// "swiftSource"
4545
/// "swiftBinary"
46-
/// "swiftPlaceholder"
4746
/// "clang""
4847
swiftscan_string_ref_t module_name;
4948

@@ -183,19 +182,6 @@ typedef struct {
183182
swiftscan_string_ref_t user_module_version;
184183
} swiftscan_swift_binary_details_t;
185184

186-
/// Swift placeholder modules carry additional details that specify their
187-
/// module doc path and source info paths.
188-
typedef struct {
189-
/// The path to the pre-compiled binary module
190-
swiftscan_string_ref_t compiled_module_path;
191-
192-
/// The path to the .swiftModuleDoc file.
193-
swiftscan_string_ref_t module_doc_path;
194-
195-
/// The path to the .swiftSourceInfo file.
196-
swiftscan_string_ref_t module_source_info_path;
197-
} swiftscan_swift_placeholder_details_t;
198-
199185
/// Clang modules are built from a module map file.
200186
typedef struct {
201187
/// The path to the module map used to build this module.
@@ -222,7 +208,6 @@ struct swiftscan_module_details_s {
222208
union {
223209
swiftscan_swift_textual_details_t swift_textual_details;
224210
swiftscan_swift_binary_details_t swift_binary_details;
225-
swiftscan_swift_placeholder_details_t swift_placeholder_details;
226211
swiftscan_clang_details_t clang_details;
227212
};
228213
};

include/swift/DependencyScan/DependencyScanningTool.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ class DependencyScanningTool {
6868
/// Construct a dependency scanning tool.
6969
DependencyScanningTool();
7070

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

8179
/// Collect the set of imports for the input module

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using llvm::BCVBR;
3939

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

@@ -109,7 +109,6 @@ enum {
109109
OPTIONAL_IMPORT_STATEMENT_ARRAY_NODE,
110110
SWIFT_INTERFACE_MODULE_DETAILS_NODE,
111111
SWIFT_SOURCE_MODULE_DETAILS_NODE,
112-
SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE,
113112
SWIFT_BINARY_MODULE_DETAILS_NODE,
114113
CLANG_MODULE_DETAILS_NODE,
115114
IDENTIFIER_NODE,
@@ -204,7 +203,6 @@ using OptionalImportStatementArrayLayout =
204203
// - SwiftInterfaceModuleDetails
205204
// - SwiftSourceModuleDetails
206205
// - SwiftBinaryModuleDetails
207-
// - SwiftPlaceholderModuleDetails
208206
// - ClangModuleDetails
209207
using ModuleInfoLayout =
210208
BCRecordLayout<MODULE_NODE, // ID
@@ -269,13 +267,6 @@ using SwiftBinaryModuleDetailsLayout =
269267
IdentifierIDField // UserModuleVersion
270268
>;
271269

272-
using SwiftPlaceholderModuleDetailsLayout =
273-
BCRecordLayout<SWIFT_PLACEHOLDER_MODULE_DETAILS_NODE, // ID
274-
FileIDField, // compiledModulePath
275-
FileIDField, // moduleDocPath
276-
FileIDField // moduleSourceInfoPath
277-
>;
278-
279270
using ClangModuleDetailsLayout =
280271
BCRecordLayout<CLANG_MODULE_DETAILS_NODE, // ID
281272
FileIDField, // pcmOutputPath

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,6 @@ def const_gather_protocols_file
258258
: Separate<["-"], "const-gather-protocols-file">, MetaVarName<"<path>">,
259259
HelpText<"Specify a list of protocols for extraction of conformances' const values'">;
260260

261-
def placeholder_dependency_module_map
262-
: Separate<["-"], "placeholder-dependency-module-map-file">, MetaVarName<"<path>">,
263-
HelpText<"Specify a JSON file containing information of external Swift module dependencies">;
264-
265261
def import_prescan : Flag<["-"], "import-prescan">,
266262
HelpText<"When performing a dependency scan, only identify all imports of the main Swift module sources">;
267263

include/swift/Serialization/ScanningLoaders.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -83,51 +83,6 @@ class SwiftModuleScanner : public SerializedModuleLoaderBase {
8383
return MDS->getKind() == MDS_plain;
8484
}
8585
};
86-
87-
/// A ModuleLoader that loads placeholder dependency module stubs specified in
88-
/// -placeholder-dependency-module-map-file
89-
/// This loader is used only in dependency scanning to inform the scanner that a
90-
/// set of modules constitute placeholder dependencies that are not visible to
91-
/// the scanner but will nevertheless be provided by the scanner's clients. This
92-
/// "loader" will not attempt to load any module files.
93-
class PlaceholderSwiftModuleScanner : public SwiftModuleScanner {
94-
/// Scan the given placeholder module map
95-
void parsePlaceholderModuleMap(StringRef fileName);
96-
97-
llvm::StringMap<ExplicitSwiftModuleInputInfo> PlaceholderDependencyModuleMap;
98-
llvm::BumpPtrAllocator Allocator;
99-
100-
public:
101-
PlaceholderSwiftModuleScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
102-
Identifier moduleName,
103-
StringRef PlaceholderDependencyModuleMap,
104-
InterfaceSubContextDelegate &astDelegate,
105-
StringRef moduleOutputPath,
106-
StringRef sdkModuleOutputPath)
107-
: SwiftModuleScanner(ctx, LoadMode, moduleName, astDelegate,
108-
moduleOutputPath, sdkModuleOutputPath, {},
109-
MDS_placeholder) {
110-
// FIXME: Find a better place for this map to live, to avoid
111-
// doing the parsing on every module.
112-
if (!PlaceholderDependencyModuleMap.empty()) {
113-
parsePlaceholderModuleMap(PlaceholderDependencyModuleMap);
114-
}
115-
}
116-
117-
virtual bool
118-
findModule(ImportPath::Element moduleID,
119-
SmallVectorImpl<char> *moduleInterfacePath,
120-
SmallVectorImpl<char> *moduleInterfaceSourcePath,
121-
std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
122-
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
123-
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
124-
bool skipBuildingInterface, bool isTestableDependencyLookup,
125-
bool &isFramework, bool &isSystemModule) override;
126-
127-
static bool classof(const SwiftModuleScanner *MDS) {
128-
return MDS->getKind() == MDS_placeholder;
129-
}
130-
};
13186
} // namespace swift
13287

13388
#endif // SWIFT_SCANNINGLOADERS_H

lib/AST/ModuleDependencies.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ModuleDependencyInfoStorageBase::~ModuleDependencyInfoStorageBase() {}
3636

3737
bool ModuleDependencyInfo::isSwiftModule() const {
3838
return isSwiftInterfaceModule() || isSwiftSourceModule() ||
39-
isSwiftBinaryModule() || isSwiftPlaceholderModule();
39+
isSwiftBinaryModule();
4040
}
4141

4242
bool ModuleDependencyInfo::isTextualSwiftModule() const {
@@ -66,10 +66,6 @@ bool ModuleDependencyInfo::isSwiftBinaryModule() const {
6666
return isa<SwiftBinaryModuleDependencyStorage>(storage.get());
6767
}
6868

69-
bool ModuleDependencyInfo::isSwiftPlaceholderModule() const {
70-
return isa<SwiftPlaceholderModuleDependencyStorage>(storage.get());
71-
}
72-
7369
bool ModuleDependencyInfo::isClangModule() const {
7470
return isa<ClangModuleDependencyStorage>(storage.get());
7571
}
@@ -97,12 +93,6 @@ ModuleDependencyInfo::getAsClangModule() const {
9793
return dyn_cast<ClangModuleDependencyStorage>(storage.get());
9894
}
9995

100-
/// Retrieve the dependencies for a placeholder dependency module stub.
101-
const SwiftPlaceholderModuleDependencyStorage *
102-
ModuleDependencyInfo::getAsPlaceholderDependencyModule() const {
103-
return dyn_cast<SwiftPlaceholderModuleDependencyStorage>(storage.get());
104-
}
105-
10696
void ModuleDependencyInfo::addTestableImport(ImportPath::Module module) {
10797
assert(getAsSwiftSourceModule() && "Expected source module for addTestableImport.");
10898
dyn_cast<SwiftSourceModuleDependenciesStorage>(storage.get())->addTestableImport(module);
@@ -361,11 +351,6 @@ std::string ModuleDependencyInfo::getModuleOutputPath() const {
361351
cast<SwiftBinaryModuleDependencyStorage>(storage.get());
362352
return swiftBinaryStorage->compiledModulePath;
363353
}
364-
case swift::ModuleDependencyKind::SwiftPlaceholder: {
365-
auto swiftPlaceholderStorage =
366-
cast<SwiftPlaceholderModuleDependencyStorage>(storage.get());
367-
return swiftPlaceholderStorage->compiledModulePath;
368-
}
369354
default:
370355
llvm_unreachable("Unexpected dependency kind");
371356
}
@@ -849,8 +834,6 @@ ModuleDependenciesCache::findSwiftDependency(StringRef moduleName) const {
849834
return found;
850835
if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftSource))
851836
return found;
852-
if (auto found = findDependency(moduleName, ModuleDependencyKind::SwiftPlaceholder))
853-
return found;
854837
return std::nullopt;
855838
}
856839

lib/AST/ModuleLoader.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ ModuleDependencyInfo::collectCrossImportOverlayNames(
240240
case swift::ModuleDependencyKind::SwiftSource: {
241241
return result;
242242
}
243-
case swift::ModuleDependencyKind::SwiftPlaceholder: {
244-
return result;
245-
}
246243
case swift::ModuleDependencyKind::LastKind:
247244
llvm_unreachable("Unhandled dependency kind.");
248245
}

0 commit comments

Comments
 (0)