Skip to content

Inline stack switching - #680

Merged
titzer merged 8 commits into
titzer:masterfrom
linxuanm:inline-stack-switching
Oct 19, 2026
Merged

titzer merged 8 commits into
titzer:masterfrom
linxuanm:inline-stack-switching

Conversation

@linxuanm

@linxuanm linxuanm commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@linxuanm
linxuanm marked this pull request as ready for review September 5, 2026 17:51
@linxuanm
linxuanm marked this pull request as draft September 16, 2026 18:03
@linxuanm
linxuanm force-pushed the inline-stack-switching branch from a11dcff to 369c040 Compare September 23, 2026 16:26
@linxuanm
linxuanm marked this pull request as ready for review September 23, 2026 18:07
Each `resume` site now records a per-pc handler table (suspend clauses
first, then switch clauses) built by the code validator and stored in
`FuncHandlerInfo.resume_sites`. When the interpreter or SPC resumes a
continuation it publishes that table and its tier on the parent
`NativeStack`, and the table is cleared when the child returns, is
unwound, or suspends. The SPC fills in each suspend clause's stub
address after compilation so generated code can redirect a parent frame
without a runtime call.

Continuations are now consumed directly from their value-stack slot
instead of being popped into an XMM register, and the stack state store
is a byte store so it does not clobber the neighbouring byte fields.
`NativeStack` shadow-checks every runtime handler lookup against the
published table so mismatches fail loudly while the tables are new.
`suspend` compiled by the SPC no longer calls into the runtime. The
generated code walks the parent chain comparing the tag against each
stack's published handler table, redirects the handling frame to the
matching clause (its SPC stub, or the interpreter suspend entry with the
frame's ip and stp rewritten), copies the payload and the continuation
onto the handler's value stack, marks the current stack suspended and
enters the handler stack directly.
`switch` compiled by the SPC consumes the target continuation, finds the
switch clause in the published handler tables, splices the target's
stack chain under that handler in place of the current chain (including
the return route through the parent's rsp pointer), passes the payload
and the continuation of the current stack to the target and enters it,
all without a runtime call.
@linxuanm
linxuanm force-pushed the inline-stack-switching branch from a3e836b to ab1ff15 Compare October 13, 2026 18:05
@linxuanm

Copy link
Copy Markdown
Contributor Author

I just rebased + inlined assembly helpers!

@titzer titzer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm going to merge and refactor this under a working tree.

@titzer
titzer merged commit 5d5f84a into titzer:master Oct 19, 2026
15 checks passed
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.

2 participants