Directly create dart2js platform files using its patch files

Change-Id: I1c7d59968bfafeeb5a8b5252fa2d47e3c05b893e
Reviewed-on: https://dart-review.googlesource.com/27404
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Emily Fortuna <efortuna@google.com>
This commit is contained in:
Sigmund Cherem 2017-12-19 20:31:57 +00:00 committed by commit-bot@chromium.org
parent 75a50a1c1c
commit 414bad86df
18 changed files with 282 additions and 81 deletions

View file

@ -645,37 +645,31 @@ class Elements {
return null;
}
/// If `true`, injected members are sorted with their corresponding class or
/// library.
/// If `true`, members are sorted using their implementation fileUri.
///
/// This is used for ensuring equivalent output order when testing against
/// .dill using the patched_dart2js_sdk.
// TODO(johnniwinther): Remove this when patching is implemented in
// package:front_end.
static bool usePatchedDart2jsSdkSorting = false;
/// .dill.
// TODO(johnniwinther): Remove this when patching correctly stores origin and
// patch file uris (issue 31579)
static bool useCFEOrder = false;
/// A `compareTo` function that places [Element]s in a consistent order based
/// on the source code order.
static int compareByPosition(Element a, Element b) {
if (identical(a, b)) return 0;
if (useCFEOrder) {
if (a is MethodElement) {
a = a.implementation;
}
if (b is MethodElement) {
b = b.implementation;
}
}
int r = utils.compareLibrariesUris(
a.library.canonicalUri, b.library.canonicalUri);
if (r != 0) return r;
Uri aUri = a.compilationUnit.script.readableUri;
Uri bUri = b.compilationUnit.script.readableUri;
if (usePatchedDart2jsSdkSorting) {
Uri computePatchedDart2jsUri(Element e, Uri uri) {
if (!e.isInjected) return uri;
if (e.enclosingClass != null) {
return e.enclosingClass.compilationUnit.script.readableUri;
} else {
return e.library.compilationUnit.script.readableUri;
}
}
aUri = computePatchedDart2jsUri(a, aUri);
bUri = computePatchedDart2jsUri(b, bUri);
}
r = utils.compareSourceUris(aUri, bUri);
if (r != 0) return r;
return utils.compareEntities(a, a.sourceOffset, -1, b, b.sourceOffset, -1);

View file

@ -217,6 +217,12 @@ abstract class ClassEnv {
}
int orderByFileOffset(ir.TreeNode a, ir.TreeNode b) {
var aLoc = a.location;
var bLoc = b.location;
var aUri = '${aLoc.file}';
var bUri = '${bLoc.file}';
var uriCompare = aUri.compareTo(bUri);
if (uriCompare != 0) return uriCompare;
return a.fileOffset.compareTo(b.fileOffset);
}

View file

@ -127,10 +127,12 @@ abstract class NativeEnqueuerBase implements NativeEnqueuer {
_elementEnvironment.getThisType(type.element);
return _dartTypes.isSubtype(nativeType, specType);
}));
} else if (type.isDynamic) {
} else if (type.isDynamic ||
type.isFunctionTypeVariable ||
type is Dart1MethodTypeVariableType) {
matchingClasses.addAll(_unusedClasses);
} else {
assert(type is VoidType);
assert(type is VoidType, '$type was ${type.runtimeType}');
}
}
if (matchingClasses.isNotEmpty && _registeredClasses.isEmpty) {

View file

@ -21,6 +21,8 @@ import 'dart:_foreign_helper' show JS;
import 'dart:_async_await_error_codes' as async_error_codes;
import "dart:collection" show IterableBase;
@patch
class _AsyncRun {
@patch

View file

@ -17,6 +17,8 @@ import 'dart:_js_helper'
LinkedHashMapKeyIterable,
LinkedHashMapKeyIterator;
import 'dart:_internal' hide Symbol;
const _USE_ES6_MAPS = const bool.fromEnvironment("dart2js.use.es6.maps");
@patch

View file

@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
// Patch file for dart:core classes.
import "dart:_internal" hide Symbol, LinkedList, LinkedListEntry;
import "dart:_internal" as _symbol_dev;
import 'dart:_interceptors';
import 'dart:_js_helper'
@ -26,7 +27,7 @@ import 'dart:_foreign_helper' show JS, JS_GET_FLAG;
import 'dart:_native_typed_data' show NativeUint8List;
import 'dart:async' show StreamController;
import "dart:convert" show Encoding, utf8;
String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);

View file

@ -6,6 +6,8 @@
import 'dart:_js_helper' show patch, ForceInline;
import 'dart:_foreign_helper' show JS;
import 'dart:async' show Zone;
import 'dart:isolate';
@patch
@ForceInline()

View file

@ -2,6 +2,8 @@
// 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.
import 'dart:core' hide Symbol;
import 'dart:core' as core;
import 'dart:_js_primitives' show printString;
import 'dart:_js_helper' show patch;
import 'dart:_interceptors' show JSArray;

View file

@ -3,6 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:_js_helper' show patch;
import 'dart:_internal' hide Symbol;
import 'dart:async';
import 'dart:convert';
import 'dart:isolate';
import 'dart:typed_data';
@patch
class _Directory {

View file

@ -4,6 +4,7 @@
// Patch file for the dart:isolate library.
import "dart:async";
import 'dart:_js_helper' show patch;
import 'dart:_isolate_helper'
show CapabilityImpl, IsolateNatives, ReceivePortImpl, RawReceivePortImpl;

View file

@ -87,6 +87,9 @@
],
"uri": "mirrors/mirrors.dart"
},
"_vmservice": {
"uri": "vmservice/vmservice.dart"
},
"io": {
"patches": [
"../../runtime/bin/common_patch.dart",
@ -130,12 +133,123 @@
"_http": {
"uri": "_http/http.dart"
},
"_vmservice": {
"uri": "vmservice/vmservice.dart"
},
"vmservice_io": {
"uri": "../../runtime/bin/vmservice/vmservice_io.dart"
}
}
},
"dart2js": {
"libraries": {
"async": {
"patches": "_internal/js_runtime/lib/async_patch.dart",
"uri": "async/async.dart"
},
"mirrors": {
"patches": "_internal/js_runtime/lib/mirrors_patch.dart",
"uri": "mirrors/mirrors.dart"
},
"_interceptors": {
"uri": "_internal/js_runtime/lib/interceptors.dart"
},
"_js_embedded_names": {
"uri": "_internal/js_runtime/lib/shared/embedded_names.dart"
},
"io": {
"patches": "_internal/js_runtime/lib/io_patch.dart",
"uri": "io/io.dart"
},
"_internal": {
"patches": "_internal/js_runtime/lib/internal_patch.dart",
"uri": "internal/internal.dart"
},
"_metadata": {
"uri": "html/html_common/metadata.dart"
},
"_async_await_error_codes": {
"uri": "_internal/js_runtime/lib/shared/async_await_error_codes.dart"
},
"_http": {
"uri": "_http/http.dart"
},
"_js_primitives": {
"uri": "_internal/js_runtime/lib/js_primitives.dart"
},
"_js_helper": {
"uri": "_internal/js_runtime/lib/js_helper.dart"
},
"_chrome": {
"uri": "_chrome/dart2js/chrome_dart2js.dart"
},
"_js_mirrors": {
"uri": "_internal/js_runtime/lib/js_mirrors.dart"
},
"js": {
"uri": "js/dart2js/js_dart2js.dart"
},
"html_common": {
"uri": "html/html_common/html_common_dart2js.dart"
},
"_native_typed_data": {
"uri": "_internal/js_runtime/lib/native_typed_data.dart"
},
"_js_names": {
"uri": "_internal/js_runtime/lib/js_names.dart"
},
"core": {
"patches": "_internal/js_runtime/lib/core_patch.dart",
"uri": "core/core.dart"
},
"collection": {
"patches": "_internal/js_runtime/lib/collection_patch.dart",
"uri": "collection/collection.dart"
},
"js_util": {
"uri": "js_util/dart2js/js_util_dart2js.dart"
},
"typed_data": {
"patches": "_internal/js_runtime/lib/typed_data_patch.dart",
"uri": "typed_data/typed_data.dart"
},
"web_audio": {
"uri": "web_audio/dart2js/web_audio_dart2js.dart"
},
"html": {
"uri": "html/dart2js/html_dart2js.dart"
},
"isolate": {
"patches": "_internal/js_runtime/lib/io_patch.dart",
"uri": "isolate/isolate.dart"
},
"developer": {
"patches": "_internal/js_runtime/lib/developer_patch.dart",
"uri": "developer/developer.dart"
},
"web_gl": {
"uri": "web_gl/dart2js/web_gl_dart2js.dart"
},
"indexed_db": {
"uri": "indexed_db/dart2js/indexed_db_dart2js.dart"
},
"convert": {
"patches": "_internal/js_runtime/lib/convert_patch.dart",
"uri": "convert/convert.dart"
},
"_isolate_helper": {
"uri": "_internal/js_runtime/lib/isolate_helper.dart"
},
"math": {
"patches": "_internal/js_runtime/lib/math_patch.dart",
"uri": "math/math.dart"
},
"_foreign_helper": {
"uri": "_internal/js_runtime/lib/foreign_helper.dart"
},
"web_sql": {
"uri": "web_sql/dart2js/web_sql_dart2js.dart"
},
"svg": {
"uri": "svg/dart2js/svg_dart2js.dart"
}
}
}
}
}

View file

@ -137,3 +137,115 @@ vm:
vmservice_io:
uri: "../../runtime/bin/vmservice/vmservice_io.dart"
dart2js:
libraries:
async:
uri: "async/async.dart"
patches: "_internal/js_runtime/lib/async_patch.dart"
_chrome:
uri: "_chrome/dart2js/chrome_dart2js.dart"
collection:
uri: "collection/collection.dart"
patches: "_internal/js_runtime/lib/collection_patch.dart"
convert:
uri: "convert/convert.dart"
patches: "_internal/js_runtime/lib/convert_patch.dart"
core:
uri: "core/core.dart"
patches: "_internal/js_runtime/lib/core_patch.dart"
developer:
uri: "developer/developer.dart"
patches: "_internal/js_runtime/lib/developer_patch.dart"
html:
uri: "html/dart2js/html_dart2js.dart"
html_common:
uri: "html/html_common/html_common_dart2js.dart"
indexed_db:
uri: "indexed_db/dart2js/indexed_db_dart2js.dart"
_http:
uri: "_http/http.dart"
io:
uri: "io/io.dart"
patches: "_internal/js_runtime/lib/io_patch.dart"
isolate:
uri: "isolate/isolate.dart"
patches: "_internal/js_runtime/lib/io_patch.dart"
js:
uri: "js/dart2js/js_dart2js.dart"
js_util:
uri: "js_util/dart2js/js_util_dart2js.dart"
math:
uri: "math/math.dart"
patches: "_internal/js_runtime/lib/math_patch.dart"
mirrors:
uri: "mirrors/mirrors.dart"
patches: "_internal/js_runtime/lib/mirrors_patch.dart"
typed_data:
uri: "typed_data/typed_data.dart"
patches: "_internal/js_runtime/lib/typed_data_patch.dart"
_native_typed_data:
uri: "_internal/js_runtime/lib/native_typed_data.dart"
svg:
uri: "svg/dart2js/svg_dart2js.dart"
web_audio:
uri: "web_audio/dart2js/web_audio_dart2js.dart"
web_gl:
uri: "web_gl/dart2js/web_gl_dart2js.dart"
web_sql:
uri: "web_sql/dart2js/web_sql_dart2js.dart"
_internal:
uri: "internal/internal.dart"
patches: "_internal/js_runtime/lib/internal_patch.dart"
_js_helper:
uri: "_internal/js_runtime/lib/js_helper.dart"
_interceptors:
uri: "_internal/js_runtime/lib/interceptors.dart"
_foreign_helper:
uri: "_internal/js_runtime/lib/foreign_helper.dart"
_isolate_helper:
uri: "_internal/js_runtime/lib/isolate_helper.dart"
_js_mirrors:
uri: "_internal/js_runtime/lib/js_mirrors.dart"
_js_names:
uri: "_internal/js_runtime/lib/js_names.dart"
_js_primitives:
uri: "_internal/js_runtime/lib/js_primitives.dart"
_js_embedded_names:
uri: "_internal/js_runtime/lib/shared/embedded_names.dart"
_async_await_error_codes:
uri: "_internal/js_runtime/lib/shared/async_await_error_codes.dart"
_metadata:
uri: "html/html_common/metadata.dart"

