Skip to content

Commit d8d4719

Browse files
Add experimental option to cache the .length access in downlevel for-of emit.
1 parent 4a91871 commit d8d4719

18 files changed

Lines changed: 163 additions & 42 deletions

Jakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
252252
options += " --stripInternal"
253253
}
254254

255+
// options += " --cacheDownlevelForOfLength";
256+
255257
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
256258
cmd = cmd + sources.join(" ");
257259
console.log(cmd + "\n");

bin/tsc.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11815,7 +11815,7 @@ var ts;
1181511815
}
1181611816
ts.bindSourceFile = bindSourceFile;
1181711817
function bindSourceFileWorker(file) {
11818-
var parent;
11818+
var _parent;
1181911819
var container;
1182011820
var blockScopeContainer;
1182111821
var lastContainer;
@@ -11956,10 +11956,10 @@ var ts;
1195611956
if (symbolKind & 255504) {
1195711957
node.locals = {};
1195811958
}
11959-
var saveParent = parent;
11959+
var saveParent = _parent;
1196011960
var saveContainer = container;
1196111961
var savedBlockScopeContainer = blockScopeContainer;
11962-
parent = node;
11962+
_parent = node;
1196311963
if (symbolKind & 262128) {
1196411964
container = node;
1196511965
if (lastContainer) {
@@ -11972,7 +11972,7 @@ var ts;
1197211972
}
1197311973
ts.forEachChild(node, bind);
1197411974
container = saveContainer;
11975-
parent = saveParent;
11975+
_parent = saveParent;
1197611976
blockScopeContainer = savedBlockScopeContainer;
1197711977
}
1197811978
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@@ -12075,7 +12075,7 @@ var ts;
1207512075
return "__" + ts.indexOf(node.parent.parameters, node);
1207612076
}
1207712077
function bind(node) {
12078-
node.parent = parent;
12078+
node.parent = _parent;
1207912079
switch (node.kind) {
1208012080
case 127:
1208112081
bindDeclaration(node, 262144, 530912, false);
@@ -12209,10 +12209,10 @@ var ts;
1220912209
bindChildren(node, 0, true);
1221012210
break;
1221112211
default:
12212-
var saveParent = parent;
12213-
parent = node;
12212+
var saveParent = _parent;
12213+
_parent = node;
1221412214
ts.forEachChild(node, bind);
12215-
parent = saveParent;
12215+
_parent = saveParent;
1221612216
}
1221712217
}
1221812218
function bindParameter(node) {
@@ -24542,6 +24542,7 @@ var ts;
2454224542
var rhsIsIdentifier = node.expression.kind === 64;
2454324543
var counter = createTempVariable(node, true);
2454424544
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
24545+
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
2454524546
emitStart(node.expression);
2454624547
write("var ");
2454724548
emitNodeWithoutSourceMap(counter);
@@ -24555,12 +24556,24 @@ var ts;
2455524556
emitNodeWithoutSourceMap(node.expression);
2455624557
emitEnd(node.expression);
2455724558
}
24559+
if (cachedLength) {
24560+
write(", ");
24561+
emitNodeWithoutSourceMap(cachedLength);
24562+
write(" = ");
24563+
emitNodeWithoutSourceMap(rhsReference);
24564+
write(".length");
24565+
}
2455824566
write("; ");
2455924567
emitStart(node.initializer);
2456024568
emitNodeWithoutSourceMap(counter);
2456124569
write(" < ");
24562-
emitNodeWithoutSourceMap(rhsReference);
24563-
write(".length");
24570+
if (cachedLength) {
24571+
emitNodeWithoutSourceMap(cachedLength);
24572+
}
24573+
else {
24574+
emitNodeWithoutSourceMap(rhsReference);
24575+
write(".length");
24576+
}
2456424577
emitEnd(node.initializer);
2456524578
write("; ");
2456624579
emitStart(node.initializer);
@@ -26921,6 +26934,12 @@ var ts;
2692126934
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
2692226935
experimental: true
2692326936
},
26937+
{
26938+
name: "cacheDownlevelForOfLength",
26939+
type: "boolean",
26940+
description: "Cache length access when downlevel emitting for-of statements",
26941+
experimental: true
26942+
},
2692426943
{
2692526944
name: "target",
2692626945
shortName: "t",

bin/tsserver.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7473,6 +7473,12 @@ var ts;
74737473
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
74747474
experimental: true
74757475
},
7476+
{
7477+
name: "cacheDownlevelForOfLength",
7478+
type: "boolean",
7479+
description: "Cache length access when downlevel emitting for-of statements",
7480+
experimental: true
7481+
},
74767482
{
74777483
name: "target",
74787484
shortName: "t",
@@ -12165,7 +12171,7 @@ var ts;
1216512171
}
1216612172
ts.bindSourceFile = bindSourceFile;
1216712173
function bindSourceFileWorker(file) {
12168-
var parent;
12174+
var _parent;
1216912175
var container;
1217012176
var blockScopeContainer;
1217112177
var lastContainer;
@@ -12306,10 +12312,10 @@ var ts;
1230612312
if (symbolKind & 255504) {
1230712313
node.locals = {};
1230812314
}
12309-
var saveParent = parent;
12315+
var saveParent = _parent;
1231012316
var saveContainer = container;
1231112317
var savedBlockScopeContainer = blockScopeContainer;
12312-
parent = node;
12318+
_parent = node;
1231312319
if (symbolKind & 262128) {
1231412320
container = node;
1231512321
if (lastContainer) {
@@ -12322,7 +12328,7 @@ var ts;
1232212328
}
1232312329
ts.forEachChild(node, bind);
1232412330
container = saveContainer;
12325-
parent = saveParent;
12331+
_parent = saveParent;
1232612332
blockScopeContainer = savedBlockScopeContainer;
1232712333
}
1232812334
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@@ -12425,7 +12431,7 @@ var ts;
1242512431
return "__" + ts.indexOf(node.parent.parameters, node);
1242612432
}
1242712433
function bind(node) {
12428-
node.parent = parent;
12434+
node.parent = _parent;
1242912435
switch (node.kind) {
1243012436
case 127:
1243112437
bindDeclaration(node, 262144, 530912, false);
@@ -12559,10 +12565,10 @@ var ts;
1255912565
bindChildren(node, 0, true);
1256012566
break;
1256112567
default:
12562-
var saveParent = parent;
12563-
parent = node;
12568+
var saveParent = _parent;
12569+
_parent = node;
1256412570
ts.forEachChild(node, bind);
12565-
parent = saveParent;
12571+
_parent = saveParent;
1256612572
}
1256712573
}
1256812574
function bindParameter(node) {
@@ -24892,6 +24898,7 @@ var ts;
2489224898
var rhsIsIdentifier = node.expression.kind === 64;
2489324899
var counter = createTempVariable(node, true);
2489424900
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
24901+
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
2489524902
emitStart(node.expression);
2489624903
write("var ");
2489724904
emitNodeWithoutSourceMap(counter);
@@ -24905,12 +24912,24 @@ var ts;
2490524912
emitNodeWithoutSourceMap(node.expression);
2490624913
emitEnd(node.expression);
2490724914
}
24915+
if (cachedLength) {
24916+
write(", ");
24917+
emitNodeWithoutSourceMap(cachedLength);
24918+
write(" = ");
24919+
emitNodeWithoutSourceMap(rhsReference);
24920+
write(".length");
24921+
}
2490824922
write("; ");
2490924923
emitStart(node.initializer);
2491024924
emitNodeWithoutSourceMap(counter);
2491124925
write(" < ");
24912-
emitNodeWithoutSourceMap(rhsReference);
24913-
write(".length");
24926+
if (cachedLength) {
24927+
emitNodeWithoutSourceMap(cachedLength);
24928+
}
24929+
else {
24930+
emitNodeWithoutSourceMap(rhsReference);
24931+
write(".length");
24932+
}
2491424933
emitEnd(node.initializer);
2491524934
write("; ");
2491624935
emitStart(node.initializer);

