Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to WIT-enabled wasmCloud #605

Closed
wants to merge 1 commit into from

Conversation

rvolosatovs
Copy link
Member

Feature or Problem

Update to NIF to wasmCloud/wasmCloud#300

Related Issues

wasmCloud/wasmCloud#300

Release Information

Consumer Impact

Testing

Built on platform(s)

  • x86_64-linux
  • aarch64-linux
  • x86_64-darwin
  • aarch64-darwin
  • x86_64-windows

Tested on platform(s)

  • x86_64-linux
  • aarch64-linux
  • x86_64-darwin
  • aarch64-darwin
  • x86_64-windows

Unit Test(s)

Acceptance or Integration

Manual Verification

Copy link
Member

@autodidaddict autodidaddict left a comment

Choose a reason for hiding this comment

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

LGTM but I think there are some opportunities to rename some things to be more clear and disambiguated.

Also I can't tell from mobile but make sure all the integration tests pass on these new nif changes

@@ -10,8 +10,7 @@ path = "src/lib.rs"
crate-type = ["dylib"]

[dependencies]
# Patched temporarily to fix TinyGo modules, branch will be removed in v0.63.0
wasmcloud = { git = "https://github.com/wasmcloud/wasmcloud", branch = "fix/0.62-tinygo"}
wasmcloud-host = { git = "https://github.com/rvolosatovs/wasmcloud", branch = "feat/wit"}
Copy link
Member

Choose a reason for hiding this comment

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

Calling this wasmCloud host is confusing as there is a full elixir project in this repo called wasmCloud host (the washboard).

Also, we shouldn't be depending on your fork.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a draft and the fork is used precisely because wasmCloud/wasmCloud#300 is not merged yet. There's nothing else to depend upon to get this up

}

#[derive(Clone)]
struct ElixirHandlerArc(Arc<ElixirHandler>);
Copy link
Member

Choose a reason for hiding this comment

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

I know naming is hard but I'd rather not put a data type like arc as a suffix on a struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you suggest a better option?

Copy link
Member

@autodidaddict autodidaddict Apr 7, 2023

Choose a reason for hiding this comment

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

It was called ElixirHandler before. The fact that the inner element is an arc shouldn't be advertised in the name.

You could call it a handler reference or elixir handler reference.. just something that doesn't have a data type in the name.

Copy link
Member Author

Choose a reason for hiding this comment

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

But what would the inner struct be called then? ElixirHandlerInner? I really don't see how that's better.

The only option to avoid this is to store an unnamed tuple in an Arc, but that'd be very difficult to maintain and use

Copy link
Member

Choose a reason for hiding this comment

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

I'm also not sure what caused the need for the arc wrapper around the elixir handler. Since I'm on a phone deferring to Taylor for thoughts on the abstraction and name

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure what caused the need for the arc wrapper around the elixir handler

Mainly, wasmtime/wit-bindgen design drawbacks, namely the fact that the host trait implementations take &mut self parameter, therefore forcing this pattern on us

Copy link
Member

Choose a reason for hiding this comment

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

But shouldn't we be insulating consumers of our rust wasmCloud library from design changes and decisions of the underlying libraries? We shouldn't have to refactor the otp nif every time wasmtime makes an internal change... Isolating the host from this kind of churn is actually the primary purpose of the rust wasmCloud library.

Copy link
Member

Choose a reason for hiding this comment

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

not sure what caused the need for the arc wrapper around the elixir handler

Mainly, wasmtime/wit-bindgen design drawbacks, namely the fact that the host trait implementations take &mut self parameter, therefore forcing this pattern on us

If they force this on our wasmCloud library then the wasmCloud library should not pass this along to its consumers. It is designed specifically to prevent this

Copy link
Member Author

@rvolosatovs rvolosatovs Apr 7, 2023

Choose a reason for hiding this comment

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

Sure, eventually we should think about this, depending on the state of things in the future - right now it's way too early to build these abstractions.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. Our job with libwasmcloud is to isolate consumers from wasmtime and its volatility. It's our job to come up with a more stable abstraction than the raw wasmtime interface.

@autodidaddict
Copy link
Member

Bottom line: if we have to refactor the nif every time wasmtime changes an API, then libwasmcloud is not doing its job.

@rvolosatovs
Copy link
Member Author

rvolosatovs commented Apr 7, 2023

Bottom line: if we have to refactor the nif every time wasmtime changes an API, then libwasmcloud is not doing its job.

Again, that comes in the future. We will reach this point some day, but now is not the right time to build these abstractions (just like the handler abstraction API was prematurely built earlier and replaced here). It's much more dangerous and costly to build the wrong abstraction, rather than pay a minuscule cost of changing a few lines of code very infrequently (if at all). Please note that "libwasmcloud" is not even 0.1.0 yet and there will be breaking changes going forward. We will follow semantic versioning completely, but now it's way too early in the lifecycle of that project to do that.

Making sure these interfaces (WIT traits, WASI etc.) are actually usable and backwards compatible is Wasmtime/Bytecode Alliance's job, not ours.

What changes are you afraid of?

Eventually, the "Arc" trick will not be necessary anymore - the (wit-bindgen generated) traits should take &self rather than &mut self as parameter - changing this should not take more than 10 seconds with a simple search-and-replace. Removing the Arc is a possibility in that case, but not a requirement - the existing implementation will keep working just the same way it did.

Next, there's the question of WIT interfaces being updated - e.g. a new method is added. Again, this maintenance burden belongs upstream - it's upstream's job to ensure backwards compatibility, e.g. ensure there are default implementations for any new methods added.

If upstream fails it's job and introduces breaking changes, then that's the point where we can abstract these traits ourselves, i.e. instead of reexporting wit-bindgen-generated traits, export our own with the same name and API. At this point, nothing is broken, so I do not see a reason (on the contrary, I see reasons not to) fix it

@brooksmtownsend
Copy link
Member

@rvolosatovs looks like we've gone through a few changes but settled that this PR is something we should do, would you mind providing a status update here on if this should stay draft, be replaced by another PR, etc?

@rvolosatovs
Copy link
Member Author

@rvolosatovs looks like we've gone through a few changes but settled that this PR is something we should do, would you mind providing a status update here on if this should stay draft, be replaced by another PR, etc?

I think we should keep this until https://github.com/wasmCloud/wasmcloud has reached 0.1 or there are features we explicitly need from the library and then get back to this and update to recent changes. We don't get anything by doing this now, but there's a lot of work that will be useful once we do

cc @autodidaddict

@autodidaddict
Copy link
Member

We don't get anything by doing this now, but there's a lot of work that will be useful once we do

cc @autodidaddict

Don't we get the ability for the OTP host to execute modules and components built using the latest standards?

@autodidaddict
Copy link
Member

The version of provider-archive should be bumped to 0.7.0

@autodidaddict
Copy link
Member

Thanks for the provider-archive bump 👍

@autodidaddict
Copy link
Member

@rvolosatovs when can this be taken out of draft and made ready to merge so we can use the new dependencies?

@rvolosatovs
Copy link
Member Author

@rvolosatovs when can this be taken out of draft and made ready to merge so we can use the new dependencies?

the NIF segfaults on startup, someone has to debug and fix that, I can take a look tomorrow, but if you can figure out the issue, then please go ahead

@stale
Copy link

stale bot commented Aug 14, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this has been closed too eagerly, please feel free to tag a maintainer so we can keep working on the issue. Thank you for contributing to wasmCloud!

@stale stale bot added the stale label Aug 14, 2023
@stale stale bot closed this Aug 21, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants