Skip to content

Commit f2ffd37

Browse files
committed
[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.
1 parent f7264e3 commit f2ffd37

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,21 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
25222522
return false;
25232523
}
25242524

2525+
/// Determine whether the given argument list enables Embedded Swift.
2526+
static bool isEmbedded(ArgList &args) {
2527+
using namespace swift::options;
2528+
2529+
for (const Arg *arg : args.filtered_reverse(
2530+
OPT_enable_experimental_feature, OPT_disable_experimental_feature)) {
2531+
if (llvm::StringRef(arg->getValue()) != "Embedded")
2532+
continue;
2533+
2534+
return arg->getOption().matches(OPT_enable_experimental_feature);
2535+
}
2536+
2537+
return false;
2538+
}
2539+
25252540
static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
25262541
DiagnosticEngine &Diags) {
25272542
// NOTE: This executes at the beginning of parsing the command line and cannot
@@ -2589,6 +2604,14 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
25892604
}
25902605
}
25912606

2607+
// If the "embedded" flag was provided, enable the EmbeddedRestrictions
2608+
// warning group. This group is opt-in in non-Embedded builds.
2609+
if (isEmbedded(Args)) {
2610+
Opts.WarningsAsErrorsRules.push_back(
2611+
WarningAsErrorRule(WarningAsErrorRule::Action::Disable,
2612+
"EmbeddedRestrictions"));
2613+
}
2614+
25922615
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
25932616
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
25942617
for (const Arg *arg : Args.filtered(OPT_warning_treating_Group)) {

test/embedded/restrictions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-typecheck-verify-swift -Wwarning EmbeddedRestrictions -verify-additional-prefix nonembedded-
2-
// RUN: %target-typecheck-verify-swift -Wwarning EmbeddedRestrictions -enable-experimental-feature Embedded -verify-additional-prefix embedded-
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Embedded -verify-additional-prefix embedded-
33

44
// REQUIRES: swift_in_compiler
55
// REQUIRES: swift_feature_Embedded

0 commit comments

Comments
 (0)