Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Don't generate redundant calls to query captured scopes
Browse files Browse the repository at this point in the history
Release notes: None

Don't generate redundant calls of the form
`var __captured__scope_2 = __scope_0[0] || __scope_1(0);`

Adding regression test.

This addresses one of the observations of #1732.
Also deleted unneeded left-over code and comment that used to refer #989.
  • Loading branch information
NTillmann committed Apr 11, 2018
1 parent 8e845d2 commit a86be68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/serializer/ResidualFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,13 @@ export class ResidualFunctions {

// Emit code for ModifiedBindings for additional functions
for (let [funcValue, funcInfo] of this.additionalFunctionValueInfos) {
let scopes = new Set();
for (let [, residualBinding] of funcInfo.modifiedBindings) {
let scope = residualBinding.scope;
if (scope === undefined) continue;
if (scope === undefined || scopes.has(scope)) continue;
scopes.add(scope);

// TODO #989: This should probably be an invariant once captures work properly
// Currently we don't referentialize bindings in additional functions (but we
// do for bindings nested in additional functions)
if (!residualBinding.referentialized) continue;
invariant(residualBinding.referentialized);

// Find the proper prelude to emit to (global vs additional function's prelude)
let bodySegment = getModifiedBindingsSegment(funcValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// add at runtime:var a = 17;
// Copies of \|\|:2
(function () {
let a, b, c, d;
global.f = function() {
a = 1;
b = 2;
c = 3;
d = 4;
}
if (global.__optimize) __optimize(f);
inspect = function() {
global.f();
return a + b + c + d;
}
})();

0 comments on commit a86be68

Please sign in to comment.