[Fuchsia] Enable sound null safety everywhere (flutter/engine#51355)

This change enables null_safety on fuchsia everywhere and remove the legacy conditions.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
zijiehe@
2024-03-13 10:56:05 -07:00
committed by GitHub
parent 0c6a230ad2
commit 224b7f08ff
17 changed files with 39 additions and 120 deletions

View File

@@ -310,8 +310,6 @@ bool DartComponentController::SetUpFromKernel() {
manifest.size());
Dart_Handle library = Dart_Null();
bool first_library = true;
bool result_sound_null_safety = false;
for (size_t start = 0; start < manifest.size();) {
size_t end = str.find("\n", start);
if (end == std::string::npos) {
@@ -330,31 +328,11 @@ bool DartComponentController::SetUpFromKernel() {
Dart_ExitScope();
return false;
}
bool sound_null_safety = Dart_DetectNullSafety(
/*script_uri=*/nullptr, /*package_config=*/nullptr,
/*original_working_directory=*/nullptr,
isolate_snapshot_data_.address(),
/*isolate_snapshot_instructions=*/nullptr, kernel.address(),
kernel.size());
if (first_library) {
result_sound_null_safety = sound_null_safety;
first_library = false;
} else if (sound_null_safety != result_sound_null_safety) {
FML_LOG(ERROR) << "Inconsistent sound null safety";
return false;
}
kernel_peices_.emplace_back(std::move(kernel));
}
Dart_IsolateFlags isolate_flags;
Dart_IsolateFlagsInitialize(&isolate_flags);
isolate_flags.null_safety = result_sound_null_safety;
if (!CreateIsolate(isolate_snapshot_data_.address(),
/*isolate_snapshot_instructions=*/nullptr,
&isolate_flags)) {
/*isolate_snapshot_instructions=*/nullptr)) {
return false;
}
@@ -404,15 +382,13 @@ bool DartComponentController::SetUpFromAppSnapshot() {
isolate_data = isolate_snapshot_data_.address();
isolate_instructions = nullptr;
}
return CreateIsolate(isolate_data, isolate_instructions,
/*isolate_flags=*/nullptr);
return CreateIsolate(isolate_data, isolate_instructions);
#endif // defined(AOT_RUNTIME)
}
bool DartComponentController::CreateIsolate(
const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instructions,
Dart_IsolateFlags* isolate_flags) {
const uint8_t* isolate_snapshot_instructions) {
// Create the isolate from the snapshot.
char* error = nullptr;
@@ -423,9 +399,13 @@ bool DartComponentController::CreateIsolate(
auto state = new std::shared_ptr<tonic::DartState>(new tonic::DartState(
namespace_fd, [this](Dart_Handle result) { MessageEpilogue(result); }));
Dart_IsolateFlags isolate_flags;
Dart_IsolateFlagsInitialize(&isolate_flags);
isolate_flags.null_safety = true;
isolate_ = Dart_CreateIsolateGroup(
url_.c_str(), label_.c_str(), isolate_snapshot_data,
isolate_snapshot_instructions, isolate_flags, state, state, &error);
isolate_snapshot_instructions, &isolate_flags, state, state, &error);
if (!isolate_) {
FML_LOG(ERROR) << "Dart_CreateIsolateGroup failed: " << error;
return false;

View File

@@ -61,8 +61,7 @@ class DartComponentController
bool SetUpFromAppSnapshot();
bool CreateIsolate(const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instructions,
Dart_IsolateFlags* isolate_flags);
const uint8_t* isolate_snapshot_instructions);
// |Echo|
void EchoString(fidl::StringPtr value, EchoStringCallback callback) override;

View File

@@ -242,8 +242,6 @@ bool DartTestComponentController::SetUpFromKernel() {
manifest.size());
Dart_Handle library = Dart_Null();
bool first_library = true;
bool result_sound_null_safety = false;
for (size_t start = 0; start < manifest.size();) {
size_t end = str.find("\n", start);
if (end == std::string::npos) {
@@ -260,31 +258,11 @@ bool DartTestComponentController::SetUpFromKernel() {
FML_LOG(ERROR) << "Cannot load kernel from namespace: " << path;
return false;
}
bool sound_null_safety = Dart_DetectNullSafety(
/*script_uri=*/nullptr, /*package_config=*/nullptr,
/*original_working_directory=*/nullptr,
isolate_snapshot_data_.address(),
/*isolate_snapshot_instructions=*/nullptr, kernel.address(),
kernel.size());
if (first_library) {
result_sound_null_safety = sound_null_safety;
first_library = false;
} else if (sound_null_safety != result_sound_null_safety) {
FML_LOG(ERROR) << "Inconsistent sound null safety";
return false;
}
kernel_peices_.emplace_back(std::move(kernel));
}
Dart_IsolateFlags isolate_flags;
Dart_IsolateFlagsInitialize(&isolate_flags);
isolate_flags.null_safety = result_sound_null_safety;
if (!CreateIsolate(isolate_snapshot_data_.address(),
/*isolate_snapshot_instructions=*/nullptr,
&isolate_flags)) {
/*isolate_snapshot_instructions=*/nullptr)) {
return false;
}
@@ -333,15 +311,13 @@ bool DartTestComponentController::SetUpFromAppSnapshot() {
isolate_data = isolate_snapshot_data_.address();
isolate_instructions = nullptr;
}
return CreateIsolate(isolate_data, isolate_instructions,
/*isolate_flags=*/nullptr);
return CreateIsolate(isolate_data, isolate_instructions);
#endif // defined(AOT_RUNTIME)
}
bool DartTestComponentController::CreateIsolate(
const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instructions,
Dart_IsolateFlags* isolate_flags) {
const uint8_t* isolate_snapshot_instructions) {
// Create the isolate from the snapshot.
char* error = nullptr;
@@ -352,9 +328,13 @@ bool DartTestComponentController::CreateIsolate(
auto state = new std::shared_ptr<tonic::DartState>(new tonic::DartState(
namespace_fd, [this](Dart_Handle result) { MessageEpilogue(result); }));
Dart_IsolateFlags isolate_flags;
Dart_IsolateFlagsInitialize(&isolate_flags);
isolate_flags.null_safety = true;
isolate_ = Dart_CreateIsolateGroup(
url_.c_str(), label_.c_str(), isolate_snapshot_data,
isolate_snapshot_instructions, isolate_flags, state, state, &error);
isolate_snapshot_instructions, &isolate_flags, state, state, &error);
if (!isolate_) {
FML_LOG(ERROR) << "Dart_CreateIsolateGroup failed: " << error;
return false;

View File

@@ -77,8 +77,7 @@ class DartTestComponentController
bool SetUpFromAppSnapshot();
bool CreateIsolate(const uint8_t* isolate_snapshot_data,
const uint8_t* isolate_snapshot_instructions,
Dart_IsolateFlags* isolate_flags);
const uint8_t* isolate_snapshot_instructions);
// |ComponentController|
void Kill() override;

View File

@@ -122,19 +122,9 @@ Dart_Isolate CreateServiceIsolate(
}
#endif
bool is_null_safe =
Dart_DetectNullSafety(nullptr, // script_uri
nullptr, // package_config
nullptr, // original_working_directory
vmservice_data, // snapshot_data
vmservice_instructions, // snapshot_instructions
nullptr, // kernel_buffer
0u // kernel_buffer_size
);
Dart_IsolateFlags flags;
Dart_IsolateFlagsInitialize(&flags);
flags.null_safety = is_null_safe;
flags.null_safety = true;
auto state = new std::shared_ptr<tonic::DartState>(new tonic::DartState());
Dart_Isolate isolate = Dart_CreateIsolateGroup(

View File

@@ -11,7 +11,6 @@ import("//flutter/tools/fuchsia/gn-sdk/src/package.gni")
dart_library("lib") {
testonly = true
package_name = "dart_echo_server"
null_safe = true
source_dir = "."
sources = [ "main.dart" ]
@@ -20,7 +19,6 @@ dart_library("lib") {
# Dart component that serves the test Echo FIDL protocol, built using the Dart AOT runner
dart_component("aot_component") {
testonly = true
null_safe = true
main_package = "dart_echo_server"
manifest = "meta/dart-aot-echo-server.cml"
@@ -32,7 +30,6 @@ dart_component("aot_component") {
# Dart component that serves the test Echo FIDL protocol, built using the Dart AOT runner
dart_component("jit_component") {
testonly = true
null_safe = true
main_package = "dart_echo_server"
manifest = "meta/dart-jit-echo-server.cml"

View File

@@ -50,7 +50,7 @@ class TestApp {
this.focusable = true}) {}
void run() {
childView.create(focusable, (ByteData reply) {
childView.create(focusable, (ByteData? reply) {
// Set up window allbacks.
window.onPointerDataPacket = (PointerDataPacket packet) {
for (final data in packet.data) {
@@ -181,8 +181,8 @@ Future<int> _launchChildView() async {
final message = Int8List.fromList([0x31]);
final completer = new Completer<ByteData>();
PlatformDispatcher.instance.sendPlatformMessage(
'fuchsia/child_view', ByteData.sublistView(message), (ByteData reply) {
completer.complete(reply);
'fuchsia/child_view', ByteData.sublistView(message), (ByteData? reply) {
completer.complete(reply!);
});
return int.parse(

View File

@@ -100,13 +100,13 @@ class MyApp {
}
void _reportMouseInput(
{double localX,
double localY,
int timeReceived,
int buttons,
String phase,
double wheelXPhysicalPixel,
double wheelYPhysicalPixel}) {
{required double localX,
required double localY,
required int timeReceived,
required int buttons,
required String phase,
required double wheelXPhysicalPixel,
required double wheelYPhysicalPixel}) {
print('mouse-input-view reporting mouse input to MouseInputListener');
final message = ByteData.sublistView(utf8.encode(json.encode({
'method': 'MouseInputListener.ReportMouseInput',
@@ -115,7 +115,7 @@ class MyApp {
'time_received': timeReceived,
'component_name': 'touch-input-view',
'buttons': buttons,
'phase': 'asdf',
'phase': phase,
'wheel_x_physical_pixel': wheelXPhysicalPixel,
'wheel_y_physical_pixel': wheelYPhysicalPixel,
})));

View File

@@ -13,7 +13,6 @@ dart_library("lib") {
package_name = "text-input-view"
sources = [ "text_input_view.dart" ]
deps = [ "//flutter/shell/platform/fuchsia/dart:args" ]
null_safe = true
}
flutter_component("component") {
@@ -22,7 +21,6 @@ flutter_component("component") {
manifest = rebase_path("meta/text-input-view.cml")
main_package = "text-input-view"
main_dart = "text_input_view.dart"
sound_null_safety = true
deps = [ ":lib" ]
}

View File

@@ -53,7 +53,7 @@ class TestApp {
}
void run() {
childView.create(focusable, (ByteData reply) {
childView.create(focusable, (ByteData? reply) {
// Set up window callbacks.
window.onPointerDataPacket = (PointerDataPacket packet) {
this.pointerDataPacket(packet);
@@ -161,7 +161,7 @@ class TestApp {
window.scheduleFrame();
}
void _reportTouchInput({double localX, double localY, int timeReceived}) {
void _reportTouchInput({required double localX, required double localY, required int timeReceived}) {
print('embedding-flutter-view reporting touch input to TouchInputListener');
final message = utf8.encode(json.encode({
'method': 'TouchInputListener.ReportTouchInput',
@@ -219,8 +219,8 @@ Future<int> _launchChildView() async {
final message = Int8List.fromList([0x31]);
final completer = new Completer<ByteData>();
PlatformDispatcher.instance.sendPlatformMessage(
'fuchsia/child_view', ByteData.sublistView(message), (ByteData reply) {
completer.complete(reply);
'fuchsia/child_view', ByteData.sublistView(message), (ByteData? reply) {
completer.complete(reply!);
});
return int.parse(

View File

@@ -80,7 +80,7 @@ class TestApp {
window.scheduleFrame();
}
void _reportTouchInput({double localX, double localY, int timeReceived}) {
void _reportTouchInput({required double localX, required double localY, required int timeReceived}) {
print('touch-input-view reporting touch input to TouchInputListener');
final message = utf8.encode(json.encode({
'method': 'TouchInputListener.ReportTouchInput',

View File

@@ -81,9 +81,6 @@ import("//flutter/tools/fuchsia/flutter/internal/flutter_dart_component.gni")
# Specifies the parameters for building the component.
# See //build/dart/dart_build_config.gni for predefined configs.
#
# null_safe (optional)
# If true, this component will be compiled with --sound-null-safety
#
# deps
# testonly
# visibility
@@ -123,7 +120,6 @@ template("dart_component") {
"build_cfg",
"deps",
"main_dart",
"null_safe",
])
main_package = _main_package
deps = _component_deps

View File

@@ -76,9 +76,6 @@ import("//flutter/tools/fuchsia/dart/toolchain.gni")
# disable_metadata_entry (optional)
# Prevents metedata entry from being written to the dart_packag_config json file.
#
# null_safe (optional)
# A flag that enables null safety check in dart libraries.
#
# Example of usage:
#
# dart_library("baz") {
@@ -183,10 +180,10 @@ if (current_toolchain == dart_toolchain) {
name = package_name
if (defined(invoker.language_version)) {
language_version = invoker.language_version
} else if (defined(invoker.null_safe) && invoker.null_safe) {
language_version = "2.12"
} else if (defined(invoker.pubspec)) {
pubspec_path = rebase_path(invoker.pubspec, root_build_dir)
} else {
language_version = "2.12"
}
root_uri = rebase_path(package_root, root_build_dir)
if (defined(invoker.source_dir)) {

View File

@@ -135,9 +135,6 @@ template("_convert_kernel_manifest") {
# Whether the kernel compiler should link the current platform.dill into
# the build. If false, the --no-link-platform flag will be passed to the
# compiler. Defaults to false.
#
# sound_null_safety (optional)
# Whether to generate sound null safe kernel.
template("dart_kernel") {
assert(defined(invoker.platform_name), "dart_kernel() requires platform_name")
assert(defined(invoker.packages_path),
@@ -278,12 +275,9 @@ template("dart_kernel") {
rebase_path(depfile, root_build_dir),
"--output",
rebase_path(_kernel_path, root_build_dir),
"--sound-null-safety",
]
if (!defined(invoker.sound_null_safety) || !invoker.sound_null_safety) {
args += [ "--no-sound-null-safety" ]
}
# TODO(richkadel): It should be possible to remove all of the build rules
# related to `generate_manifest`. Without the following two flags, the
# `gen_kernel` step will produce one large `.dil` file, instead of multiple

View File

@@ -84,9 +84,6 @@ import("//flutter/tools/fuchsia/flutter/internal/flutter_dart_component.gni")
# Specifies the parameters for building the component.
# See //flutter/tools/fuchsia/flutter/flutter_build_config.gni for predefined configs.
#
# sound_null_safety (optional)
# Whether to generate sound null safe Dart kernel.
#
# deps
# testonly
# visibility

View File

@@ -48,9 +48,6 @@ import("//flutter/tools/fuchsia/gn-sdk/src/component.gni")
# Type: boolean
# Default: false
#
# sound_null_safety (optional)
# If true, generate sound null safe Dart kernel.
#
# deps
# testonly
# visibility
@@ -147,7 +144,6 @@ template("flutter_dart_component") {
"visibility",
"main_dart",
"main_package",
"sound_null_safety",
])
deps = [ ":$_dart_package_config_target_name" ]

View File

@@ -17,11 +17,7 @@ template("_fuchsia_dart_library") {
_sources = []
_deps = []
if (defined(meta.dart_library_null_safe) && meta.dart_library_null_safe) {
_dart_language_version = "2.12"
} else {
_dart_language_version = "2.0"
}
_dart_language_version = "2.12"
foreach(source, meta.sources) {
_sources += [ string_replace("$source", "${meta.root}/lib/", "") ]