Skip to content

Commit c440b0b

Browse files
committed
Diagnose parse-only invocations trying to emit dependency information
Parse-only invocations do not support the proper creation of dependency files or reference dependency files because they have not yet run name binding. Ban these invocations by diagnostic and add a new diagnostic specifically for reference dependencies.
1 parent 6ecfe7a commit c440b0b

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ NOTE(note_valid_swift_versions, none,
108108
"valid arguments to '-swift-version' are %0", (StringRef))
109109

110110
ERROR(error_mode_cannot_emit_dependencies,none,
111-
"this mode does not support emitting dependency files", ())
111+
"this mode does not support emitting dependency files", ())
112+
ERROR(error_mode_cannot_emit_reference_dependencies,none,
113+
"this mode does not support emitting reference dependency files", ())
112114
ERROR(error_mode_cannot_emit_header,none,
113-
"this mode does not support emitting Objective-C headers", ())
115+
"this mode does not support emitting Objective-C headers", ())
114116
ERROR(error_mode_cannot_emit_loaded_module_trace,none,
115-
"this mode does not support emitting the loaded module trace", ())
117+
"this mode does not support emitting the loaded module trace", ())
116118
ERROR(error_mode_cannot_emit_module,none,
117-
"this mode does not support emitting modules", ())
119+
"this mode does not support emitting modules", ())
118120
ERROR(error_mode_cannot_emit_module_doc,none,
119-
"this mode does not support emitting module documentation files", ())
121+
"this mode does not support emitting module documentation files", ())
120122

121123
WARNING(emit_reference_dependencies_without_primary_file,none,
122124
"ignoring -emit-reference-dependencies (requires -primary-file)", ())

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ class FrontendOptions {
296296

297297
private:
298298
static bool canActionEmitDependencies(ActionType);
299+
static bool canActionEmitReferenceDependencies(ActionType);
299300
static bool canActionEmitObjCHeader(ActionType);
300301
static bool canActionEmitLoadedModuleTrace(ActionType);
301302
static bool canActionEmitModule(ActionType);

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ ArgsToFrontendOptionsConverter::determineRequestedAction(const ArgList &args) {
322322
return FrontendOptions::ActionType::EmitImportedModules;
323323
if (Opt.matches(OPT_parse))
324324
return FrontendOptions::ActionType::Parse;
325+
if (Opt.matches(OPT_namebind))
326+
return FrontendOptions::ActionType::NameBind;
325327
if (Opt.matches(OPT_typecheck))
326328
return FrontendOptions::ActionType::Typecheck;
327329
if (Opt.matches(OPT_dump_parse))
@@ -467,6 +469,12 @@ bool ArgsToFrontendOptionsConverter::checkUnusedSupplementaryOutputPaths()
467469
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_dependencies);
468470
return true;
469471
}
472+
if (!FrontendOptions::canActionEmitReferenceDependencies(Opts.RequestedAction)
473+
&& Opts.InputsAndOutputs.hasReferenceDependenciesPath()) {
474+
Diags.diagnose(SourceLoc(),
475+
diag::error_mode_cannot_emit_reference_dependencies);
476+
return true;
477+
}
470478
if (!FrontendOptions::canActionEmitObjCHeader(Opts.RequestedAction) &&
471479
Opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
472480
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_header);

lib/Frontend/FrontendOptions.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ FrontendOptions::suffixForPrincipalOutputFileForAction(ActionType action) {
184184
bool FrontendOptions::canActionEmitDependencies(ActionType action) {
185185
switch (action) {
186186
case ActionType::NoneAction:
187+
case ActionType::Parse:
187188
case ActionType::DumpParse:
188189
case ActionType::DumpInterfaceHash:
189190
case ActionType::DumpAST:
@@ -194,7 +195,37 @@ bool FrontendOptions::canActionEmitDependencies(ActionType action) {
194195
case ActionType::Immediate:
195196
case ActionType::REPL:
196197
return false;
198+
case ActionType::Typecheck:
199+
case ActionType::MergeModules:
200+
case ActionType::EmitModuleOnly:
201+
case ActionType::EmitPCH:
202+
case ActionType::EmitSILGen:
203+
case ActionType::EmitSIL:
204+
case ActionType::EmitSIBGen:
205+
case ActionType::EmitSIB:
206+
case ActionType::EmitIR:
207+
case ActionType::EmitBC:
208+
case ActionType::EmitAssembly:
209+
case ActionType::EmitObject:
210+
case ActionType::EmitImportedModules:
211+
return true;
212+
}
213+
}
214+
215+
bool FrontendOptions::canActionEmitReferenceDependencies(ActionType action) {
216+
switch (action) {
217+
case ActionType::NoneAction:
197218
case ActionType::Parse:
219+
case ActionType::DumpParse:
220+
case ActionType::DumpInterfaceHash:
221+
case ActionType::DumpAST:
222+
case ActionType::EmitSyntax:
223+
case ActionType::PrintAST:
224+
case ActionType::DumpScopeMaps:
225+
case ActionType::DumpTypeRefinementContexts:
226+
case ActionType::Immediate:
227+
case ActionType::REPL:
228+
return false;
198229
case ActionType::Typecheck:
199230
case ActionType::MergeModules:
200231
case ActionType::EmitModuleOnly:

test/Driver/options.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727
// RUN: not %target-swift-frontend -typecheck -emit-module %s 2>&1 | %FileCheck -check-prefix=PARSE_NO_MODULE %s
2828
// PARSE_NO_MODULE: error: this mode does not support emitting modules{{$}}
2929

30+
// RUN: not %target-swift-frontend -parse -emit-dependencies %s 2>&1 | %FileCheck -check-prefix=PARSE_NO_DEPS %s
31+
// PARSE_NO_DEPS: error: this mode does not support emitting dependency files{{$}}
3032
// RUN: not %target-swift-frontend -dump-ast -emit-dependencies %s 2>&1 | %FileCheck -check-prefix=DUMP_NO_DEPS %s
3133
// DUMP_NO_DEPS: error: this mode does not support emitting dependency files{{$}}
3234

35+
// RUN: not %target-swift-frontend -parse -emit-reference-dependencies %s 2>&1 | %FileCheck -check-prefix=PARSE_NO_REFERENCE_DEPS %s
36+
// PARSE_NO_REFERENCE_DEPS: error: this mode does not support emitting reference dependency files{{$}}
37+
// RUN: not %target-swift-frontend -dump-ast -emit-reference-dependencies %s 2>&1 | %FileCheck -check-prefix=DUMP_NO_REFERENCE_DEPS %s
38+
// DUMP_NO_REFERENCE_DEPS: error: this mode does not support emitting reference dependency files{{$}}
39+
3340
// Should not fail with non-zero exit code.
3441
// RUN: %target-swift-frontend -emit-silgen %S/Inputs/invalid-module-name.swift > /dev/null
3542
// RUN: %target-swift-frontend -emit-silgen -parse-as-library %S/Inputs/invalid-module-name.swift -module-name foo > /dev/null

0 commit comments

Comments
 (0)