Skip to content

Commit 746e89b

Browse files
committed
Rename external dependencies to placeholder dependencies.
1 parent 1d49d22 commit 746e89b

File tree

11 files changed

+112
-70
lines changed

11 files changed

+112
-70
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ ERROR(explicit_swift_module_map_corrupted,none,
266266
"explicit Swift module map from %0 is malformed",
267267
(StringRef))
268268

269-
ERROR(external_dependency_module_map_missing,none,
270-
"cannot open Swift external dependency module map from %0",
269+
ERROR(placeholder_dependency_module_map_missing,none,
270+
"cannot open Swift placeholder dependency module map from %0",
271271
(StringRef))
272272

273-
ERROR(external_dependency_module_map_corrupted,none,
274-
"Swift external dependency module map from %0 is malformed",
273+
ERROR(placeholder_dependency_module_map_corrupted,none,
274+
"Swift placeholder dependency module map from %0 is malformed",
275275
(StringRef))
276276

277277
REMARK(default_previous_install_name, none,

include/swift/AST/ModuleDependencies.h

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ class Identifier;
3535
/// Which kind of module dependencies we are looking for.
3636
enum class ModuleDependenciesKind : int8_t {
3737
Swift,
38+
// Placeholder dependencies are a kind of dependencies used only by the
39+
// dependency scanner. They are swift modules that the scanner will not be
40+
// able to locate in its search paths and which are the responsibility of the
41+
// scanner's client to ensure are provided.
42+
//
43+
// Placeholder dependencies will be specified in the scanner's output
44+
// dependency graph where it is the responsibility of the scanner's client to
45+
// ensure required post-processing takes place to "resolve" them. In order to
46+
// do so, the client (swift driver, or any other client build system) is
47+
// expected to have access to a full dependency graph of all placeholder
48+
// dependencies and be able to replace placeholder nodes in the dependency
49+
// graph with their full dependency trees, `uniquing` common dependency module
50+
// nodes in the process.
51+
//
52+
// One example where placeholder dependencies are employed is when using
53+
// SwiftPM in Explicit Module Build mode. SwiftPM constructs a build plan for
54+
// all targets ahead-of-time. When planning a build for a target that depends
55+
// on other targets, the dependency scanning action is not able to locate
56+
// dependency target modules, because they have not yet been built. Instead,
57+
// the build system treats them as placeholder dependencies and resolves them
58+
// with `actual` dependencies in a post-processing step once dependency graphs
59+
// of all targets, individually, have been computed.
60+
SwiftPlaceholder,
3861
Clang,
3962
};
4063

@@ -160,21 +183,21 @@ class ClangModuleDependenciesStorage : public ModuleDependenciesStorageBase {
160183
}
161184
};
162185

163-
/// Describes an external Swift module dependency module stub.
186+
/// Describes an placeholder Swift module dependency module stub.
164187
///
165188
/// This class is mostly an implementation detail for \c ModuleDependencies.
166-
class ExternalSwiftModuleDependencyStorage : public ModuleDependenciesStorageBase {
189+
class PlaceholderSwiftModuleDependencyStorage : public ModuleDependenciesStorageBase {
167190
public:
168-
ExternalSwiftModuleDependencyStorage(const std::string &compiledModulePath,
191+
PlaceholderSwiftModuleDependencyStorage(const std::string &compiledModulePath,
169192
const std::string &moduleDocPath,
170193
const std::string &sourceInfoPath)
171-
: ModuleDependenciesStorageBase(ModuleDependenciesKind::SwiftExternal,
194+
: ModuleDependenciesStorageBase(ModuleDependenciesKind::SwiftPlaceholder,
172195
compiledModulePath),
173196
moduleDocPath(moduleDocPath),
174197
sourceInfoPath(sourceInfoPath) {}
175198

176199
ModuleDependenciesStorageBase *clone() const override {
177-
return new ExternalSwiftModuleDependencyStorage(*this);
200+
return new PlaceholderSwiftModuleDependencyStorage(*this);
178201
}
179202

180203
/// The path to the .swiftModuleDoc file.
@@ -184,7 +207,7 @@ class ExternalSwiftModuleDependencyStorage : public ModuleDependenciesStorageBas
184207
const std::string sourceInfoPath;
185208

186209
static bool classof(const ModuleDependenciesStorageBase *base) {
187-
return base->dependencyKind == ModuleDependenciesKind::SwiftExternal;
210+
return base->dependencyKind == ModuleDependenciesKind::SwiftPlaceholder;
188211
}
189212
};
190213

@@ -259,13 +282,13 @@ class ModuleDependencies {
259282
fileDependencies));
260283
}
261284

262-
/// Describe an external dependency swift module.
263-
static ModuleDependencies forExternalSwiftModuleStub(
285+
/// Describe a placeholder dependency swift module.
286+
static ModuleDependencies forPlaceholderSwiftModuleStub(
264287
const std::string &compiledModulePath,
265288
const std::string &moduleDocPath,
266289
const std::string &sourceInfoPath) {
267290
return ModuleDependencies(
268-
std::make_unique<ExternalSwiftModuleDependencyStorage>(
291+
std::make_unique<PlaceholderSwiftModuleDependencyStorage>(
269292
compiledModulePath, moduleDocPath, sourceInfoPath));
270293
}
271294

@@ -282,6 +305,9 @@ class ModuleDependencies {
282305
/// Whether the dependencies are for a Swift module.
283306
bool isSwiftModule() const;
284307

308+
/// Whether this represents a placeholder module stub
309+
bool isPlaceholderSwiftModule() const;
310+
285311
ModuleDependenciesKind getKind() const {
286312
return storage->dependencyKind;
287313
}
@@ -291,6 +317,10 @@ class ModuleDependencies {
291317
/// Retrieve the dependencies for a Clang module.
292318
const ClangModuleDependenciesStorage *getAsClangModule() const;
293319

320+
/// Retrieve the dependencies for a placeholder dependency module stub.
321+
const PlaceholderSwiftModuleDependencyStorage *
322+
getAsPlaceholderDependencyModule() const;
323+
294324
/// Add a dependency on the given module, if it was not already in the set.
295325
void addModuleDependency(StringRef module,
296326
llvm::StringSet<> *alreadyAddedModules = nullptr);

include/swift/AST/SearchPathOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class SearchPathOptions {
9191
/// A map of explict Swift module information.
9292
std::string ExplicitSwiftModuleMap;
9393

94-
/// A map of external Swift module dependency information.
95-
std::string ExternalDependencyModuleMap;
94+
/// A map of placeholder Swift module dependency information.
95+
std::string PlaceholderDependencyModuleMap;
9696
private:
9797
static StringRef
9898
pathStringFromFrameworkSearchPath(const FrameworkSearchPath &next) {

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ def explict_swift_module_map
225225
: Separate<["-"], "explicit-swift-module-map-file">, MetaVarName<"<path>">,
226226
HelpText<"Specify a JSON file containing information of explict Swift modules">;
227227

228-
def external_dependency_module_map
229-
: Separate<["-"], "external-dependency-module-map-file">, MetaVarName<"<path>">,
228+
def placeholder_dependency_module_map
229+
: Separate<["-"], "placeholder-dependency-module-map-file">, MetaVarName<"<path>">,
230230
HelpText<"Specify a JSON file containing information of external Swift module dependencies">;
231231
}
232232

lib/AST/ModuleDependencies.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ bool ModuleDependencies::isSwiftModule() const {
2424
return isa<SwiftModuleDependenciesStorage>(storage.get());
2525
}
2626

27+
bool ModuleDependencies::isPlaceholderSwiftModule() const {
28+
return isa<PlaceholderSwiftModuleDependencyStorage>(storage.get());
29+
}
30+
2731
/// Retrieve the dependencies for a Swift module.
2832
const SwiftModuleDependenciesStorage *
2933
ModuleDependencies::getAsSwiftModule() const {
@@ -36,6 +40,12 @@ ModuleDependencies::getAsClangModule() const {
3640
return dyn_cast<ClangModuleDependenciesStorage>(storage.get());
3741
}
3842

43+
/// Retrieve the dependencies for a placeholder dependency module stub.
44+
const PlaceholderSwiftModuleDependencyStorage *
45+
ModuleDependencies::getAsPlaceholderDependencyModule() const {
46+
return dyn_cast<PlaceholderSwiftModuleDependencyStorage>(storage.get());
47+
}
48+
3949
void ModuleDependencies::addModuleDependency(
4050
StringRef module, llvm::StringSet<> *alreadyAddedModules) {
4151
if (!alreadyAddedModules || alreadyAddedModules->insert(module).second)
@@ -102,7 +112,8 @@ ModuleDependenciesCache::getDependenciesMap(ModuleDependenciesKind kind) {
102112
switch (kind) {
103113
case ModuleDependenciesKind::Swift:
104114
return SwiftModuleDependencies;
105-
115+
case ModuleDependenciesKind::SwiftPlaceholder:
116+
return ExternalSwiftModuleDependencies;
106117
case ModuleDependenciesKind::Clang:
107118
return ClangModuleDependencies;
108119
}
@@ -114,7 +125,8 @@ ModuleDependenciesCache::getDependenciesMap(ModuleDependenciesKind kind) const {
114125
switch (kind) {
115126
case ModuleDependenciesKind::Swift:
116127
return SwiftModuleDependencies;
117-
128+
case ModuleDependenciesKind::SwiftPlaceholder:
129+
return ExternalSwiftModuleDependencies;
118130
case ModuleDependenciesKind::Clang:
119131
return ClangModuleDependencies;
120132
}
@@ -126,7 +138,7 @@ bool ModuleDependenciesCache::hasDependencies(
126138
Optional<ModuleDependenciesKind> kind) const {
127139
if (!kind) {
128140
return hasDependencies(moduleName, ModuleDependenciesKind::Swift) ||
129-
hasDependencies(moduleName, ModuleDependenciesKind::SwiftExternal) ||
141+
hasDependencies(moduleName, ModuleDependenciesKind::SwiftPlaceholder) ||
130142
hasDependencies(moduleName, ModuleDependenciesKind::Clang);
131143
}
132144

@@ -141,9 +153,9 @@ Optional<ModuleDependencies> ModuleDependenciesCache::findDependencies(
141153
if (auto swiftDep = findDependencies(
142154
moduleName, ModuleDependenciesKind::Swift))
143155
return swiftDep;
144-
else if (auto swiftExternalDep = findDependencies(
145-
moduleName, ModuleDependenciesKind::SwiftExternal))
146-
return swiftExternalDep;
156+
else if (auto swiftPlaceholderDep = findDependencies(
157+
moduleName, ModuleDependenciesKind::SwiftPlaceholder))
158+
return swiftPlaceholderDep;
147159
else
148160
return findDependencies(moduleName, ModuleDependenciesKind::Clang);
149161
}

lib/Driver/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ static void validateProfilingArgs(DiagnosticEngine &diags,
165165

166166
static void validateDependencyScanningArgs(DiagnosticEngine &diags,
167167
const ArgList &args) {
168-
const Arg *ExternalDependencyMap = args.getLastArg(options::OPT_external_dependency_module_map);
168+
const Arg *ExternalDependencyMap = args.getLastArg(options::OPT_placeholder_dependency_module_map);
169169
const Arg *ScanDependencies = args.getLastArg(options::OPT_scan_dependencies);
170170
if (ExternalDependencyMap && !ScanDependencies) {
171171
diags.diagnose(SourceLoc(), diag::error_requirement_not_met,
172-
"-external-dependency-module-map-file", "-scan-dependencies");
172+
"-placeholder-dependency-module-map-file", "-scan-dependencies");
173173
}
174174
}
175175

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,8 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
905905
for (auto A: Args.filtered(OPT_candidate_module_file)) {
906906
Opts.CandidateCompiledModules.push_back(resolveSearchPath(A->getValue()));
907907
}
908-
if (const Arg *A = Args.getLastArg(OPT_external_dependency_module_map))
909-
Opts.ExternalDependencyModuleMap = A->getValue();
908+
if (const Arg *A = Args.getLastArg(OPT_placeholder_dependency_module_map))
909+
Opts.PlaceholderDependencyModuleMap = A->getValue();
910910

911911
// Opts.RuntimeIncludePath is set by calls to
912912
// setRuntimeIncludePath() or setMainExecutablePath().

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ namespace {
224224
std::string moduleKind;
225225
if (module.second == ModuleDependenciesKind::Swift)
226226
moduleKind = "swift";
227-
else if (module.second == ModuleDependenciesKind::SwiftExternal)
228-
moduleKind = "swiftExternal";
227+
else if (module.second == ModuleDependenciesKind::SwiftPlaceholder)
228+
moduleKind = "swiftPlaceholder";
229229
else
230230
moduleKind = "clang";
231231

@@ -324,7 +324,7 @@ static void writeJSON(llvm::raw_ostream &out,
324324
out.indent(2 * 2);
325325
out << "{\n";
326326

327-
auto externalSwiftDep = moduleDeps.getAsExternalDependencyModuleStub();
327+
auto externalSwiftDep = moduleDeps.getAsPlaceholderDependencyModule();
328328
auto swiftDeps = moduleDeps.getAsSwiftModule();
329329
auto clangDeps = moduleDeps.getAsClangModule();
330330

@@ -426,7 +426,7 @@ static void writeJSON(llvm::raw_ostream &out,
426426
out << "}\n";
427427
}
428428
} else if (externalSwiftDep) {
429-
out << "\"swiftExternal\": {\n";
429+
out << "\"swiftPlaceholder\": {\n";
430430

431431
// Module doc file
432432
if (externalSwiftDep->moduleDocPath != "")

lib/Serialization/ModuleDependencyScanner.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,29 @@ class ModuleDependencyScanner : public SerializedModuleLoaderBase {
9292
}
9393
};
9494

95-
/// A ModuleLoader that loads external dependency module stubs specified in
96-
/// -external-dependency-module-map-file
95+
/// A ModuleLoader that loads placeholder dependency module stubs specified in
96+
/// -placeholder-dependency-module-map-file
9797
/// This loader is used only in dependency scanning to inform the scanner that a
98-
/// set of modules constitute external dependencies that are not visible to the
98+
/// set of modules constitute placeholder dependencies that are not visible to the
9999
/// scanner but will nevertheless be provided by the scanner's clients.
100100
/// This "loader" will not attempt to load any module files.
101-
class ExternalSwiftModuleStubScanner : public ModuleDependencyScanner {
102-
/// Scan the given external module map
103-
void parseExternalModuleMap(StringRef fileName);
104-
llvm::StringMap<ExplicitModuleInfo> ExternalDependencyModuleMap;
101+
class PlaceholderSwiftModuleScanner : public ModuleDependencyScanner {
102+
/// Scan the given placeholder module map
103+
void parsePlaceholderModuleMap(StringRef fileName);
104+
llvm::StringMap<ExplicitModuleInfo> PlaceholderDependencyModuleMap;
105105
llvm::BumpPtrAllocator Allocator;
106106

107107
public:
108-
ExternalSwiftModuleStubScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
108+
PlaceholderSwiftModuleScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
109109
Identifier moduleName,
110-
StringRef ExternalDependencyModuleMap,
110+
StringRef PlaceholderDependencyModuleMap,
111111
InterfaceSubContextDelegate &astDelegate)
112112
: ModuleDependencyScanner(ctx, LoadMode, moduleName, astDelegate,
113-
ModuleDependenciesKind::SwiftExternal) {
113+
ModuleDependenciesKind::SwiftPlaceholder) {
114114

115115
// FIXME: Find a better place for this map to live, to avoid
116116
// doing the parsing on every module.
117-
parseExternalModuleMap(ExternalDependencyModuleMap);
117+
parsePlaceholderModuleMap(PlaceholderDependencyModuleMap);
118118
}
119119

120120
std::error_code findModuleFilesInDirectory(
@@ -124,17 +124,17 @@ class ExternalSwiftModuleStubScanner : public ModuleDependencyScanner {
124124
std::unique_ptr<llvm::MemoryBuffer> *ModuleDocBuffer,
125125
std::unique_ptr<llvm::MemoryBuffer> *ModuleSourceInfoBuffer) override {
126126
StringRef moduleName = ModuleID.Item.str();
127-
auto it = ExternalDependencyModuleMap.find(moduleName);
128-
// If no external module stub path is given matches the name, return with an
127+
auto it = PlaceholderDependencyModuleMap.find(moduleName);
128+
// If no placeholder module stub path is given matches the name, return with an
129129
// error code.
130-
if (it == ExternalDependencyModuleMap.end()) {
130+
if (it == PlaceholderDependencyModuleMap.end()) {
131131
return std::make_error_code(std::errc::not_supported);
132132
}
133133
auto &moduleInfo = it->getValue();
134134
assert(!moduleInfo.moduleBuffer &&
135-
"External dependency module stubs cannot have an associated buffer");
135+
"Placeholder dependency module stubs cannot have an associated buffer");
136136

137-
auto dependencies = ModuleDependencies::forExternalSwiftModuleStub(
137+
auto dependencies = ModuleDependencies::forPlaceholderSwiftModuleStub(
138138
moduleInfo.modulePath, moduleInfo.moduleDocPath,
139139
moduleInfo.moduleSourceInfoPath);
140140
this->dependencies = std::move(dependencies);
@@ -143,16 +143,16 @@ class ExternalSwiftModuleStubScanner : public ModuleDependencyScanner {
143143
};
144144
} // namespace
145145

146-
void ExternalSwiftModuleStubScanner::parseExternalModuleMap(StringRef fileName) {
146+
void PlaceholderSwiftModuleScanner::parsePlaceholderModuleMap(StringRef fileName) {
147147
ExplicitModuleMapParser parser(Allocator);
148148
auto result =
149-
parser.parseSwiftExplicitModuleMap(fileName, ExternalDependencyModuleMap);
149+
parser.parseSwiftExplicitModuleMap(fileName, PlaceholderDependencyModuleMap);
150150
if (result == std::errc::invalid_argument)
151151
Ctx.Diags.diagnose(
152-
SourceLoc(), diag::external_dependency_module_map_corrupted, fileName);
152+
SourceLoc(), diag::placeholder_dependency_module_map_corrupted, fileName);
153153
else if (result == std::errc::no_such_file_or_directory)
154154
Ctx.Diags.diagnose(SourceLoc(),
155-
diag::external_dependency_module_map_missing, fileName);
155+
diag::placeholder_dependency_module_map_missing, fileName);
156156
}
157157

158158
static std::vector<std::string> getCompiledCandidates(ASTContext &ctx,
@@ -221,16 +221,16 @@ Optional<ModuleDependencies> SerializedModuleLoaderBase::getModuleDependencies(
221221
moduleName, ModuleDependenciesKind::Swift))
222222
return found;
223223
if (auto found =
224-
cache.findDependencies(moduleName, ModuleDependenciesKind::SwiftExternal))
224+
cache.findDependencies(moduleName, ModuleDependenciesKind::SwiftPlaceholder))
225225
return found;
226226

227227
auto moduleId = Ctx.getIdentifier(moduleName);
228228
// Instantiate dependency scanning "loaders".
229229
SmallVector<std::unique_ptr<ModuleDependencyScanner>, 2> scanners;
230230
scanners.push_back(std::make_unique<ModuleDependencyScanner>(
231231
Ctx, LoadMode, moduleId, delegate));
232-
scanners.push_back(std::make_unique<ExternalSwiftModuleStubScanner>(
233-
Ctx, LoadMode, moduleId, Ctx.SearchPathOpts.ExternalDependencyModuleMap,
232+
scanners.push_back(std::make_unique<PlaceholderSwiftModuleScanner>(
233+
Ctx, LoadMode, moduleId, Ctx.SearchPathOpts.PlaceholderDependencyModuleMap,
234234
delegate));
235235

236236
// Check whether there is a module with this name that we can import.

0 commit comments

Comments
 (0)