Skip to content

Commit

Permalink
[web] Move libraries to a shared location
Browse files Browse the repository at this point in the history
These libraries will be shared between the dart2js and DDC runtimes.

Also renames the `shared` directory to `synced` to avoid confusion.
Synced directories are copied to be in sync with the compilers and
runtimes.

Change-Id: Ic36076938741d7102792f09413666de0033da3a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238300
Reviewed-by: Mayank Patke <fishythefish@google.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
  • Loading branch information
nshahan authored and Commit Bot committed May 18, 2022
1 parent 2b0cd3c commit 58c8427
Show file tree
Hide file tree
Showing 29 changed files with 95 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js/rewrite_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library rewrite_async;
import 'dart:collection';
import 'dart:math' show max;

import 'package:js_runtime/shared/async_await_error_codes.dart' as error_codes;
import 'package:js_runtime/synced/async_await_error_codes.dart' as error_codes;

import '../common.dart';
import '../io/source_information.dart' show SourceInformation;
Expand Down
3 changes: 2 additions & 1 deletion pkg/compiler/lib/src/js_backend/backend_usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class BackendUsageBuilderImpl implements BackendUsageBuilder {
if (_isValidEntity(element)) return true;
SourceSpan span = _frontendStrategy.spanFromSpannable(element, element);
if (library.canonicalUri.isScheme('dart') &&
span.uri.path.contains('_internal/js_runtime/lib/')) {
(span.uri.path.contains('_internal/js_runtime/lib') ||
span.uri.path.contains('_internal/js_shared/lib'))) {
// TODO(johnniwinther): We should be more precise about these.
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js_backend/namer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library js_backend.namer;
import 'package:front_end/src/api_unstable/dart2js.dart'
show $0, $9, $A, $Z, $_, $a, $g, $s, $z;

import 'package:js_runtime/shared/embedded_names.dart' show JsGetName;
import 'package:js_runtime/synced/embedded_names.dart' show JsGetName;

import '../closure.dart';
import '../common.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js_backend/runtime_types_new.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

library js_backend.runtime_types_new;

import 'package:js_runtime/shared/recipe_syntax.dart';
import 'package:js_shared/synced/recipe_syntax.dart';

import '../common/elements.dart' show CommonElements, JCommonElements;
import '../elements/entities.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

library dart2js.js_emitter.class_stub_generator;

import 'package:js_runtime/shared/embedded_names.dart'
import 'package:js_runtime/synced/embedded_names.dart'
show TearOffParametersPropertyNames;

import '../common/elements.dart' show CommonElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

library dart2js.js_emitter.interceptor_stub_generator;

import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
import 'package:js_runtime/synced/embedded_names.dart' as embeddedNames;

import '../common/elements.dart';
import '../constants/values.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
library dart2js.js_emitter.main_call_stub_generator;

import 'package:compiler/src/options.dart';
import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
import 'package:js_runtime/synced/embedded_names.dart' as embeddedNames;

import '../common/elements.dart';
import '../elements/entities.dart';
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js_emitter/native_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

library dart2js.js_emitter.native_generator;

import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
import 'package:js_runtime/synced/embedded_names.dart' as embeddedNames;

import '../js/js.dart' as jsAst;
import '../js/js.dart' show js;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ library dart2js.js_emitter.startup_emitter.model_emitter;

import 'dart:convert' show JsonEncoder;

import 'package:js_runtime/shared/embedded_names.dart'
import 'package:js_runtime/synced/embedded_names.dart'
show
ARRAY_RTI_PROPERTY,
DEFERRED_INITIALIZED,
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/kernel/element_map_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import 'package:front_end/src/api_prototype/constant_evaluator.dart' as ir;
import 'package:front_end/src/api_unstable/dart2js.dart' as ir;
import 'package:js_runtime/shared/embedded_names.dart';
import 'package:js_runtime/synced/embedded_names.dart';
import 'package:kernel/ast.dart' as ir;
import 'package:kernel/class_hierarchy.dart' as ir;
import 'package:kernel/core_types.dart' as ir;
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ssa/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// @dart = 2.10

import 'package:js_runtime/shared/embedded_names.dart';
import 'package:js_runtime/synced/embedded_names.dart';
import 'package:kernel/ast.dart' as ir;

import '../closure.dart';
Expand Down
1 change: 1 addition & 0 deletions pkg/compiler/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
front_end: any
js_ast: any
js_runtime: any
js_shared: any
kernel: any

dev_dependencies:
Expand Down
4 changes: 2 additions & 2 deletions pkg/js_runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This package contains code that is shared between the dart2js compiler and the
dart2js runtime libraries.

*Important*: all code under the `lib/shared/` must be kept in sync with the
runtime at all times (in `sdk/lib/_internal/js_runtime/lib/shared`). The
*Important*: all code under the `lib/synced/` must be kept in sync with the
runtime at all times (in `sdk/lib/_internal/js_runtime/lib/synced`). The
`test/in_sync_test.dart` test verifies this.

4 changes: 2 additions & 2 deletions pkg/js_runtime/test/in_sync_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import 'package:_fe_analyzer_shared/src/util/relativize.dart';
import 'package:expect/expect.dart';

void main(List<String> argv) {
var packageDir = Platform.script.resolve('../lib/shared/');
var packageDir = Platform.script.resolve('../lib/synced/');
var sdkDir = Platform.script
.resolve('../../../sdk/lib/_internal/js_runtime/lib/shared/');
.resolve('../../../sdk/lib/_internal/js_runtime/lib/synced/');
var rPackageDir =
relativizeUri(Directory.current.uri, packageDir, Platform.isWindows);
var rSdkDir =
Expand Down
1 change: 1 addition & 0 deletions pkg/js_shared/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file:/tools/OWNERS_WEB
13 changes: 13 additions & 0 deletions pkg/js_shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Package `js_shared`:

This code is a compile time dependency of dart2js and DDC. It is imported as
a `package:` import by both compilers.

There is an exact copy in the SDK of the libraries in the
`pkg/js_shared/lib/synced` sub-directory.
Those libraries are imported as `dart:` imports by the dart2js and DDC runtime
libraries.

*Important*: all code under `pkg/js_shared/lib/synced` must be kept in sync with
the runtime (in `sdk/lib/_internal/js_shared/lib/synced`) at all times. The
`test/in_sync_test.dart` test verifies this.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

/// Constants and predicates used for encoding and decoding type recipes.
///
/// This library is shared between the compiler and the runtime system.
library dart2js._recipe_syntax;
/// This library is synchronized between the compiler and the runtime system.
library js_shared._recipe_syntax;

abstract class Recipe {
Recipe._();
Expand Down
10 changes: 10 additions & 0 deletions pkg/js_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: js_shared
# This package is not intended for consumption on pub.dev. DO NOT publish.
publish_to: none

environment:
sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
expect: any
_fe_analyzer_shared: any
37 changes: 37 additions & 0 deletions pkg/js_shared/test/in_sync_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.

/// Test to verify that this package is in-sync with shared runtime libraries.
import 'dart:io';

import 'package:_fe_analyzer_shared/src/util/relativize.dart';
import 'package:expect/expect.dart';

void main(List<String> argv) {
var packageDir = Platform.script.resolve('../lib/synced/');
var sdkDir = Platform.script
.resolve('../../../sdk/lib/_internal/js_shared/lib/synced/');
var rPackageDir =
relativizeUri(Directory.current.uri, packageDir, Platform.isWindows);
var rSdkDir =
relativizeUri(Directory.current.uri, sdkDir, Platform.isWindows);

for (var file in Directory.fromUri(sdkDir).listSync()) {
if (file is File) {
var filename = file.uri.pathSegments.last;
var packageFile = File.fromUri(packageDir.resolve(filename));
Expect.isTrue(
packageFile.existsSync(),
"$filename not in sync. Please update it by running:\n"
" cp $rSdkDir$filename $rPackageDir$filename");
var original = file.readAsBytesSync();
var copy = packageFile.readAsBytesSync();
Expect.listEquals(
original,
copy,
"$filename not in sync. Please update it by running:\n"
" cp $rSdkDir$filename $rPackageDir$filename");
}
}
}
1 change: 1 addition & 0 deletions pkg/pkg.status
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ dev_compiler/test/options/*: SkipByDesign
front_end/test/hot_reload_e2e_test: Skip
frontend_server/test/*: SkipByDesign # Only meant to run on vm
js_runtime/test/*: SkipByDesign # Only meant to run on vm
js_shared/test/*: SkipByDesign # Only meant to run on vm
vm/test/*: SkipByDesign # Only meant to run on vm
vm_service/test/*: SkipByDesign # Uses dart:io
vm_snapshot_analysis/test/*: SkipByDesign # Only meant to run on vm
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

/// Constants and predicates used for encoding and decoding type recipes.
///
/// This library is shared between the compiler and the runtime system.
library dart2js._recipe_syntax;
/// This library is synchronized between the compiler and the runtime system.
library js_shared._recipe_syntax;

abstract class Recipe {
Recipe._();
Expand Down
8 changes: 4 additions & 4 deletions sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const Map<String, LibraryInfo> libraries = const {
categories: "", documented: false, platforms: DART2JS_PLATFORM),
"_late_helper": const LibraryInfo("_internal/js_runtime/lib/late_helper.dart",
categories: "", documented: false, platforms: DART2JS_PLATFORM),
"_rti": const LibraryInfo("_internal/js_runtime/lib/rti.dart",
"_rti": const LibraryInfo("_internal/js_shared/lib/rti.dart",
categories: "", documented: false, platforms: DART2JS_PLATFORM),
"_dart2js_runtime_metrics": const LibraryInfo(
"_internal/js_runtime/lib/dart2js_runtime_metrics.dart",
Expand All @@ -172,17 +172,17 @@ const Map<String, LibraryInfo> libraries = const {
documented: false,
platforms: DART2JS_PLATFORM),
"_js_embedded_names": const LibraryInfo(
"_internal/js_runtime/lib/shared/embedded_names.dart",
"_internal/js_runtime/lib/synced/embedded_names.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_async_await_error_codes": const LibraryInfo(
"_internal/js_runtime/lib/shared/async_await_error_codes.dart",
"_internal/js_runtime/lib/synced/async_await_error_codes.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_recipe_syntax": const LibraryInfo(
"_internal/js_runtime/lib/shared/recipe_syntax.dart",
"_internal/js_shared/lib/synced/recipe_syntax.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
Expand Down
8 changes: 4 additions & 4 deletions sdk/lib/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
"uri": "_internal/js_runtime/lib/late_helper.dart"
},
"_rti": {
"uri": "_internal/js_runtime/lib/rti.dart"
"uri": "_internal/js_shared/lib/rti.dart"
},
"_interceptors": {
"uri": "_internal/js_runtime/lib/interceptors.dart"
Expand All @@ -384,13 +384,13 @@
"uri": "_internal/js_runtime/lib/js_primitives.dart"
},
"_js_embedded_names": {
"uri": "_internal/js_runtime/lib/shared/embedded_names.dart"
"uri": "_internal/js_runtime/lib/synced/embedded_names.dart"
},
"_async_await_error_codes": {
"uri": "_internal/js_runtime/lib/shared/async_await_error_codes.dart"
"uri": "_internal/js_runtime/lib/synced/async_await_error_codes.dart"
},
"_recipe_syntax": {
"uri": "_internal/js_runtime/lib/shared/recipe_syntax.dart"
"uri": "_internal/js_shared/lib/synced/recipe_syntax.dart"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions sdk/lib/libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ _dart2js_common:
uri: "_internal/js_runtime/lib/late_helper.dart"

_rti:
uri: "_internal/js_runtime/lib/rti.dart"
uri: "_internal/js_shared/lib/rti.dart"

_interceptors:
uri: "_internal/js_runtime/lib/interceptors.dart"
Expand All @@ -352,13 +352,13 @@ _dart2js_common:
uri: "_internal/js_runtime/lib/js_primitives.dart"

_js_embedded_names:
uri: "_internal/js_runtime/lib/shared/embedded_names.dart"
uri: "_internal/js_runtime/lib/synced/embedded_names.dart"

_async_await_error_codes:
uri: "_internal/js_runtime/lib/shared/async_await_error_codes.dart"
uri: "_internal/js_runtime/lib/synced/async_await_error_codes.dart"

_recipe_syntax:
uri: "_internal/js_runtime/lib/shared/recipe_syntax.dart"
uri: "_internal/js_shared/lib/synced/recipe_syntax.dart"

dartdevc:
libraries:
Expand Down

0 comments on commit 58c8427

Please sign in to comment.