Skip to content

[hyperlight_component_util] Properly track positivity/negativity - #1723

Merged
syntactically merged 1 commit into
mainfrom
lm/component-positivity
Aug 13, 2026
Merged

[hyperlight_component_util] Properly track positivity/negativity#1723
syntactically merged 1 commit into
mainfrom
lm/component-positivity

Conversation

@syntactically

Copy link
Copy Markdown
Member

Previously, bindgen code relied upon state that it tracked at compile time to determine whether a particular definition was in a positive or negative position (see State::is_export). Unfortunately, since type definitions presently are maintained based on wit-style names, and the same wit interface can be both imported and exported from the main component, this did not work very well.

This commit changes the generated types to include a type parameter that tracks whether they are being used in a positive or negative manner. It also changes the one current user of State::is_export to instead use that type parameter, ensuring that the single generated definition can be used both as an import and as an export.

@syntactically syntactically added the kind/bugfix For PRs that fix bugs label Aug 12, 2026
@syntactically
syntactically force-pushed the lm/component-positivity branch from 7bb80fb to c1f8d53 Compare August 12, 2026 16:32
Copilot AI lite review requested due to automatic review settings August 12, 2026 16:32
Comment thread src/tests/rust_guests/witguest/src/main.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Hyperlight’s component bindgen to track positive vs negative positions via an explicit type parameter (instead of relying on compile-time State::is_export), allowing the same generated interface definitions to be used correctly as both imports and exports.

Changes:

  • Introduces hyperlight_common::component::{Positivity, Positive, Negative} and uses Positivity::Borrow to encode borrowed-handle representation by position.
  • Updates bindgen emission to thread positivity through generated traits/types and fixes resource/type referencing to use the positivity parameter.
  • Updates host/guest tests and the Rust WIT guest to use the new positivity-parameterized generated APIs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/tests/rust_guests/witguest/src/main.rs Updates guest-side generated trait impl usage to pass explicit Positive/Negative parameters.
src/hyperlight_host/tests/wit_test.rs Updates host-side tests to implement/consume positivity-parameterized bindings and adds a regression case for same-interface import+export with resources.
src/hyperlight_component_util/src/rtypes.rs Threads positivity through trait/type references and replaces State::is_export logic with Positivity::Borrow.
src/hyperlight_component_util/src/host.rs Adjusts host bindgen output to use positivity-parameterized imports/exports traits.
src/hyperlight_component_util/src/guest.rs Adjusts guest bindgen output for positivity-parameterized traits and impl emission.
src/hyperlight_component_util/src/emit.rs Adds positivity parameter to emitted trait generics and refactors impl tracking to carry impl generic args.
src/hyperlight_common/src/lib.rs Exposes the new component module from hyperlight_common.
src/hyperlight_common/src/component.rs Adds Positivity trait and Positive/Negative marker types defining borrow-handle representation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hyperlight_component_util/src/emit.rs
Comment thread src/hyperlight_component_util/src/emit.rs
Comment thread src/hyperlight_component_util/src/host.rs
Comment thread src/hyperlight_component_util/src/guest.rs Outdated
Comment thread src/hyperlight_component_util/src/guest.rs
jsturtevant
jsturtevant previously approved these changes Aug 12, 2026
Previously, bindgen code relied upon state that it tracked at compile
time to determine whether a particular definition was in a positive or
negative position (see `State::is_export`).  Unfortunately, since type
definitions presently are maintained based on wit-style names, and the
same wit interface can be both imported and exported from the main
component, this did not work very well.

This commit changes the generated types to include a type parameter
that tracks whether they are being used in a positive or negative
manner. It also changes the one current user of `State::is_export` to
instead use that type parameter, ensuring that the single generated
definition can be used both as an import and as an export.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
@syntactically
syntactically force-pushed the lm/component-positivity branch from 928a40d to 03ef756 Compare August 13, 2026 10:47
@syntactically syntactically added the ready-for-review PR is ready for (re-)review label Aug 13, 2026
Comment thread src/tests/rust_guests/witguest/src/main.rs
Base automatically changed from lm/component-disambiguate-chains to main August 13, 2026 21:26
@syntactically
syntactically merged commit 03ef756 into main Aug 13, 2026
61 of 66 checks passed
@syntactically
syntactically deleted the lm/component-positivity branch August 13, 2026 21:30
@github-actions github-actions Bot removed the ready-for-review PR is ready for (re-)review label Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix For PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants