Split the ComponentValue trait into... components (#4236)

This commit splits the current `ComponentValue` trait into three
separate traits:

* `ComponentType` - contains size/align/typecheck information in
  addition to the "lower" representation.
* `Lift` - only contains `lift` and `load`
* `Lower` - only contains `lower` and `store`

When describing the original implementation of host functions to Nick he
immediately pointed out this superior solution to the traits involved
with Wasmtime's support for typed parameters/returns in exported and
imported functions. Instead of having dynamic errors at runtime for
things like "you can't lift a `String`" that's instead a static
compile-time error now.

While I was doing this split I also refactored the `ComponentParams`
trait a bit to have `ComponentType` as a supertrait instead of a subtype
which made its implementations a bit more compact. Additionally its impl
blocks were folded into the existing tuple impl blocks.
This commit is contained in:
Alex Crichton
2022-06-07 12:29:26 -05:00
committed by GitHub
parent 511c53703a
commit 11ff9650e5
6 changed files with 348 additions and 422 deletions

View File

@@ -158,10 +158,6 @@ fn typecheck() -> Result<()> {
assert!(thunk.typed::<(u32,), (), _>(&store).is_err());
assert!(thunk.typed::<(), (), _>(&store).is_ok());
assert!(take_string.typed::<(), (), _>(&store).is_err());
assert!(take_string.typed::<(), String, _>(&store).is_err());
assert!(take_string
.typed::<(String, String), String, _>(&store)
.is_err());
assert!(take_string.typed::<(String,), (), _>(&store).is_ok());
assert!(take_string.typed::<(&str,), (), _>(&store).is_ok());
assert!(take_string.typed::<(&[u8],), (), _>(&store).is_err());
@@ -175,11 +171,7 @@ fn typecheck() -> Result<()> {
assert!(ret_tuple1.typed::<(), (u32,), _>(&store).is_ok());
assert!(ret_tuple1.typed::<(), u32, _>(&store).is_err());
assert!(ret_string.typed::<(), (), _>(&store).is_err());
assert!(ret_string.typed::<(), String, _>(&store).is_err());
assert!(ret_string.typed::<(), &str, _>(&store).is_err());
assert!(ret_string.typed::<(), WasmStr, _>(&store).is_ok());
assert!(ret_list_u8.typed::<(), &[u8], _>(&store).is_err());
assert!(ret_list_u8.typed::<(), Vec<u8>, _>(&store).is_err());
assert!(ret_list_u8.typed::<(), WasmList<u16>, _>(&store).is_err());
assert!(ret_list_u8.typed::<(), WasmList<i8>, _>(&store).is_err());
assert!(ret_list_u8.typed::<(), WasmList<u8>, _>(&store).is_ok());