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

Add Instruction and InstructionIterator #3201

Merged
merged 1 commit into from
Sep 6, 2023
Merged

Conversation

HalidOdat
Copy link
Member

This PR adds a fat enum that represents a full instruction (opcode + operands) and an iterator that takes bytecode and produces instructions.

I implemented something like this in #3037, this PR just extracts and refines it.

Why is this useful/needed?

  • It allows us to iterate over instructions without worrying, whether we are reading the operands correctly. Currently we do the same thing in instruction_operands() and flowgraph generation, this is duplicate code and can easily lead to mistakes (also doing it in Implement control flow graph construction #3037 )
  • Extracting the operands is harder when manually accessing bytecode.
  • If we have a list of instructions it's easier to do changes in it.

Note: This is not intended to replace the compact bytecode representation, that is optimized for execution and storage.

... This also makes it easier to implement an bytecode size optimization on operands, that I'm working on ;)

@HalidOdat HalidOdat added enhancement New feature or request Internal Category for changelog labels Aug 5, 2023
@github-actions
Copy link

github-actions bot commented Aug 5, 2023

Test262 conformance changes

Test result main count PR count difference
Total 95,368 95,368 0
Passed 75,046 75,046 0
Ignored 19,302 19,302 0
Failed 1,020 1,020 0
Panics 0 0 0
Conformance 78.69% 78.69% 0.00%

@codecov
Copy link

codecov bot commented Aug 5, 2023

Codecov Report

Merging #3201 (cfe700b) into main (dda713d) will decrease coverage by 0.09%.
The diff coverage is 1.88%.

@@            Coverage Diff             @@
##             main    #3201      +/-   ##
==========================================
- Coverage   50.42%   50.34%   -0.09%     
==========================================
  Files         436      436              
  Lines       42549    42618      +69     
==========================================
  Hits        21457    21457              
- Misses      21092    21161      +69     
Files Changed Coverage Δ
boa_engine/src/vm/call_frame/mod.rs 90.47% <ø> (ø)
boa_engine/src/vm/code_block.rs 52.99% <0.00%> (-1.51%) ⬇️
boa_engine/src/vm/flowgraph/mod.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/mod.rs 62.50% <ø> (ø)
boa_engine/src/vm/opcode/mod.rs 7.03% <ø> (-62.20%) ⬇️
boa_engine/src/bytecompiler/mod.rs 66.58% <100.00%> (ø)
boa_engine/src/vm/opcode/control_flow/jump.rs 92.68% <100.00%> (ø)

@HalidOdat HalidOdat force-pushed the instruction-iterator branch 2 times, most recently from b952db4 to 776a25b Compare August 5, 2023 06:09
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Really nice improvement! It simplifies our logic a LOT.
Any plans for extending it to Operation implementers or is it just not worth?

boa_engine/src/vm/opcode/mod.rs Outdated Show resolved Hide resolved
@HalidOdat HalidOdat force-pushed the instruction-iterator branch from 776a25b to 9922448 Compare August 6, 2023 04:03
@HalidOdat
Copy link
Member Author

HalidOdat commented Aug 6, 2023

Any plans for extending it to Operation implementers or is it just not worth?

No, this representation is intended for easier bytecode analysis, not really execution, the compact bytecode version is smaller and faster.

@HalidOdat HalidOdat requested a review from a team August 12, 2023 14:13
@HalidOdat HalidOdat added this to the v0.18.0 milestone Aug 12, 2023
}
}

macro_rules! generate_opcodes {
Copy link
Member

Choose a reason for hiding this comment

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

Should we start writing implementation notes to break down macros?

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.

Overall looks good to me. Nice work! Just one thought I had while reviewing the macro.

@HalidOdat HalidOdat force-pushed the instruction-iterator branch from 9922448 to b2a8126 Compare August 24, 2023 01:50
@jasonwilliams
Copy link
Member

Whats the affect on performance with this change?

@HalidOdat
Copy link
Member Author

HalidOdat commented Sep 5, 2023

Whats the affect on performance with this change?

There is no change in performance, this is doesn't change the way we execute bytecode. It only implements an iterator and the result being an Instruction (opcode + operands). For easier iteration of bytecode, without worrying about the size of operands.

@HalidOdat HalidOdat added this pull request to the merge queue Sep 6, 2023
Merged via the queue into main with commit 3ea0a77 Sep 6, 2023
@HalidOdat HalidOdat deleted the instruction-iterator branch September 7, 2023 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Internal Category for changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants