Skip to content

Commit 6a5619e

Browse files
authored
Merge pull request #19012 from jrose-apple/driver-off-into-the-sunset
Break Driver's dependency on Frontend
2 parents 2e5b398 + e4e4f3e commit 6a5619e

24 files changed

+68
-66
lines changed

include/swift/Frontend/OutputFileMap.h renamed to include/swift/Basic/OutputFileMap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- OutputFileMap.h - Driver output file map ---------------*- C++ -*-===//
1+
//===--- OutputFileMap.h - Map of inputs to multiple outputs ----*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_DRIVER_OUTPUTFILEMAP_H
14-
#define SWIFT_DRIVER_OUTPUTFILEMAP_H
13+
#ifndef SWIFT_BASIC_OUTPUTFILEMAP_H
14+
#define SWIFT_BASIC_OUTPUTFILEMAP_H
1515

1616
#include "swift/Basic/FileTypes.h"
1717
#include "swift/Basic/LLVM.h"

include/swift/Frontend/ReferenceDependencyKeys.h renamed to include/swift/Basic/ReferenceDependencyKeys.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef SWIFT_FRONTENDTOOL_REFERENCEDEPENDENCYKEYS_H
14-
#define SWIFT_FRONTENDTOOL_REFERENCEDEPENDENCYKEYS_H
13+
#ifndef SWIFT_BASIC_REFERENCEDEPENDENCYKEYS_H
14+
#define SWIFT_BASIC_REFERENCEDEPENDENCYKEYS_H
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "llvm/ADT/StringRef.h"

include/swift/Driver/Compilation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
#include "swift/Basic/ArrayRefView.h"
2121
#include "swift/Basic/LLVM.h"
22+
#include "swift/Basic/OutputFileMap.h"
2223
#include "swift/Basic/Statistic.h"
2324
#include "swift/Driver/Driver.h"
2425
#include "swift/Driver/Job.h"
2526
#include "swift/Driver/Util.h"
26-
#include "swift/Frontend/OutputFileMap.h"
2727
#include "llvm/ADT/DenseSet.h"
2828
#include "llvm/ADT/StringRef.h"
2929
#include "llvm/Support/Chrono.h"

include/swift/Driver/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include "swift/Basic/FileTypes.h"
2222
#include "swift/Basic/LLVM.h"
2323
#include "swift/Basic/OptionSet.h"
24+
#include "swift/Basic/OutputFileMap.h"
2425
#include "swift/Basic/Sanitizers.h"
2526
#include "swift/Driver/Util.h"
26-
#include "swift/Frontend/OutputFileMap.h"
2727
#include "llvm/ADT/DenseMap.h"
2828
#include "llvm/ADT/StringMap.h"
2929
#include "llvm/ADT/StringRef.h"

include/swift/Driver/FrontendUtil.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,33 @@
1414
#define SWIFT_DRIVER_FRONTENDUTIL_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/STLExtras.h"
1718

1819
#include <memory>
1920

2021
namespace swift {
2122

22-
class CompilerInvocation;
2323
class DiagnosticEngine;
2424

2525
namespace driver {
2626

27-
/// \brief Creates a CompilerInvocation from the given driver arguments.
27+
/// Generates the list of arguments that would be passed to the compiler
28+
/// frontend from the given driver arguments.
2829
///
29-
/// \param ArgList The driver arguments for which a CompilerInvocation
30-
/// should be created.
31-
/// \param Diags The DiagnosticEngine which should be used for parsing arguments
30+
/// \param ArgList The driver arguments (i.e. normal arguments for \c swiftc).
31+
/// \param Diags The DiagnosticEngine used to report any errors parsing the
32+
/// arguments.
33+
/// \param Action Called with the list of frontend arguments if there were no
34+
/// errors in processing \p ArgList. This is a callback rather than a return
35+
/// value to avoid copying the arguments more than necessary.
3236
///
33-
/// \returns A fully-formed CompilerInvocation, or nullptr if one couldn't be
34-
/// created.
37+
/// \returns True on error, or if \p Action returns true.
3538
///
36-
/// \note This function is not intended to create CompilerInvocation instances
37-
/// which are suitable for use in REPL or immediate modes, since it will have
38-
/// the effect of overriding the frontend's requested action to
39-
/// FrontendOptions::ActionType::Parse.
40-
std::unique_ptr<CompilerInvocation> createCompilerInvocation(
41-
ArrayRef<const char *> ArgList, DiagnosticEngine &Diags);
39+
/// \note This function is not intended to create invocations which are
40+
/// suitable for use in REPL or immediate modes.
41+
bool getSingleFrontendInvocationFromDriverArguments(
42+
ArrayRef<const char *> ArgList, DiagnosticEngine &Diags,
43+
llvm::function_ref<bool(ArrayRef<const char *> FrontendArgs)> Action);
4244

4345
} // end namespace driver
4446
} // end namespace swift

include/swift/Driver/Job.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
#include "swift/Basic/FileTypes.h"
1717
#include "swift/Basic/LLVM.h"
18+
#include "swift/Basic/OutputFileMap.h"
1819
#include "swift/Driver/Action.h"
1920
#include "swift/Driver/Util.h"
20-
#include "swift/Frontend/OutputFileMap.h"
2121
#include "llvm/ADT/ArrayRef.h"
2222
#include "llvm/ADT/DenseMap.h"
2323
#include "llvm/ADT/PointerIntPair.h"

lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ add_swift_library(swiftBasic STATIC
7878
LangOptions.cpp
7979
LLVMContext.cpp
8080
Mangler.cpp
81+
OutputFileMap.cpp
8182
Platform.cpp
8283
PrefixMap.cpp
8384
PrettyStackTrace.cpp

lib/Frontend/OutputFileMap.cpp renamed to lib/Basic/OutputFileMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- OutputFileMap.cpp - Driver output file map -----------------------===//
1+
//===--- OutputFileMap.h - Map of inputs to multiple outputs --------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "swift/Frontend/OutputFileMap.h"
13+
#include "swift/Basic/OutputFileMap.h"
1414
#include "llvm/ADT/SmallString.h"
1515
#include "llvm/ADT/StringRef.h"
1616
#include "llvm/Support/Path.h"

lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(swiftDriver_targetDefines)
1919
add_swift_library(swiftDriver STATIC
2020
${swiftDriver_sources}
2121
DEPENDS SwiftOptions
22-
LINK_LIBRARIES swiftAST swiftBasic swiftFrontend swiftOption)
22+
LINK_LIBRARIES swiftAST swiftBasic swiftOption)
2323

2424
# Generate the static-stdlib-args.lnk file used by -static-stdlib option
2525
# for 'GenericUnix' (eg linux)

lib/Driver/Compilation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "swift/AST/DiagnosticEngine.h"
1616
#include "swift/AST/DiagnosticsDriver.h"
17+
#include "swift/Basic/OutputFileMap.h"
1718
#include "swift/Basic/Program.h"
1819
#include "swift/Basic/STLExtras.h"
1920
#include "swift/Basic/Statistic.h"
@@ -26,7 +27,6 @@
2627
#include "swift/Driver/Job.h"
2728
#include "swift/Driver/ParseableOutput.h"
2829
#include "swift/Driver/ToolChain.h"
29-
#include "swift/Frontend/OutputFileMap.h"
3030
#include "swift/Option/Options.h"
3131
#include "llvm/ADT/DenseSet.h"
3232
#include "llvm/ADT/MapVector.h"

lib/Driver/DarwinToolChains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Basic/Platform.h"
1818
#include "swift/Basic/Range.h"
19+
#include "swift/Basic/STLExtras.h"
1920
#include "swift/Basic/TaskQueue.h"
2021
#include "swift/Config.h"
2122
#include "swift/Driver/Compilation.h"
2223
#include "swift/Driver/Driver.h"
2324
#include "swift/Driver/Job.h"
24-
#include "swift/Frontend/Frontend.h"
2525
#include "swift/Option/Options.h"
2626
#include "clang/Basic/Version.h"
2727
#include "clang/Driver/Util.h"

lib/Driver/DependencyGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/Basic/ReferenceDependencyKeys.h"
1314
#include "swift/Basic/Statistic.h"
1415
#include "swift/Driver/DependencyGraph.h"
1516
#include "swift/Demangling/Demangle.h"
16-
#include "swift/Frontend/ReferenceDependencyKeys.h"
1717
#include "llvm/ADT/SmallString.h"
1818
#include "llvm/ADT/SmallVector.h"
1919
#include "llvm/ADT/StringSwitch.h"

lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/DiagnosticsDriver.h"
2222
#include "swift/AST/DiagnosticsFrontend.h"
2323
#include "swift/Basic/LLVM.h"
24+
#include "swift/Basic/OutputFileMap.h"
2425
#include "swift/Basic/Range.h"
2526
#include "swift/Basic/Statistic.h"
2627
#include "swift/Basic/TaskQueue.h"
@@ -31,7 +32,6 @@
3132
#include "swift/Driver/Job.h"
3233
#include "swift/Driver/PrettyStackTrace.h"
3334
#include "swift/Driver/ToolChain.h"
34-
#include "swift/Frontend/OutputFileMap.h"
3535
#include "swift/Option/Options.h"
3636
#include "swift/Option/SanitizerOptions.h"
3737
#include "swift/Parse/Lexer.h"

