-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Refactor vm calling convention to allow locals #3496
Conversation
Test262 conformance changes
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #3496 +/- ##
==========================================
- Coverage 48.88% 48.87% -0.01%
==========================================
Files 471 471
Lines 48492 48499 +7
==========================================
+ Hits 23705 23706 +1
- Misses 24787 24793 +6 ☔ View full report in Codecov by Sentry. |
93d7a48
to
a7aea59
Compare
4f33a15
to
1bd91eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Always glad to see the size of CallFrame
go down! 😄 Had a couple small doc nits and one general thought that I had when reviewing.
/// The position of the elements are relative to the [`CallFrame::fp`]. | ||
/// The position of the elements are relative to the [`CallFrame::fp`] (frame pointer). | ||
/// | ||
/// ```text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General thought on this: Would it be better to store this fp
as a sp
(although I'm not sure it's a true stack pointer, maybe lp
for local pointer), and keep the fp
and make up the memory by computing the argument count via self.sp - self.fp - Self::FUNCTION_PROLOGUE
or would computing the args count be more inefficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to store this
fp
as asp
I don't think calling it sp would be correct, sp is implict in the stack vec itself that being the length (pointing to the position that the next value will be put).
Native calling conventions the arguments passed are not part of the call frame of the callee. But it doesn't really matter, since we can make our own convention. 😄
The biggest reason for fp
change is to reduce the computation needed to access locals before we would have to do fp + FUNCTION_PROLOGUE + arg_count + local_offset
with this change we only do fp + local_offset
.
I kind of hinted at the next change, switching to a register based VM 😄 Registers will be used extensively so we want fast access. I think it's a good time to switch before we are too dependent on the stack version, while working on #3037 Modeling data flow of stack based VMs is much harder, and was conflicted whether to continue development, since it would make switching much harder and it will have to be redone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yepp! I noticed the register based shift!
Just for clarity, I meant keep fp
and then local pointer
/sp
(whatever we call it) in exchange for argument_count
. It would then exchanging restore_fp
in exchange for calculating argument_count
. I think we still compute the argument_start anyways, which can then just be fp + FUNCTION_PROLOGUE
over fp - argument_count
.
// Current dumbed down version of `CallFrame`
struct DummyFrame {
fp: u32,
argument_count: u32
}
// New version
struct NewFrame {
fp: u32,
lp: u32
}
// argument_count
impl NewFrame {
// Trade off would be that we compute arg_count over compute fp
fn arg_count(&self) -> u32 {
self.lp - self.arg_start()
}
// Throwing this in as a utility
fn arg_start(&self) -> u32 {
self.fp + FUNCTION_PROLOGUE
}
}
The idea was that maybe we save a bit of compute by not having to use restore_fp
in exchange for calculating the arg_count. At least that was the thought I had (could be off on that), but thought I'd run it by you nonetheless. Of course, if that would somehow undercut the register shift you had in mind, then completely disregard this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I decided to leave this for after we implement the register VM, added a todo so I don't forget 😅 .
I renamed the fp into rp (register pointer), calling it register pointer, instead of local pointer for consistency with the registers that will be added into the future.
1bd91eb
to
887a3f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this!
This PR makes storing locals after
fp
much easier by moving thefp
at the end of the stack that the caller sets up, making the frame pointer the in the middle, the locals start at fp and accessing the caller setup values we offset back instead.This adds a local ( /register 😉 ) count variable to
CodeBlock
.Checkout
call_frame.rs
for the new calling convention.This makes #3194 easier and allows us to move stuff from the call frame that is only for a specific type of function (like
async
promise capability or generator function) reducing the size of the call frame and only paying for things the user uses.Moves async generator object out of
CallFrame
to the stack. Reducing the usage of memory of a CallFrame for non-async-generator functions.