[Embedded] Enable Embedded Swift restrictions diagnostics (as warnings) in embedded builds

These restrictions will generally manifest as failures of various forms
later in the compiler process. Enable the diagnostics to give earlier
feedback to help stay within the bounds of Embedded Swift.

Fixes rdar://121205043.
This commit is contained in:
Doug Gregor
2025-09-17 12:38:23 -07:00
parent f7264e327f
commit f2ffd3771e
2 changed files with 24 additions and 1 deletions

View File

@@ -2522,6 +2522,21 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
return false;
}
/// Determine whether the given argument list enables Embedded Swift.
static bool isEmbedded(ArgList &args) {
using namespace swift::options;
for (const Arg *arg : args.filtered_reverse(
OPT_enable_experimental_feature, OPT_disable_experimental_feature)) {
if (llvm::StringRef(arg->getValue()) != "Embedded")
continue;
return arg->getOption().matches(OPT_enable_experimental_feature);
}
return false;
}
static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
DiagnosticEngine &Diags) {
// NOTE: This executes at the beginning of parsing the command line and cannot
@@ -2589,6 +2604,14 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
}
}
// If the "embedded" flag was provided, enable the EmbeddedRestrictions
// warning group. This group is opt-in in non-Embedded builds.
if (isEmbedded(Args)) {
Opts.WarningsAsErrorsRules.push_back(
WarningAsErrorRule(WarningAsErrorRule::Action::Disable,
"EmbeddedRestrictions"));
}
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
for (const Arg *arg : Args.filtered(OPT_warning_treating_Group)) {