[dart2js, ddc] Clean up conditional imports in dart2js_runtime_metrics

This CL:
* adds empty dart:_dart2js_only and dart:_ddc_only libraries for use in
  conditional imports,
* updates pkg/dart2js_runtime_metrics to use the new libraries rather
  than dart:_dart2js_runtime_metrics and dart:js,
* and removes some unnecessary libraries, including VM-specific
  implementations in pkg/dart2js_runtime_metrics and the DDC
  implementation of dart:_dart2js_runtime_metrics.

Change-Id: I9500aa303fa5ad8aba0e1d413f69957c268f3f11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350681
Reviewed-by: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Mayank Patke
2024-02-09 18:38:55 +00:00
committed by Commit Queue
parent 08f0ffeb60
commit 85037bf96d
17 changed files with 64 additions and 57 deletions
@@ -260,6 +260,7 @@ const implicitlyUsedLibraries = <String>[
const requiredLibraries = <String, List<String>>{
'dart2js': [
'dart:_async_status_codes',
'dart:_dart2js_only',
'dart:_dart2js_runtime_metrics',
'dart:_foreign_helper',
'dart:_http',
@@ -301,6 +302,7 @@ const requiredLibraries = <String, List<String>>{
],
'dart2js_server': [
'dart:_async_status_codes',
'dart:_dart2js_only',
'dart:_dart2js_runtime_metrics',
'dart:_foreign_helper',
'dart:_http',
@@ -360,6 +362,8 @@ class Dart2jsConstantsBackend extends ConstantsBackend {
}
class Dart2jsDartLibrarySupport extends CustomizedDartLibrarySupport {
const Dart2jsDartLibrarySupport()
: super(supported: const {'_dart2js_runtime_metrics'});
// This is required so that `dart.library._dart2js_only` can be used as an
// import condition. Libraries with leading underscores are otherwise
// considered unsupported regardless of the library specification.
const Dart2jsDartLibrarySupport() : super(supported: const {'_dart2js_only'});
}
@@ -1,12 +0,0 @@
// Copyright (c) 2022, 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.
/// A collection of metrics collected during the runtime of a Dart app.
///
/// The contents of the map depend on the platform. The map values are simple
/// objects (strings, numbers, Booleans). There is always an entry for the key
/// `'runtime'` with a [String] value.
Map<String, Object> get runtimeMetrics {
return {'runtime': 'vm'};
}
@@ -1,12 +0,0 @@
// Copyright (c) 2021, 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.
/// A collection of metrics for events that happen before `main()` is entered.
///
/// The contents of the map depend on the platform. The map values are simple
/// objects (strings, numbers, Booleans). There is always an entry for the key
/// `'runtime'` with a [String] value.
Map<String, Object> get startupMetrics {
return {'runtime': 'vm'};
}
@@ -3,5 +3,5 @@
// BSD-style license that can be found in the LICENSE file.
export '_null_safety_other.dart'
if (dart.library._dart2js_runtime_metrics) '_null_safety_dart2js.dart'
if (dart.library.js) '_null_safety_dartdevc.dart';
if (dart.library._dart2js_only) '_null_safety_dart2js.dart'
if (dart.library._ddc_only) '_null_safety_dartdevc.dart';
@@ -3,6 +3,5 @@
// BSD-style license that can be found in the LICENSE file.
export '_runtime_metrics_unknown.dart'
if (dart.library._dart2js_runtime_metrics) '_runtime_metrics_dart2js.dart'
if (dart.library.ffi) '_runtime_metrics_vm.dart'
if (dart.library.js) '_runtime_metrics_dartdevc.dart';
if (dart.library._dart2js_only) '_runtime_metrics_dart2js.dart'
if (dart.library._ddc_only) '_runtime_metrics_dartdevc.dart';
@@ -3,6 +3,5 @@
// BSD-style license that can be found in the LICENSE file.
export '_startup_metrics_unknown.dart'
if (dart.library._dart2js_runtime_metrics) '_startup_metrics_dart2js.dart'
if (dart.library.ffi) '_startup_metrics_vm.dart'
if (dart.library.js) '_startup_metrics_dartdevc.dart';
if (dart.library._dart2js_only) '_startup_metrics_dart2js.dart'
if (dart.library._ddc_only) '_startup_metrics_dartdevc.dart';
@@ -12,7 +12,7 @@ void main() {
String expectedRuntime;
if (1.0 is! int) {
expectedRuntime = 'vm';
expectedRuntime = 'unknown';
} else if (ClassWithLongName().toString().contains('minified:')) {
// dart2js minified: "Instance of 'minified:xy'".
expectedRuntime = 'dart2js';
@@ -42,7 +42,7 @@ void main() {
return;
}
if (expectedRuntime == 'vm') {
if (expectedRuntime == 'unknown') {
return;
}
@@ -12,7 +12,7 @@ void main() {
String expectedRuntime;
if (1.0 is! int) {
expectedRuntime = 'vm';
expectedRuntime = 'unknown';
} else if (ClassWithLongName().toString().contains('minified:')) {
// dart2js minified: "Instance of 'minified:xy'".
expectedRuntime = 'dart2js';
@@ -40,7 +40,7 @@ void main() {
return;
}
if (expectedRuntime == 'vm') {
if (expectedRuntime == 'unknown') {
Expect.equals(1, metrics.length);
return;
}
+12 -1
View File
@@ -56,11 +56,11 @@ class DevCompilerTarget extends Target {
@override
List<String> get extraRequiredLibraries => const [
'dart:_ddc_only',
'dart:_runtime',
'dart:_js_shared_embedded_names',
'dart:_recipe_syntax',
'dart:_rti',
'dart:_dart2js_runtime_metrics',
'dart:_debugger',
'dart:_foreign_helper',
'dart:_interceptors',
@@ -302,6 +302,17 @@ class DevCompilerTarget extends Target {
@override
ConstantsBackend get constantsBackend => const DevCompilerConstantsBackend();
@override
DartLibrarySupport get dartLibrarySupport =>
const DevCompilerDartLibrarySupport();
}
class DevCompilerDartLibrarySupport extends CustomizedDartLibrarySupport {
// This is required so that `dart.library._ddc_only` can be used as an import
// condition. Libraries with leading underscores are otherwise considered
// unsupported regardless of the library specification.
const DevCompilerDartLibrarySupport() : super(supported: const {'_ddc_only'});
}
/// Analyzes a component to determine if any covariance checks in private
@@ -52,9 +52,10 @@ class ScopeOffsetValidator extends VisitorDefault<void> with VisitorVoidMixin {
static void validate(Library library) {
var validator = ScopeOffsetValidator._();
validator.visitLibrary(library);
final importUri = library.importUri.toString();
// TODO(joshualitt): Currently, there's nothing in `dart:_js_types` that
// would be indexed. Remove this exception when we add things to it.
if (library.importUri.toString() != 'dart:_js_types') {
if (importUri != 'dart:_js_types' && importUri != 'dart:_ddc_only') {
expect(validator.classCount + validator.memberCount, greaterThan(0),
reason: 'Validation was not empty');
}
+3 -3
View File
@@ -166,9 +166,9 @@ abstract class DartLibrarySupport {
/// libraries specification.
///
/// This is used to allow AOT to consider `dart:mirrors` as unsupported
/// despite it being supported in the platform dill, and dart2js to consider
/// `dart:_dart2js_runtime_metrics` to be supported despite it being an
/// internal library.
/// despite it being supported in the platform dill, and for dart2js and DDC
/// to consider `dart:_dart2js_only` and `dart:_ddc_only`, respectively, to be
/// supported despite them being internal libraries.
bool computeDartLibrarySupport(String libraryName,
{required bool isSupportedBySpec});
@@ -0,0 +1,7 @@
// Copyright (c) 2024, 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.
/// This library is only intended to be used to identify DDC in conditional
/// imports and should not have any contents.
library;
@@ -1,10 +0,0 @@
// Copyright (c) 2022, 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.
// This file is a stub to allow dart:_dart2js_runtime_metrics to be discovered
// across web contexts.
get runtimeMetrics => throw UnimplementedError();
get startupMetrics => throw UnimplementedError();
@@ -0,0 +1,7 @@
// Copyright (c) 2024, 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.
/// This library is only intended to be used to identify dart2js in conditional
/// imports and should not have any contents.
library;
@@ -224,6 +224,13 @@ const Map<String, LibraryInfo> libraries = const {
documented: false,
platforms: DART2JS_PLATFORM,
),
'_dart2js_only': const LibraryInfo(
'_internal/js_runtime/lib/dart2js_only.dart',
categories: '',
implementation: true,
documented: false,
platforms: DART2JS_PLATFORM,
),
'_dart2js_runtime_metrics': const LibraryInfo(
'_internal/js_runtime/lib/dart2js_runtime_metrics.dart',
categories: '',
+5 -2
View File
@@ -486,6 +486,9 @@
"uri": "internal/internal.dart",
"patches": "_internal/js_runtime/lib/internal_patch.dart"
},
"_dart2js_only": {
"uri": "_internal/js_runtime/lib/dart2js_only.dart"
},
"_dart2js_runtime_metrics": {
"uri": "_internal/js_runtime/lib/dart2js_runtime_metrics.dart"
},
@@ -580,8 +583,8 @@
"_native_typed_data": {
"uri": "_internal/js_dev_runtime/private/native_typed_data.dart"
},
"_dart2js_runtime_metrics": {
"uri": "_internal/js_dev_runtime/private/runtime_metrics.dart"
"_ddc_only": {
"uri": "_internal/js_dev_runtime/private/ddc_only.dart"
},
"_rti": {
"uri": "_internal/js_shared/lib/rti.dart"
+5 -2
View File
@@ -397,6 +397,9 @@ _dart2js_common:
uri: "internal/internal.dart"
patches: "_internal/js_runtime/lib/internal_patch.dart"
_dart2js_only:
uri: "_internal/js_runtime/lib/dart2js_only.dart"
_dart2js_runtime_metrics:
uri: "_internal/js_runtime/lib/dart2js_runtime_metrics.dart"
@@ -486,8 +489,8 @@ dartdevc:
_native_typed_data:
uri: "_internal/js_dev_runtime/private/native_typed_data.dart"
_dart2js_runtime_metrics:
uri: "_internal/js_dev_runtime/private/runtime_metrics.dart"
_ddc_only:
uri: "_internal/js_dev_runtime/private/ddc_only.dart"
_rti:
uri: "_internal/js_shared/lib/rti.dart"