Skip to content

Commit 7d08a24

Browse files
committed
ModuleInterface: reconstruct command-line arguments for building Swift module from interface explicitly
1 parent d8f5b20 commit 7d08a24

File tree

8 files changed

+217
-80
lines changed

8 files changed

+217
-80
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {
6868
/// The Swift interface file, if it can be used to generate the module file.
6969
const Optional<std::string> swiftInterfaceFile;
7070

71+
/// The Swift frontend invocation arguments to build the Swift module from the
72+
/// interface.
73+
const std::vector<std::string> buildCommandLine;
74+
75+
/// The hash value that will be used for the generated module
76+
const std::string contextHash;
77+
7178
/// Bridging header file, if there is one.
7279
Optional<std::string> bridgingHeaderFile;
7380

@@ -82,9 +89,13 @@ class SwiftModuleDependenciesStorage : public ModuleDependenciesStorageBase {
8289

8390
SwiftModuleDependenciesStorage(
8491
const std::string &compiledModulePath,
85-
const Optional<std::string> &swiftInterfaceFile
92+
const Optional<std::string> &swiftInterfaceFile,
93+
ArrayRef<StringRef> buildCommandLine,
94+
StringRef contextHash
8695
) : ModuleDependenciesStorageBase(/*isSwiftModule=*/true, compiledModulePath),
87-
swiftInterfaceFile(swiftInterfaceFile) { }
96+
swiftInterfaceFile(swiftInterfaceFile),
97+
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
98+
contextHash(contextHash) { }
8899

89100
ModuleDependenciesStorageBase *clone() const override {
90101
return new SwiftModuleDependenciesStorage(*this);
@@ -162,18 +173,20 @@ class ModuleDependencies {
162173
/// built from a Swift interface file (\c .swiftinterface).
163174
static ModuleDependencies forSwiftInterface(
164175
const std::string &compiledModulePath,
165-
const std::string &swiftInterfaceFile) {
176+
const std::string &swiftInterfaceFile,
177+
ArrayRef<StringRef> buildCommands,
178+
StringRef contextHash) {
166179
return ModuleDependencies(
167180
std::make_unique<SwiftModuleDependenciesStorage>(
168-
compiledModulePath, swiftInterfaceFile));
181+
compiledModulePath, swiftInterfaceFile, buildCommands, contextHash));
169182
}
170183

171184
/// Describe the module dependencies for a serialized or parsed Swift module.
172185
static ModuleDependencies forSwiftModule(
173186
const std::string &compiledModulePath) {
174187
return ModuleDependencies(
175188
std::make_unique<SwiftModuleDependenciesStorage>(
176-
compiledModulePath, None));
189+
compiledModulePath, None, ArrayRef<StringRef>(), StringRef()));
177190
}
178191

179192
/// Describe the module dependencies for a Clang module that can be

include/swift/AST/ModuleLoader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class DependencyTracker {
8989
struct SubCompilerInstanceInfo {
9090
StringRef CompilerVersion;
9191
CompilerInstance* Instance;
92+
StringRef Hash;
93+
ArrayRef<StringRef> BuildArguments;
9294
};
9395

9496
/// Abstract interface to run an action in a sub ASTContext.
@@ -97,7 +99,7 @@ struct InterfaceSubContextDelegate {
9799
StringRef interfacePath,
98100
StringRef outputPath,
99101
SourceLoc diagLoc,
100-
llvm::function_ref<bool(ASTContext&)> action) = 0;
102+
llvm::function_ref<bool(ASTContext&,ArrayRef<StringRef>, StringRef)> action) = 0;
101103
virtual bool runInSubCompilerInstance(StringRef moduleName,
102104
StringRef interfacePath,
103105
StringRef outputPath,

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
208208
private:
209209
SourceManager &SM;
210210
DiagnosticEngine &Diags;
211+
llvm::BumpPtrAllocator Allocator;
212+
llvm::StringSaver ArgSaver;
213+
std::vector<StringRef> GenericArgs;
211214
CompilerInvocation subInvocation;
215+
std::vector<SupplementaryOutputPaths> ModuleOutputPaths;
212216

213217
template<typename ...ArgTypes>
214218
InFlightDiagnostic diagnose(StringRef interfacePath,
@@ -222,45 +226,43 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
222226
}
223227
return Diags.diagnose(loc, ID, std::move(Args)...);
224228
}
225-
226-
bool extractSwiftInterfaceVersionAndArgs(llvm::StringSaver &SubArgSaver,
227-
SmallVectorImpl<const char *> &SubArgs,
229+
void inheritOptionsForBuildingInterface(const SearchPathOptions &SearchPathOpts,
230+
const LangOptions &LangOpts);
231+
bool extractSwiftInterfaceVersionAndArgs(SmallVectorImpl<const char *> &SubArgs,
228232
std::string &CompilerVersion,
229233
StringRef interfacePath,
230234
SourceLoc diagnosticLoc);
231-
SubCompilerInstanceInfo createInstance(StringRef moduleName,
232-
StringRef interfacePath,
233-
StringRef outputPath,
234-
SourceLoc diagLoc);
235235
public:
236236
InterfaceSubContextDelegateImpl(SourceManager &SM,
237237
DiagnosticEngine &Diags,
238238
const SearchPathOptions &searchPathOpts,
239239
const LangOptions &langOpts,
240-
ClangModuleLoader *clangImporter = nullptr,
241-
StringRef moduleCachePath = StringRef(),
242-
StringRef prebuiltCachePath = StringRef(),
243-
bool serializeDependencyHashes = false,
244-
bool trackSystemDependencies = false,
245-
bool remarkOnRebuildFromInterface = false,
246-
bool disableInterfaceFileLock = false);
240+
ClangModuleLoader *clangImporter,
241+
bool buildModuleCacheDirIfAbsent,
242+
StringRef moduleCachePath,
243+
StringRef prebuiltCachePath,
244+
bool serializeDependencyHashes,
245+
bool trackSystemDependencies,
246+
bool remarkOnRebuildFromInterface,
247+
bool disableInterfaceFileLock);
247248
bool runInSubContext(StringRef moduleName,
248249
StringRef interfacePath,
249250
StringRef outputPath,
250251
SourceLoc diagLoc,
251-
llvm::function_ref<bool(ASTContext&)> action) override;
252+
llvm::function_ref<bool(ASTContext&, ArrayRef<StringRef>, StringRef)> action) override;
252253
bool runInSubCompilerInstance(StringRef moduleName,
253254
StringRef interfacePath,
254255
StringRef outputPath,
255256
SourceLoc diagLoc,
256-
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;
257+
llvm::function_ref<bool(SubCompilerInstanceInfo&)> action) override;
257258

258259
~InterfaceSubContextDelegateImpl() = default;
259260

260261
/// includes a hash of relevant key data.
261-
void computeCachedOutputPath(StringRef moduleName,
262-
StringRef UseInterfacePath,
263-
llvm::SmallString<256> &OutPath);
262+
StringRef computeCachedOutputPath(StringRef moduleName,
263+
StringRef UseInterfacePath,
264+
llvm::SmallString<256> &OutPath,
265+
StringRef &CacheHash);
264266
std::string getCacheHash(StringRef useInterfacePath);
265267
};
266268
}

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
163163
llvm::RestorePrettyStackState(savedInnerPrettyStackState);
164164
};
165165

166-
SubError = subASTDelegate.runInSubCompilerInstance(moduleName, interfacePath,
167-
OutPath, diagnosticLoc,
166+
SubError = subASTDelegate.runInSubCompilerInstance(moduleName,
167+
interfacePath,
168+
OutPath,
169+
diagnosticLoc,
168170
[&](SubCompilerInstanceInfo &info) {
169171
auto &SubInstance = *info.Instance;
170172
auto subInvocation = SubInstance.getInvocation();

0 commit comments

Comments
 (0)