Skip to content

Commit 2cda5a9

Browse files
author
David Ungar
authored
Merge pull request #13233 from davidungar/PR2-5
Preparatory, simple changes to ease reviewing of the next PR.
2 parents ab0c44d + 67fc5e3 commit 2cda5a9

File tree

5 files changed

+64
-62
lines changed

5 files changed

+64
-62
lines changed

Diff for: include/swift/Frontend/Frontend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class CompilerInvocation {
306306
/// sil-opt, sil-func-extractor, sil-llvm-gen, and sil-nm.
307307
/// Return value includes the buffer so caller can keep it alive.
308308
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
309-
setUpInputForSILTool(StringRef InputFilename, StringRef ModuleNameArg,
309+
setUpInputForSILTool(StringRef inputFilename, StringRef moduleNameArg,
310310
bool alwaysSetModuleToMain,
311311
serialization::ExtendedValidationInfo &extendedInfo);
312312
bool hasSerializedAST() {

Diff for: include/swift/Frontend/FrontendOptions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ class FrontendOptions {
514514
/// -dump-scope-maps.
515515
SmallVector<std::pair<unsigned, unsigned>, 2> DumpScopeMapLocations;
516516

517-
/// Indicates whether the RequestedAction will immediately run code.
518-
bool actionIsImmediate() const;
517+
/// Indicates whether the action will immediately run code.
518+
static bool isActionImmediate(ActionType);
519519

520520
/// Return a hash code of any components from these options that should
521521
/// contribute to a Swift Bridging PCH hash.

Diff for: lib/Frontend/CompilerInvocation.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,40 @@ std::string FrontendArgsToOptionsConverter::determineBaseNameOfOutput() const {
771771
return llvm::sys::path::stem(nameToStem).str();
772772
}
773773

774+
ArrayRef<std::string>
775+
FrontendArgsToOptionsConverter::getOutputFilenamesFromCommandLineOrFilelist() {
776+
if (cachedOutputFilenamesFromCommandLineOrFilelist) {
777+
return *cachedOutputFilenamesFromCommandLineOrFilelist;
778+
}
779+
780+
if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) {
781+
assert(!Args.hasArg(options::OPT_o) &&
782+
"don't use -o with -output-filelist");
783+
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
784+
readOutputFileList(A->getValue()));
785+
} else {
786+
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
787+
Args.getAllArgValues(options::OPT_o));
788+
}
789+
return *cachedOutputFilenamesFromCommandLineOrFilelist;
790+
}
791+
792+
/// Try to read an output file list file.
793+
std::vector<std::string> FrontendArgsToOptionsConverter::readOutputFileList(
794+
const StringRef filelistPath) const {
795+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
796+
llvm::MemoryBuffer::getFile(filelistPath);
797+
if (!buffer) {
798+
Diags.diagnose(SourceLoc(), diag::cannot_open_file, filelistPath,
799+
buffer.getError().message());
800+
}
801+
std::vector<std::string> outputFiles;
802+
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
803+
outputFiles.push_back(line.str());
804+
}
805+
return outputFiles;
806+
}
807+
774808
void FrontendArgsToOptionsConverter::determineSupplementaryOutputFilenames() {
775809
using namespace options;
776810
auto determineOutputFilename =
@@ -884,40 +918,6 @@ void FrontendArgsToOptionsConverter::computeLLVMArgs() {
884918
}
885919
}
886920

887-
ArrayRef<std::string>
888-
FrontendArgsToOptionsConverter::getOutputFilenamesFromCommandLineOrFilelist() {
889-
if (cachedOutputFilenamesFromCommandLineOrFilelist) {
890-
return *cachedOutputFilenamesFromCommandLineOrFilelist;
891-
}
892-
893-
if (const Arg *A = Args.getLastArg(options::OPT_output_filelist)) {
894-
assert(!Args.hasArg(options::OPT_o) &&
895-
"don't use -o with -output-filelist");
896-
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
897-
readOutputFileList(A->getValue()));
898-
} else {
899-
cachedOutputFilenamesFromCommandLineOrFilelist.emplace(
900-
Args.getAllArgValues(options::OPT_o));
901-
}
902-
return *cachedOutputFilenamesFromCommandLineOrFilelist;
903-
}
904-
905-
/// Try to read an output file list file.
906-
std::vector<std::string> FrontendArgsToOptionsConverter::readOutputFileList(
907-
const StringRef filelistPath) const {
908-
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
909-
llvm::MemoryBuffer::getFile(filelistPath);
910-
if (!buffer) {
911-
Diags.diagnose(SourceLoc(), diag::cannot_open_file, filelistPath,
912-
buffer.getError().message());
913-
}
914-
std::vector<std::string> outputFiles;
915-
for (StringRef line : make_range(llvm::line_iterator(*buffer.get()), {})) {
916-
outputFiles.push_back(line.str());
917-
}
918-
return outputFiles;
919-
}
920-
921921
static bool ParseFrontendArgs(FrontendOptions &opts, ArgList &args,
922922
DiagnosticEngine &diags) {
923923
return FrontendArgsToOptionsConverter(diags, args, opts).convert();

Diff for: lib/Frontend/Frontend.cpp

+25-23
Original file line numberDiff line numberDiff line change
@@ -111,32 +111,34 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
111111
SourceMgr, Diagnostics));
112112

113113
if (Invocation.getFrontendOptions().EnableSourceImport) {
114-
bool immediate = Invocation.getFrontendOptions().actionIsImmediate();
114+
bool immediate = FrontendOptions::isActionImmediate(
115+
Invocation.getFrontendOptions().RequestedAction);
115116
bool enableResilience = Invocation.getFrontendOptions().EnableResilience;
116117
Context->addModuleLoader(SourceLoader::create(*Context,
117118
!immediate,
118119
enableResilience,
119120
DepTracker));
120121
}
121-
122-
auto SML = SerializedModuleLoader::create(*Context, DepTracker);
123-
this->SML = SML.get();
124-
Context->addModuleLoader(std::move(SML));
122+
{
123+
auto SML = SerializedModuleLoader::create(*Context, DepTracker);
124+
this->SML = SML.get();
125+
Context->addModuleLoader(std::move(SML));
126+
}
127+
{
128+
// Wire up the Clang importer. If the user has specified an SDK, use it.
129+
// Otherwise, we just keep it around as our interface to Clang's ABI
130+
// knowledge.
131+
auto clangImporter =
132+
ClangImporter::create(*Context, Invocation.getClangImporterOptions(),
133+
Invocation.getPCHHash(), DepTracker);
134+
if (!clangImporter) {
135+
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
136+
return true;
137+
}
125138

126-
// Wire up the Clang importer. If the user has specified an SDK, use it.
127-
// Otherwise, we just keep it around as our interface to Clang's ABI
128-
// knowledge.
129-
auto clangImporter =
130-
ClangImporter::create(*Context, Invocation.getClangImporterOptions(),
131-
Invocation.getPCHHash(),
132-
DepTracker);
133-
if (!clangImporter) {
134-
Diagnostics.diagnose(SourceLoc(), diag::error_clang_importer_create_fail);
135-
return true;
139+
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
136140
}
137141

138-
Context->addModuleLoader(std::move(clangImporter), /*isClang*/true);
139-
140142
assert(Lexer::isIdentifier(Invocation.getModuleName()));
141143

142144
Optional<unsigned> CodeCompletionBufferID;
@@ -390,11 +392,11 @@ void CompilerInstance::getImplicitlyImportedModules(
390392

391393
void CompilerInstance::createREPLFile(
392394
const ImplicitImports &implicitImports) const {
393-
auto *SingleInputFile = new (*Context) SourceFile(
395+
auto *singleInputFile = new (*Context) SourceFile(
394396
*MainModule, Invocation.getSourceFileKind(), None, implicitImports.kind,
395397
Invocation.getLangOptions().KeepSyntaxInfoInSourceFile);
396-
MainModule->addFile(*SingleInputFile);
397-
addAdditionalInitialImportsTo(SingleInputFile, implicitImports);
398+
MainModule->addFile(*singleInputFile);
399+
addAdditionalInitialImportsTo(singleInputFile, implicitImports);
398400
}
399401

400402
std::unique_ptr<DelayedParsingCallbacks>
@@ -534,7 +536,7 @@ OptionSet<TypeCheckingFlags> CompilerInstance::computeTypeCheckingOptions() {
534536
if (options.DebugTimeFunctionBodies) {
535537
TypeCheckOptions |= TypeCheckingFlags::DebugTimeFunctionBodies;
536538
}
537-
if (options.actionIsImmediate()) {
539+
if (FrontendOptions::isActionImmediate(options.RequestedAction)) {
538540
TypeCheckOptions |= TypeCheckingFlags::ForImmediateMode;
539541
}
540542
if (options.DebugTimeExpressionTypeChecking) {
@@ -627,8 +629,8 @@ void CompilerInstance::parseAndTypeCheckMainFile(
627629
static void
628630
forEachSourceFileIn(ModuleDecl *module,
629631
llvm::function_ref<void(SourceFile &)> fn) {
630-
for (auto File : module->getFiles()) {
631-
if (auto SF = dyn_cast<SourceFile>(File))
632+
for (auto file : module->getFiles()) {
633+
if (auto SF = dyn_cast<SourceFile>(file))
632634
fn(*SF);
633635
}
634636
}

Diff for: lib/Frontend/FrontendOptions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ bool FrontendOptions::needsProperModuleName(ActionType action) {
130130
llvm_unreachable("Unknown ActionType");
131131
}
132132

133-
bool FrontendOptions::actionIsImmediate() const {
134-
switch (RequestedAction) {
133+
bool FrontendOptions::isActionImmediate(ActionType action) {
134+
switch (action) {
135135
case ActionType::NoneAction:
136136
case ActionType::Parse:
137137
case ActionType::Typecheck:

0 commit comments

Comments
 (0)