Skip to content

Commit 9fd5918

Browse files
committed
Swap InputFileKind for ParseInputMode
Tying InputFile to this option meant that every input that was not one of the explictly-blessed kinds was modeled as a Swift file. With the new InputFile that infers file kinds, we no longer need CompilerInvocation::setInputKind
1 parent ac0814e commit 9fd5918

File tree

10 files changed

+28
-42
lines changed

10 files changed

+28
-42
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,6 @@ class CompilerInvocation {
287287
return FrontendOpts.ParseStdlib;
288288
}
289289

290-
void setInputKind(InputFileKind K) {
291-
FrontendOpts.InputKind = K;
292-
}
293-
294-
InputFileKind getInputKind() const {
295-
return FrontendOpts.InputKind;
296-
}
297290
void setModuleName(StringRef Name) {
298291
FrontendOpts.ModuleName = Name.str();
299292
IRGenOpts.ModuleName = Name.str();
@@ -332,7 +325,7 @@ class CompilerInvocation {
332325

333326
/// Retrieve the stdlib kind to implicitly import.
334327
ImplicitStdlibKind getImplicitStdlibKind() const {
335-
if (getInputKind() == InputFileKind::SIL) {
328+
if (FrontendOpts.InputMode == FrontendOptions::ParseInputMode::SIL) {
336329
return ImplicitStdlibKind::None;
337330
}
338331
if (getParseStdlib()) {

include/swift/Frontend/FrontendOptions.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class FrontendOptions {
3939
public:
4040
FrontendInputsAndOutputs InputsAndOutputs;
4141

42-
/// The kind of input on which the frontend should operate.
43-
InputFileKind InputKind = InputFileKind::Swift;
44-
4542
void forAllOutputPaths(const InputFile &input,
4643
llvm::function_ref<void(StringRef)> fn) const;
4744

@@ -143,6 +140,14 @@ class FrontendOptions {
143140
/// Indicates the action the user requested that the frontend perform.
144141
ActionType RequestedAction = ActionType::NoneAction;
145142

143+
enum class ParseInputMode {
144+
Swift,
145+
SwiftLibrary,
146+
SwiftModuleInterface,
147+
SIL,
148+
};
149+
ParseInputMode InputMode = ParseInputMode::Swift;
150+
146151
/// Indicates that the input(s) should be parsed as the Swift stdlib.
147152
bool ParseStdlib = false;
148153

@@ -316,8 +321,8 @@ class FrontendOptions {
316321
StringRef determineFallbackModuleName() const;
317322

318323
bool isCompilingExactlyOneSwiftFile() const {
319-
return InputKind == InputFileKind::Swift &&
320-
InputsAndOutputs.hasSingleInput();
324+
return InputsAndOutputs.hasSingleInput() &&
325+
InputMode == ParseInputMode::Swift;
321326
}
322327

323328
const PrimarySpecificPaths &

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ bool ArgsToFrontendOptionsConverter::convert(
143143
Opts.InputsAndOutputs = std::move(inputsAndOutputs).getValue();
144144
}
145145

146+
if (Args.hasArg(OPT_parse_sil) || Opts.InputsAndOutputs.shouldTreatAsSIL()) {
147+
Opts.InputMode = FrontendOptions::ParseInputMode::SIL;
148+
} else if (Opts.InputsAndOutputs.shouldTreatAsModuleInterface()) {
149+
Opts.InputMode = FrontendOptions::ParseInputMode::SwiftModuleInterface;
150+
} else if (Args.hasArg(OPT_parse_as_library)) {
151+
Opts.InputMode = FrontendOptions::ParseInputMode::SwiftLibrary;
152+
} else {
153+
Opts.InputMode = FrontendOptions::ParseInputMode::Swift;
154+
}
155+
146156
if (Opts.RequestedAction == FrontendOptions::ActionType::NoneAction) {
147157
Opts.RequestedAction = determineRequestedAction(Args);
148158
}
@@ -163,7 +173,7 @@ bool ArgsToFrontendOptionsConverter::convert(
163173
return true;
164174
}
165175

166-
if (setUpInputKindAndImmediateArgs())
176+
if (setUpImmediateArgs())
167177
return true;
168178

169179
if (computeModuleName())
@@ -398,7 +408,7 @@ ArgsToFrontendOptionsConverter::determineRequestedAction(const ArgList &args) {
398408
llvm_unreachable("Unhandled mode option");
399409
}
400410

401-
bool ArgsToFrontendOptionsConverter::setUpInputKindAndImmediateArgs() {
411+
bool ArgsToFrontendOptionsConverter::setUpImmediateArgs() {
402412
using namespace options;
403413
bool treatAsSIL =
404414
Args.hasArg(OPT_parse_sil) || Opts.InputsAndOutputs.shouldTreatAsSIL();
@@ -419,19 +429,6 @@ bool ArgsToFrontendOptionsConverter::setUpInputKindAndImmediateArgs() {
419429
}
420430
}
421431

422-
if (treatAsSIL)
423-
Opts.InputKind = InputFileKind::SIL;
424-
else if (Opts.InputsAndOutputs.shouldTreatAsLLVM())
425-
Opts.InputKind = InputFileKind::LLVM;
426-
else if (Opts.InputsAndOutputs.shouldTreatAsObjCHeader())
427-
Opts.InputKind = InputFileKind::ObjCHeader;
428-
else if (Opts.InputsAndOutputs.shouldTreatAsModuleInterface())
429-
Opts.InputKind = InputFileKind::SwiftModuleInterface;
430-
else if (Args.hasArg(OPT_parse_as_library))
431-
Opts.InputKind = InputFileKind::SwiftLibrary;
432-
else
433-
Opts.InputKind = InputFileKind::Swift;
434-
435432
return false;
436433
}
437434

lib/Frontend/ArgsToFrontendOptionsConverter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ArgsToFrontendOptionsConverter {
4747
void computePrintStatsOptions();
4848
void computeTBDOptions();
4949

50-
bool setUpInputKindAndImmediateArgs();
50+
bool setUpImmediateArgs();
5151

5252
bool checkUnusedSupplementaryOutputPaths() const;
5353

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ CompilerInvocation::setUpInputForSILTool(
18591859
// If it looks like we have an AST, set the source file kind to SIL and the
18601860
// name of the module to the file's name.
18611861
getFrontendOptions().InputsAndOutputs.addInput(
1862-
InputFile(inputFilename, bePrimary, fileBufOrErr.get().get()));
1862+
InputFile(inputFilename, bePrimary, fileBufOrErr.get().get(), file_types::TY_SIL));
18631863

18641864
auto result = serialization::validateSerializedAST(
18651865
fileBufOrErr.get()->getBuffer(), &extendedInfo);
@@ -1870,13 +1870,14 @@ CompilerInvocation::setUpInputForSILTool(
18701870
? moduleNameArg
18711871
: llvm::sys::path::stem(inputFilename);
18721872
setModuleName(stem);
1873-
setInputKind(InputFileKind::SwiftLibrary);
1873+
getFrontendOptions().InputMode =
1874+
FrontendOptions::ParseInputMode::SwiftLibrary;
18741875
} else {
18751876
const StringRef name = (alwaysSetModuleToMain || moduleNameArg.empty())
18761877
? "main"
18771878
: moduleNameArg;
18781879
setModuleName(name);
1879-
setInputKind(InputFileKind::SIL);
1880+
getFrontendOptions().InputMode = FrontendOptions::ParseInputMode::SIL;
18801881
}
18811882
return fileBufOrErr;
18821883
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
11421142
genericSubInvocation.setSDKPath(SearchPathOpts.SDKPath);
11431143
}
11441144

1145-
genericSubInvocation.setInputKind(InputFileKind::SwiftModuleInterface);
11461145
if (!SearchPathOpts.RuntimeResourcePath.empty()) {
11471146
genericSubInvocation.setRuntimeResourcePath(SearchPathOpts.RuntimeResourcePath);
11481147
}

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ static bool makeParserAST(CompilerInstance &CI, StringRef Text,
850850
CompilerInvocation Invocation) {
851851
Invocation.getFrontendOptions().InputsAndOutputs.clearInputs();
852852
Invocation.setModuleName("main");
853-
Invocation.setInputKind(InputFileKind::Swift);
854853
Invocation.getLangOptions().DisablePoundIfEvaluation = true;
855854

856855
std::unique_ptr<llvm::MemoryBuffer> Buf;
@@ -1440,7 +1439,6 @@ SourceFile *SwiftLangSupport::getSyntacticSourceFile(
14401439
Error = "Compiler invocation init failed";
14411440
return nullptr;
14421441
}
1443-
Invocation.setInputKind(InputFileKind::Swift);
14441442
Invocation.getFrontendOptions().InputsAndOutputs.addInput(
14451443
InputFile(InputBuf->getBufferIdentifier(), /*isPrimary*/false, InputBuf,
14461444
file_types::TY_Swift));

tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ static bool makeParserAST(CompilerInstance &CI, StringRef Text,
218218
CompilerInvocation Invocation) {
219219
Invocation.getFrontendOptions().InputsAndOutputs.clearInputs();
220220
Invocation.setModuleName("main");
221-
Invocation.setInputKind(InputFileKind::Swift);
222221
Invocation.getLangOptions().DisablePoundIfEvaluation = true;
223222

224223
std::unique_ptr<llvm::MemoryBuffer> Buf;

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,6 @@ static int doREPLCodeCompletion(const CompilerInvocation &InitInvok,
13221322
BufferText = BufferText.drop_back(1);
13231323

13241324
CompilerInvocation Invocation(InitInvok);
1325-
Invocation.setInputKind(InputFileKind::Swift);
1326-
13271325
CompilerInstance CI;
13281326

13291327
// Display diagnostics to stderr.
@@ -3790,8 +3788,6 @@ int main(int argc, char *argv[]) {
37903788

37913789
for (auto &File : options::InputFilenames)
37923790
InitInvok.getFrontendOptions().InputsAndOutputs.addInputFile(File);
3793-
if (!options::InputFilenames.empty())
3794-
InitInvok.setInputKind(InputFileKind::SwiftLibrary);
37953791

37963792
InitInvok.setMainExecutablePath(
37973793
llvm::sys::fs::getMainExecutable(argv[0],

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,6 @@ int parseFile(
613613

614614
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(InputFileName);
615615

616-
if (InputFileName.endswith(".swiftinterface"))
617-
Invocation.setInputKind(InputFileKind::SwiftModuleInterface);
618616
Invocation.setMainExecutablePath(
619617
llvm::sys::fs::getMainExecutable(MainExecutablePath,
620618
reinterpret_cast<void *>(&anchorForGetMainExecutable)));

0 commit comments

Comments
 (0)