Skip to content

Commit

Permalink
Smarter js temp naming, fixes #136
Browse files Browse the repository at this point in the history
JSTemporary is now identified by instance, not its String name. This provides enough information to do renaming correctly and avoid the bug in #136.

The namer now considers all scopes where the temporary is visible, and chooses a name that doesn't conflict with other identifiers. Because it only considers scopes where the temp appears, it does less renaming that the previous version.
  • Loading branch information
John Messerly committed Apr 15, 2015
1 parent da91435 commit 33322cb
Show file tree
Hide file tree
Showing 17 changed files with 628 additions and 507 deletions.
4 changes: 2 additions & 2 deletions pkg/dev_compiler/lib/runtime/dart/_interceptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ var _interceptors;
JSString[dart.implements] = () => [core.String, JSIndexable];
let _string = Symbol('_string');
class _CodeUnits extends _internal.UnmodifiableListBase$(core.int) {
_CodeUnits(string$) {
this[_string] = string$;
_CodeUnits(string) {
this[_string] = string;
super.UnmodifiableListBase();
}
get [core.$length]() {
Expand Down
96 changes: 48 additions & 48 deletions pkg/dev_compiler/lib/runtime/dart/_internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ var _internal;
let _startIndex = dart.JsSymbol('_startIndex');
let SubListIterable$ = dart.generic(function(E) {
class SubListIterable extends ListIterable$(E) {
SubListIterable(iterable$, start$, endOrLength) {
this[_iterable] = iterable$;
this[_start] = start$;
SubListIterable(iterable, start, endOrLength) {
this[_iterable] = iterable;
this[_start] = start;
this[_endOrLength] = endOrLength;
super.ListIterable();
core.RangeError.checkNotNegative(this[_start], "start");
Expand Down Expand Up @@ -361,9 +361,9 @@ var _internal;
}
return new MappedIterable$(S, T)[_](dart.as(iterable, core.Iterable$(S)), func);
}
[_](iterable$, f$) {
this[_iterable] = iterable$;
this[_f] = f$;
[_](iterable, f) {
this[_iterable] = iterable;
this[_f] = f;
super.IterableBase();
}
get [core.$iterator]() {
Expand Down Expand Up @@ -405,9 +405,9 @@ var _internal;
let _iterator = dart.JsSymbol('_iterator');
let MappedIterator$ = dart.generic(function(S, T) {
class MappedIterator extends core.Iterator$(T) {
MappedIterator(iterator$, f$) {
this[_iterator] = iterator$;
this[_f] = f$;
MappedIterator(iterator, f) {
this[_iterator] = iterator;
this[_f] = f;
this[_current] = null;
super.Iterator();
}
Expand All @@ -429,9 +429,9 @@ var _internal;
let _source = dart.JsSymbol('_source');
let MappedListIterable$ = dart.generic(function(S, T) {
class MappedListIterable extends ListIterable$(T) {
MappedListIterable(source, f$) {
MappedListIterable(source, f) {
this[_source] = source;
this[_f] = f$;
this[_f] = f;
super.ListIterable();
}
get [core.$length]() {
Expand All @@ -452,9 +452,9 @@ var _internal;
let _ElementPredicate = _ElementPredicate$();
let WhereIterable$ = dart.generic(function(E) {
class WhereIterable extends collection.IterableBase$(E) {
WhereIterable(iterable$, f$) {
this[_iterable] = iterable$;
this[_f] = f$;
WhereIterable(iterable, f) {
this[_iterable] = iterable;
this[_f] = f;
super.IterableBase();
}
get [core.$iterator]() {
Expand All @@ -466,9 +466,9 @@ var _internal;
let WhereIterable = WhereIterable$();
let WhereIterator$ = dart.generic(function(E) {
class WhereIterator extends core.Iterator$(E) {
WhereIterator(iterator$, f$) {
this[_iterator] = iterator$;
this[_f] = f$;
WhereIterator(iterator, f) {
this[_iterator] = iterator;
this[_f] = f;
super.Iterator();
}
moveNext() {
Expand All @@ -493,9 +493,9 @@ var _internal;
let _ExpandFunction = _ExpandFunction$();
let ExpandIterable$ = dart.generic(function(S, T) {
class ExpandIterable extends collection.IterableBase$(T) {
ExpandIterable(iterable$, f$) {
this[_iterable] = iterable$;
this[_f] = f$;
ExpandIterable(iterable, f) {
this[_iterable] = iterable;
this[_f] = f;
super.IterableBase();
}
get [core.$iterator]() {
Expand All @@ -509,9 +509,9 @@ var _internal;
let _nextExpansion = dart.JsSymbol('_nextExpansion');
let ExpandIterator$ = dart.generic(function(S, T) {
class ExpandIterator extends core.Object {
ExpandIterator(iterator$, f$) {
this[_iterator] = iterator$;
this[_f] = f$;
ExpandIterator(iterator, f) {
this[_iterator] = iterator;
this[_f] = f;
this[_currentExpansion] = dart.as(new EmptyIterator(), core.Iterator$(T));
this[_current] = null;
}
Expand Down Expand Up @@ -551,9 +551,9 @@ var _internal;
}
return new TakeIterable$(E)[_](iterable, takeCount);
}
[_](iterable$, takeCount$) {
this[_iterable] = iterable$;
this[_takeCount] = takeCount$;
[_](iterable, takeCount) {
this[_iterable] = iterable;
this[_takeCount] = takeCount;
super.IterableBase();
}
get [core.$iterator]() {
Expand Down Expand Up @@ -583,8 +583,8 @@ var _internal;
let _remaining = dart.JsSymbol('_remaining');
let TakeIterator$ = dart.generic(function(E) {
class TakeIterator extends core.Iterator$(E) {
TakeIterator(iterator$, remaining) {
this[_iterator] = iterator$;
TakeIterator(iterator, remaining) {
this[_iterator] = iterator;
this[_remaining] = remaining;
super.Iterator();
dart.assert(typeof this[_remaining] == 'number' && dart.notNull(this[_remaining]) >= 0);
Expand All @@ -608,9 +608,9 @@ var _internal;
let TakeIterator = TakeIterator$();
let TakeWhileIterable$ = dart.generic(function(E) {
class TakeWhileIterable extends collection.IterableBase$(E) {
TakeWhileIterable(iterable$, f$) {
this[_iterable] = iterable$;
this[_f] = f$;
TakeWhileIterable(iterable, f) {
this[_iterable] = iterable;
this[_f] = f;
super.IterableBase();
}
get [core.$iterator]() {
Expand All @@ -623,9 +623,9 @@ var _internal;
let _isFinished = dart.JsSymbol('_isFinished');
let TakeWhileIterator$ = dart.generic(function(E) {
class TakeWhileIterator extends core.Iterator$(E) {
TakeWhileIterator(iterator$, f$) {
this[_iterator] = iterator$;
this[_f] = f$;
TakeWhileIterator(iterator, f) {
this[_iterator] = iterator;
this[_f] = f;
this[_isFinished] = false;
super.Iterator();
}
Expand Down Expand Up @@ -656,9 +656,9 @@ var _internal;
}
return new SkipIterable$(E)[_](iterable, count);
}
[_](iterable$, skipCount$) {
this[_iterable] = iterable$;
this[_skipCount] = skipCount$;
[_](iterable, skipCount) {
this[_iterable] = iterable;
this[_skipCount] = skipCount;
super.IterableBase();
if (!(typeof this[_skipCount] == 'number')) {
throw new core.ArgumentError.value(this[_skipCount], "count is not an integer");
Expand Down Expand Up @@ -698,9 +698,9 @@ var _internal;
let EfficientLengthSkipIterable = EfficientLengthSkipIterable$();
let SkipIterator$ = dart.generic(function(E) {
class SkipIterator extends core.Iterator$(E) {
SkipIterator(iterator$, skipCount$) {
this[_iterator] = iterator$;
this[_skipCount] = skipCount$;
SkipIterator(iterator, skipCount) {
this[_iterator] = iterator;
this[_skipCount] = skipCount;
super.Iterator();
dart.assert(typeof this[_skipCount] == 'number' && dart.notNull(this[_skipCount]) >= 0);
}
Expand All @@ -719,9 +719,9 @@ var _internal;
let SkipIterator = SkipIterator$();
let SkipWhileIterable$ = dart.generic(function(E) {
class SkipWhileIterable extends collection.IterableBase$(E) {
SkipWhileIterable(iterable$, f$) {
this[_iterable] = iterable$;
this[_f] = f$;
SkipWhileIterable(iterable, f) {
this[_iterable] = iterable;
this[_f] = f;
super.IterableBase();
}
get [core.$iterator]() {
Expand All @@ -734,9 +734,9 @@ var _internal;
let _hasSkipped = dart.JsSymbol('_hasSkipped');
let SkipWhileIterator$ = dart.generic(function(E) {
class SkipWhileIterator extends core.Iterator$(E) {
SkipWhileIterator(iterator$, f$) {
this[_iterator] = iterator$;
this[_f] = f$;
SkipWhileIterator(iterator, f) {
this[_iterator] = iterator;
this[_f] = f;
this[_hasSkipped] = false;
super.Iterator();
}
Expand Down Expand Up @@ -1839,8 +1839,8 @@ var _internal;
Symbol(name) {
this[_name] = name;
}
unvalidated(name$) {
this[_name] = name$;
unvalidated(name) {
this[_name] = name;
}
validated(name) {
this[_name] = Symbol.validatePublicSymbol(name);
Expand Down
54 changes: 27 additions & 27 deletions pkg/dev_compiler/lib/runtime/dart/_isolate_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,21 +350,21 @@ var _isolate_helper;
}
}
// Function _callInIsolate: (_IsolateContext, Function) → dynamic
function _callInIsolate(isolate, function$0) {
let result = isolate.eval(function$0);
function _callInIsolate(isolate, func) {
let result = isolate.eval(func);
exports._globalState.topEventLoop.run();
return result;
}
let _activeJsAsyncCount = Symbol('_activeJsAsyncCount');
// Function enterJsAsync: () → dynamic
function enterJsAsync() {
let o$ = exports._globalState.topEventLoop;
o$[_activeJsAsyncCount] = dart.notNull(o$[_activeJsAsyncCount]) + 1;
let o = exports._globalState.topEventLoop;
o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) + 1;
}
// Function leaveJsAsync: () → dynamic
function leaveJsAsync() {
let o$ = exports._globalState.topEventLoop;
o$[_activeJsAsyncCount] = dart.notNull(o$[_activeJsAsyncCount]) - 1;
let o = exports._globalState.topEventLoop;
o[_activeJsAsyncCount] = dart.notNull(o[_activeJsAsyncCount]) - 1;
dart.assert(dart.notNull(exports._globalState.topEventLoop[_activeJsAsyncCount]) >= 0);
}
// Function isWorker: () → bool
Expand Down Expand Up @@ -449,12 +449,12 @@ var _isolate_helper;
this.fromCommandLine = !dart.notNull(isWindowDefined) && !dart.notNull(this.isWorker);
}
[_nativeInitWorkerMessageHandler]() {
let function$0 = function(f, a) {
let func = function(f, a) {
return function(e) {
f(a, e);
};
}(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]), this.mainManager);
self.onmessage = function$0;
self.onmessage = func;
self.dartPrint = self.dartPrint || function(serialize) {
return function(object) {
if (self.console && self.console.log) {
Expand Down Expand Up @@ -484,9 +484,9 @@ var _isolate_helper;
class _IsolateContext extends core.Object {
_IsolateContext() {
this.id = (() => {
let o$ = exports._globalState, x$ = o$.nextIsolateId;
o$.nextIsolateId = dart.notNull(x$) + 1;
return x$;
let o = exports._globalState, x = o.nextIsolateId;
o.nextIsolateId = dart.notNull(x) + 1;
return x;
})();
this.ports = new (core.Map$(core.int, RawReceivePortImpl))();
this.weakPorts = new (core.Set$(core.int))();
Expand Down Expand Up @@ -1098,9 +1098,9 @@ var _isolate_helper;
};
}(_foreign_helper.DART_CLOSURE_TO_JS(IsolateNatives[_processWorkerMessage]), worker);
worker.onmessage = processWorkerMessageTrampoline;
let o$ = exports._globalState;
let workerId = o$.nextManagerId;
o$.nextManagerId = dart.notNull(workerId) + 1;
let o = exports._globalState;
let workerId = o.nextManagerId;
o.nextManagerId = dart.notNull(workerId) + 1;
IsolateNatives.workerIds.set(worker, workerId);
exports._globalState.managers.set(workerId, worker);
worker.postMessage(_serializeMessage(dart.map({command: 'start', id: workerId, replyTo: _serializeMessage(replyPort), args: args, msg: _serializeMessage(message), isSpawnUri: isSpawnUri, startPaused: startPaused, functionName: functionName})));
Expand Down Expand Up @@ -1129,8 +1129,8 @@ var _isolate_helper;
});
let _checkReplyTo = Symbol('_checkReplyTo');
class _BaseSendPort extends core.Object {
_BaseSendPort(isolateId$) {
this[_isolateId] = isolateId$;
_BaseSendPort(isolateId) {
this[_isolateId] = isolateId;
}
[_checkReplyTo](replyTo) {
if (dart.notNull(replyTo != null) && !dart.is(replyTo, _NativeJsSendPort) && !dart.is(replyTo, _WorkerSendPort)) {
Expand All @@ -1142,8 +1142,8 @@ var _isolate_helper;
let _isClosed = Symbol('_isClosed');
let _add = Symbol('_add');
class _NativeJsSendPort extends _BaseSendPort {
_NativeJsSendPort(receivePort$, isolateId) {
this[_receivePort] = receivePort$;
_NativeJsSendPort(receivePort, isolateId) {
this[_receivePort] = receivePort;
super._BaseSendPort(isolateId);
}
send(message) {
Expand Down Expand Up @@ -1172,9 +1172,9 @@ var _isolate_helper;
}
_NativeJsSendPort[dart.implements] = () => [isolate.SendPort];
class _WorkerSendPort extends _BaseSendPort {
_WorkerSendPort(workerId$, isolateId, receivePortId$) {
this[_workerId] = workerId$;
this[_receivePortId] = receivePortId$;
_WorkerSendPort(workerId, isolateId, receivePortId) {
this[_workerId] = workerId;
this[_receivePortId] = receivePortId;
super._BaseSendPort(isolateId);
}
send(message) {
Expand Down Expand Up @@ -1202,19 +1202,19 @@ var _isolate_helper;
RawReceivePortImpl(handler) {
this[_handler] = handler;
this[_id] = (() => {
let x$ = RawReceivePortImpl[_nextFreeId];
RawReceivePortImpl[_nextFreeId] = dart.notNull(x$) + 1;
return x$;
let x = RawReceivePortImpl[_nextFreeId];
RawReceivePortImpl[_nextFreeId] = dart.notNull(x) + 1;
return x;
})();
this[_isClosed] = false;
exports._globalState.currentContext.register(this[_id], this);
}
weak(handler) {
this[_handler] = handler;
this[_id] = (() => {
let x$ = RawReceivePortImpl[_nextFreeId];
RawReceivePortImpl[_nextFreeId] = dart.notNull(x$) + 1;
return x$;
let x = RawReceivePortImpl[_nextFreeId];
RawReceivePortImpl[_nextFreeId] = dart.notNull(x) + 1;
return x;
})();
this[_isClosed] = false;
exports._globalState.currentContext.registerWeak(this[_id], this);
Expand Down
Loading

0 comments on commit 33322cb

Please sign in to comment.