Skip to content

feat: add debug function index lookup - #14128

Open
smarcd wants to merge 1 commit into
bytecodealliance:mainfrom
smarcd:codex/debug-function-index
Open

feat: add debug function index lookup#14128
smarcd wants to merge 1 commit into
bytecodealliance:mainfrom
smarcd:codex/debug-function-index

Conversation

@smarcd

@smarcd smarcd commented Aug 12, 2026

Copy link
Copy Markdown

Adds a host-only inverse to Instance::debug_function for debugging tools that need to serialize a same-instance funcref as a Wasm function index. The lookup never exposes VM pointers and returns None when guest debugging is disabled or the function is not part of the instance.\n\nTests cover private functions, imports, an unrelated host function, and disabled guest debugging.

@smarcd
smarcd requested review from a team as code owners August 12, 2026 17:14
@smarcd
smarcd requested review from alexcrichton and removed request for a team August 12, 2026 17:14
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:meta Everything related to the meta-language. cranelift:module isle Related to the ISLE domain-specific language wasmtime:c-api Issues pertaining to the C API. wasmtime:docs Issues related to Wasmtime's documentation labels Aug 12, 2026
@github-actions

Copy link
Copy Markdown

Subscribe to Label Action

cc @cfallin, @fitzgen

Details This issue or pull request has been labeled: "cranelift", "cranelift:meta", "cranelift:module", "isle", "wasmtime:c-api", "wasmtime:docs"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@pchickey

Copy link
Copy Markdown
Contributor

It looks like a bunch of commits from the 47 release branch got included in your PR branch for some reason - can you please rebase this cleanly on main?

@smarcd
smarcd force-pushed the codex/debug-function-index branch from 12199ef to 7fe093a Compare August 13, 2026 05:43
@github-actions github-actions Bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Aug 13, 2026
@alexcrichton

Copy link
Copy Markdown
Member

Could you detail your use case a bit more here? This is a pretty powerful debugging capability which also sort of inherently can't be efficient (e.g. the linear search here) and may also not hold up in future possible refactorings. Given the cost of supporting such an API I'd like to better understand the intended use case.

@smarcd

smarcd commented Aug 13, 2026

Copy link
Copy Markdown
Author

This is for a host-side debugging workflow. The debugger captures an instance’s private mutable state at a breakpoint/checkpoint, then materializes that state into an isolated Store so it can inspect or continue the snapshot without mutating the original execution.

This is deliberately not production runtime functionality. The path is only enabled with guest debugging, runs at debug snapshot boundaries rather than during normal execution, and is allowed to trade efficiency for a small, well-contained API.

The specific need for debug_function_index is that function references are store-local. To restore a captured table/global funcref in the isolated debugging store, the debugger needs to serialize the same-module function identity as an index and resolve it through debug_function in the destination instance.

@cfallin

cfallin commented Aug 13, 2026

Copy link
Copy Markdown
Member

The specific need for debug_function_index is that function references are store-local. To restore a captured table/global funcref in the isolated debugging store, the debugger needs to serialize the same-module function identity as an index and resolve it through debug_function in the destination instance.

But given that the implementation here is linear in the number of functions, your whole-store snapshot is going to run in quadratic time overall, which does not seem workable for anything semi-large. I'll second Alex's point that "linear search for this function" is not something we want to support.

I could see a Func::eq implementation making sense (because the primitive is harder to argue against -- it may be independently useful); if we also had Func::hash, then you could build a hashtable of funcrefs to defining instance and index within that instance in a single linear pass, then rename through that hashtable -- asymptotically better. I am not sure if I'm missing anything that would prevent us from providing Func::eq though (@alexcrichton ?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:meta Everything related to the meta-language. cranelift:module cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API. wasmtime:docs Issues related to Wasmtime's documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants