Skip to content

Commit 29fdb62

Browse files
authored
Merge pull request #70672 from bnbarham/error-not-exit
[Frontend] Diagnose rather than exit/assert on experimental features
2 parents 91c62de + a6c8bf3 commit 29fdb62

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ ERROR(objc_with_embedded,none,
563563
"Objective-C interoperability cannot be enabled with embedded Swift.", ())
564564
ERROR(no_allocations_without_embedded,none,
565565
"-no-allocations is only applicable with embedded Swift.", ())
566+
ERROR(no_swift_sources_with_embedded,none,
567+
"embedded swift cannot be enabled in a compiler built without Swift sources", ())
568+
569+
ERROR(experimental_not_supported_in_production,none,
570+
"experimental feature '%0' cannot be enabled in production compiler",
571+
(StringRef))
566572

567573
#define UNDEFINE_DIAGNOSTIC_MACROS
568574
#include "DefineDiagnosticMacros.h"

lib/Frontend/CompilerInvocation.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,13 +845,15 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
845845
if (auto feature = getExperimentalFeature(value)) {
846846
#ifdef NDEBUG
847847
if (!isFeatureAvailableInProduction(*feature)) {
848-
llvm::errs() << "error: experimental feature '" << A->getValue()
849-
<< "' cannot be enabled in a production compiler\n";
850-
exit(1);
848+
Diags.diagnose(SourceLoc(), diag::experimental_not_supported_in_production,
849+
A->getValue());
850+
HadError = true;
851+
} else {
852+
Opts.Features.insert(*feature);
851853
}
852-
#endif
853-
854+
#else
854855
Opts.Features.insert(*feature);
856+
#endif
855857
}
856858

857859
// Hack: In order to support using availability macros in SPM packages, we
@@ -1368,12 +1370,15 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
13681370
Opts.BypassResilienceChecks |= Args.hasArg(OPT_bypass_resilience);
13691371

13701372
if (Opts.hasFeature(Feature::Embedded)) {
1371-
assert(swiftModulesInitialized() && "no SwiftCompilerSources");
1372-
13731373
Opts.UnavailableDeclOptimizationMode = UnavailableDeclOptimization::Complete;
13741374
Opts.DisableImplicitStringProcessingModuleImport = true;
13751375
Opts.DisableImplicitConcurrencyModuleImport = true;
13761376

1377+
if (!swiftModulesInitialized()) {
1378+
Diags.diagnose(SourceLoc(), diag::no_swift_sources_with_embedded);
1379+
HadError = true;
1380+
}
1381+
13771382
if (FrontendOpts.EnableLibraryEvolution) {
13781383
Diags.diagnose(SourceLoc(), diag::evolution_with_embedded);
13791384
HadError = true;

0 commit comments

Comments
 (0)