Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 9156469

Browse files
committed
Reifier hookup
Hook the coercion reifier into the JS backend. The principle observed changes in the output are from the downward type inference eliminating casts. The coercion reifier changes in this CL in two ways. The first is a relatively minor change to factor out the instrumented runtime calls. The reifier is now parameterized by a runtime object. If present, casts, wraps, and type object creation are delegated to the runtime. Otherwise the reifier just produces cast objects directly. The JS codegen always does the latter. The larger change is an attempt to make the new AST nodes be resolved. This is principally done for the typedefs produced for casts - we're not using wrapping right now so I've left that for future if we want it. This is a bit painful - if we continue down this path I think I'll want to factor this out into a ResolvedAstBuilder or somesuch, but for now this seems to be working. The rest of the changes are just plumbing in the coercion reifier and its dependencies into the js backend. BUG= [email protected] Review URL: https://codereview.chromium.org/1096583002
1 parent 88b8462 commit 9156469

28 files changed

+575
-318
lines changed

lib/runtime/dart/_internal.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ var _internal;
499499
super.IterableBase();
500500
}
501501
get [core.$iterator]() {
502-
return new (ExpandIterator$(S, T))(this[_iterable][core.$iterator], dart.as(this[_f], dart.functionType(core.Iterable$(T), [S])));
502+
return new (ExpandIterator$(S, T))(this[_iterable][core.$iterator], dart.as(this[_f], __CastType0));
503503
}
504504
}
505505
return ExpandIterable;
@@ -512,7 +512,7 @@ var _internal;
512512
ExpandIterator(iterator, f) {
513513
this[_iterator] = iterator;
514514
this[_f] = f;
515-
this[_currentExpansion] = dart.as(new EmptyIterator(), core.Iterator$(T));
515+
this[_currentExpansion] = new (EmptyIterator$(T))();
516516
this[_current] = null;
517517
}
518518
[_nextExpansion]() {}
@@ -614,7 +614,7 @@ var _internal;
614614
super.IterableBase();
615615
}
616616
get [core.$iterator]() {
617-
return new (TakeWhileIterator$(E))(this[_iterable][core.$iterator], dart.as(this[_f], dart.functionType(core.bool, [E])));
617+
return new (TakeWhileIterator$(E))(this[_iterable][core.$iterator], dart.as(this[_f], __CastType2));
618618
}
619619
}
620620
return TakeWhileIterable;
@@ -725,7 +725,7 @@ var _internal;
725725
super.IterableBase();
726726
}
727727
get [core.$iterator]() {
728-
return new (SkipWhileIterator$(E))(this[_iterable][core.$iterator], dart.as(this[_f], dart.functionType(core.bool, [E])));
728+
return new (SkipWhileIterator$(E))(this[_iterable][core.$iterator], dart.as(this[_f], __CastType4));
729729
}
730730
}
731731
return SkipWhileIterable;
@@ -763,7 +763,7 @@ var _internal;
763763
super.IterableBase();
764764
}
765765
get [core.$iterator]() {
766-
return dart.as(new EmptyIterator(), core.Iterator$(E));
766+
return new (EmptyIterator$(E))();
767767
}
768768
[core.$forEach](action) {}
769769
get [core.$isEmpty]() {
@@ -1060,7 +1060,7 @@ var _internal;
10601060
return buffer.toString();
10611061
}
10621062
where(iterable, f) {
1063-
return new (WhereIterable$(T))(dart.as(iterable, core.Iterable$(T)), dart.as(f, dart.functionType(core.bool, [T])));
1063+
return new (WhereIterable$(T))(dart.as(iterable, core.Iterable$(T)), dart.as(f, __CastType6));
10641064
}
10651065
static map(iterable, f) {
10661066
return new MappedIterable(iterable, f);
@@ -1251,6 +1251,26 @@ var _internal;
12511251
return new core.StateError("Too few elements");
12521252
}
12531253
}
1254+
let __CastType0$ = dart.generic(function(S, T) {
1255+
let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(core.Iterable$(T), [S]));
1256+
return __CastType0;
1257+
});
1258+
let __CastType0 = __CastType0$();
1259+
let __CastType2$ = dart.generic(function(E) {
1260+
let __CastType2 = dart.typedef('__CastType2', () => dart.functionType(core.bool, [E]));
1261+
return __CastType2;
1262+
});
1263+
let __CastType2 = __CastType2$();
1264+
let __CastType4$ = dart.generic(function(E) {
1265+
let __CastType4 = dart.typedef('__CastType4', () => dart.functionType(core.bool, [E]));
1266+
return __CastType4;
1267+
});
1268+
let __CastType4 = __CastType4$();
1269+
let __CastType6$ = dart.generic(function(T) {
1270+
let __CastType6 = dart.typedef('__CastType6', () => dart.functionType(core.bool, [T]));
1271+
return __CastType6;
1272+
});
1273+
let __CastType6 = __CastType6$();
12541274
let FixedLengthListMixin$ = dart.generic(function(E) {
12551275
class FixedLengthListMixin extends core.Object {
12561276
set length(newLength) {

lib/runtime/dart/_isolate_helper.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var _isolate_helper;
111111
}
112112
serializeMap(x) {
113113
let serializeTearOff = this.serialize;
114-
return new core.List.from(['map', x.keys[core.$map](dart.as(serializeTearOff, dart.functionType(dart.dynamic, [dart.dynamic])))[core.$toList](), x.values[core.$map](dart.as(serializeTearOff, dart.functionType(dart.dynamic, [dart.dynamic])))[core.$toList]()]);
114+
return new core.List.from(['map', x.keys[core.$map](dart.as(serializeTearOff, __CastType0))[core.$toList](), x.values[core.$map](dart.as(serializeTearOff, dart.functionType(dart.dynamic, [dart.dynamic])))[core.$toList]()]);
115115
}
116116
serializeJSObject(x) {
117117
if (!!x.constructor && x.constructor !== Object) {
@@ -349,6 +349,7 @@ var _isolate_helper;
349349
return initializeObject(classId, emptyInstance, fields);
350350
}
351351
}
352+
let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(dart.dynamic, [dart.dynamic]));
352353
// Function _callInIsolate: (_IsolateContext, Function) → dynamic
353354
function _callInIsolate(isolate, func) {
354355
let result = isolate.eval(func);
@@ -494,9 +495,9 @@ var _isolate_helper;
494495
this.controlPort = new RawReceivePortImpl[_controlPort]();
495496
this.pauseCapability = new isolate.Capability();
496497
this.terminateCapability = new isolate.Capability();
497-
this.delayedEvents = dart.as(new core.List.from([]), core.List$(_IsolateEvent));
498-
this.pauseTokens = dart.as(new core.Set(), core.Set$(isolate.Capability));
499-
this.errorPorts = dart.as(new core.Set(), core.Set$(isolate.SendPort));
498+
this.delayedEvents = new core.List$(_IsolateEvent).from([]);
499+
this.pauseTokens = new (core.Set$(isolate.Capability))();
500+
this.errorPorts = new (core.Set$(isolate.SendPort))();
500501
this.initialized = false;
501502
this.isPaused = false;
502503
this.doneHandlers = null;
@@ -959,9 +960,9 @@ var _isolate_helper;
959960
}
960961
static handleSpawnWorkerRequest(msg) {
961962
let replyPort = dart.dindex(msg, 'replyPort');
962-
IsolateNatives.spawn(dart.as(dart.dindex(msg, 'functionName'), core.String), dart.as(dart.dindex(msg, 'uri'), core.String), dart.as(dart.dindex(msg, 'args'), core.List$(core.String)), dart.dindex(msg, 'msg'), false, dart.as(dart.dindex(msg, 'isSpawnUri'), core.bool), dart.as(dart.dindex(msg, 'startPaused'), core.bool)).then(dart.as(msg => {
963+
IsolateNatives.spawn(dart.as(dart.dindex(msg, 'functionName'), core.String), dart.as(dart.dindex(msg, 'uri'), core.String), dart.as(dart.dindex(msg, 'args'), core.List$(core.String)), dart.dindex(msg, 'msg'), false, dart.as(dart.dindex(msg, 'isSpawnUri'), core.bool), dart.as(dart.dindex(msg, 'startPaused'), core.bool)).then(msg => {
963964
dart.dsend(replyPort, 'send', msg);
964-
}, dart.functionType(dart.dynamic, [core.List])), {
965+
}, {
965966
onError: errorMessage => {
966967
dart.dsend(replyPort, 'send', new core.List.from([_SPAWN_FAILED_SIGNAL, errorMessage]));
967968
}
@@ -1015,7 +1016,7 @@ var _isolate_helper;
10151016
uri = dart.notNull(uri) + ".js";
10161017
}
10171018
let port = new isolate.ReceivePort();
1018-
let completer = dart.as(new async.Completer(), async.Completer$(core.List));
1019+
let completer = new (async.Completer$(core.List))();
10191020
port.first.then(msg => {
10201021
if (dart.equals(dart.dindex(msg, 0), _SPAWNED_SIGNAL)) {
10211022
completer.complete(msg);

lib/runtime/dart/_js_helper.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var _js_helper;
102102
return new (_ConstantMapKeyIterable$(K))(this);
103103
}
104104
get values() {
105-
return new (_internal.MappedIterable$(K, V))(this[_keys], dart.as((key => this[_fetch](key)).bind(this), dart.functionType(V, [K])));
105+
return new (_internal.MappedIterable$(K, V))(this[_keys], (key => dart.as(this[_fetch](key), V)).bind(this));
106106
}
107107
}
108108
ConstantStringMap[dart.implements] = () => [_internal.EfficientLength];
@@ -606,7 +606,7 @@ var _js_helper;
606606
return dart.notNull(this[_match][core.$length]) - 1;
607607
}
608608
groups(groups) {
609-
let out = dart.as(new core.List.from([]), core.List$(core.String));
609+
let out = new core.List$(core.String).from([]);
610610
for (let i of groups) {
611611
out[core.$add](this.group(i));
612612
}
@@ -1740,7 +1740,7 @@ var _js_helper;
17401740
}
17411741
static parseInt(source, radix, handleError) {
17421742
if (handleError == null)
1743-
handleError = dart.as(Primitives[_throwFormatException], dart.functionType(core.int, [core.String]));
1743+
handleError = dart.as(Primitives[_throwFormatException], __CastType0);
17441744
checkString(source);
17451745
let match = /^\s*[+-]?((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$/i.exec(source);
17461746
let digitsIndex = 1;
@@ -1792,7 +1792,7 @@ var _js_helper;
17921792
static parseDouble(source, handleError) {
17931793
checkString(source);
17941794
if (handleError == null)
1795-
handleError = dart.as(Primitives[_throwFormatException], dart.functionType(core.double, [core.String]));
1795+
handleError = dart.as(Primitives[_throwFormatException], __CastType2);
17961796
if (!/^\s*[+-]?(?:Infinity|NaN|(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(source)) {
17971797
return handleError(source);
17981798
}
@@ -2279,7 +2279,7 @@ var _js_helper;
22792279
message = message.replace(new RegExp(ESCAPE_REGEXP, 'g'), '\\$&');
22802280
let match = dart.as(message.match(/\\\$[a-zA-Z]+\\\$/g), core.List$(core.String));
22812281
if (match == null)
2282-
match = dart.as(new core.List.from([]), core.List$(core.String));
2282+
match = new core.List$(core.String).from([]);
22832283
let arguments$ = match.indexOf('\\$arguments\\$');
22842284
let argumentsExpr = match.indexOf('\\$argumentsExpr\\$');
22852285
let expr = match.indexOf('\\$expr\\$');
@@ -3709,12 +3709,12 @@ var _js_helper;
37093709
let hashesMap = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.DEFERRED_LIBRARY_HASHES);
37103710
let hashes = dart.as(hashesMap[loadId], core.List$(core.String));
37113711
if (uris == null)
3712-
return dart.as(new async.Future.value(null), async.Future$(core.Null));
3713-
let indices = dart.as(new core.List.generate(uris[core.$length], dart.as(i => i, dart.functionType(dart.dynamic, [core.int]))), core.List$(core.int));
3712+
return new async.Future$(core.Null).value(null);
3713+
let indices = new core.List$(core.int).generate(uris[core.$length], i => dart.as(i, core.int));
37143714
let isHunkLoaded = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.IS_HUNK_LOADED);
37153715
let isHunkInitialized = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.IS_HUNK_INITIALIZED);
37163716
let indicesToLoad = indices[core.$where](i => !isHunkLoaded(hashes[core.$get](i)))[core.$toList]();
3717-
return dart.as(async.Future.wait(dart.as(indicesToLoad[core.$map](i => _loadHunk(uris[core.$get](i))), core.Iterable$(async.Future))).then(dart.as(_ => {
3717+
return dart.as(async.Future.wait(dart.as(indicesToLoad[core.$map](i => _loadHunk(uris[core.$get](i))), core.Iterable$(async.Future))).then(_ => {
37183718
let indicesToInitialize = indices[core.$where](i => !isHunkInitialized(hashes[core.$get](i)))[core.$toList]();
37193719
for (let i of indicesToInitialize) {
37203720
let initializer = _foreign_helper.JS_EMBEDDED_GLOBAL('', _js_embedded_names.INITIALIZE_LOADED_HUNK);
@@ -3724,13 +3724,13 @@ var _js_helper;
37243724
if (dart.notNull(updated) && dart.notNull(exports.deferredLoadHook != null)) {
37253725
exports.deferredLoadHook();
37263726
}
3727-
}, dart.functionType(dart.dynamic, [core.List]))), async.Future$(core.Null));
3727+
}), async.Future$(core.Null));
37283728
}
37293729
// Function _loadHunk: (String) → Future<Null>
37303730
function _loadHunk(hunkName) {
37313731
let future = exports._loadingLibraries.get(hunkName);
37323732
if (future != null) {
3733-
return dart.as(future.then(dart.as(_ => null, dart.functionType(dart.dynamic, [core.Null]))), async.Future$(core.Null));
3733+
return dart.as(future.then(_ => null), async.Future$(core.Null));
37343734
}
37353735
let uri = _isolate_helper.IsolateNatives.thisScript;
37363736
let index = uri.lastIndexOf('/');
@@ -3819,6 +3819,8 @@ var _js_helper;
38193819
function mainHasTooManyParameters() {
38203820
throw new MainError("'main' expects too many parameters.");
38213821
}
3822+
let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(core.int, [core.String]));
3823+
let __CastType2 = dart.typedef('__CastType2', () => dart.functionType(core.double, [core.String]));
38223824
// Exports:
38233825
exports.NoSideEffects = NoSideEffects;
38243826
exports.NoThrows = NoThrows;

0 commit comments

Comments
 (0)