fix: substituted_component_type panic on guest-exported resources#13608
Merged
alexcrichton merged 2 commits intoJun 10, 2026
Merged
Conversation
`Linker::substituted_component_type` builds a `types::Component` whose resource substitution map is `Some(..)` but only covers the component's *imported* resources. Introspecting an exported function that references an *exported* (non-imported) resource then panics with an index-out-of-bounds, because `InstanceType::resource_type` hard-indexes that partial map (`matching.rs`) instead of falling back to treating an absent resource as uninstantiated. This adds a test that builds a component exporting a resource plus a constructor returning `own<t>` and a method taking `borrow<t>`, then walks the introspected function types via `substituted_component_type`. It panics today (index out of bounds) and will pass once the resolver falls back gracefully. Assisted-by: claude:claude-opus-4-8
`Linker::substituted_component_type` constructs the introspection type with `resources: Some(&cx.imported_resources)`, a map that only contains the component's *imported* resources. `InstanceType::resource_type` previously hard-indexed that map (`self.resources.map(|t| t[ty])`), so resolving a resource that is not in the map -- e.g. a resource the component *exports* -- panicked with an index-out-of-bounds whenever an exported function's params/results referenced it. Fix this by using a fallible lookup and falling back to `ResourceType::uninstantiated` when the resource is absent from the map, exactly as the `resources: None` path already does. This is the semantically correct behavior: a resource that has no substitution is "not (yet) instantiated", which is also what `Component::component_type()` relies on (it passes `resources: None`). With this fix the same safe, public introspection API no longer panics depending on which (also public) API produced the `types::Component`. Assisted-by: claude:claude-opus-4-8
alexcrichton
approved these changes
Jun 10, 2026
alexcrichton
left a comment
Member
There was a problem hiding this comment.
Thanks!
The only mild comment I'd have is that LLMs tend to be a bit too verbose in tests insofar as they try to document the exact state of the world before a test was added and when it was added, so the comment basically becomes irrelevant after a test lands. Not a huge thing though, so no worries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've encountered a panic working with guest-exported resources and
Linker::substituted_component_type:I had an LLM debug and add a test, which fails on current
mainwith:Other than me changing the commit message titles (and opening this PR/writing the description), this contribution is entirely LLM-generated, but reviewed by me.
The fix itself is a one-line change, which seems correct to me.
The analysis added by the LLM in the commits seems valid.
Test seems to make sense - I guess we could make it shorter, but I'll leave this up to reviewers to decide.
This is my first LLM-assisted contribution to Wasmtime, I belive it's compliant with https://github.com/bytecodealliance/governance/blob/main/AI_TOOL_POLICY.md, but please let me know if I have missed something.