Skip to content

Commit 605cc71

Browse files
committed
Make static assertions an experimental feature
1 parent dd85ab8 commit 605cc71

File tree

7 files changed

+10
-12
lines changed

7 files changed

+10
-12
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
langOpts.hasFeature(#FeatureName))
6161
#endif
6262

63-
LANGUAGE_FEATURE(StaticAssert, 0, "#assert", langOpts.EnableExperimentalStaticAssert)
6463
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
6564
LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties", true)
6665
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
@@ -93,6 +92,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)"
9392
FUTURE_FEATURE(ConciseMagicFile, 274, 6)
9493
FUTURE_FEATURE(ForwardTrailingClosures, 286, 6)
9594

95+
EXPERIMENTAL_FEATURE(StaticAssert)
9696
EXPERIMENTAL_FEATURE(VariadicGenerics)
9797

9898
#undef EXPERIMENTAL_FEATURE

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,6 @@ namespace swift {
310310
/// Specifies how strict concurrency checking will be.
311311
StrictConcurrency StrictConcurrencyLevel = StrictConcurrency::Targeted;
312312

313-
/// Enable experimental #assert feature.
314-
bool EnableExperimentalStaticAssert = false;
315-
316313
/// Enable experimental concurrency model.
317314
bool EnableExperimentalConcurrency = false;
318315

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
448448
Opts.DiagnosticsEditorMode |= Args.hasArg(OPT_diagnostics_editor_mode,
449449
OPT_serialize_diagnostics_path);
450450

451-
Opts.EnableExperimentalStaticAssert |=
452-
Args.hasArg(OPT_enable_experimental_static_assert);
453-
454451
Opts.EnableExperimentalConcurrency |=
455452
Args.hasArg(OPT_enable_experimental_concurrency);
456453

@@ -706,6 +703,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
706703
// compilers because that's how existing experimental feature flags work.
707704
if (Args.hasArg(OPT_enable_experimental_variadic_generics))
708705
Opts.Features.insert(Feature::VariadicGenerics);
706+
if (Args.hasArg(OPT_enable_experimental_static_assert))
707+
Opts.Features.insert(Feature::StaticAssert);
709708

710709
Opts.EnableAppExtensionRestrictions |= Args.hasArg(OPT_enable_app_extension);
711710

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ ParserResult<Stmt> Parser::parseStmtPoundAssert() {
27192719

27202720
// We check this after consuming everything, so that the SyntaxContext
27212721
// understands this statement even when the feature is disabled.
2722-
if (!Context.LangOpts.EnableExperimentalStaticAssert) {
2722+
if (!Context.LangOpts.hasFeature(Feature::StaticAssert)) {
27232723
diagnose(startLoc, diag::pound_assert_disabled);
27242724
return makeParserError();
27252725
}

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class EmitDFDiagnostics : public SILFunctionTransform {
271271
}
272272
}
273273

274-
if (M.getASTContext().LangOpts.EnableExperimentalStaticAssert) {
274+
if (M.getASTContext().LangOpts.hasFeature(Feature::StaticAssert)) {
275275
SymbolicValueBumpAllocator allocator;
276276
ConstExprEvaluator constantEvaluator(allocator,
277277
getOptions().AssertConfig);

test/Parse/features.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// RUN: not %target-swift-frontend -typecheck %s 2>&1 | %FileCheck --check-prefix=CHECK-WITHOUT %s
22
// RUN: %target-typecheck-verify-swift -enable-experimental-static-assert
3+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature StaticAssert
4+
// REQUIRES: asserts
35

4-
#if compiler(>=5.3) && $StaticAssert
6+
#if compiler(>=5.3) && hasFeature(StaticAssert)
57
#assert(true)
68
#else
79
// CHECK-WITHOUT: cannot find 'complete' in scope

tools/sil-opt/SILOpt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ int main(int argc, char **argv) {
574574
Invocation.getLangOptions().OptimizationRemarkMissedPattern =
575575
createOptRemarkRegex(PassRemarksMissed);
576576

577-
Invocation.getLangOptions().EnableExperimentalStaticAssert =
578-
EnableExperimentalStaticAssert;
577+
if (EnableExperimentalStaticAssert)
578+
Invocation.getLangOptions().Features.insert(Feature::StaticAssert);
579579

580580
Invocation.getLangOptions().EnableExperimentalDifferentiableProgramming =
581581
EnableExperimentalDifferentiableProgramming;

0 commit comments

Comments
 (0)