Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/bugc/src/evmgen/call-contexts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ code {
expect(typeof invoke.declaration!.range!.length).toBe("number");

// Target should be a code pointer (not stack)
expect(Pointer.Region.isCode(call.target.pointer)).toBe(true);
expect(call.target).toBeDefined();
expect(Pointer.Region.isCode(call.target!.pointer)).toBe(true);

// Caller JUMP should NOT have argument pointers
// (args live on the callee JUMPDEST invoke context)
Expand Down Expand Up @@ -156,7 +157,8 @@ code {
expect(call.identifier).toBe("add");

// Target should be a code pointer
expect(Pointer.Region.isCode(call.target.pointer)).toBe(true);
expect(call.target).toBeDefined();
expect(Pointer.Region.isCode(call.target!.pointer)).toBe(true);

// Should have argument pointers matching
// function parameters
Expand Down
2 changes: 2 additions & 0 deletions packages/bugc/src/evmgen/generation/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ function patchInvokeInContext(
const offset = functionRegistry[invoke.identifier];
if (offset === undefined) return;

if (!invoke.target) return;

const ptr = invoke.target.pointer;
if (Format.Pointer.Region.isCode(ptr)) {
ptr.offset = `0x${offset.toString(16)}`;
Expand Down
3 changes: 2 additions & 1 deletion packages/bugc/src/evmgen/optimizer-contexts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ code { r = count(0, 5); }`;
expect(Invocation.isInternalCall(invocation)).toBe(true);
const internalCall =
invocation as Format.Program.Context.Invoke.Invocation.InternalCall;
const invokeTarget = internalCall.target.pointer;
expect(internalCall.target).toBeDefined();
const invokeTarget = internalCall.target!.pointer;
expect(invokeTarget).toBeDefined();
expect(
"offset" in invokeTarget ? invokeTarget.offset : undefined,
Expand Down
5 changes: 2 additions & 3 deletions packages/format/src/types/program/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export namespace Context {
export namespace Invocation {
export interface InternalCall extends Function.Identity {
jump: true;
target: Function.PointerRef;
target?: Function.PointerRef;
arguments?: Function.PointerRef;
}

Expand All @@ -180,8 +180,7 @@ export namespace Context {
!!value &&
"jump" in value &&
value.jump === true &&
"target" in value &&
Function.isPointerRef(value.target) &&
(!("target" in value) || Function.isPointerRef(value.target)) &&
(!("arguments" in value) || Function.isPointerRef(value.arguments));

export interface ExternalCall extends Function.Identity {
Expand Down
9 changes: 9 additions & 0 deletions packages/web/spec/program/context/function/invoke.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ caller's JUMP has already consumed the destination from the stack, so
pointer slot values reflect the post-JUMP layout. The target points
to a code location and arguments are passed on the stack.

The `target` field is optional. It may be omitted when there is no
meaningful code pointer to record — most notably at the first
instruction of an inlined function body, where the inlining pass
has elided the JUMP that would normally carry the target. The
callee identity (`identifier`, `declaration`, `type`) remains
meaningful in this case; a sibling `transform: ["inline"]` key
on the same context indicates that the call was inlined rather
than physically invoked.

<SchemaViewer
schema={{ id: "schema:ethdebug/format/program/context/function/invoke" }}
pointer="#/$defs/InternalCall"
Expand Down
29 changes: 28 additions & 1 deletion schemas/program/context/function/invoke.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ $defs:
description: |
Pointer to the target of the invocation. For internal
calls, this typically points to a code location.
Optional: may be omitted when there is no meaningful
target pointer to record, e.g., at the first
instruction of an inlined function body where the
inlining pass has elided the JUMP that would normally
carry this pointer. The callee identity
(`identifier`, `declaration`, `type`) is still
meaningful in this case.
properties:
pointer:
$ref: "schema:ethdebug/format/pointer"
Expand All @@ -107,7 +114,7 @@ $defs:
- pointer
additionalProperties: false

required: [jump, target]
required: [jump]

ExternalCall:
title: External call
Expand Down Expand Up @@ -284,6 +291,26 @@ examples:
location: stack
slot: 2

# -----------------------------------------------------------
# Inlined internal call: no target pointer
# -----------------------------------------------------------
# When the compiler inlines a function, the JUMP that would
# normally carry the invoke context has been elided — there
# is no physical call instruction and no code target to
# point at. The invoke context still records the callee's
# identity so the debugger can maintain a source-level call
# stack, and a `transform: ["inline"]` context (typically
# via `gather`) annotates the inlining.
- invoke:
identifier: "transfer"
declaration:
source:
id: 0
range:
offset: 128
length: 95
jump: true

# -----------------------------------------------------------
# External CALL: token.balanceOf(account)
# -----------------------------------------------------------
Expand Down
Loading