Add experimental option to cache the .length access in downlevel for-of emit.

This commit is contained in:
Cyrus Najmabadi 2015-03-13 16:15:25 -07:00
parent 4a9187172e
commit d8d4719765
18 changed files with 163 additions and 42 deletions

View File

@ -252,6 +252,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
options += " --stripInternal"
}
// options += " --cacheDownlevelForOfLength";
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
cmd = cmd + sources.join(" ");
console.log(cmd + "\n");

View File

@ -11815,7 +11815,7 @@ var ts;
}
ts.bindSourceFile = bindSourceFile;
function bindSourceFileWorker(file) {
var parent;
var _parent;
var container;
var blockScopeContainer;
var lastContainer;
@ -11956,10 +11956,10 @@ var ts;
if (symbolKind & 255504) {
node.locals = {};
}
var saveParent = parent;
var saveParent = _parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
parent = node;
_parent = node;
if (symbolKind & 262128) {
container = node;
if (lastContainer) {
@ -11972,7 +11972,7 @@ var ts;
}
ts.forEachChild(node, bind);
container = saveContainer;
parent = saveParent;
_parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@ -12075,7 +12075,7 @@ var ts;
return "__" + ts.indexOf(node.parent.parameters, node);
}
function bind(node) {
node.parent = parent;
node.parent = _parent;
switch (node.kind) {
case 127:
bindDeclaration(node, 262144, 530912, false);
@ -12209,10 +12209,10 @@ var ts;
bindChildren(node, 0, true);
break;
default:
var saveParent = parent;
parent = node;
var saveParent = _parent;
_parent = node;
ts.forEachChild(node, bind);
parent = saveParent;
_parent = saveParent;
}
}
function bindParameter(node) {
@ -24542,6 +24542,7 @@ var ts;
var rhsIsIdentifier = node.expression.kind === 64;
var counter = createTempVariable(node, true);
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
emitStart(node.expression);
write("var ");
emitNodeWithoutSourceMap(counter);
@ -24555,12 +24556,24 @@ var ts;
emitNodeWithoutSourceMap(node.expression);
emitEnd(node.expression);
}
if (cachedLength) {
write(", ");
emitNodeWithoutSourceMap(cachedLength);
write(" = ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
write("; ");
emitStart(node.initializer);
emitNodeWithoutSourceMap(counter);
write(" < ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
if (cachedLength) {
emitNodeWithoutSourceMap(cachedLength);
}
else {
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
emitEnd(node.initializer);
write("; ");
emitStart(node.initializer);
@ -26921,6 +26934,12 @@ var ts;
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
experimental: true
},
{
name: "cacheDownlevelForOfLength",
type: "boolean",
description: "Cache length access when downlevel emitting for-of statements",
experimental: true
},
{
name: "target",
shortName: "t",

View File

@ -7473,6 +7473,12 @@ var ts;
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
experimental: true
},
{
name: "cacheDownlevelForOfLength",
type: "boolean",
description: "Cache length access when downlevel emitting for-of statements",
experimental: true
},
{
name: "target",
shortName: "t",
@ -12165,7 +12171,7 @@ var ts;
}
ts.bindSourceFile = bindSourceFile;
function bindSourceFileWorker(file) {
var parent;
var _parent;
var container;
var blockScopeContainer;
var lastContainer;
@ -12306,10 +12312,10 @@ var ts;
if (symbolKind & 255504) {
node.locals = {};
}
var saveParent = parent;
var saveParent = _parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
parent = node;
_parent = node;
if (symbolKind & 262128) {
container = node;
if (lastContainer) {
@ -12322,7 +12328,7 @@ var ts;
}
ts.forEachChild(node, bind);
container = saveContainer;
parent = saveParent;
_parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@ -12425,7 +12431,7 @@ var ts;
return "__" + ts.indexOf(node.parent.parameters, node);
}
function bind(node) {
node.parent = parent;
node.parent = _parent;
switch (node.kind) {
case 127:
bindDeclaration(node, 262144, 530912, false);
@ -12559,10 +12565,10 @@ var ts;
bindChildren(node, 0, true);
break;
default:
var saveParent = parent;
parent = node;
var saveParent = _parent;
_parent = node;
ts.forEachChild(node, bind);
parent = saveParent;
_parent = saveParent;
}
}
function bindParameter(node) {
@ -24892,6 +24898,7 @@ var ts;
var rhsIsIdentifier = node.expression.kind === 64;
var counter = createTempVariable(node, true);
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
emitStart(node.expression);
write("var ");
emitNodeWithoutSourceMap(counter);
@ -24905,12 +24912,24 @@ var ts;
emitNodeWithoutSourceMap(node.expression);
emitEnd(node.expression);
}
if (cachedLength) {
write(", ");
emitNodeWithoutSourceMap(cachedLength);
write(" = ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
write("; ");
emitStart(node.initializer);
emitNodeWithoutSourceMap(counter);
write(" < ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
if (cachedLength) {
emitNodeWithoutSourceMap(cachedLength);
}
else {
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
emitEnd(node.initializer);
write("; ");
emitStart(node.initializer);

1
bin/typescript.d.ts vendored
View File

@ -1202,6 +1202,7 @@ declare module "typescript" {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {

View File

@ -12444,7 +12444,7 @@ var ts;
}
ts.bindSourceFile = bindSourceFile;
function bindSourceFileWorker(file) {
var parent;
var _parent;
var container;
var blockScopeContainer;
var lastContainer;
@ -12585,10 +12585,10 @@ var ts;
if (symbolKind & 255504) {
node.locals = {};
}
var saveParent = parent;
var saveParent = _parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
parent = node;
_parent = node;
if (symbolKind & 262128) {
container = node;
if (lastContainer) {
@ -12601,7 +12601,7 @@ var ts;
}
ts.forEachChild(node, bind);
container = saveContainer;
parent = saveParent;
_parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@ -12704,7 +12704,7 @@ var ts;
return "__" + ts.indexOf(node.parent.parameters, node);
}
function bind(node) {
node.parent = parent;
node.parent = _parent;
switch (node.kind) {
case 127:
bindDeclaration(node, 262144, 530912, false);
@ -12838,10 +12838,10 @@ var ts;
bindChildren(node, 0, true);
break;
default:
var saveParent = parent;
parent = node;
var saveParent = _parent;
_parent = node;
ts.forEachChild(node, bind);
parent = saveParent;
_parent = saveParent;
}
}
function bindParameter(node) {
@ -25171,6 +25171,7 @@ var ts;
var rhsIsIdentifier = node.expression.kind === 64;
var counter = createTempVariable(node, true);
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
emitStart(node.expression);
write("var ");
emitNodeWithoutSourceMap(counter);
@ -25184,12 +25185,24 @@ var ts;
emitNodeWithoutSourceMap(node.expression);
emitEnd(node.expression);
}
if (cachedLength) {
write(", ");
emitNodeWithoutSourceMap(cachedLength);
write(" = ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
write("; ");
emitStart(node.initializer);
emitNodeWithoutSourceMap(counter);
write(" < ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
if (cachedLength) {
emitNodeWithoutSourceMap(cachedLength);
}
else {
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
emitEnd(node.initializer);
write("; ");
emitStart(node.initializer);
@ -27550,6 +27563,12 @@ var ts;
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
experimental: true
},
{
name: "cacheDownlevelForOfLength",
type: "boolean",
description: "Cache length access when downlevel emitting for-of statements",
experimental: true
},
{
name: "target",
shortName: "t",

View File

@ -1202,6 +1202,7 @@ declare module ts {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {

View File

@ -12444,7 +12444,7 @@ var ts;
}
ts.bindSourceFile = bindSourceFile;
function bindSourceFileWorker(file) {
var parent;
var _parent;
var container;
var blockScopeContainer;
var lastContainer;
@ -12585,10 +12585,10 @@ var ts;
if (symbolKind & 255504) {
node.locals = {};
}
var saveParent = parent;
var saveParent = _parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
parent = node;
_parent = node;
if (symbolKind & 262128) {
container = node;
if (lastContainer) {
@ -12601,7 +12601,7 @@ var ts;
}
ts.forEachChild(node, bind);
container = saveContainer;
parent = saveParent;
_parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@ -12704,7 +12704,7 @@ var ts;
return "__" + ts.indexOf(node.parent.parameters, node);
}
function bind(node) {
node.parent = parent;
node.parent = _parent;
switch (node.kind) {
case 127:
bindDeclaration(node, 262144, 530912, false);
@ -12838,10 +12838,10 @@ var ts;
bindChildren(node, 0, true);
break;
default:
var saveParent = parent;
parent = node;
var saveParent = _parent;
_parent = node;
ts.forEachChild(node, bind);
parent = saveParent;
_parent = saveParent;
}
}
function bindParameter(node) {
@ -25171,6 +25171,7 @@ var ts;
var rhsIsIdentifier = node.expression.kind === 64;
var counter = createTempVariable(node, true);
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
emitStart(node.expression);
write("var ");
emitNodeWithoutSourceMap(counter);
@ -25184,12 +25185,24 @@ var ts;
emitNodeWithoutSourceMap(node.expression);
emitEnd(node.expression);
}
if (cachedLength) {
write(", ");
emitNodeWithoutSourceMap(cachedLength);
write(" = ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
write("; ");
emitStart(node.initializer);
emitNodeWithoutSourceMap(counter);
write(" < ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
if (cachedLength) {
emitNodeWithoutSourceMap(cachedLength);
}
else {
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
emitEnd(node.initializer);
write("; ");
emitStart(node.initializer);
@ -27550,6 +27563,12 @@ var ts;
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
experimental: true
},
{
name: "cacheDownlevelForOfLength",
type: "boolean",
description: "Cache length access when downlevel emitting for-of statements",
experimental: true
},
{
name: "target",
shortName: "t",

View File

@ -146,6 +146,12 @@ module ts {
description: Diagnostics.Preserve_new_lines_when_emitting_code,
experimental: true
},
{
name: "cacheDownlevelForOfLength",
type: "boolean",
description: "Cache length access when downlevel emitting for-of statements",
experimental: true,
},
{
name: "target",
shortName: "t",

View File

@ -3583,6 +3583,8 @@ module ts {
let counter = createTempVariable(node, /*forLoopVariable*/ true);
let rhsReference = rhsIsIdentifier ? <Identifier>node.expression : createTempVariable(node, /*forLoopVariable*/ false);
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, /*forLoopVariable:*/ false) : undefined;
// This is the let keyword for the counter and rhsReference. The let keyword for
// the LHS will be emitted inside the body.
emitStart(node.expression);
@ -3602,14 +3604,30 @@ module ts {
emitNodeWithoutSourceMap(node.expression);
emitEnd(node.expression);
}
if (cachedLength) {
write(", ");
emitNodeWithoutSourceMap(cachedLength);
write(" = ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
write("; ");
// _i < _a.length;
emitStart(node.initializer);
emitNodeWithoutSourceMap(counter);
write(" < ");
emitNodeWithoutSourceMap(rhsReference);
write(".length");
if (cachedLength) {
emitNodeWithoutSourceMap(cachedLength);
}
else {
emitNodeWithoutSourceMap(rhsReference);
write(".length");
}
emitEnd(node.initializer);
write("; ");

View File

@ -1560,6 +1560,7 @@ module ts {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}

View File

@ -1239,6 +1239,7 @@ declare module "typescript" {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {

View File

@ -3953,6 +3953,9 @@ declare module "typescript" {
preserveNewLines?: boolean;
>preserveNewLines : boolean
cacheDownlevelForOfLength?: boolean;
>cacheDownlevelForOfLength : boolean
[option: string]: string | number | boolean;
>option : string
}

View File

@ -1270,6 +1270,7 @@ declare module "typescript" {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {

View File

@ -4099,6 +4099,9 @@ declare module "typescript" {
preserveNewLines?: boolean;
>preserveNewLines : boolean
cacheDownlevelForOfLength?: boolean;
>cacheDownlevelForOfLength : boolean
[option: string]: string | number | boolean;
>option : string
}

View File

@ -1271,6 +1271,7 @@ declare module "typescript" {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {

View File

@ -4049,6 +4049,9 @@ declare module "typescript" {
preserveNewLines?: boolean;
>preserveNewLines : boolean
cacheDownlevelForOfLength?: boolean;
>cacheDownlevelForOfLength : boolean
[option: string]: string | number | boolean;
>option : string
}

View File

@ -1308,6 +1308,7 @@ declare module "typescript" {
watch?: boolean;
stripInternal?: boolean;
preserveNewLines?: boolean;
cacheDownlevelForOfLength?: boolean;
[option: string]: string | number | boolean;
}
const enum ModuleKind {

View File

@ -4222,6 +4222,9 @@ declare module "typescript" {
preserveNewLines?: boolean;
>preserveNewLines : boolean
cacheDownlevelForOfLength?: boolean;
>cacheDownlevelForOfLength : boolean
[option: string]: string | number | boolean;
>option : string
}