Skip to content

Frontend: add an ABI checker flag to avoid downgrading detected ABI breakages into warnings. #78418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,10 @@ def compiler_style_diags: Flag<["-", "--"], "compiler-style-diags">,
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
HelpText<"Print compiler style diagnostics to stderr.">;

def error_on_abi_breakage: Flag<["-", "--"], "error-on-abi-breakage">,
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
HelpText<"Always treat ABI checker issues as errors">;

def json: Flag<["-", "--"], "json">,
Flags<[NoDriverOption, SwiftAPIDigesterOption]>,
HelpText<"Print output in JSON format.">;
Expand Down
23 changes: 18 additions & 5 deletions lib/DriverTool/swift_api_digester_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,7 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
llvm::StringSet<> ProtocolReqAllowlist,
bool DisableFailOnError,
bool CompilerStyleDiags,
bool ExplicitErrOnABIBreakage,
StringRef SerializedDiagPath,
StringRef BreakageAllowlistPath,
bool DebugMapping) {
Expand All @@ -1936,11 +1937,16 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
Ctx.getDiags().diagnose(SourceLoc(), diag::cannot_read_allowlist,
BreakageAllowlistPath);
}
auto shouldDowngrade = false;
// If explicitly specified, avoid downgrading ABI breakage errors to warnings.
if (ExplicitErrOnABIBreakage) {
shouldDowngrade = false;
}
auto pConsumer = std::make_unique<FilteringDiagnosticConsumer>(
createDiagConsumer(*OS, FailOnError, DisableFailOnError, CompilerStyleDiags,
SerializedDiagPath),
std::move(allowedBreakages),
/*DowngradeToWarning*/false);
/*DowngradeToWarning*/shouldDowngrade);
SWIFT_DEFER { pConsumer->finishProcessing(); };
Ctx.addDiagConsumer(*pConsumer);
Ctx.setCommonVersion(std::min(LeftModule->getJsonFormatVersion(),
Expand All @@ -1962,6 +1968,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
llvm::StringSet<> ProtocolReqAllowlist,
bool DisableFailOnError,
bool CompilerStyleDiags,
bool ExplicitErrOnABIBreakage,
StringRef SerializedDiagPath,
StringRef BreakageAllowlistPath,
bool DebugMapping) {
Expand All @@ -1980,7 +1987,8 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
RightCollector.deSerialize(RightPath);
return diagnoseModuleChange(
Ctx, LeftCollector.getSDKRoot(), RightCollector.getSDKRoot(), OutputPath,
std::move(ProtocolReqAllowlist), DisableFailOnError, CompilerStyleDiags, SerializedDiagPath,
std::move(ProtocolReqAllowlist), DisableFailOnError,
ExplicitErrOnABIBreakage, CompilerStyleDiags, SerializedDiagPath,
BreakageAllowlistPath, DebugMapping);
}

Expand Down Expand Up @@ -2240,6 +2248,7 @@ class SwiftAPIDigesterInvocation {
std::string OutputFile;
std::string OutputDir;
bool CompilerStyleDiags;
bool ExplicitErrOnABIBreakage;
std::string SerializedDiagPath;
std::string BaselineFilePath;
std::string BaselineDirPath;
Expand Down Expand Up @@ -2339,6 +2348,7 @@ class SwiftAPIDigesterInvocation {
OutputFile = ParsedArgs.getLastArgValue(OPT_o).str();
OutputDir = ParsedArgs.getLastArgValue(OPT_output_dir).str();
CompilerStyleDiags = ParsedArgs.hasArg(OPT_compiler_style_diags);
ExplicitErrOnABIBreakage = ParsedArgs.hasArg(OPT_error_on_abi_breakage);
SerializedDiagPath =
ParsedArgs.getLastArgValue(OPT_serialize_diagnostics_path).str();
BaselineFilePath = ParsedArgs.getLastArgValue(OPT_baseline_path).str();
Expand Down Expand Up @@ -2578,21 +2588,24 @@ class SwiftAPIDigesterInvocation {
return diagnoseModuleChange(
SDKJsonPaths[0], SDKJsonPaths[1], OutputFile, CheckerOpts,
std::move(protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
ExplicitErrOnABIBreakage, SerializedDiagPath,
BreakageAllowlistPath, DebugMapping);
}
case ComparisonInputMode::BaselineJson: {
SDKContext Ctx(CheckerOpts);
return diagnoseModuleChange(
Ctx, getBaselineFromJson(Ctx), getSDKRoot(Ctx, false), OutputFile,
std::move(protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
ExplicitErrOnABIBreakage, SerializedDiagPath, BreakageAllowlistPath,
DebugMapping);
}
case ComparisonInputMode::BothLoad: {
SDKContext Ctx(CheckerOpts);
return diagnoseModuleChange(
Ctx, getSDKRoot(Ctx, true), getSDKRoot(Ctx, false), OutputFile,
std::move(protocolAllowlist), DisableFailOnError, CompilerStyleDiags,
SerializedDiagPath, BreakageAllowlistPath, DebugMapping);
ExplicitErrOnABIBreakage, SerializedDiagPath, BreakageAllowlistPath,
DebugMapping);
}
}
}
Expand Down