View file

@ -50,6 +50,10 @@ sourcemaps/source_mapping_operators_test: Pass, Slow
sourcemaps/source_mapping_test: Pass, Slow
subtype_test: Slow, Pass
uri_retention_test: Fail # Issue 26504
kernel/compile_from_dill_fast_startup_test: RuntimeError # Test must be updated to support FE with patching.
kernel/compile_from_dill_test: RuntimeError # Test must be updated to support FE with patching.
kernel/closed_world2_test: RuntimeError # Test must be updated to support FE with patching.
inference/swarm_test: RuntimeError # Test must be updated to support FE with patching.
[ $mode == debug ]
old_frontend/analyze_api_test: Pass, Slow # DON'T CHANGE THIS LINE -- Don't mark these tests as failing. Instead, fix the errors/warnings that they report or update the whitelist in the test-files to temporarily allow digression.

View file

@ -382,7 +382,7 @@ Future<ResultKind> runTest(
bool expectAstEquivalence: false,
bool expectIdenticalOutput: true}) async {
enableDebugMode();
Elements.usePatchedDart2jsSdkSorting = true;
Elements.useCFEOrder = true;
useOptimizedMixins = true;
print('---- compile from ast ----------------------------------------------');

View file

@ -69,11 +69,6 @@ Future runTest(Test test, String config,
List<LineException> testAfterExceptions = <LineException>[];
if (config == kernelMarker) {
for (LineException exception in afterExceptions) {
if (exception.fileName == 'async_patch.dart') {
testAfterExceptions
.add(new LineException(exception.methodName, 'async.dart'));
continue;
}
testAfterExceptions.add(exception);
}
} else {

View file

@ -657,7 +657,7 @@
{
"name": "build dart",
"script": "tools/build.py",
"arguments": ["dart2js_bot","patched_dart2js_sdk"]
"arguments": ["dart2js_bot", "compile_dart2js_platform"]
},
{
"name": "dart2js tests",

View file

@ -83,11 +83,10 @@ void usage(String mode) {
exit(1);
}
const validModes = const ['vm', 'dart2js', 'flutter'];
const validModes = const ['vm', 'flutter'];
String mode;
bool get forVm => mode == 'vm';
bool get forFlutter => mode == 'flutter';
bool get forDart2js => mode == 'dart2js';
Future _main(List<String> argv) async {
if (argv.isEmpty) usage('[${validModes.join('|')}]');
@ -115,8 +114,7 @@ Future _main(List<String> argv) async {
// Enumerate core libraries and apply patches
for (SdkLibrary library in sdkLibraries) {
if (forDart2js && library.isVmLibrary) continue;
if (!forDart2js && library.isDart2JsLibrary) continue;
if (library.isDart2JsLibrary) continue;
_applyPatch(library, sdkLibIn, patchIn, sdkOut, locations);
}
@ -174,9 +172,9 @@ Future _main(List<String> argv) async {
// [platformForDeps] is always the VM-specific `platform.dill` file.
var platformForDeps = platform;
var sdkDir = outDirUri;
if (forDart2js || forFlutter) {
if (forFlutter) {
// Note: this fails if `$root_out_dir/vm_platform.dill` doesn't exist. The
// target //utils/compiler:patched_dart2js_sdk depends on
// target to build the flutter patched sdk depends on
// //runtime/vm:kernel_platform_files to ensure this file exists.
platformForDeps = outDirUri.resolve('../vm_platform.dill');
sdkDir = null;
@ -313,7 +311,6 @@ String _updateLibraryMetadata(String sdkOut, String libContents) {
/// patched_sdk folder. For the VM< this includes files under 'runtime/bin/',
/// for flutter, this is includes also the ui library.
_copyExtraLibraries(String sdkOut, Map<String, Map<String, String>> locations) {
if (forDart2js) return;
var base = path.fromUri(Platform.script);
var dartDir = path.dirname(path.dirname(path.absolute(base)));
@ -576,7 +573,7 @@ class PatchApplier extends GeneralizingAstVisitor {
var name = _qualifiedName(node);
var patchNode = patch.patches[name];
if (patchNode == null) {
if (externalKeyword != null && _shouldHaveImplementation(name)) {
if (externalKeyword != null) {
print('warning: patch not found for $name: $node');
exitCode = 1;
}
@ -595,23 +592,6 @@ class PatchApplier extends GeneralizingAstVisitor {
}
}
/// Whether a member should have an implementation after patching the SDK.
///
/// True for most members except for the *.fromEnvironment constructors under
/// the dart2js target.
bool _shouldHaveImplementation(String qualifiedName) {
if (!forDart2js) return true;
// Note: dart2js implements int.fromEnvironment, bool.fromEnvironment
// and String.fromEnvironment directly and expects the SDK code to
// have an external declaration.
var isFromEnvironment = const [
'bool.fromEnvironment',
'int.fromEnvironment',
'String.fromEnvironment'
].contains(qualifiedName);
return !isFromEnvironment;
}
class PatchFinder extends GeneralizingAstVisitor {
final String contents;
final CompilationUnit unit;
@ -781,7 +761,7 @@ class _StringEdit implements Comparable<_StringEdit> {
}
List<SdkLibrary> _getSdkLibraries(String contents) {
var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(forDart2js);
var libraryBuilder = new SdkLibrariesReader_LibraryBuilder(false);
parseCompilationUnit(contents).accept(libraryBuilder);
return libraryBuilder.librariesMap.sdkLibraries;
}

View file

@ -80,26 +80,9 @@ application_snapshot("utils_wrapper") {
training_args = [ "--help" ]
}
generate_patched_sdk("patched_dart2js_sdk") {
mode = "dart2js"
deps = [
# TODO(ahe): This is needed by ../../tools/patch_sdk.dart to compute
# dependencies.
"../../runtime/vm:kernel_platform_files($dart_host_toolchain)",
]
input_patches_dir = "../../sdk/lib/_internal/js_runtime/lib"
patched_sdk_dir = "patched_dart2js_sdk"
outputs = [
# Instead of listing all outputs we list those consumed by
# other BUILD rules.
"$root_out_dir/$patched_sdk_dir/lib/libraries.json",
]
}
compile_platform("compile_dart2js_platform") {
sources = [
"$root_out_dir/patched_dart2js_sdk/lib/libraries.json",
"../../sdk/lib/libraries.json",
]
outputs = [
@ -107,10 +90,6 @@ compile_platform("compile_dart2js_platform") {
"$root_out_dir/dart2js_outline.dill",
]
deps = [
":patched_dart2js_sdk",
]
args = [
"--target=dart2js",
"dart:core",