Skip to content

Frontend: Allow -enable-experimental-feature to specify upcoming features #75962

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
Aug 22, 2024
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
42 changes: 25 additions & 17 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,21 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableExperimentalStringProcessing = true;
}

auto enableUpcomingFeature = [&Opts, &Diags](Feature feature) -> bool {
// Check if this feature was introduced already in this language version.
if (auto firstVersion = getFeatureLanguageVersion(feature)) {
if (Opts.isSwiftVersionAtLeast(*firstVersion)) {
Diags.diagnose(SourceLoc(), diag::error_upcoming_feature_on_by_default,
getFeatureName(feature), *firstVersion);
return true;
}
}

Opts.enableFeature(feature);
return false;
};

// Enable experimental features.
for (const Arg *A : Args.filtered(OPT_enable_experimental_feature)) {
// Allow StrictConcurrency to have a value that corresponds to the
// -strict-concurrency=<blah> settings.
Expand All @@ -1040,12 +1055,14 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
} else {
Opts.enableFeature(*feature);
}
}

if (*feature == Feature::NoncopyableGenerics2)
Opts.enableFeature(Feature::NoncopyableGenerics);

if (*feature == Feature::IsolatedAny2)
Opts.enableFeature(Feature::IsolatedAny);
// For compatibility, upcoming features can be enabled with the
// -enable-experimental-feature flag too since the feature may have
// graduated from being experimental.
if (auto feature = getUpcomingFeature(value)) {
if (enableUpcomingFeature(*feature))
HadError = true;
}

// Hack: In order to support using availability macros in SPM packages, we
Expand All @@ -1062,24 +1079,15 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}

// Map historical flags over to future features.
// Enable upcoming features.
for (const Arg *A : Args.filtered(OPT_enable_upcoming_feature)) {
// Ignore unknown features.
auto feature = getUpcomingFeature(A->getValue());
if (!feature)
continue;

// Check if this feature was introduced already in this language version.
if (auto firstVersion = getFeatureLanguageVersion(*feature)) {
if (Opts.isSwiftVersionAtLeast(*firstVersion)) {
Diags.diagnose(SourceLoc(), diag::error_upcoming_feature_on_by_default,
A->getValue(), *firstVersion);
continue;
}
}

// Add the feature.
Opts.enableFeature(*feature);
if (enableUpcomingFeature(*feature))
HadError = true;
}

// Map historical flags over to experimental features. We do this for all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %target-swift-frontend -emit-module -swift-version 5 -emit-module-path %t/SerializedDefaultArguments.swiftmodule -module-name SerializedDefaultArguments -enable-upcoming-feature IsolatedDefaultValues %S/Inputs/serialized_default_arguments.swift

// RUN: %target-swift-frontend %s -emit-sil -o /dev/null -verify -disable-availability-checking -swift-version 6 -I %t
// RUN: %target-swift-frontend %s -emit-sil -o /dev/null -verify -disable-availability-checking -swift-version 6 -I %t -enable-upcoming-feature RegionBasedIsolation -enable-upcoming-feature IsolatedDefaultValues
// RUN: %target-swift-frontend %s -emit-sil -o /dev/null -verify -disable-availability-checking -swift-version 5 -I %t -enable-upcoming-feature RegionBasedIsolation -enable-upcoming-feature IsolatedDefaultValues -enable-upcoming-feature StrictConcurrency

// REQUIRES: concurrency

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift

// RUN: %target-swift-frontend -swift-version 6 -I %t %s -emit-sil -o /dev/null -verify -parse-as-library
// RUN: %target-swift-frontend -swift-version 6 -I %t %s -emit-sil -o /dev/null -verify -enable-upcoming-feature RegionBasedIsolation -parse-as-library

@preconcurrency import NonStrictModule
@preconcurrency import StrictModule
Expand Down
1 change: 0 additions & 1 deletion test/Concurrency/property_initializers_swift6.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %target-swift-frontend -swift-version 6 -disable-availability-checking -strict-concurrency=complete -emit-sil -o /dev/null -verify %s
// RUN: %target-swift-frontend -swift-version 6 -disable-availability-checking -strict-concurrency=complete -emit-sil -o /dev/null -verify %s -enable-upcoming-feature RegionBasedIsolation

// REQUIRES: concurrency

Expand Down
4 changes: 4 additions & 0 deletions test/Frontend/upcoming_feature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
// RUN: %target-swift-frontend -typecheck -enable-upcoming-feature ConciseMagicFile -enable-upcoming-feature UnknownFeature %s
// RUN: %target-swift-frontend -typecheck -enable-upcoming-feature UnknownFeature -enable-upcoming-feature ConciseMagicFile %s

// For compatibility when a feature graduates, it's fine to refer to an
// upcoming feature as an experimental feature.
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature ConciseMagicFile %s

// It's not fine to provide a feature that's in the specified language version.
// RUN: not %target-swift-frontend -typecheck -enable-upcoming-feature ConciseMagicFile -swift-version 6 %s 2>&1 | %FileCheck %s
// RUN: not %target-swift-frontend -typecheck -enable-experimental-feature ConciseMagicFile -swift-version 6 %s 2>&1 | %FileCheck %s

// CHECK: error: upcoming feature 'ConciseMagicFile' is already enabled as of Swift version 6

Expand Down
1 change: 0 additions & 1 deletion test/Sema/access-level-import-flag-check.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// RUN: %target-swift-frontend -typecheck %t/ClientWithoutTheFlag.swift -I %t \
// RUN: -enable-upcoming-feature InternalImportsByDefault \
// RUN: -package-name package -verify
// REQUIRES: asserts

/// swiftinterfaces don't need the flag.
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.swiftinterface) -I %t
Expand Down
1 change: 1 addition & 0 deletions test/type/explicit_existential.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %target-typecheck-verify-swift -verify-additional-prefix default-swift-mode-
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift-6-
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature ExistentialAny -verify-additional-prefix explicit-any- -verify-additional-prefix default-swift-mode-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ExistentialAny -verify-additional-prefix explicit-any- -verify-additional-prefix default-swift-mode-


protocol HasSelfRequirements {
Expand Down