Repository navigation
Conversation
…ation Every reference of a function to its own let, const or class variable was a get_loc_check/put_loc_check, even long after the declaration. Besides the test at each access, the peephole optimizations only match get_loc and put_loc (add_loc, inc_loc, set_loc...), so 'c += 1' on a let ran 48% slower than on a var (30M iterations: 348 ms, now 172 ms; the 'i++' of a 'for (let i ...)' loop now becomes inc_loc too, so the var loop also went from 236 to 170 ms). resolve_variables() reads the code in the order it was emitted. When it resolves the OP_scope_put_var_init of a declaration in the scope of its variable, it marks the variable as initialized, and the following references of the function to it in that scope get get_loc/put_loc. They can only run after the declaration in the current entry of the scope: the entry of a scope makes its variables uninitialized again and a loop jumps back before it, a break or continue leaves the scope, and a declaration is always a direct statement of its block. Not marked: - the body of a switch (new JSVarScope.is_switch): a case label jumps past the declarations of the previous cases; - 'this' of a derived class constructor, initialized by super() anywhere; - the references of closures (get_var_ref_check), which can run before the declaration. Python functions emit their final opcodes directly and are unchanged. The two properties of the code generator this relies on are stated at lexical_var_needs_check() and at the switch statement. CONFIG_CHECK_TDZ=y builds a qjs whose reads of a local let/const/class variable without check abort if it is uninitialized (private names, read without check by design, are left out): test262 runs with it without abort (44/52778 errors, as master), and clearing is_switch makes a case label reading a declaration of a previous case abort. test262: same results as master (44/52778 errors, the same 3 host time zone failures).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every reference of a function to its own let, const or class variable was
a get_loc_check/put_loc_check, even long after the declaration. Besides
the test at each access, the peephole optimizations only match get_loc and
put_loc (add_loc, inc_loc, set_loc...), so 'c += 1' on a let ran 48%
slower than on a var (30M iterations: 348 ms, now 172 ms; the 'i++' of a
'for (let i ...)' loop now becomes inc_loc too, so the var loop also went
from 236 to 170 ms).
resolve_variables() reads the code in the order it was emitted. When it
resolves the OP_scope_put_var_init of a declaration in the scope of its
variable, it marks the variable as initialized, and the following
references of the function to it in that scope get get_loc/put_loc. They
can only run after the declaration in the current entry of the scope:
the entry of a scope makes its variables uninitialized again and a loop
jumps back before it, a break or continue leaves the scope, and a
declaration is always a direct statement of its block. Not marked:
the declarations of the previous cases;
the declaration.
Python functions emit their final opcodes directly and are unchanged.
The two properties of the code generator this relies on are stated at
lexical_var_needs_check() and at the switch statement. CONFIG_CHECK_TDZ=y
builds a qjs whose reads of a local let/const/class variable without
check abort if it is uninitialized (private names, read without check by
design, are left out): test262 runs with it without abort (44/52778
errors, as master), and clearing is_switch makes a case label reading a
declaration of a previous case abort.
test262: same results as master (44/52778 errors, the same 3 host time
zone failures).
Testing
Based on
68be18f(the tip offeat/py), so the same commit applies tomasterand tofeat/pywithout conflicts, alone or with the other PRs of this series.make test,tests/py/interop/run.shand a short Python script (string indexing/iteration/concatenation,marshal, list pop/insert/clear/extend) pass with the Python build, on this PR alone and with the whole series, onmasterand onfeat/py(plus perf(arrays): O(1)shift()on fast arrays for feat/py #10 for the array PRs).master+ the series: 44/52778 errors, as onmaster(the same 3 host time zone failures); the same withCONFIG_CHECK_TDZ=y, without abort.master+ the series:test_language,test_builtin,test_loop,test_closure,test_bigint,test_decorators,test_usingand test262language/(0/23162 errors).feat/pyitself needs665e816(gcc 15 / glibc fixes frommaster) to build here; it was added for testing only.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.