Skip to content

Commit 3c69837

Browse files
committed
Add a debug flag to emit invalid swiftinterface files
1 parent d48e397 commit 3c69837

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

include/swift/Frontend/ModuleInterfaceSupport.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ struct ModuleInterfaceOptions {
4141
/// back .swiftinterface and reconstructing .swiftmodule.
4242
std::string Flags;
4343

44-
// Print SPI decls and attributes.
44+
/// Print SPI decls and attributes.
4545
bool PrintSPIs = false;
4646

4747
/// Print imports with both @_implementationOnly and @_spi, only applies
4848
/// when PrintSPIs is true.
4949
bool ExperimentalSPIImports = false;
50+
51+
/// Intentionally print invalid syntax into the file.
52+
bool DebugPrintInvalidSyntax = false;
5053
};
5154

5255
extern version::Version InterfaceFormatVersion;

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ def debug_forbid_typecheck_prefix : Separate<["-"], "debug-forbid-typecheck-pref
256256
HelpText<"Triggers llvm fatal_error if typechecker tries to typecheck a decl "
257257
"with the provided prefix name">;
258258

259+
def debug_emit_invalid_swiftinterface_syntax : Flag<["-"], "debug-emit-invalid-swiftinterface-syntax">,
260+
HelpText<"Write an invalid declaration into swiftinterface files">;
261+
259262
def debug_cycles : Flag<["-"], "debug-cycles">,
260263
HelpText<"Print out debug dumps when cycles are detected in evaluation">;
261264
def build_request_dependency_graph : Flag<["-"], "build-request-dependency-graph">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ static void ParseModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
325325
Args.hasArg(OPT_experimental_print_full_convention);
326326
Opts.ExperimentalSPIImports |=
327327
Args.hasArg(OPT_experimental_spi_imports);
328+
Opts.DebugPrintInvalidSyntax |=
329+
Args.hasArg(OPT_debug_emit_invalid_swiftinterface_syntax);
328330
}
329331

330332
/// Save a copy of any flags marked as ModuleInterfaceOption, if running

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,5 +551,8 @@ bool swift::emitSwiftInterface(raw_ostream &out,
551551
if (needDummyProtocolDeclaration)
552552
InheritedProtocolCollector::printDummyProtocolDeclaration(out);
553553

554+
if (Opts.DebugPrintInvalidSyntax)
555+
out << "#__debug_emit_invalid_swiftinterface_syntax__\n";
556+
554557
return false;
555558
}

0 commit comments

Comments
 (0)