Skip to content

Commit

Permalink
Add experiment flag for enum shorthands.
Browse files Browse the repository at this point in the history
This CL adds an experiment flag named `enum-shorthands`. We can start prototyping the work needed for the feature under the flag.

Bug: #57037
Change-Id: I5d5e679b20f993e0af59ce5b2d28e47269ecaedb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393521
Reviewed-by: Johnni Winther <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
  • Loading branch information
kallentu authored and Commit Queue committed Nov 7, 2024
1 parent 073a700 commit 8b3c5aa
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 28 deletions.
8 changes: 8 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ enum ExperimentalFlag {
experimentReleasedVersion: const Version(3, 6),
),

enumShorthands(
name: 'enum-shorthands',
isEnabledByDefault: false,
isExpired: false,
experimentEnabledVersion: defaultLanguageVersion,
experimentReleasedVersion: defaultLanguageVersion,
),

extensionMethods(
name: 'extension-methods',
isEnabledByDefault: true,
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/dart/analysis/features.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ abstract class Feature {
/// Feature information for enhanced parts.
static final enhanced_parts = ExperimentalFeatures.enhanced_parts;

/// Feature information for enum shorthands.
static final enum_shorthands = ExperimentalFeatures.enum_shorthands;

/// Feature information for extension methods.
static final extension_methods = ExperimentalFeatures.extension_methods;

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 416;
static const int DATA_VERSION = 417;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
77 changes: 50 additions & 27 deletions pkg/analyzer/lib/src/dart/analysis/experiments.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final _knownFeatures = <String, ExperimentalFeature>{
EnableString.digit_separators: ExperimentalFeatures.digit_separators,
EnableString.enhanced_enums: ExperimentalFeatures.enhanced_enums,
EnableString.enhanced_parts: ExperimentalFeatures.enhanced_parts,
EnableString.enum_shorthands: ExperimentalFeatures.enum_shorthands,
EnableString.extension_methods: ExperimentalFeatures.extension_methods,
EnableString.generic_metadata: ExperimentalFeatures.generic_metadata,
EnableString.inference_update_1: ExperimentalFeatures.inference_update_1,
Expand Down Expand Up @@ -88,6 +89,9 @@ class EnableString {
/// String to enable the experiment "enhanced-parts"
static const String enhanced_parts = 'enhanced-parts';

/// String to enable the experiment "enum-shorthands"
static const String enum_shorthands = 'enum-shorthands';

/// String to enable the experiment "extension-methods"
static const String extension_methods = 'extension-methods';

Expand Down Expand Up @@ -263,8 +267,18 @@ class ExperimentalFeatures {
releaseVersion: null,
);

static final extension_methods = ExperimentalFeature(
static final enum_shorthands = ExperimentalFeature(
index: 9,
enableString: EnableString.enum_shorthands,
isEnabledByDefault: IsEnabledByDefault.enum_shorthands,
isExpired: IsExpired.enum_shorthands,
documentation: 'Shorter dot syntax for enum values.',
experimentalReleaseVersion: null,
releaseVersion: null,
);

static final extension_methods = ExperimentalFeature(
index: 10,
enableString: EnableString.extension_methods,
isEnabledByDefault: IsEnabledByDefault.extension_methods,
isExpired: IsExpired.extension_methods,
Expand All @@ -274,7 +288,7 @@ class ExperimentalFeatures {
);

static final generic_metadata = ExperimentalFeature(
index: 10,
index: 11,
enableString: EnableString.generic_metadata,
isEnabledByDefault: IsEnabledByDefault.generic_metadata,
isExpired: IsExpired.generic_metadata,
Expand All @@ -285,7 +299,7 @@ class ExperimentalFeatures {
);

static final inference_update_1 = ExperimentalFeature(
index: 11,
index: 12,
enableString: EnableString.inference_update_1,
isEnabledByDefault: IsEnabledByDefault.inference_update_1,
isExpired: IsExpired.inference_update_1,
Expand All @@ -296,7 +310,7 @@ class ExperimentalFeatures {
);

static final inference_update_2 = ExperimentalFeature(
index: 12,
index: 13,
enableString: EnableString.inference_update_2,
isEnabledByDefault: IsEnabledByDefault.inference_update_2,
isExpired: IsExpired.inference_update_2,
Expand All @@ -306,7 +320,7 @@ class ExperimentalFeatures {
);

static final inference_update_3 = ExperimentalFeature(
index: 13,
index: 14,
enableString: EnableString.inference_update_3,
isEnabledByDefault: IsEnabledByDefault.inference_update_3,
isExpired: IsExpired.inference_update_3,
Expand All @@ -317,7 +331,7 @@ class ExperimentalFeatures {
);

static final inference_update_4 = ExperimentalFeature(
index: 14,
index: 15,
enableString: EnableString.inference_update_4,
isEnabledByDefault: IsEnabledByDefault.inference_update_4,
isExpired: IsExpired.inference_update_4,
Expand All @@ -327,7 +341,7 @@ class ExperimentalFeatures {
);

static final inference_using_bounds = ExperimentalFeature(
index: 15,
index: 16,
enableString: EnableString.inference_using_bounds,
isEnabledByDefault: IsEnabledByDefault.inference_using_bounds,
isExpired: IsExpired.inference_using_bounds,
Expand All @@ -338,7 +352,7 @@ class ExperimentalFeatures {
);

static final inline_class = ExperimentalFeature(
index: 16,
index: 17,
enableString: EnableString.inline_class,
isEnabledByDefault: IsEnabledByDefault.inline_class,
isExpired: IsExpired.inline_class,
Expand All @@ -348,7 +362,7 @@ class ExperimentalFeatures {
);

static final macros = ExperimentalFeature(
index: 17,
index: 18,
enableString: EnableString.macros,
isEnabledByDefault: IsEnabledByDefault.macros,
isExpired: IsExpired.macros,
Expand All @@ -358,7 +372,7 @@ class ExperimentalFeatures {
);

static final named_arguments_anywhere = ExperimentalFeature(
index: 18,
index: 19,
enableString: EnableString.named_arguments_anywhere,
isEnabledByDefault: IsEnabledByDefault.named_arguments_anywhere,
isExpired: IsExpired.named_arguments_anywhere,
Expand All @@ -368,7 +382,7 @@ class ExperimentalFeatures {
);

static final native_assets = ExperimentalFeature(
index: 19,
index: 20,
enableString: EnableString.native_assets,
isEnabledByDefault: IsEnabledByDefault.native_assets,
isExpired: IsExpired.native_assets,
Expand All @@ -378,7 +392,7 @@ class ExperimentalFeatures {
);

static final non_nullable = ExperimentalFeature(
index: 20,
index: 21,
enableString: EnableString.non_nullable,
isEnabledByDefault: IsEnabledByDefault.non_nullable,
isExpired: IsExpired.non_nullable,
Expand All @@ -388,7 +402,7 @@ class ExperimentalFeatures {
);

static final nonfunction_type_aliases = ExperimentalFeature(
index: 21,
index: 22,
enableString: EnableString.nonfunction_type_aliases,
isEnabledByDefault: IsEnabledByDefault.nonfunction_type_aliases,
isExpired: IsExpired.nonfunction_type_aliases,
Expand All @@ -398,7 +412,7 @@ class ExperimentalFeatures {
);

static final null_aware_elements = ExperimentalFeature(
index: 22,
index: 23,
enableString: EnableString.null_aware_elements,
isEnabledByDefault: IsEnabledByDefault.null_aware_elements,
isExpired: IsExpired.null_aware_elements,
Expand All @@ -408,7 +422,7 @@ class ExperimentalFeatures {
);

static final patterns = ExperimentalFeature(
index: 23,
index: 24,
enableString: EnableString.patterns,
isEnabledByDefault: IsEnabledByDefault.patterns,
isExpired: IsExpired.patterns,
Expand All @@ -418,7 +432,7 @@ class ExperimentalFeatures {
);

static final record_use = ExperimentalFeature(
index: 24,
index: 25,
enableString: EnableString.record_use,
isEnabledByDefault: IsEnabledByDefault.record_use,
isExpired: IsExpired.record_use,
Expand All @@ -428,7 +442,7 @@ class ExperimentalFeatures {
);

static final records = ExperimentalFeature(
index: 25,
index: 26,
enableString: EnableString.records,
isEnabledByDefault: IsEnabledByDefault.records,
isExpired: IsExpired.records,
Expand All @@ -438,7 +452,7 @@ class ExperimentalFeatures {
);

static final sealed_class = ExperimentalFeature(
index: 26,
index: 27,
enableString: EnableString.sealed_class,
isEnabledByDefault: IsEnabledByDefault.sealed_class,
isExpired: IsExpired.sealed_class,
Expand All @@ -448,7 +462,7 @@ class ExperimentalFeatures {
);

static final set_literals = ExperimentalFeature(
index: 27,
index: 28,
enableString: EnableString.set_literals,
isEnabledByDefault: IsEnabledByDefault.set_literals,
isExpired: IsExpired.set_literals,
Expand All @@ -458,7 +472,7 @@ class ExperimentalFeatures {
);

static final spread_collections = ExperimentalFeature(
index: 28,
index: 29,
enableString: EnableString.spread_collections,
isEnabledByDefault: IsEnabledByDefault.spread_collections,
isExpired: IsExpired.spread_collections,
Expand All @@ -468,7 +482,7 @@ class ExperimentalFeatures {
);

static final super_parameters = ExperimentalFeature(
index: 29,
index: 30,
enableString: EnableString.super_parameters,
isEnabledByDefault: IsEnabledByDefault.super_parameters,
isExpired: IsExpired.super_parameters,
Expand All @@ -478,7 +492,7 @@ class ExperimentalFeatures {
);

static final test_experiment = ExperimentalFeature(
index: 30,
index: 31,
enableString: EnableString.test_experiment,
isEnabledByDefault: IsEnabledByDefault.test_experiment,
isExpired: IsExpired.test_experiment,
Expand All @@ -489,7 +503,7 @@ class ExperimentalFeatures {
);

static final triple_shift = ExperimentalFeature(
index: 31,
index: 32,
enableString: EnableString.triple_shift,
isEnabledByDefault: IsEnabledByDefault.triple_shift,
isExpired: IsExpired.triple_shift,
Expand All @@ -499,7 +513,7 @@ class ExperimentalFeatures {
);

static final unnamed_libraries = ExperimentalFeature(
index: 32,
index: 33,
enableString: EnableString.unnamed_libraries,
isEnabledByDefault: IsEnabledByDefault.unnamed_libraries,
isExpired: IsExpired.unnamed_libraries,
Expand All @@ -509,7 +523,7 @@ class ExperimentalFeatures {
);

static final unquoted_imports = ExperimentalFeature(
index: 33,
index: 34,
enableString: EnableString.unquoted_imports,
isEnabledByDefault: IsEnabledByDefault.unquoted_imports,
isExpired: IsExpired.unquoted_imports,
Expand All @@ -519,7 +533,7 @@ class ExperimentalFeatures {
);

static final variance = ExperimentalFeature(
index: 34,
index: 35,
enableString: EnableString.variance,
isEnabledByDefault: IsEnabledByDefault.variance,
isExpired: IsExpired.variance,
Expand All @@ -529,7 +543,7 @@ class ExperimentalFeatures {
);

static final wildcard_variables = ExperimentalFeature(
index: 35,
index: 36,
enableString: EnableString.wildcard_variables,
isEnabledByDefault: IsEnabledByDefault.wildcard_variables,
isExpired: IsExpired.wildcard_variables,
Expand Down Expand Up @@ -570,6 +584,9 @@ class IsEnabledByDefault {
/// Default state of the experiment "enhanced-parts"
static const bool enhanced_parts = false;

/// Default state of the experiment "enum-shorthands"
static const bool enum_shorthands = false;

/// Default state of the experiment "extension-methods"
static const bool extension_methods = true;

Expand Down Expand Up @@ -683,6 +700,9 @@ class IsExpired {
/// Expiration status of the experiment "enhanced-parts"
static const bool enhanced_parts = false;

/// Expiration status of the experiment "enum-shorthands"
static const bool enum_shorthands = false;

/// Expiration status of the experiment "extension-methods"
static const bool extension_methods = true;

Expand Down Expand Up @@ -796,6 +816,9 @@ mixin _CurrentState {
/// Current state for the flag "enhanced-parts"
bool get enhanced_parts => isEnabled(ExperimentalFeatures.enhanced_parts);

/// Current state for the flag "enum-shorthands"
bool get enum_shorthands => isEnabled(ExperimentalFeatures.enum_shorthands);

/// Current state for the flag "extension-methods"
bool get extension_methods =>
isEnabled(ExperimentalFeatures.extension_methods);
Expand Down
Loading

0 comments on commit 8b3c5aa

Please sign in to comment.