mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 12:57:42 +00:00
[vm] Get experimental flag default values from YAML
Bug: https://github.com/dart-lang/sdk/issues/44053 Change-Id: Ia7ee5fe212cf0f5c619026d967e5747d71bf31ec Fixes: https://github.com/dart-lang/sdk/issues/44053 TEST=No behavior change, so just running existing tests. Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171663 Commit-Queue: Liam Appelbe <liama@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
parent
4a7aad370f
commit
fadf8fd85d
|
@ -806,7 +806,7 @@ bool Dart::DetectNullSafety(const char* script_uri,
|
|||
}
|
||||
|
||||
// If we are loading from source, figure out the mode from the source.
|
||||
if (!KernelIsolate::GetExperimentalFlag("no-non-nullable")) {
|
||||
if (KernelIsolate::GetExperimentalFlag(ExperimentalFeature::non_nullable)) {
|
||||
return KernelIsolate::DetectNullSafety(script_uri, package_config,
|
||||
original_working_directory);
|
||||
}
|
||||
|
|
45
runtime/vm/experimental_features.cc
Normal file
45
runtime/vm/experimental_features.cc
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Instead modify 'tools/experimental_features.yaml' and run
|
||||
// 'dart tools/generate_experimental_flags.dart' to update.
|
||||
//
|
||||
// Current version: 2.12.0
|
||||
|
||||
#include "vm/experimental_features.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "platform/assert.h"
|
||||
#include "vm/globals.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
bool GetExperimentalFeatureDefault(ExperimentalFeature feature) {
|
||||
constexpr bool kFeatureValues[] = {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
};
|
||||
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureValues));
|
||||
return kFeatureValues[static_cast<int>(feature)];
|
||||
}
|
||||
|
||||
const char* GetExperimentalFeatureName(ExperimentalFeature feature) {
|
||||
constexpr const char* kFeatureNames[] = {
|
||||
"non-nullable",
|
||||
"extension-methods",
|
||||
"constant-update-2018",
|
||||
"control-flow-collections",
|
||||
"set-literals",
|
||||
"spread-collections",
|
||||
};
|
||||
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureNames));
|
||||
return kFeatureNames[static_cast<int>(feature)];
|
||||
}
|
||||
|
||||
} // namespace dart
|
30
runtime/vm/experimental_features.h
Normal file
30
runtime/vm/experimental_features.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Instead modify 'tools/experimental_features.yaml' and run
|
||||
// 'dart tools/generate_experimental_flags.dart' to update.
|
||||
//
|
||||
// Current version: 2.12.0
|
||||
|
||||
#ifndef RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
|
||||
#define RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
|
||||
|
||||
namespace dart {
|
||||
|
||||
enum class ExperimentalFeature {
|
||||
non_nullable,
|
||||
extension_methods,
|
||||
constant_update_2018,
|
||||
control_flow_collections,
|
||||
set_literals,
|
||||
spread_collections,
|
||||
};
|
||||
|
||||
bool GetExperimentalFeatureDefault(ExperimentalFeature feature);
|
||||
const char* GetExperimentalFeatureName(ExperimentalFeature feature);
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
|
|
@ -417,13 +417,16 @@ void KernelIsolate::AddExperimentalFlag(const char* value) {
|
|||
free(temp);
|
||||
}
|
||||
|
||||
bool KernelIsolate::GetExperimentalFlag(const char* value) {
|
||||
bool KernelIsolate::GetExperimentalFlag(ExperimentalFeature feature) {
|
||||
const char* value = GetExperimentalFeatureName(feature);
|
||||
for (const char* str : *experimental_flags_) {
|
||||
if (strcmp(str, value) == 0) {
|
||||
return true;
|
||||
} else if (strstr(str, "no-") == str && strcmp(str + 3, value) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return GetExperimentalFeatureDefault(feature);
|
||||
}
|
||||
|
||||
DEFINE_OPTION_HANDLER(KernelIsolate::AddExperimentalFlag,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "vm/allocation.h"
|
||||
#include "vm/dart.h"
|
||||
#include "vm/experimental_features.h"
|
||||
#include "vm/os_thread.h"
|
||||
|
||||
namespace dart {
|
||||
|
@ -78,7 +79,7 @@ class KernelIsolate : public AllStatic {
|
|||
static void NotifyAboutIsolateShutdown(const Isolate* isolate);
|
||||
|
||||
static void AddExperimentalFlag(const char* value);
|
||||
static bool GetExperimentalFlag(const char* value);
|
||||
static bool GetExperimentalFlag(ExperimentalFeature feature);
|
||||
|
||||
protected:
|
||||
static void InitCallback(Isolate* I);
|
||||
|
|
|
@ -220,7 +220,7 @@ const char* TestCase::GetTestLib(const char* url) {
|
|||
}
|
||||
|
||||
bool TestCase::IsNNBD() {
|
||||
return !KernelIsolate::GetExperimentalFlag("no-non-nullable");
|
||||
return KernelIsolate::GetExperimentalFlag(ExperimentalFeature::non_nullable);
|
||||
}
|
||||
|
||||
#ifndef PRODUCT
|
||||
|
|
|
@ -98,6 +98,8 @@ vm_sources = [
|
|||
"elf.h",
|
||||
"exceptions.cc",
|
||||
"exceptions.h",
|
||||
"experimental_features.cc",
|
||||
"experimental_features.h",
|
||||
"ffi_callback_trampolines.cc",
|
||||
"ffi_callback_trampolines.h",
|
||||
"field_table.cc",
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#
|
||||
# ### Code Generation
|
||||
#
|
||||
# When you change this file, run the following to update analyzer and kernel:
|
||||
# When you change this file, run the following to update analyzer, kernel, and
|
||||
# vm:
|
||||
#
|
||||
# analyzer:
|
||||
# dart pkg/analyzer/tool/experiments/generate.dart
|
||||
|
@ -18,6 +19,9 @@
|
|||
# kernel:
|
||||
# pkg/front_end/tool/fasta generate-experimental-flags
|
||||
#
|
||||
# vm:
|
||||
# dart tools/generate_experimental_flags.dart
|
||||
#
|
||||
# ### Overview
|
||||
#
|
||||
# This document consists mostly of a map called "features".
|
||||
|
|
125
tools/generate_experimental_flags.dart
Normal file
125
tools/generate_experimental_flags.dart
Normal file
|
@ -0,0 +1,125 @@
|
|||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:io' show File, Platform;
|
||||
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
|
||||
|
||||
void main() {
|
||||
YamlMap yaml =
|
||||
loadYaml(new File.fromUri(computeYamlFile()).readAsStringSync());
|
||||
final currentVersion = getAsVersionNumber(yaml['current-version']);
|
||||
final enumNames = new StringBuffer();
|
||||
final featureValues = new StringBuffer();
|
||||
final featureNames = new StringBuffer();
|
||||
|
||||
YamlMap features = yaml['features'];
|
||||
for (var entry in features.entries) {
|
||||
final category = (entry.value as YamlMap)['category'];
|
||||
if (category == null || category == "vm" || category == "language") {
|
||||
final version = getAsVersionNumber((entry.value as YamlMap)['enabledIn']);
|
||||
if (version != null) {
|
||||
final value = isGreaterOrEqualVersion(currentVersion, version);
|
||||
final name = entry.key.replaceAll('-', '_');
|
||||
enumNames.write(' $name,\n');
|
||||
featureValues.write(' $value,\n');
|
||||
featureNames.write(' "${entry.key}",\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final h = '''
|
||||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Instead modify 'tools/experimental_features.yaml' and run
|
||||
// 'dart tools/generate_experimental_flags.dart' to update.
|
||||
//
|
||||
// Current version: ${currentVersion.join('.')}
|
||||
|
||||
#ifndef RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
|
||||
#define RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
|
||||
|
||||
namespace dart {
|
||||
|
||||
enum class ExperimentalFeature {
|
||||
$enumNames};
|
||||
|
||||
bool GetExperimentalFeatureDefault(ExperimentalFeature feature);
|
||||
const char* GetExperimentalFeatureName(ExperimentalFeature feature);
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // RUNTIME_VM_EXPERIMENTAL_FEATURES_H_
|
||||
''';
|
||||
|
||||
final cc = '''
|
||||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// NOTE: THIS FILE IS GENERATED. DO NOT EDIT.
|
||||
//
|
||||
// Instead modify 'tools/experimental_features.yaml' and run
|
||||
// 'dart tools/generate_experimental_flags.dart' to update.
|
||||
//
|
||||
// Current version: ${currentVersion.join('.')}
|
||||
|
||||
#include "vm/experimental_features.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "platform/assert.h"
|
||||
#include "vm/globals.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
bool GetExperimentalFeatureDefault(ExperimentalFeature feature) {
|
||||
constexpr bool kFeatureValues[] = {
|
||||
$featureValues };
|
||||
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureValues));
|
||||
return kFeatureValues[static_cast<int>(feature)];
|
||||
}
|
||||
|
||||
const char* GetExperimentalFeatureName(ExperimentalFeature feature) {
|
||||
constexpr const char* kFeatureNames[] = {
|
||||
$featureNames };
|
||||
ASSERT(static_cast<size_t>(feature) < ARRAY_SIZE(kFeatureNames));
|
||||
return kFeatureNames[static_cast<int>(feature)];
|
||||
}
|
||||
|
||||
} // namespace dart
|
||||
''';
|
||||
|
||||
File.fromUri(computeHFile()).writeAsStringSync(h);
|
||||
File.fromUri(computeCcFile()).writeAsStringSync(cc);
|
||||
}
|
||||
|
||||
Uri computeYamlFile() {
|
||||
return Platform.script.resolve("experimental_features.yaml");
|
||||
}
|
||||
|
||||
Uri computeCcFile() {
|
||||
return Platform.script.resolve("../runtime/vm/experimental_features.cc");
|
||||
}
|
||||
|
||||
Uri computeHFile() {
|
||||
return Platform.script.resolve("../runtime/vm/experimental_features.h");
|
||||
}
|
||||
|
||||
List<num> getAsVersionNumber(dynamic value) {
|
||||
if (value == null) return null;
|
||||
final version = List.of("$value".split(".").map(int.parse));
|
||||
while (version.length < 3) version.add(0);
|
||||
return version;
|
||||
}
|
||||
|
||||
bool isGreaterOrEqualVersion(List<num> left, List<num> right) {
|
||||
assert(left.length == right.length);
|
||||
for (var i = 0; i < left.length; ++i) {
|
||||
if (left[i] != right[i]) return left[i] > right[i];
|
||||
}
|
||||
return true;
|
||||
}
|
Loading…
Reference in a new issue