Skip to content

Commit

Permalink
Remove dart:isolate runtime support in DDC
Browse files Browse the repository at this point in the history
This disables most runtime features of dart:isolate, similar to dart:io.

For now, this supports `new ReceivePort()` and `ReceivePort.close` as
those are used by async tests to keep the Dart VM alive. Those are
no-ops in DDC. Also removes most of dart:_isolate_helper, except for
the JS API that's used to bootstrap DDC `main()`.

Change-Id: I84eab6cd39d05a70a6afe982e952076ddaaa8c0f
Reviewed-on: https://dart-review.googlesource.com/45754
Commit-Queue: Jenny Messerly <[email protected]>
Reviewed-by: Vijay Menon <[email protected]>
  • Loading branch information
Jenny Messerly authored and [email protected] committed Mar 28, 2018
1 parent 0482cf4 commit c9e9c1d
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 2,065 deletions.
1 change: 0 additions & 1 deletion pkg/dev_compiler/lib/src/kernel/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class DevCompilerTarget extends Target {
'dart:_interceptors',
'dart:_internal',
'dart:_isolate_helper',
'dart:_js_embedded_names',
'dart:_js_helper',
'dart:_js_mirrors',
'dart:_js_primitives',
Expand Down
16 changes: 15 additions & 1 deletion pkg/dev_compiler/test/sourcemap/ddc_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// 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.

library dev_compiler.test.sourcemap.ddc_common;

import 'dart:io';
import 'dart:mirrors' show currentMirrorSystem;

import 'package:front_end/src/api_unstable/ddc.dart' as fe;
import 'package:path/path.dart' as path;
Expand Down Expand Up @@ -127,10 +130,14 @@ String getWrapperContent(
return """
import { dart, _isolate_helper } from '${uriPathForwardSlashed(jsSdkPath)}';
import { $inputFileNameNoExt } from '$outputFilename';
let global = new Function('return this;')();
$d8Preambles
let main = $inputFileNameNoExt.main;
dart.ignoreWhitelistedErrors(false);
try {
_isolate_helper.startRootIsolate(main, []);
dartMainRunner(main, []);
} catch(e) {
console.error(e.toString(), dart.stackTrace(e).toString());
}
Expand Down Expand Up @@ -181,3 +188,10 @@ String getWrapperHtmlContent(String jsRootDart, String outFileRootBuild) {
</html>
""";
}

Uri selfUri = currentMirrorSystem()
.findLibrary(#dev_compiler.test.sourcemap.ddc_common)
.uri;
String d8Preambles = new File.fromUri(
selfUri.resolve('../../tool/input_sdk/private/preambles/d8.js'))
.readAsStringSync();
1 change: 0 additions & 1 deletion pkg/dev_compiler/tool/build_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ main(List<String> arguments) {
'dart:_interceptors',
'dart:_internal',
'dart:_isolate_helper',
'dart:_js_embedded_names',
'dart:_js_helper',
'dart:_js_mirrors',
'dart:_js_primitives',
Expand Down
3 changes: 0 additions & 3 deletions pkg/dev_compiler/tool/input_sdk/lib/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"_isolate_helper": {
"uri": "../private/isolate_helper.dart"
},
"_js_embedded_names": {
"uri": "../private/shared/embedded_names.dart"
},
"_js_helper": {
"uri": "../private/js_helper.dart"
},
Expand Down
5 changes: 0 additions & 5 deletions pkg/dev_compiler/tool/input_sdk/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ const Map<String, LibraryInfo> libraries = const {
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_js_embedded_names": const LibraryInfo(
"_internal/js_runtime/lib/shared/embedded_names.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_metadata": const LibraryInfo("html/html_common/metadata.dart",
categories: "", documented: false, platforms: DART2JS_PLATFORM),
"_debugger": const LibraryInfo("_internal/js_runtime/lib/debugger.dart",
Expand Down
3 changes: 0 additions & 3 deletions pkg/dev_compiler/tool/input_sdk/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
"_isolate_helper": {
"uri": "_internal/js_runtime/lib/isolate_helper.dart"
},
"_js_embedded_names": {
"uri": "_internal/js_runtime/lib/shared/embedded_names.dart"
},
"_js_helper": {
"uri": "_internal/js_runtime/lib/js_helper.dart"
},
Expand Down
11 changes: 2 additions & 9 deletions pkg/dev_compiler/tool/input_sdk/patch/async_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@

// Patch file for the dart:async library.

import 'dart:_js_helper'
show patch, Primitives, ReifyFunctionTypes, DartIterator;
import 'dart:_js_helper' show patch, ReifyFunctionTypes;
import 'dart:_isolate_helper'
show
IsolateNatives,
TimerImpl,
global,
leaveJsAsync,
enterJsAsync,
isWorker;
show TimerImpl, global, leaveJsAsync, enterJsAsync;

import 'dart:_foreign_helper' show JS, JSExportName;

Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Error {
}

@patch
StackTrace get stackTrace => Primitives.extractStackTrace(this);
StackTrace get stackTrace => getTraceFromException(this);
}

@patch
Expand Down
223 changes: 53 additions & 170 deletions pkg/dev_compiler/tool/input_sdk/patch/isolate_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,22 @@

// Patch file for the dart:isolate library.

import 'dart:_js_helper' show patch;
import 'dart:_isolate_helper'
show CapabilityImpl, IsolateNatives, ReceivePortImpl, RawReceivePortImpl;
import 'dart:_js_helper' show patch, NoReifyGeneric;

@patch
class Isolate {
static final _currentIsolateCache = IsolateNatives.currentIsolate;

// `current` must be a getter, not just a final field,
// to match the external declaration.
@patch
static Isolate get current => _currentIsolateCache;
static Isolate get current => _unsupported();

@patch
static Future<Uri> get packageRoot {
throw new UnsupportedError("Isolate.packageRoot");
}
static Future<Uri> get packageRoot => _unsupported();

@patch
static Future<Uri> get packageConfig {
throw new UnsupportedError("Isolate.packageConfig");
}
static Future<Uri> get packageConfig => _unsupported();

static Uri _packageBase = Uri.base.resolve(IsolateNatives.packagesBase);
static Uri _packageBase = Uri.base.resolve('packages/');

@patch
static Future<Uri> resolvePackageUri(Uri packageUri) async {
Expand All @@ -37,199 +29,90 @@ class Isolate {

@patch
static Future<Isolate> spawn<T>(void entryPoint(T message), T message,
{bool paused: false,
bool errorsAreFatal,
SendPort onExit,
SendPort onError}) {
bool forcePause =
(errorsAreFatal != null) || (onExit != null) || (onError != null);
try {
// TODO: Consider passing the errorsAreFatal/onExit/onError values
// as arguments to the internal spawnUri instead of setting
// them after the isolate has been created.
return IsolateNatives
.spawnFunction(entryPoint, message, paused || forcePause)
.then((msg) {
var isolate = new Isolate(msg[1],
pauseCapability: msg[2], terminateCapability: msg[3]);
if (forcePause) {
if (errorsAreFatal != null) {
isolate.setErrorsFatal(errorsAreFatal);
}
if (onExit != null) {
isolate.addOnExitListener(onExit);
}
if (onError != null) {
isolate.addErrorListener(onError);
}
if (!paused) {
isolate.resume(isolate.pauseCapability);
}
}
return isolate;
});
} catch (e, st) {
return new Future<Isolate>.error(e, st);
}
}
{bool paused: false,
bool errorsAreFatal,
SendPort onExit,
SendPort onError}) =>
_unsupported();

@patch
static Future<Isolate> spawnUri(Uri uri, List<String> args, var message,
{bool paused: false,
SendPort onExit,
SendPort onError,
bool errorsAreFatal,
bool checked,
Map<String, String> environment,
Uri packageRoot,
Uri packageConfig,
bool automaticPackageResolution: false}) {
if (environment != null) throw new UnimplementedError("environment");
if (packageRoot != null) throw new UnimplementedError("packageRoot");
if (packageConfig != null) throw new UnimplementedError("packageConfig");
// TODO(lrn): Figure out how to handle the automaticPackageResolution
// parameter.
bool forcePause =
(errorsAreFatal != null) || (onExit != null) || (onError != null);
try {
if (args is List<String>) {
for (int i = 0; i < args.length; i++) {
if (args[i] is! String) {
throw new ArgumentError("Args must be a list of Strings $args");
}
}
} else if (args != null) {
throw new ArgumentError("Args must be a list of Strings $args");
}
// TODO: Handle [packageRoot] somehow, possibly by throwing.
// TODO: Consider passing the errorsAreFatal/onExit/onError values
// as arguments to the internal spawnUri instead of setting
// them after the isolate has been created.
return IsolateNatives
.spawnUri(uri, args, message, paused || forcePause)
.then((msg) {
var isolate = new Isolate(msg[1],
pauseCapability: msg[2], terminateCapability: msg[3]);
if (forcePause) {
if (errorsAreFatal != null) {
isolate.setErrorsFatal(errorsAreFatal);
}
if (onExit != null) {
isolate.addOnExitListener(onExit);
}
if (onError != null) {
isolate.addErrorListener(onError);
}
if (!paused) {
isolate.resume(isolate.pauseCapability);
}
}
return isolate;
});
} catch (e, st) {
return new Future<Isolate>.error(e, st);
}
}
{bool paused: false,
SendPort onExit,
SendPort onError,
bool errorsAreFatal,
bool checked,
Map<String, String> environment,
Uri packageRoot,
Uri packageConfig,
bool automaticPackageResolution: false}) =>
_unsupported();

@patch
void _pause(Capability resumeCapability) {
var message = new List(3)
..[0] = "pause"
..[1] = pauseCapability
..[2] = resumeCapability;
controlPort.send(message);
}
void _pause(Capability resumeCapability) => _unsupported();

@patch
void resume(Capability resumeCapability) {
var message = new List(2)
..[0] = "resume"
..[1] = resumeCapability;
controlPort.send(message);
}
void resume(Capability resumeCapability) => _unsupported();

@patch
void addOnExitListener(SendPort responsePort, {Object response}) {
// TODO(lrn): Can we have an internal method that checks if the receiving
// isolate of a SendPort is still alive?
var message = new List(3)
..[0] = "add-ondone"
..[1] = responsePort
..[2] = response;
controlPort.send(message);
}
void addOnExitListener(SendPort responsePort, {Object response}) =>
_unsupported();

@patch
void removeOnExitListener(SendPort responsePort) {
var message = new List(2)
..[0] = "remove-ondone"
..[1] = responsePort;
controlPort.send(message);
}
void removeOnExitListener(SendPort responsePort) => _unsupported();

@patch
void setErrorsFatal(bool errorsAreFatal) {
var message = new List(3)
..[0] = "set-errors-fatal"
..[1] = terminateCapability
..[2] = errorsAreFatal;
controlPort.send(message);
}
void setErrorsFatal(bool errorsAreFatal) => _unsupported();

@patch
void kill({int priority: beforeNextEvent}) {
controlPort.send(["kill", terminateCapability, priority]);
}

void kill({int priority: beforeNextEvent}) => _unsupported();
@patch
void ping(SendPort responsePort, {Object response, int priority: immediate}) {
var message = new List(4)
..[0] = "ping"
..[1] = responsePort
..[2] = priority
..[3] = response;
controlPort.send(message);
}
void ping(SendPort responsePort,
{Object response, int priority: immediate}) =>
_unsupported();

@patch
void addErrorListener(SendPort port) {
var message = new List(2)
..[0] = "getErrors"
..[1] = port;
controlPort.send(message);
}
void addErrorListener(SendPort port) => _unsupported();

@patch
void removeErrorListener(SendPort port) {
var message = new List(2)
..[0] = "stopErrors"
..[1] = port;
controlPort.send(message);
}
void removeErrorListener(SendPort port) => _unsupported();
}

/** Default factory for receive ports. */
@patch
class ReceivePort {
@patch
factory ReceivePort() = ReceivePortImpl;
factory ReceivePort() = _ReceivePort;

@patch
factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) {
return new ReceivePortImpl.fromRawReceivePort(rawPort);
}
factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) =>
_unsupported();
}

/// ReceivePort is supported by dev_compiler because async test packages
/// (async_helper, unittest) create a dummy receive port to keep the Dart VM
/// alive.
class _ReceivePort extends Stream implements ReceivePort {
close() {}

get sendPort => _unsupported();

listen(onData, {onError, onDone, cancelOnError}) => _unsupported();
}

@patch
class RawReceivePort {
@patch
factory RawReceivePort([void handler(event)]) {
return new RawReceivePortImpl(handler);
}
factory RawReceivePort([void handler(event)]) => _unsupported();
}

@patch
class Capability {
@patch
factory Capability() = CapabilityImpl;
factory Capability() => _unsupported();
}

@NoReifyGeneric()
T _unsupported<T>() {
throw new UnsupportedError('dart:isolate is not supported on dart4web');
}
Loading

0 comments on commit c9e9c1d

Please sign in to comment.