Skip to content

Add stack reconstruction methods for inlined contexts and wrap reconstruction points in SPC#595

Open
matthew-mojira wants to merge 14 commits intotitzer:masterfrom
matthew-mojira:pr/reconstruction
Open

Add stack reconstruction methods for inlined contexts and wrap reconstruction points in SPC#595
matthew-mojira wants to merge 14 commits intotitzer:masterfrom
matthew-mojira:pr/reconstruction

Conversation

@matthew-mojira
Copy link
Copy Markdown
Contributor

@matthew-mojira matthew-mojira commented Mar 23, 2026

This commit contains:

  • SinglePassCompiler.emitReconstructStackFrames which is the general purpose stack reconstruction method. It is called from withReconstructedInlinedFrames which wraps stack reconstruction (only needed if in an inlined context) around a piece of compiler code.
  • X86_64SpcModuleCode.reconstructInlinedFramesForTrap which reconstructs stack frames by bumping rsp and inserting fid and pc in the case of a hardware trap (which bypasses the usual stack reconstruction point for traps).
  • SPC code that requires the stack to be reconstructed around that point is wrapped with withReconstructedInlinedFrames

@matthew-mojira matthew-mojira marked this pull request as ready for review March 23, 2026 07:08
@matthew-mojira
Copy link
Copy Markdown
Contributor Author

I had "fun" using lambdas to make withReconstructedInlinedFrames feel like a syntax object.

@matthew-mojira matthew-mojira changed the title Reconstruct stack frames Add stack reconstruction methods for inlined contexts and wrap reconstruction points in SPC Mar 23, 2026
// Save mem0 base
masm.emit_mov_m_r(ValueKind.REF, frame.mem0_base_slot, mem_reg);

// use same vfp for all frames
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.

This is probably not right; you probably need to compute the right VFP for each frame as some delta from the current VFP.

Copy link
Copy Markdown
Contributor Author

@matthew-mojira matthew-mojira Mar 26, 2026

Choose a reason for hiding this comment

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

Done in e4b2d4a. Does this make sense?

@matthew-mojira
Copy link
Copy Markdown
Contributor Author

Sneaking in another change in 9bf2aeb to actually increment the metrics added in this PR.

@matthew-mojira
Copy link
Copy Markdown
Contributor Author

I separated reconstruction of a single frame in 7b8ae6d but it seems a little cumbersome to pass around pre-allocated registers and offsets like that. Is this what you had in mind?


// get functions[func_index] and save into frame
def wasm_func_slot = frame.wasm_func_slot.plus(frame_offset);
masm.emit_v3_Array_elem_r_ri(ValueKind.REF, wasm_func_reg, func_reg, spcFrame.func.func_index);
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 think this should be inst_reg instead of func_reg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it should. This is indexing into the array instance.functions

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