Commit graph

495 commits

Author SHA1 Message Date
Luke Wilde
d66eb4e3ba LibJS/Bytecode: Add Await and AsyncIteratorClose instructions 2023-07-15 01:08:52 +02:00
Daniel Bertalan
e3f65f215d LibJS/Bytecode: Do not rethrow caught exception from finally
If the exception from the `try` block has already been caught by
`catch`, we need to clear the saved exception before entering `finally`
so that ContinuePendingUnwind will not re-throw it.

9 new passes on test262 :^)
2023-07-14 17:05:29 +02:00
Gabriel Dinner-David
d29bd55b48 LibJS: Implement import.meta for bytecode 2023-07-14 06:06:04 +02:00
Aliaksandr Kalenik
a1692931af LibJS/Bytecode: Skip CreateVariable for locals in "for" loop head
CreateVariable is not needed for locals because they are not stored in
environment and created binding will not be used. Also if all variables
in loop initialization sections are local then CreateLexicalEnvironment
and LeaveLexicalEnvironment can also be ommitted.
2023-07-14 05:58:30 +02:00
Andreas Kling
c0f985ffcf LibJS/Bytecode: Don't reparse regular expressions on instantiation
The RegExpLiteral AST node already has the parsed regex::Parser::Result
so let's plumb that over to the bytecode executable instead of reparsing
the regex every time NewRegExp is executed.

~12% speed-up on language/literals/regexp/S7.8.5_A2.1_T2.js in test262.
2023-07-13 13:30:49 +02:00
Andreas Kling
640d48255b LibJS: Remove unhelpful environment lookup optimization for globals
This optimization was no longer helpful after the bug fix for missing
invalidation on global delete was introduced in 331f6a9e6, since we
now have to check bindings for presence in the global environment every
time anyway.

Since the bytecode VM now has fast GetGlobal in most cases, let's not
even worry about this and just remove the unhelpful "optimization".

In fact, removing this is actually an *optimization*, since we avoid
a redundant has_binding() check on every global variable access. :^)
2023-07-13 10:56:59 +02:00
Andreas Kling
9e468579ce LibJS/Bytecode: Use malloc instead of mmap for BasicBlock buffers
Using mmap was quite punishing on inputs with lots of basic blocks,
such as test262 tests with eval() in a loop that goes 64k times..

~27% speed-up on language/literals/regexp/S7.8.5_A2.1_T2.js but
presumably everything everywhere will benefit from this. :^)
2023-07-13 10:19:10 +02:00
Andreas Kling
acd8c94e88 LibJS/Bytecode: Make Bytecode::Register constexpr
A trivial change for 2% speed-up on Kraken/ai-astar.js :^)
2023-07-12 22:57:03 +02:00
Aliaksandr Kalenik
3661d674ae LibJS: Add optimized GetGlobal instruction to access global variables
Using a special instruction to access global variables allows skipping
the environment chain traversal for them and going directly to the
module/global environment. Currently, this instruction only caches the
offset for bindings that belong to the global object environment.
However, there is also an opportunity to cache the offset in the global
declarative record.

This change results in a 57% increase in speed for
imaging-gaussian-blur.js in Kraken.
2023-07-12 16:03:16 +02:00
Andreas Kling
cf6792ec40 LibJS/Bytecode: Invalidate inline caches on unique shape mutation
Since we can't rely on shape identity (i.e its pointer address) for
unique shapes, give them a serial number that increments whenever a
mutation occurs.

Inline caches can then compare this serial number against what they
have seen before.
2023-07-11 00:14:50 +02:00
Andreas Kling
e0b2757f95 LibJS/Bytecode: Always make own properties in object expressions
When building an object from an object expression, we don't want to
go through the full property setting machinery. This patch adds a new
PropertyKind::DirectKeyValue for PutById which guarantees that the
property becomes an own property.

This fixes an issue where setting the "__proto__" property in object
expressions wasn't working right.

12 new passes on test262. :^)
2023-07-10 09:29:54 +01:00
Andreas Kling
de8e4b1853 LibJS/Bytecode: Cache object own property accesses
The instructions GetById and GetByIdWithThis now remember the last-seen
Shape, and if we see the same object again, we reuse the property offset
from last time without doing a new lookup.

This allows us to use Object::get_direct(), bypassing the entire lookup
machinery and saving lots of time.

~23% speed-up on Kraken/ai-astar.js :^)
2023-07-09 12:54:06 +02:00
Aliaksandr Kalenik
167495b87b LibJS/Bytecode: Always return false on attempt to delete local variable
Since it is not possible for delete operator to return true when it is
applied to local variable, DeleteVariable can safely always return
false for locals.

