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(runtime): add marshalling of value structs #93

Merged
merged 6 commits into from
Mar 7, 2020

Conversation

Wodann
Copy link
Collaborator

@Wodann Wodann commented Mar 1, 2020

  struct(value) Foo {
      x: int,
      y: int
  }

  pub fn foo_new(x: int, y: int): Foo {
      Foo { x: x, y: y, }
  }

  pub fn foo_add(foo: Foo): int { foo.x + foo.y }
  fn main() {
      let lib_dir = env::args().nth(1).expect("Expected path to a Mun library.");
      let mut runtime = RuntimeBuilder::new(lib_dir)
          .spawn()
          .expect("Failed to spawn Runtime");

      // The Mun compiler automatically generates a wrapper for `pub fn`s that
      // contain `struct(value)` arguments or return types, which allocates the
      // marshalled data in the runtime's allocator.
      let mut foo: StructRef = invoke_fn!(runtime, "foo_new", 1i64, 2i64).wait();
      let x = foo.get::<i64>("x").unwrap();
      let y = foo.replace("y", x + 1).unwrap();
      foo.set("x", y).wait();
  }

@baszalmstra Can you check whether my approach is valid?

What is a good way to implement the generation of the wrapper? Should it be a copy of the body of the statically linked version, or should it just dereference the struct(value) parameters and pass it to the original function?

@Wodann Wodann requested a review from baszalmstra March 1, 2020 14:51
@Wodann Wodann self-assigned this Mar 1, 2020
@codecov
Copy link

codecov bot commented Mar 1, 2020

Codecov Report

Merging #93 into master will increase coverage by 0.39%.
The diff coverage is 92.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   76.82%   77.22%   +0.39%     
==========================================
  Files         122      124       +2     
  Lines        9601     9816     +215     
==========================================
+ Hits         7376     7580     +204     
- Misses       2225     2236      +11     
Impacted Files Coverage Δ
crates/mun_runtime/src/macros.rs 71.69% <0.00%> (-0.53%) ⬇️
crates/mun_codegen/src/ir/module.rs 100.00% <0.00%> (ø)
crates/mun_runtime/src/function.rs 97.43% <0.00%> (ø)
crates/mun_codegen/src/lib.rs 100.00% <0.00%> (ø)
crates/mun_codegen/src/ir/body.rs 90.39% <0.00%> (+0.75%) ⬆️
crates/mun_codegen/src/ir.rs 55.17% <0.00%> (+5.17%) ⬆️
crates/mun_hir/src/ty.rs 90.99% <0.00%> (+2.52%) ⬆️
crates/mun_codegen/src/type_info.rs 65.00% <0.00%> (+5.38%) ⬆️
crates/mun_runtime/src/struct.rs 88.63% <0.00%> (+8.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f4834e...3a716ad. Read the comment docs.

@baszalmstra
Copy link
Collaborator

I would say we call the original function in the wrapper/bridge function.

@Wodann Wodann force-pushed the feature/marshal-value-struct branch from d1868b4 to 3a716ad Compare March 7, 2020 13:09
@Wodann Wodann changed the title feat(marshal): create marshallable wrapper for function signatures that contain value struct types feat(runtime): add marshalling of value structs Mar 7, 2020
@Wodann Wodann marked this pull request as ready for review March 7, 2020 13:09
@Wodann
Copy link
Collaborator Author

Wodann commented Mar 7, 2020

@baszalmstra baszalmstra merged commit 9db3a2f into mun-lang:master Mar 7, 2020
@Wodann Wodann deleted the feature/marshal-value-struct branch March 25, 2020 11:25
@Wodann Wodann added this to the Mun v0.2 milestone May 14, 2020
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.

2 participants