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

[Merged by Bors] - Implement CompletionRecords for the Vm #2618

Closed
wants to merge 23 commits into from

Conversation

nekevss
Copy link
Member

@nekevss nekevss commented Feb 26, 2023

This goal of this draft is to begin to implement CompletionRecords. This draft switches the Vm's Opcode from JsResult<ShouldExit> to CompletionType where the value is the top of the stack and returns a CompletionRecord. Primarily submitting as a draft for now for feedback.

It changes the following:

  • Adds CompletionRecord and CompletionType to Vm.
  • Changes the evaluation loop from while to loop that returns a CompletionType.
  • Adapts Context::run to handle CompletionType and CompletionRecord.
  • Removes FinallyAddresses in favor of just checking the env_stack.

@github-actions
Copy link

github-actions bot commented Feb 26, 2023

Test262 conformance changes

Test result main count PR count difference
Total 94,181 94,181 0
Passed 71,950 71,950 0
Ignored 17,218 17,218 0
Failed 5,013 5,013 0
Panics 12 12 0
Conformance 76.40% 76.40% 0.00%

@codecov
Copy link

codecov bot commented Feb 26, 2023

Codecov Report

Merging #2618 (34eccb4) into main (7f6af7b) will decrease coverage by 0.06%.
The diff coverage is 63.72%.

@@            Coverage Diff             @@
##             main    #2618      +/-   ##
==========================================
- Coverage   49.63%   49.57%   -0.06%     
==========================================
  Files         386      388       +2     
  Lines       39176    39280     +104     
==========================================
+ Hits        19445    19475      +30     
- Misses      19731    19805      +74     
Impacted Files Coverage Δ
boa_engine/src/builtins/async_generator/mod.rs 5.07% <0.00%> (ø)
boa_engine/src/builtins/generator/mod.rs 9.31% <0.00%> (ø)
boa_engine/src/vm/opcode/await_stm/mod.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/define/class/getter.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/define/class/method.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/define/class/setter.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/generator/mod.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/generator/yield_stm.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/get/generator.rs 0.00% <0.00%> (ø)
boa_engine/src/vm/opcode/get/private.rs 0.00% <0.00%> (ø)
... and 65 more

... and 13 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jedel1043
Copy link
Member

Nice work! Does this close #1542, #1543 and #1544? If that's the case, it would be good to link them :)

@nekevss
Copy link
Member Author

nekevss commented Feb 26, 2023

Does this close #1542, #1543 and #1544?

I think it does in a way. It's a bit hard to say as I think those issues may predate the move to the VM.

It does have Context::run return a CompletionRecord, but it is only a CompletionRecord and not a JsResult<CompletionRecord>, which is one of the main reasons I submitted this as a draft first for feedback. Also, the Operations trait would now return a CompletionType where the top of the stack would essentially be the [[value]] field.

Essentially, this should allow us to use JsResult<JsValue> for any method or operation that returns only a Normal or Throw Completion. But for the operations or value that can return an abrupt completion, we should be able to use the CompletionRecord.

Comment on lines 38 to 34
pub(crate) fn convert(self, context: &mut Context<'_>) -> JsResult<JsValue> {
match self.completion_type {
CompletionType::Throw => {
let err = JsError::from_opaque(self.value);
if let Ok(native) = err.try_native(context) {
Err(JsError::from_native(native))
} else {
Err(err)
}
}
_ => Ok(self.value),
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to instead make CompletionRecord something like:

enum CompletionRecord {
    Normal(JsValue),
    Return(JsValue),
    Throw(JsError)
}

?

That way we don't need to convert JsErrors to opaque errors back and forth.

@@ -0,0 +1,24 @@
use crate::{JsError, JsResult, JsValue};

#[derive(Debug, Clone)]
Copy link
Member

@HalidOdat HalidOdat Mar 8, 2023

Choose a reason for hiding this comment

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

Suggested change
#[derive(Debug, Clone)]
// spec: <https://tc39.es/ecma262/#sec-completion-record-specification-type>
#[derive(Debug, Clone)]

Would be nice to have a link to spec :)

}

/// This function will consume the current `CompletionRecord` and return a `JsResult<JsValue>`
#[allow(clippy::missing_const_for_fn)]
Copy link
Member

@HalidOdat HalidOdat Mar 8, 2023

Choose a reason for hiding this comment

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

Why is this lint allowed? If there is a valid reason could we have a comment explaining it :)

} else {
Err(JsNativeError::typ()
return Err(JsNativeError::typ()
Copy link
Member

Choose a reason for hiding this comment

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

Why explicitly use return keyword here?

@HalidOdat
Copy link
Member

Looks good! Great work @nekevss , Will try to do a more thorough review tomorrow! :)

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

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

Looks good to me! :)

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.

I like the new logic.
If @jedel1043 agrees and you want to merge this as is lets do it @nekevss.

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.

Good work! The changes look almost perfect :)

boa_engine/src/vm/completion_record.rs Show resolved Hide resolved
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.

Looks great to me!

@nekevss nekevss added this to the v0.17.0 milestone Mar 16, 2023
@nekevss
Copy link
Member Author

nekevss commented Mar 16, 2023

bors r+

bors bot pushed a commit that referenced this pull request Mar 16, 2023
<!---
Thank you for contributing to Boa! Please fill out the template below, and remove or add any
information as you feel necessary.
--->

This goal of this draft is to begin to implement `CompletionRecords`. This draft switches the `Vm`'s `Opcode` from `JsResult<ShouldExit>` to `CompletionType` where the value is the top of the stack and returns a `CompletionRecord`. Primarily submitting as a draft for now for feedback. 

It changes the following:

- Adds `CompletionRecord` and `CompletionType` to `Vm`.
- Changes the evaluation loop from `while` to `loop` that returns a `CompletionType`.
- Adapts `Context::run` to handle `CompletionType` and `CompletionRecord`.
- Removes `FinallyAddresses` in favor of just checking the `env_stack`.
@bors
Copy link

bors bot commented Mar 16, 2023

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Implement CompletionRecords for the Vm [Merged by Bors] - Implement CompletionRecords for the Vm Mar 16, 2023
@bors bors bot closed this Mar 16, 2023
@bors bors bot deleted the impl-completion-records branch March 16, 2023 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants