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

Remove backend::Backend from runtime-core #1099

Merged
merged 31 commits into from
Jan 13, 2020
Merged

Remove backend::Backend from runtime-core #1099

merged 31 commits into from
Jan 13, 2020

Conversation

syrusakbary
Copy link
Member

@syrusakbary syrusakbary commented Dec 21, 2019

Description

This PR removes the dependency of a Backend in runtime-core. So it's agnostic and more backends can be plugged in easily.

Why this is important?

  • By removing backends from wasmer-runtime-core we can make the runtime agnostic, so anyone can plug their own backend into Wasmer without needing to touch the main source code (V8, JavascriptCore, wasm3, ...).
  • It simplifies the codebase and avoids code leaks from the backend to the runtime API.

Review

  • Add a short description of the the change to the CHANGELOG.md file

@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Dec 21, 2019
@bors
Copy link
Contributor

bors bot commented Dec 21, 2019

try

Build failed

  • wasmerio.wasmer

@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Dec 21, 2019
@syrusakbary
Copy link
Member Author

bors r-

@syrusakbary
Copy link
Member Author

bors try-

@syrusakbary
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Dec 21, 2019
@bors
Copy link
Contributor

bors bot commented Dec 21, 2019

try

Build succeeded

Makefile Outdated Show resolved Hide resolved
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

I'll do a full review later but my knee-jerk reaction is that I don't like this change. I do agree that we should have better support for other backends and that the current Backend enum in runtime-core doesn't seem to be flexible enough for what we want. I'll have to think about alternatives more later though

fn backend_id() -> Backend {
Backend::Cranelift
fn backend_id() -> String {
"cranelift".to_string()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to have typed backend ids. An approach similar to InternalField for middlewares might work:

pub struct InternalField {

Copy link
Contributor

Choose a reason for hiding this comment

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

We can do this with a wrapper struct and (static) strings too.

I think we'll probably want to have a way to print out the name of the backend in either case, so we'll either need to have the string be part of the id or have a mapping from id to string.

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Here's a list of issues I see from most severe to least severe:

  • the current changes to the Makefile in the check section remove most of the checking we do -- we can't ship that.
  • this changes some of the semantics of the crates: we need to document them in any case, but especially with these changes. We may want to add a crate between runtime and runtime-core. edit: after reviewing the PR in depth, I don't see a use for an additional crate right now.
  • We can improve type safety, in addition or instead of using a static string (described below), by providing a wrapper type -- this is more for our sake than the public API's sake, but I think it will improve readability in some places.
  • I think &'static str might be a better choice than String. String is a dynamic, runtime value, &'static str is a compile-time string. It seems that being forced to use values you declared at compile-time is less error prone than a dynamic string here. I personally can't think of any case where the string would need to be dynamic right now.

lib/runtime-core/src/vm.rs Outdated Show resolved Hide resolved
src/bin/wasmer.rs Outdated Show resolved Hide resolved
lib/runtime-core/src/backend.rs Show resolved Hide resolved
@syrusakbary
Copy link
Member Author

syrusakbary commented Jan 7, 2020

  • the current changes to the Makefile in the check section remove most of the checking we do -- we can't ship that.

I just reverted that

  • We can improve type safety, in addition or instead of using a static string (described below), by providing a wrapper type -- this is more for our sake than the public API's sake, but I think it will improve readability in some places.
  • I think &'static str might be a better choice than String. String is a dynamic, runtime value, &'static str is a compile-time string. It seems that being forced to use values you declared at compile-time is less error prone than a dynamic string here. I personally can't think of any case where the string would need to be dynamic right now.

Agreed. I talked with @losfair and he thinks we can use a similar strategy as we are doing with Internal Fields (here's a POC: #1106 ).

I think we can merge this, and then merge the other PR apart, or we can do the static str changes meanwhile. Let me know!

@MarkMcCaskey
Copy link
Contributor

I think we can merge this, and then merge the other PR apart, or we can do the static str changes meanwhile. Let me know!

Sure, I'm fine merging in in-progress work in general as long as we have plans to follow up and we don't release until the public APIs are in the shape we want them to be.

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

The core changes look good -- I'm not fully on board with this being the way the public API looks though but as discussed, we can follow up on that!

One last thought: perhaps it would simplify the code to have the Backend enum always contain all our backends regardless of features and have the conditional compilation logic in other places Not high priority, but because you've just interacted with this code you're in a good position to decide if that kind of change would be helpful.

@@ -52,7 +52,7 @@ cc = "1.0"
[features]
debug = []
trace = ["debug"]
# backend flags used in conditional compilation of Backend::variants
# backend flags no longer used
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer just deleting them if we're not using them!

features = ["rc"]
[dependencies.serde_derive]
version = "1.0"

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this chunk of the Cargo.toml came from runtime-core, do you know if we can remove the feature from runtime-core?

Copy link
Member Author

@syrusakbary syrusakbary Jan 10, 2020

Choose a reason for hiding this comment

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

Unfortunately both need serde_derive as they use #[derive(Serialize, Deserialize, ...)].

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, the git diff shows 4 lines, I intended to point to just the top one with features = ["rc"]!

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a very minor thing, just thought it'd be better to remove it if it's not needed

lib/runtime/src/lib.rs Show resolved Hide resolved
@syrusakbary
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jan 10, 2020
1099: Remove backend::Backend from runtime-core r=syrusakbary a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

This PR removes the dependency of a Backend in runtime-core. So it's agnostic and more backends can be plugged in easily.

Why this is important?
* By removing backends from wasmer-runtime-core we can make the runtime agnostic, so anyone can plug their own backend into Wasmer without needing to touch the main source code (V8, JavascriptCore, wasm3, ...).
* It simplifies the codebase and avoids code leaks from the backend to the runtime API.

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
@bors
Copy link
Contributor

bors bot commented Jan 10, 2020

Build failed

  • wasmerio.wasmer

Mark McCaskey and others added 9 commits January 13, 2020 10:17
Bumps [getrandom](https://github.com/rust-random/getrandom) from 0.1.13 to 0.1.14.
- [Release notes](https://github.com/rust-random/getrandom/releases)
- [Changelog](https://github.com/rust-random/getrandom/blob/master/CHANGELOG.md)
- [Commits](rust-random/getrandom@v0.1.13...v0.1.14)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Bumps [parking_lot](https://github.com/Amanieu/parking_lot) from 0.9.0 to 0.10.0.
- [Release notes](https://github.com/Amanieu/parking_lot/releases)
- [Changelog](https://github.com/Amanieu/parking_lot/blob/master/CHANGELOG.md)
- [Commits](Amanieu/parking_lot@0.9.0...0.10.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Bumps [regex](https://github.com/rust-lang/regex) from 1.3.1 to 1.3.3.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](rust-lang/regex@1.3.1...1.3.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Bumps [cc](https://github.com/alexcrichton/cc-rs) from 1.0.48 to 1.0.50.
- [Release notes](https://github.com/alexcrichton/cc-rs/releases)
- [Commits](rust-lang/cc-rs@1.0.48...1.0.50)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
@syrusakbary
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jan 13, 2020
1099: Remove backend::Backend from runtime-core r=syrusakbary a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

This PR removes the dependency of a Backend in runtime-core. So it's agnostic and more backends can be plugged in easily.

Why this is important?
* By removing backends from wasmer-runtime-core we can make the runtime agnostic, so anyone can plug their own backend into Wasmer without needing to touch the main source code (V8, JavascriptCore, wasm3, ...).
* It simplifies the codebase and avoids code leaks from the backend to the runtime API.

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Jan 13, 2020

Build failed

  • wasmerio.wasmer

@syrusakbary
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Jan 13, 2020
1099: Remove backend::Backend from runtime-core r=syrusakbary a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

This PR removes the dependency of a Backend in runtime-core. So it's agnostic and more backends can be plugged in easily.

Why this is important?
* By removing backends from wasmer-runtime-core we can make the runtime agnostic, so anyone can plug their own backend into Wasmer without needing to touch the main source code (V8, JavascriptCore, wasm3, ...).
* It simplifies the codebase and avoids code leaks from the backend to the runtime API.

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
@bors
Copy link
Contributor

bors bot commented Jan 13, 2020

Build succeeded

@bors bors bot merged commit 3892ea8 into master Jan 13, 2020
@bors bors bot deleted the backend-refactor branch January 13, 2020 11:25
@syrusakbary syrusakbary mentioned this pull request Jan 13, 2020
1 task
bors bot added a commit that referenced this pull request Jan 15, 2020
1143: Set backend_id to static str r=MarkMcCaskey a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

As per feedback in #1099, set backend_id to static str.

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Mark McCaskey <mark@wasmer.io>
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.

3 participants