lib/Driver/FrontendUtil.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include "swift/Driver/Driver.h"
1919
#include "swift/Driver/Job.h"
2020
#include "swift/Driver/ToolChain.h"
21-
#include "swift/Frontend/Frontend.h"
21+
#include "llvm/Option/ArgList.h"
2222

2323
using namespace swift;
2424
using namespace swift::driver;
2525

26-
std::unique_ptr<CompilerInvocation>
27-
swift::driver::createCompilerInvocation(ArrayRef<const char *> Argv,
28-
DiagnosticEngine &Diags) {
26+
bool swift::driver::getSingleFrontendInvocationFromDriverArguments(
27+
ArrayRef<const char *> Argv, DiagnosticEngine &Diags,
28+
llvm::function_ref<bool(ArrayRef<const char *> FrontendArgs)> Action) {
2929
SmallVector<const char *, 16> Args;
3030
Args.push_back("<swiftc>"); // FIXME: Remove dummy argument.
3131
Args.insert(Args.end(), Argv.begin(), Argv.end());
@@ -55,16 +55,16 @@ swift::driver::createCompilerInvocation(ArrayRef<const char *> Argv,
5555
std::unique_ptr<llvm::opt::InputArgList> ArgList =
5656
TheDriver.parseArgStrings(ArrayRef<const char *>(Args).slice(1));
5757
if (Diags.hadAnyError())
58-
return nullptr;
58+
return true;
5959

6060
std::unique_ptr<ToolChain> TC = TheDriver.buildToolChain(*ArgList);
6161
if (Diags.hadAnyError())
62-
return nullptr;
62+
return true;
6363

6464
std::unique_ptr<Compilation> C =
6565
TheDriver.buildCompilation(*TC, std::move(ArgList));
6666
if (!C || C->getJobs().empty())
67-
return nullptr; // Don't emit an error; one should already have been emitted
67+
return true; // Don't emit an error; one should already have been emitted
6868

6969
SmallPtrSet<const Job *, 4> CompileCommands;
7070
for (const Job *Cmd : C->getJobs())
@@ -74,22 +74,15 @@ swift::driver::createCompilerInvocation(ArrayRef<const char *> Argv,
7474
if (CompileCommands.size() != 1) {
7575
// TODO: include Jobs in the diagnostic.
7676
Diags.diagnose(SourceLoc(), diag::error_expected_one_frontend_job);
77-
return nullptr;
77+
return true;
7878
}
7979

8080
const Job *Cmd = *CompileCommands.begin();
8181
if (StringRef("-frontend") != Cmd->getArguments().front()) {
8282
Diags.diagnose(SourceLoc(), diag::error_expected_frontend_command);
83-
return nullptr;
83+
return true;
8484
}
8585

86-
std::unique_ptr<CompilerInvocation> Invocation(new CompilerInvocation());
8786
const llvm::opt::ArgStringList &BaseFrontendArgs = Cmd->getArguments();
88-
ArrayRef<const char *> FrontendArgs =
89-
llvm::makeArrayRef(BaseFrontendArgs.data() + 1,
90-
BaseFrontendArgs.data() + BaseFrontendArgs.size());
91-
if (Invocation->parseArgs(FrontendArgs, Diags))
92-
return nullptr; // Don't emit an error; one should already have been emitted
93-
94-
return Invocation;
87+
return Action(llvm::makeArrayRef(BaseFrontendArgs).drop_front());
9588
}

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Basic/Platform.h"
1818
#include "swift/Basic/Range.h"
19+
#include "swift/Basic/STLExtras.h"
1920
#include "swift/Basic/TaskQueue.h"
2021
#include "swift/Config.h"
2122
#include "swift/Driver/Compilation.h"
2223
#include "swift/Driver/Driver.h"
2324
#include "swift/Driver/Job.h"
24-
#include "swift/Frontend/Frontend.h"
2525
#include "swift/Option/Options.h"
2626
#include "clang/Basic/Version.h"
2727
#include "clang/Driver/Util.h"

lib/Driver/UnixToolChains.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/Driver/Compilation.h"
2222
#include "swift/Driver/Driver.h"
2323
#include "swift/Driver/Job.h"
24-
#include "swift/Frontend/Frontend.h"
2524
#include "swift/Option/Options.h"
2625
#include "clang/Basic/Version.h"
2726
#include "clang/Driver/Util.h"

lib/Driver/WindowsToolChains.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/Driver/Compilation.h"
2222
#include "swift/Driver/Driver.h"
2323
#include "swift/Driver/Job.h"
24-
#include "swift/Frontend/Frontend.h"
2524
#include "swift/Option/Options.h"
2625
#include "clang/Basic/Version.h"
2726
#include "clang/Driver/Util.h"

lib/Frontend/ArgsToFrontendOutputsConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include "ArgsToFrontendInputsConverter.h"
1515
#include "ArgsToFrontendOptionsConverter.h"
1616
#include "swift/AST/DiagnosticsFrontend.h"
17+
#include "swift/Basic/OutputFileMap.h"
1718
#include "swift/Basic/Platform.h"
1819
#include "swift/Frontend/Frontend.h"
19-
#include "swift/Frontend/OutputFileMap.h"
2020
#include "swift/Option/Options.h"
2121
#include "swift/Option/SanitizerOptions.h"
2222
#include "swift/Strings.h"

lib/Frontend/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_swift_library(swiftFrontend STATIC
77
Frontend.cpp
88
FrontendInputsAndOutputs.cpp
99
FrontendOptions.cpp
10-
OutputFileMap.cpp
1110
PrintingDiagnosticConsumer.cpp
1211
SerializedDiagnosticConsumer.cpp
1312
DEPENDS

lib/FrontendTool/ReferenceDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "swift/AST/ReferencedNameTracker.h"
2424
#include "swift/AST/Types.h"
2525
#include "swift/Basic/LLVM.h"
26+
#include "swift/Basic/ReferenceDependencyKeys.h"
2627
#include "swift/Frontend/FrontendOptions.h"
27-
#include "swift/Frontend/ReferenceDependencyKeys.h"
2828
#include "llvm/ADT/MapVector.h"
2929
#include "llvm/ADT/SetVector.h"
3030
#include "llvm/ADT/SmallVector.h"

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,12 @@ bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation,
434434
Args.push_back("-resource-dir");
435435
Args.push_back(Impl.RuntimeResourcePath.c_str());
436436

437-
if (auto driverInvocation = driver::createCompilerInvocation(Args, Diags)) {
438-
Invocation = *driverInvocation;
439-
} else {
437+
bool HadError = driver::getSingleFrontendInvocationFromDriverArguments(
438+
Args, Diags, [&](ArrayRef<const char *> FrontendArgs) {
439+
return Invocation.parseArgs(FrontendArgs, Diags);
440+
});
441+
442+
if (HadError) {
440443
// FIXME: Get the actual diagnostic.
441444
Error = "error when parsing the compiler arguments";
442445
return true;

tools/swift-ide-test/ModuleAPIDiff.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -907,27 +907,30 @@ int swift::doGenerateModuleAPIDescription(StringRef MainExecutablePath,
907907
DiagnosticEngine Diags(SM);
908908
Diags.addConsumer(PDC);
909909

910-
std::unique_ptr<CompilerInvocation> Invocation =
911-
driver::createCompilerInvocation(CStringArgs, Diags);
910+
CompilerInvocation Invocation;
911+
bool HadError = driver::getSingleFrontendInvocationFromDriverArguments(
912+
CStringArgs, Diags, [&](ArrayRef<const char *> FrontendArgs) {
913+
return Invocation.parseArgs(FrontendArgs, Diags);
914+
});
912915

913-
if (!Invocation) {
916+
if (HadError) {
914917
llvm::errs() << "error: unable to create a CompilerInvocation\n";
915918
return 1;
916919
}
917920

918-
Invocation->setMainExecutablePath(MainExecutablePath);
921+
Invocation.setMainExecutablePath(MainExecutablePath);
919922

920923
CompilerInstance CI;
921924
CI.addDiagnosticConsumer(&PDC);
922-
if (CI.setup(*Invocation))
925+
if (CI.setup(Invocation))
923926
return 1;
924927
CI.performSema();
925928

926929
PrintOptions Options = PrintOptions::printEverything();
927930

928931
ModuleDecl *M = CI.getMainModule();
929-
M->getMainSourceFile(Invocation->getSourceFileKind()).print(llvm::outs(),
930-
Options);
932+
M->getMainSourceFile(Invocation.getSourceFileKind()).print(llvm::outs(),
933+
Options);
931934

932935
auto SMAModel = createSMAModel(M);
933936
llvm::yaml::Output YOut(llvm::outs());

0 commit comments

Comments
 (0)