Skip to content

Draft function call context schemas#154

Draft
gnidan wants to merge 18 commits intomainfrom
call-return
Draft

Draft function call context schemas#154
gnidan wants to merge 18 commits intomainfrom
call-return

Conversation

@gnidan
Copy link
Member

@gnidan gnidan commented May 29, 2025

No description provided.

@github-actions
Copy link
Contributor

github-actions bot commented May 29, 2025

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://ethdebug.github.io/format/pr-preview/pr-154/

Built to branch gh-pages at 2026-03-11 09:25 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

gnidan added 12 commits March 11, 2026 03:11
Introduce a shared context/function schema defining identifier,
declaration, and type properties (mirroring Variable's pattern)
and compose it into invoke, return, and revert via allOf. Switch
return and revert from additionalProperties to
unevaluatedProperties to support allOf composition.
Wrap the Monaco-based Playground component in BrowserOnly with
React.lazy so it only loads client-side, preventing SSR-related
initialization errors that caused [object Object] crashes on refresh.
Move function call lifecycle contexts (invoke, return, revert) into
a function/ subcategory and extract shared identity fields
(identifier, declaration, type) into a base function schema that
each context extends via $ref.
Reduces ambiguity: `call` could mean any function call, and
`internal` vs `create` doesn't clearly convey the mechanism.
The new names (jump/message/create) map directly to the three
EVM invocation mechanisms.

Also enforces mutual exclusivity of delegate/static on external
calls via `not: required: [delegate, static]`.
Frame descriptions from the perspective of contexts marking
instructions rather than "representing" things. A context
indicates association with a function lifecycle event; it does
not represent the event itself.
Each example now describes a concrete EVM execution scenario:
which instruction the context marks, what the stack and memory
layout looks like, and why each pointer points where it does.
Introduce schema:ethdebug/format/type/specifier to formalize
the "type or type reference" pattern. Update type wrapper,
variables, and doc pages to use the new schema instead of
inline oneOf/if-then discrimination. Remove the now-unnecessary
allow-list entry for the function context schema.
gnidan added 6 commits March 11, 2026 03:40
Add Type.Reference, Type.Specifier, and type guards for the
new function call context schemas (invoke, return, revert).

- Type.Reference: { id: string | number } for type references
- Type.Specifier: Type | Reference union (matches type/specifier schema)
- Context.Function.Identity: shared function identity fields
- Context.Invoke: internal calls, external calls, contract creation
- Context.Return: function return with data and optional success
- Context.Revert: function revert with optional reason/panic
- Update Variable.type to accept Type.Specifier (was Type only)
- Update Type.Wrapper to use Type.Specifier
Add debug context annotations for function call boundaries
using the typed Format.Program.Context.Invoke and
Context.Return interfaces:

- Invoke context on caller's JUMP instruction with target
  pointer and argument group pointers (stack slots)
- Return context on continuation JUMPDEST with data pointer
  to return value at stack slot 0
- Invoke context on callee entry JUMPDEST with target and
  argument pointers

Includes tests verifying context emission for single-arg,
multi-arg, nested, and void function call scenarios.
The call setup sequence (POP cleanup, PUSH return address,
MSTORE, push arguments, PUSH function address) was using
remark-only debug contexts, leaving these instructions
unmapped in tracing output. Now threads the call
terminator's operationDebug (which carries the source
code range for the call expression) through all setup
instructions, matching how other instruction generators
use operationDebug.
* Add function call tracing documentation

Add invoke/return/revert context documentation across concept,
reference, and spec pages:

- concepts/programs.mdx: new "Function call contexts" section
  explaining the three context types with a SchemaExample
- tracing.mdx: walkthrough of tracing through an internal function
  call (Adder contract), plus external call and revert examples
- Spec pages: added intro prose to function.mdx, return.mdx,
  revert.mdx

* Make function call tracing example interactive

Replace the static BUG code block with an interactive TraceExample
component that lets readers compile and step through the Adder
contract, seeing invoke/return contexts at function boundaries.

Static SchemaExample blocks are kept for the narrative walkthrough
and for external call/revert examples (which BUG can't demonstrate).

* Fix BUG source indentation in tracing examples

Add 2-space indentation inside block bodies (storage, create, code,
if) to match the canonical style used in .bug example files.

* Revert BUG indentation to match prettier formatting

Prettier strips indentation inside template literal strings in MDX
JSX props. Revert to the unindented style that prettier enforces.
* bugc: add debug contexts to all remaining unmapped bytecodes

Thread remark/code contexts through all compiler-generated
instructions that previously lacked debug info:

- Free memory pointer initialization (remark)
- Return value spill after call continuation (call expr source range)
- STOP guard between main and user functions (remark)
- Function prologue MSTORE for param storage (thread existing remark)
- Function prologue return PC save sequence (thread existing remark)
- Deployment wrapper CODECOPY+RETURN (remark)

All 82 instructions across runtime and create programs now
carry debug contexts (previously 22 were unmapped).

* bugc: add code contexts with source ranges to compiler-generated instructions

Add source location info (loc, sourceId) to Ir.Function so EVM
codegen can build code contexts for compiler-generated instructions.

Instructions that map to a source location now use gather contexts
combining both a remark (for debugger tooling) and a code context
(for source highlighting):
- Free memory pointer init → code block / create block range
- Function prologue (param stores, return PC save) → function decl range
- STOP guard → code block range

Deployment wrapper remains remark-only (no corresponding source).
Return value spill already had correct source mapping (call expr).
* Add call stack breadcrumb and call info panel components

Surface invoke/return/revert context information in the
trace viewer: a breadcrumb showing the current call stack,
and a panel showing call details with async-resolved
pointer ref values.

New components: CallStackDisplay, CallInfoPanel
New utilities: extractCallInfoFromInstruction, buildCallStack,
  buildPcToInstructionMap
New types: CallInfo, CallFrame, ResolvedCallInfo,
  ResolvedPointerRef

* Integrate CallStackDisplay and CallInfoPanel into TraceViewer

The components were exported from programs-react but never
rendered in the web package's TraceViewer. Add them to the
layout: call stack breadcrumb in the header, call info
panel at the top of the right sidebar.

* Add call stack breadcrumb and call info banner to TraceDrawer

The deploy preview uses TraceDrawer (not TraceViewer) for the
interactive trace playground. Add call context display directly
to TraceDrawer: a breadcrumb bar showing nested call frames
with clickable navigation, and a colored banner showing
invoke/return/revert status at the current step.

* Show always-visible call stack and fix duplicate frame bug

- Call stack bar now always visible with "(top level)" empty
  state so users know the feature exists
- Fix duplicate call stack frames: compiler emits invoke
  context on both the caller JUMP and callee entry JUMPDEST,
  so skip push if top frame already matches the same call
- Applied fix to both TraceDrawer and programs-react utility
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.

1 participant