Skip to content

Commit ccb7378

Browse files
committed
Bug fixes & module name cleanup.
Unify actionHasOutput w/ doesActionProduceOutput & correct both. Do not set an output filename if there is no output. Add test to ensure no output is created in immediate mode. Restore NFC module name computation.
1 parent 6de07d0 commit ccb7378

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,6 @@ class FrontendOptions {
514514
/// -dump-scope-maps.
515515
SmallVector<std::pair<unsigned, unsigned>, 2> DumpScopeMapLocations;
516516

517-
/// Indicates whether the RequestedAction has output.
518-
bool actionHasOutput() const;
519-
520517
/// Indicates whether the RequestedAction will immediately run code.
521518
bool actionIsImmediate() const;
522519

@@ -551,6 +548,7 @@ class FrontendOptions {
551548

552549
static bool doesActionProduceOutput(ActionType);
553550
static bool doesActionProduceTextualOutput(ActionType);
551+
static bool doesActionImplyMainModule(ActionType);
554552
};
555553

556554
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ bool FrontendArgsToOptionsConverter::computeModuleName() {
640640
(Opts.ModuleName != STDLIB_NAME || Opts.ParseStdlib)) {
641641
return false;
642642
}
643-
if (!Opts.actionHasOutput() || Opts.isCompilingExactlyOneSwiftFile()) {
643+
if (FrontendOptions::doesActionImplyMainModule(Opts.RequestedAction) ||
644+
Opts.isCompilingExactlyOneSwiftFile()) {
644645
Opts.ModuleName = "main";
645646
return false;
646647
}
@@ -680,10 +681,10 @@ bool FrontendArgsToOptionsConverter::computeFallbackModuleName() {
680681
}
681682

682683
bool FrontendArgsToOptionsConverter::computeOutputFilenames() {
683-
assert(
684-
FrontendOptions::doesActionProduceOutput(Opts.RequestedAction) ||
685-
!FrontendOptions::doesActionProduceTextualOutput(Opts.RequestedAction));
686-
684+
if (!FrontendOptions::doesActionProduceOutput(Opts.RequestedAction)) {
685+
Opts.OutputFilenames.clear();
686+
return false;
687+
}
687688
ArrayRef<std::string> outputFilenamesFromCommandLineOrFilelist =
688689
getOutputFilenamesFromCommandLineOrFilelist();
689690

lib/Frontend/FrontendOptions.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void FrontendInputs::transformInputFilenames(
9696
}
9797
}
9898

99-
bool FrontendOptions::actionHasOutput() const {
100-
switch (RequestedAction) {
99+
bool FrontendOptions::doesActionImplyMainModule(ActionType action) {
100+
switch (action) {
101101
case ActionType::NoneAction:
102102
case ActionType::Parse:
103103
case ActionType::Typecheck:
@@ -108,24 +108,24 @@ bool FrontendOptions::actionHasOutput() const {
108108
case ActionType::PrintAST:
109109
case ActionType::DumpScopeMaps:
110110
case ActionType::DumpTypeRefinementContexts:
111-
return false;
111+
return true;
112112
case ActionType::EmitPCH:
113113
case ActionType::EmitSILGen:
114114
case ActionType::EmitSIL:
115115
case ActionType::EmitSIBGen:
116116
case ActionType::EmitSIB:
117117
case ActionType::EmitModuleOnly:
118118
case ActionType::MergeModules:
119-
return true;
119+
return false;
120120
case ActionType::Immediate:
121121
case ActionType::REPL:
122-
return false;
122+
return true;
123123
case ActionType::EmitAssembly:
124124
case ActionType::EmitIR:
125125
case ActionType::EmitBC:
126126
case ActionType::EmitObject:
127127
case ActionType::EmitImportedModules:
128-
return true;
128+
return false;
129129
}
130130
llvm_unreachable("Unknown ActionType");
131131
}
@@ -406,37 +406,35 @@ bool FrontendOptions::canActionEmitModuleDoc(ActionType action) {
406406

407407
bool FrontendOptions::doesActionProduceOutput(ActionType action) {
408408
switch (action) {
409-
// FIXME: Some of these don't actually produce output
410-
// but for now stay consistent with the status quo.
411-
case ActionType::NoneAction:
412-
case ActionType::EmitPCH:
413-
case ActionType::EmitSIBGen:
414-
case ActionType::EmitSIB:
415-
case ActionType::MergeModules:
416-
case ActionType::EmitModuleOnly:
417-
case ActionType::EmitBC:
418-
case ActionType::EmitObject:
419409
case ActionType::Parse:
420410
case ActionType::Typecheck:
421411
case ActionType::DumpParse:
422-
case ActionType::DumpInterfaceHash:
423412
case ActionType::DumpAST:
424413
case ActionType::EmitSyntax:
414+
case ActionType::DumpInterfaceHash:
425415
case ActionType::PrintAST:
426416
case ActionType::DumpScopeMaps:
427417
case ActionType::DumpTypeRefinementContexts:
428-
case ActionType::EmitImportedModules:
418+
case ActionType::EmitPCH:
429419
case ActionType::EmitSILGen:
430420
case ActionType::EmitSIL:
421+
case ActionType::EmitSIBGen:
422+
case ActionType::EmitSIB:
423+
case ActionType::EmitModuleOnly:
431424
case ActionType::EmitAssembly:
432425
case ActionType::EmitIR:
426+
case ActionType::EmitBC:
427+
case ActionType::EmitObject:
428+
case ActionType::EmitImportedModules:
429+
case ActionType::MergeModules:
433430
return true;
434431

432+
case ActionType::NoneAction:
435433
case ActionType::Immediate:
436434
case ActionType::REPL:
437-
// These modes have no frontend-generated output.
438435
return false;
439436
}
437+
llvm_unreachable("Unknown ActionType");
440438
}
441439

442440
bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// RUN: rm -rf %t && mkdir -p %t && cd %t && echo >test.swift && %swift -interpret test.swift && rm test.swift && test `ls | wc -w` -eq 0

0 commit comments

Comments
 (0)