bin/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ declare module "typescript" {
12021202
watch?: boolean;
12031203
stripInternal?: boolean;
12041204
preserveNewLines?: boolean;
1205+
cacheDownlevelForOfLength?: boolean;
12051206
[option: string]: string | number | boolean;
12061207
}
12071208
const enum ModuleKind {

bin/typescript.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12444,7 +12444,7 @@ var ts;
1244412444
}
1244512445
ts.bindSourceFile = bindSourceFile;
1244612446
function bindSourceFileWorker(file) {
12447-
var parent;
12447+
var _parent;
1244812448
var container;
1244912449
var blockScopeContainer;
1245012450
var lastContainer;
@@ -12585,10 +12585,10 @@ var ts;
1258512585
if (symbolKind & 255504) {
1258612586
node.locals = {};
1258712587
}
12588-
var saveParent = parent;
12588+
var saveParent = _parent;
1258912589
var saveContainer = container;
1259012590
var savedBlockScopeContainer = blockScopeContainer;
12591-
parent = node;
12591+
_parent = node;
1259212592
if (symbolKind & 262128) {
1259312593
container = node;
1259412594
if (lastContainer) {
@@ -12601,7 +12601,7 @@ var ts;
1260112601
}
1260212602
ts.forEachChild(node, bind);
1260312603
container = saveContainer;
12604-
parent = saveParent;
12604+
_parent = saveParent;
1260512605
blockScopeContainer = savedBlockScopeContainer;
1260612606
}
1260712607
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
@@ -12704,7 +12704,7 @@ var ts;
1270412704
return "__" + ts.indexOf(node.parent.parameters, node);
1270512705
}
1270612706
function bind(node) {
12707-
node.parent = parent;
12707+
node.parent = _parent;
1270812708
switch (node.kind) {
1270912709
case 127:
1271012710
bindDeclaration(node, 262144, 530912, false);
@@ -12838,10 +12838,10 @@ var ts;
1283812838
bindChildren(node, 0, true);
1283912839
break;
1284012840
default:
12841-
var saveParent = parent;
12842-
parent = node;
12841+
var saveParent = _parent;
12842+
_parent = node;
1284312843
ts.forEachChild(node, bind);
12844-
parent = saveParent;
12844+
_parent = saveParent;
1284512845
}
1284612846
}
1284712847
function bindParameter(node) {
@@ -25171,6 +25171,7 @@ var ts;
2517125171
var rhsIsIdentifier = node.expression.kind === 64;
2517225172
var counter = createTempVariable(node, true);
2517325173
var rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node, false);
25174+
var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, false) : undefined;
2517425175
emitStart(node.expression);
2517525176
write("var ");
2517625177
emitNodeWithoutSourceMap(counter);
@@ -25184,12 +25185,24 @@ var ts;
2518425185
emitNodeWithoutSourceMap(node.expression);
2518525186
emitEnd(node.expression);
2518625187
}
25188+
if (cachedLength) {
25189+
write(", ");
25190+
emitNodeWithoutSourceMap(cachedLength);
25191+
write(" = ");
25192+
emitNodeWithoutSourceMap(rhsReference);
25193+
write(".length");
25194+
}
2518725195
write("; ");
2518825196
emitStart(node.initializer);
2518925197
emitNodeWithoutSourceMap(counter);
2519025198
write(" < ");
25191-
emitNodeWithoutSourceMap(rhsReference);
25192-
write(".length");
25199+
if (cachedLength) {
25200+
emitNodeWithoutSourceMap(cachedLength);
25201+
}
25202+
else {
25203+
emitNodeWithoutSourceMap(rhsReference);
25204+
write(".length");
25205+
}
2519325206
emitEnd(node.initializer);
2519425207
write("; ");
2519525208
emitStart(node.initializer);
@@ -27550,6 +27563,12 @@ var ts;
2755027563
description: ts.Diagnostics.Preserve_new_lines_when_emitting_code,
2755127564
experimental: true
2755227565
},
27566+
{
27567+
name: "cacheDownlevelForOfLength",
27568+
type: "boolean",
27569+
description: "Cache length access when downlevel emitting for-of statements",
27570+
experimental: true
27571+
},
2755327572
{
2755427573
name: "target",
2755527574
shortName: "t",

bin/typescriptServices.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ declare module ts {
12021202
watch?: boolean;
12031203
stripInternal?: boolean;
12041204
preserveNewLines?: boolean;
1205+
cacheDownlevelForOfLength?: boolean;
12051206
[option: string]: string | number | boolean;
12061207
}
12071208
const enum ModuleKind {

0 commit comments

Comments
 (0)