This also fixes operators/delete-local-variable.js in test-js.
2023-07-09 06:26:10 +02:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Timothy Flynn
2f1d6c0b9a LibJS/Bytecode: Ensure we do not generate bytecode for super expressions
Similar to AST mode, super expressions are handled elsewhere.
2023-07-07 18:11:51 +02:00
Timothy Flynn
23daf5097b LibJS/Bytecode: Generate bytecode for deleting super properties 2023-07-07 18:11:51 +02:00
Timothy Flynn
0d50e5eeee LibJS/Bytecode: Extract code to generate a super reference to a helper
This code is already repeated twice, and would be repeated a third time
for the `delete` operator.
2023-07-07 18:11:51 +02:00
Timothy Flynn
621d55ad65 LibJS/Bytecode: Do note coerce referenced values to an Object too early
Converting a base value to an Object is performed by Reference::delete_.
Doing this early in the bytecode operator could be observable, although
it would likely be the first observable step in Reference::delete_
anyways. This will just align these operators with upcoming operators
for super references, where doing this coercion first will be observable
(we need to throw an exception for deleting a super property before this
coercion).
2023-07-07 18:11:51 +02:00
Daniel Bertalan
c6c20d3bf3 LibJS/Bytecode: Use CopyDataProperties AO for destructuring
The previous ad-hoc implementation ignored the non-enumerable flag.
2023-07-06 12:11:02 +01:00
Daniel Bertalan
b39d8af5a6 LibJS/Bytecode: Remove redundant property uniqueness check
This invariant is enforced by virtue of `items` being a HashTable.
2023-07-06 10:30:42 +02:00
Daniel Bertalan
d0dce5c60f LibJS/Bytecode: Handle shadowed non-enumerable properties in for-in
Invariants 5 and 6 of the `EnumerateObjectProperties` AO mean that we
must not include an enumerate property if there is a non-enumerable
property higher up the prototype chain with the same name. The previous
implementation did not adhere to this, as `EnumerableOwnPropertyNames`
does not carry information about present but non-enumerable properties.
2023-07-06 10:30:42 +02:00
Luke Wilde
442ca4f9b4 LibJS: Avoid RequireObjectCoercible when creating super references
This is part of an old normative change that happened soon after
Andreas made `super` closer to spec in 1270df2.
See https://github.com/tc39/ecma262/pull/2267/

This was introduced into bytecode by virtue of copy and paste :^)

Bytecode results:
Summary:
    Diff Tests:
        +2     -2 
2023-07-06 08:54:46 +02:00
Luke Wilde
b271d9a6bf LibJS/Bytecode: Use proper this for receiver in get/set for super expr
Summary:
    Diff Tests:
        +14     -2     -12 📝
2023-07-06 08:54:46 +02:00
Aliaksandr Kalenik
ae3a7fd4b8 LibJS: Update bytecode generator to use local variables
- Update ECMAScriptFunctionObject::function_declaration_instantiation
  to initialize local variables
- Introduce GetLocal, SetLocal, TypeofLocal that will be used to
  operate on local variables.
- Update bytecode generator to emit instructions for local variables
2023-07-05 21:03:01 +02:00
Aliaksandr Kalenik
7765ebb5f2 LibJS+LibWeb: Plumb local variables names to ECMAScriptFunctionObject
Saving vector of local variables names in ECMAScriptFunctionObject
will allow to get a name by index in case message of ReferenceError
needs to contain a variable name.
2023-07-05 21:03:01 +02:00
Aliaksandr Kalenik
c734f2b5e6 LibJS: Use Identifier to represent name of ClassExpression
By using Identifier class to represent the name of a class expression,
it becomes possible to consistently store information within the
identifier object, indicating whether the name refers to a local
variable or not.
2023-07-05 21:03:01 +02:00
Andreas Kling
dfd0942e41 LibJS/Bytecode: Clear accumulator before entering for body
2 new passes on test262. :^)
2023-07-05 15:39:25 +02:00
Andreas Kling
24b815d4a0 LibJS/Bytecode: Clear accumulator before entering while body
2 new passes on test262. :^)
2023-07-05 15:39:25 +02:00
Andreas Kling
b14032bbfa LibJS/Bytecode: Leave for in and for of with right completion value
14 new passes on test262. :^)
2023-07-05 15:39:25 +02:00
Andreas Kling
7430dee5cf LibJS/Bytecode: Make ClassDeclaration not clobber the accumulator
2 new passes on test262. :^)
2023-07-05 15:39:25 +02:00
Andreas Kling
e87d84f883 LibJS/Bytecode: Support in binary operator for private fields
11 new passes on test262. :^)
2023-07-05 15:39:25 +02:00
Hendiadyoin1
b26dad3d62 LibJS: Handle Calls argument range during EliminateLoads pass
Otherwise we could forget to emit stores those registers, thinking that
they are only directly accessed.
2023-07-03 16:55:13 +02:00
Daniel Bertalan
d165590809 LibJS/Bytecode: Do not coerce the receiver to Object for internal_set
This makes the behavior of `Symbol` correct in strict mode, wherein if
the receiver is a symbol primitive, assigning new properties should
throw a TypeError.
2023-07-02 22:08:48 +01:00
Andreas Kling
c37b204ce1 LibJS/Bytecode: Add Call opcode for fixed-argument-count calls
This avoids the overhead of allocating a new Array on every function
call, saving a substantial amount of time and avoiding GC thrash.

This patch only makes use of Op::Call in CallExpression. There are other
places we should codegen this op. We should also do the same for super
expression calls.

~5% speed-up on Kraken/stanford-crypto-ccm.js
2023-07-02 18:30:02 +02:00
Andreas Kling
7eb87dec9f LibJS/Bytecode: Rename Call and SuperCall to &WithArgumentArray
Forcing every function call to allocate a new Array just to accommodate
spread parameters is not very nice, so let's start moving towards making
this a special case rather than the general (and only) case.
2023-07-02 18:30:02 +02:00
Andreas Kling
dc884aa0d3 LibJS/Bytecode: Remove unnecessary variable environment stack
The var environments will unwind as needed with the ExecutionContext
and there's no need to include it in the unwind info.

We still need to do this for lexical environments though, since they
can have short local lifetimes inside a function.
2023-07-02 18:30:02 +02:00
Andreas Kling
fb979dcf34 LibJS/Bytecode: Make Bytecode::Interpreter participate in GC marking
Since the relationship between VM and Bytecode::Interpreter is now
clear, we can have VM ask the Interpreter for roots in the GC marking
pass. This avoids having to register and unregister handles and
MarkedVectors over and over.

Since GeneratorObject can also own a RegisterWindow, we share the code
in a RegisterWindow::visit_edges() helper.

~4% speed-up on Kraken/stanford-crypto-ccm.js :^)
2023-07-02 14:50:02 +02:00
Andreas Kling
cea2071349 LibJS/Bytecode: Infer name of anonymous exported classes when possible
5 new passes on test262. :^)
2023-07-02 12:18:25 +02:00
Andreas Kling
b0ae1e80fb LibJS/Bytecode: Support using MemberExpression as rest property
Also, don't assert while dumping an AST with this construct.

7 new passes on test262. :^)
2023-07-02 11:53:10 +02:00
Daniel Bertalan
0df7255fe7 LibJS/Bytecode: Do not clobber completion value with VariableDeclaration
While the completion value of a variable declaration is specified to be
empty, we might already have a completion value in the accumulator from
a previous statement. Preserve it so as to avoid clobbering it.

This fixes 6 tests on test262.
2023-07-02 10:54:35 +02:00
Andreas Kling
bd2c3ace68 LibJS/Bytecode: Make sure empty with statement results in undefined
2 new passes on test262. :^)
2023-07-02 10:54:28 +02:00
Andreas Kling
1efe4b58aa LibJS/Bytecode: Store current interpreter register window as a Span
This avoids a bunch of indirections on every single register access.

~17% speed-up on Kraken/stanford-crypto-aes.js :^)
2023-07-01 20:29:12 +01:00
Aliaksandr Kalenik
1550e7c421 LibJS: Stop using execute_ast_node in NewClass instruction
This change replaces usage of `execute_ast_node` to evaluate super
expression in NewClass by generating instructions instead.
2023-06-29 07:14:14 +02:00
Hendiadyoin1
37067cf3ca LibJS: Use the IdentifierTable for NewFunction and NewClass lhs names
This makes them trivially copyable, which is an assumption multiple
optimizations use when rebuilding the instruction stream.

This fixes most optimized crashes in the test262 suite.
2023-06-29 05:32:08 +02:00
Daniel Bertalan
50d6b1ba19 LibJS/Bytecode: Keep completion value of switch case if falling through
We do this by moving the `LoadImmediate undefined` instruction to a
separate basic block which jumps to the case's block unconditionally.
We enter a case initially using this wrapper, but when falling through,
we directly jump to the next case's block.
2023-06-28 12:30:23 +02:00
Daniel Bertalan
fda619c7c2 LibJS/Bytecode: Implement Annex B Initializers in ForIn Statement Heads 2023-06-28 10:42:32 +02:00
Daniel Bertalan
fc7de74b12 LibJS/Bytecode: Improve export statement handling
This adds support for exporting class expressions, which was previously
TODO'd.

We now correctly set the binding name of exports to `"*default*"` if
they are unnamed. I'm not sure what the difference between the
`InitializationMode` kinds is, but using `Initialize` fixes a bunch of
tests.

Note that some export tests (e.g. `eval-export-dflt-expr-cls-named.js`)
still fail, as we don't set the "name" property of exported classes
correctly.

176 new passes on test262
2023-06-28 05:13:52 +02:00
Daniel Bertalan
11a7014b4e LibJS/Bytecode: Handle ImportStatement in codegen
There is nothing to do here at runtime as imports are handled in
`Interpreter::run`.
2023-06-27 21:10:08 +02:00
Luke Wilde
363bf114c0 LibJS/Bytecode: Implement for await of
Summary:
    Diff Tests:
        +391    +15    +2 💥️    -408 📝
2023-06-27 21:04:22 +02:00
Andreas Kling
aec3d9d84e LibJS/Bytecode: Prefer alias over name in object pattern bindings
10 new passes on test262. :^)
2023-06-27 15:08:14 +02:00