Details
-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
None
-
b89
Description
Currently, we're being overly conservative/pessimistic in our compilation assumptions with functions containing with statements and eval calls. Specifically:
- functions having a with statement fall back to "all vars in scope". This in unnecessary, as only those variables that are referenced from a with block have to be in scope; it's an unnecessary penalty to move all of them into scope.
- functions having an eval call *or* (transitively) having a nested function that uses either eval or has a with statement don't use "fast scope access" (FSA) mechanism in codegen. This is also unnecessarily broad generalization. FSA can be used as long as the lexical contexts between the use of a variable and its declaration don't contain either a with statement or a non-strict function with an eval call. This is because the only way to introduce new variables into scope that can't be statically detected is with those two constructs: a with statement, and an eval() call in a non-strict function. In all other situations, fast scopes can be used. This includes the current very broad "has an eval call or with block in nested function" condition - that's no reason to disable fast scopes; a with statement or eval call in a nested function can't introduce new variables into any of its outer functions' scopes, it can only modify the value of existing variables.
Fixing this will let the compiler move variables from scope into local variables in presence of with statements, and allow the compiler to use FSA in broader number of scenarios involving with/eval.
- functions having a with statement fall back to "all vars in scope". This in unnecessary, as only those variables that are referenced from a with block have to be in scope; it's an unnecessary penalty to move all of them into scope.
- functions having an eval call *or* (transitively) having a nested function that uses either eval or has a with statement don't use "fast scope access" (FSA) mechanism in codegen. This is also unnecessarily broad generalization. FSA can be used as long as the lexical contexts between the use of a variable and its declaration don't contain either a with statement or a non-strict function with an eval call. This is because the only way to introduce new variables into scope that can't be statically detected is with those two constructs: a with statement, and an eval() call in a non-strict function. In all other situations, fast scopes can be used. This includes the current very broad "has an eval call or with block in nested function" condition - that's no reason to disable fast scopes; a with statement or eval call in a nested function can't introduce new variables into any of its outer functions' scopes, it can only modify the value of existing variables.
Fixing this will let the compiler move variables from scope into local variables in presence of with statements, and allow the compiler to use FSA in broader number of scenarios involving with/eval.