Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple Context from ByteCompiler #3829

Merged
merged 5 commits into from
Apr 28, 2024
Merged

Decouple Context from ByteCompiler #3829

merged 5 commits into from
Apr 28, 2024

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Apr 25, 2024

This PR removes the &mut Context field from the ByteCompiler making it possible to put the bytecompiler in its own crate (there is still work to move JsString and other parts to their own crate so they can be used it both crates, but this is a step in the right direction).

This also fixes the some failing eval test262 tests.
EDIT: Oops, Tested with an older version of test262 result, so no bonus passing tests 😅

TODO:

  • Clean-up and documentation of spec deviation

@HalidOdat HalidOdat added execution Issues or PRs related to code execution Internal Category for changelog labels Apr 25, 2024
Copy link

Test262 conformance changes

Test result main count PR count difference
Total 50,731 50,731 0
Passed 42,973 42,973 0
Ignored 1,395 1,395 0
Failed 6,363 6,363 0
Panics 18 18 0
Conformance 84.71% 84.71% 0.00%

@HalidOdat HalidOdat force-pushed the decuple-context-compiler branch 2 times, most recently from a46a04f to 9608fc5 Compare April 26, 2024 13:55
@HalidOdat HalidOdat requested a review from a team April 26, 2024 13:55
@HalidOdat HalidOdat added this to the v0.18.1 milestone Apr 26, 2024
@HalidOdat HalidOdat marked this pull request as ready for review April 26, 2024 13:55
@HalidOdat HalidOdat force-pushed the decuple-context-compiler branch 2 times, most recently from d69070a to 3896d78 Compare April 26, 2024 14:02
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple things I missed.

Sort of general question: did you happen to benchmark this? Was sort of curious what impact the new global opcodes have.

Also, would it make sense for the global opcodes to occur in the instantiation functions like in the spec vs. opcodes?

core/engine/src/bytecompiler/declarations.rs Outdated Show resolved Hide resolved
///
/// [spec]: https://tc39.es/ecma262/#sec-globaldeclarationinstantiation
#[cfg(feature = "annex-b")]
pub(crate) fn global_declaration_instantiation_context(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: Potentially move these out of bytecompiler to script

Now that these are separated, is there any need for these functions to still live in this module (especially if the bytecompiler is eventually moved to it's own crate).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we can put them in separate locations, the only reason I left them there was because the context and non-context variants are close to each other.

@HalidOdat
Copy link
Member Author

HalidOdat commented Apr 27, 2024

Sort of general question: did you happen to benchmark this? Was sort of curious what impact the new global opcodes have.

The opcodes execute only once in the execution of a script, when I checked for rust benchmarks as well as quickjs benchmarks I didn't notice any regressions.

Also, would it make sense for the global opcodes to occur in the instantiation functions like in the spec vs. opcodes?

The problem with this is that some functions need to already be compiled and instantiated to be put into the global object, that's why it's delayed when we execute the bytecode so we can separate them. It might be possible by having some post _context functions calls as well as pre calls (as we do now).

The main benefit to having opcodes for them (besides the complexity reduction) is reproducibility of CodeBlock execution, this will be needed when we implement CodeBlock serialization to disk and back, we wont need to store the AST (there is still work to be done for this, ideally all of the _context function should be converted to bytecode, but this is a separate issue, not related to splitting the bytecompiler into its own crate).

Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. :)

core/engine/src/bytecompiler/declarations.rs Outdated Show resolved Hide resolved
Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the above, I'm fine with merging this. Nice work on this! 😄

@HalidOdat HalidOdat added this pull request to the merge queue Apr 28, 2024
Merged via the queue into main with commit 6ee208f Apr 28, 2024
13 checks passed
@HalidOdat HalidOdat deleted the decuple-context-compiler branch April 28, 2024 11:53
@raskad raskad modified the milestones: v0.18.1, v0.19.0 Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
execution Issues or PRs related to code execution Internal Category for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants