Skip to content

Conversation

@rylev
Copy link
Collaborator

@rylev rylev commented Jul 3, 2024

Fixes #127

When performing target validation (i.e., whether a component graph represents a component that matches the given world), we were just iterating the explicit imports. Now, we iterate all imports both implicit and explicit.

This PR also contains a slight refactoring of encode_imports that isn't necessary but came from an early exploration and which I think makes the code more readable. Let me know if I should remove this.

When an implicit import is the cause of a validation error, the error message isn't wonderful since we don't have a span to point to like we do in the explicit import case. I think we can land this though before we figure out exactly how to improve the error message.

@rylev rylev requested review from fibonacci1729 and peterhuene July 3, 2024 15:50
@rylev rylev force-pushed the implicit-import-check branch from a3223c0 to 3accf7a Compare July 3, 2024 16:14
Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@rylev rylev force-pushed the implicit-import-check branch from 3accf7a to 3fb7ef4 Compare July 3, 2024 16:15
@fibonacci1729
Copy link
Collaborator

Thanks for digging into this! I haven't extensively studied the code just yet but I did try out the changes with the following example:

I have a component called spin:kv that targets:

world {
  import wasi:io/poll@0.2.0;
  import wasi:io/error@0.2.0;
  import wasi:io/streams@0.2.0;
  import wasi:http/types@0.2.0;
  import fermyon:spin/key-value@2.0.0;
  import wasi:cli/environment@0.2.0;
  import wasi:cli/exit@0.2.0;
  import wasi:cli/stdin@0.2.0;
  import wasi:cli/stdout@0.2.0;
  import wasi:cli/stderr@0.2.0;
  import wasi:clocks/wall-clock@0.2.0;
  import wasi:filesystem/types@0.2.0;
  import wasi:filesystem/preopens@0.2.0;
  import wasi:random/random@0.2.0;

  export wasi:http/incoming-handler@0.2.0;
}

And this wac script to do a targets check:

package test:test targets wasi:http/proxy@0.2.0;

export new spin:kv{...}...;

When running wac resolve script.wac I am getting the following error which I can't quite wrap my head around:

error: failed to resolve document

  × import `wasi:io/error@0.2.0` has a mismatched type for target world `wasi:http/proxy@0.2.0`
  ╰─▶ instance has unexpected instance export `wasi:http/incoming-handler@0.2.0`

Thanks again for tackling this; could you add a test or two when you get a chance?

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@rylev
Copy link
Collaborator Author

rylev commented Jul 4, 2024

@fibonacci1729 thanks for finding the issue! It turns out we were always assuming a 1 to 1 correspondence between an import node (i.e., a node in the wac graph) and the item we wanted to type check. However, implicit imports don't have nodes in the wac graph (that's what makes them implicit after all!). The latest change more directly provides the validate_target function with the item definitions it needs to check instead of it having to look up items by node id from the graph.

I think this should fix the issue you're seeing - in my testing I got errors that made much more sense and correctly identified where the component and the target world didn't line up.

I'll look into how we can add tests for this.

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@rylev
Copy link
Collaborator Author

rylev commented Jul 4, 2024

I looked into adding a test, and discovered a new issue I'd like to address first. The issue is that just like wac, wit sort of has a similar concept of implicit imports. If you use an item inside of an imported interface from another interface, that other interface will be implicitly imported. I'll need to do the work of looking up interfaces through used items as well as direct imports.

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@rylev
Copy link
Collaborator Author

rylev commented Jul 5, 2024

I've addressed the issue of interfaces implicitly imported through uses and the test I've added now passes. I believe this is ready for final review and merge.

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@fibonacci1729
Copy link
Collaborator

Awesome work @rylev! I'll give this a review and test on monday.

Copy link
Collaborator

@fibonacci1729 fibonacci1729 left a comment

Choose a reason for hiding this comment

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

Great work @rylev ! The code looks great (very understandable) and the manual tests i was running now pass.

From my example earlier, i now see:

× target world `wasi:http/proxy@0.2.0` does not have an import named `fermyon:spin/key-value@2.0.0`

... which is exactly how I expect it to fail.

@rylev rylev merged commit 1d314b0 into bytecodealliance:main Jul 9, 2024
@rylev rylev deleted the implicit-import-check branch July 9, 2024 11:22
mergify bot referenced this pull request in andrzejressel/pulumi-gestalt Jul 9, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [wac-graph](https://togithub.com/bytecodealliance/wac) | workspace.dependencies | minor | `0.3.0` -> `0.4.0` |

---

### Release Notes

<details>
<summary>bytecodealliance/wac (wac-graph)</summary>

### [`v0.4.0`](https://togithub.com/bytecodealliance/wac/releases/tag/v0.4.0)

[Compare Source](https://togithub.com/bytecodealliance/wac/compare/v0.3.0...v0.4.0)

#### What's Changed

-   docs: more generic command listing prose by [@&#8203;vados-cosmonic](https://togithub.com/vados-cosmonic) in [https://github.com/bytecodealliance/wac/pull/125](https://togithub.com/bytecodealliance/wac/pull/125)
-   Bump h2 from 0.4.3 to 0.4.5 by [@&#8203;dependabot](https://togithub.com/dependabot) in [https://github.com/bytecodealliance/wac/pull/126](https://togithub.com/bytecodealliance/wac/pull/126)
-   Update semver regex to not swallow trailing `.` by [@&#8203;itowlson](https://togithub.com/itowlson) in [https://github.com/bytecodealliance/wac/pull/129](https://togithub.com/bytecodealliance/wac/pull/129)
-   Implicit import check during target validation by [@&#8203;rylev](https://togithub.com/rylev) in [https://github.com/bytecodealliance/wac/pull/130](https://togithub.com/bytecodealliance/wac/pull/130)

#### New Contributors

-   [@&#8203;vados-cosmonic](https://togithub.com/vados-cosmonic) made their first contribution in [https://github.com/bytecodealliance/wac/pull/125](https://togithub.com/bytecodealliance/wac/pull/125)
-   [@&#8203;dependabot](https://togithub.com/dependabot) made their first contribution in [https://github.com/bytecodealliance/wac/pull/126](https://togithub.com/bytecodealliance/wac/pull/126)
-   [@&#8203;itowlson](https://togithub.com/itowlson) made their first contribution in [https://github.com/bytecodealliance/wac/pull/129](https://togithub.com/bytecodealliance/wac/pull/129)

**Full Changelog**: bytecodealliance/wac@v0.3.0...v0.4.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/andrzejressel/pulumi-wasm).
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.

Targets check not validating implicit imports

2 participants