[ModuleInterfaceLoader] Save a parseArg in subInvocation

Avoid parseArg twice with the same compiler invocation with minimal flag
differences. NFC.
This commit is contained in:
Steven Wu
2024-02-26 11:10:13 -08:00
parent 7b5502b410
commit be80b95e42

View File

@@ -1703,6 +1703,17 @@ bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(
interfacePath, diagnosticLoc))
return true;
// Prior to Swift 5.9, swiftinterfaces were always built (accidentally) with
// `-target-min-inlining-version target` prepended to the argument list. To
// preserve compatibility we must continue to prepend those flags to the
// invocation when the interface was generated by an older compiler.
if (auto toolsVersion = interfaceInfo.CompilerToolsVersion) {
if (toolsVersion < version::Version{5, 9}) {
interfaceInfo.Arguments.push_back("-target-min-inlining-version");
interfaceInfo.Arguments.push_back("target");
}
}
SmallString<32> ExpectedModuleName = subInvocation.getModuleName();
if (subInvocation.parseArgs(interfaceInfo.Arguments, *Diags)) {
return true;
@@ -2023,7 +2034,6 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
subInvocation.getFrontendOptions().InputsAndOutputs
.setMainAndSupplementaryOutputs(outputFiles, ModuleOutputPaths);
SmallVector<const char *, 64> SubArgs;
SwiftInterfaceInfo interfaceInfo;
// Extract compiler arguments from the interface file and use them to configure
// the compiler invocation.
@@ -2032,25 +2042,9 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
return std::make_error_code(std::errc::not_supported);
}
// Prior to Swift 5.9, swiftinterfaces were always built (accidentally) with
// `-target-min-inlining-version target` prepended to the argument list. To
// preserve compatibility we must continue to prepend those flags to the
// invocation when the interface was generated by an older compiler.
if (auto toolsVersion = interfaceInfo.CompilerToolsVersion) {
if (toolsVersion < version::Version{5, 9}) {
SubArgs.push_back("-target-min-inlining-version");
SubArgs.push_back("target");
}
}
SubArgs.insert(SubArgs.end(), interfaceInfo.Arguments.begin(),
interfaceInfo.Arguments.end());
// Insert arguments collected from the interface file.
BuildArgs.insert(BuildArgs.end(), SubArgs.begin(), SubArgs.end());
if (subInvocation.parseArgs(SubArgs, *Diags)) {
return std::make_error_code(std::errc::not_supported);
}
BuildArgs.insert(BuildArgs.end(), interfaceInfo.Arguments.begin(),
interfaceInfo.Arguments.end());
// If the target triple parsed from the Swift interface file differs
// only in subarchitecture from the original target triple, then