Skip to content

Commit

Permalink
Renamed get_native_function to get_typed_function, marked former …
Browse files Browse the repository at this point in the history
…as deprecated.
  • Loading branch information
epilys committed Jun 28, 2022
1 parent f9ce65a commit 6c57aee
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 136 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
### Changed
- #2946 Remove dylib,staticlib engines in favor of a single Universal engine
- [#2949](https://github.com/wasmerio/wasmer/pull/2949) Switch back to using custom LLVM builds on CI
- #2892 Renamed `get_native_function` to `get_typed_function`, marked former as deprecated.

### Fixed
- [#2963](https://github.com/wasmerio/wasmer/pull/2963) Remove accidental dependency on libwayland and libxcb in ClI
Expand Down
2 changes: 1 addition & 1 deletion examples/early_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn main() -> anyhow::Result<()> {
//
// Get the `run` function which we'll use as our entrypoint.
println!("Calling `run` function...");
let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("run")?;
let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function("run")?;

// When we call a function it can either succeed or fail. We expect it to fail.
match run_func.call(1, 7) {
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let load = instance
.exports
.get_native_function::<(), (WasmPtr<u8>, i32)>("load")?;
.get_typed_function::<(), (WasmPtr<u8>, i32)>("load")?;

// Here we go.
//
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn main() -> anyhow::Result<()> {
// Recall that the Wasm module exported a function named "run", this is getting
// that exported function from the `Instance`.
let run_func: TypedFunction<(), ()> =
instance.exports.get_native_function(&mut context, "run")?;
instance.exports.get_typed_function(&mut context, "run")?;

// Finally, we call our exported Wasm function which will call our "say_hello"
// function and return.
Expand Down
6 changes: 3 additions & 3 deletions examples/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ fn main() -> anyhow::Result<()> {
// The module exports some utility functions, let's get them.
//
// These function will be used later in this example.
let mem_size: TypedFunction<(), i32> = instance.exports.get_native_function("mem_size")?;
let get_at: TypedFunction<i32, i32> = instance.exports.get_native_function("get_at")?;
let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_native_function("set_at")?;
let mem_size: TypedFunction<(), i32> = instance.exports.get_typed_function("mem_size")?;
let get_at: TypedFunction<i32, i32> = instance.exports.get_typed_function("get_at")?;
let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_typed_function("set_at")?;
let memory = instance.exports.get_memory("memory")?;

// We now have an instance ready to be used.
Expand Down
2 changes: 1 addition & 1 deletion examples/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() -> anyhow::Result<()> {
// The first argument is the table index and the next 2 are the 2 arguments
// to be passed to the function found in the table.
let call_via_table: TypedFunction<(i32, i32, i32), i32> =
instance.exports.get_native_function("call_callback")?;
instance.exports.get_typed_function("call_callback")?;

// And then call it with table index 1 and arguments 2 and 7.
let result = call_via_table.call(1, 2, 7)?;
Expand Down
16 changes: 16 additions & 0 deletions lib/api/src/js/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,27 @@ impl Exports {
self.get(name)
}

#[deprecated(
since = "3.0.0",
note = "get_native_function() has been renamed to get_typed_function(), just like NativeFunc has been renamed to TypedFunction."
)]
/// Get an export as a `TypedFunction`.
pub fn get_native_function<Args, Rets>(
&self,
name: &str,
) -> Result<TypedFunction<Args, Rets>, ExportError>
where
Args: WasmTypeList,
Rets: WasmTypeList,
{
self.get_typed_function(name)
}

/// Get an export as a `TypedFunction`.
pub fn get_typed_function<Args, Rets>(
&self,
name: &str,
) -> Result<TypedFunction<Args, Rets>, ExportError>
where
Args: WasmTypeList,
Rets: WasmTypeList,
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
//! # fn exports_example(instance: &Instance) -> anyhow::Result<()> {
//! let memory = instance.exports.get_memory("memory")?;
//! let memory: &Memory = instance.exports.get("some_other_memory")?;
//! let add: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
//! let add: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function("add")?;
//! let result = add.call(5, 37)?;
//! assert_eq!(result, 42);
//! # Ok(())
Expand Down
17 changes: 17 additions & 0 deletions lib/api/src/sys/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,29 @@ impl Exports {
self.get(name)
}

#[deprecated(
since = "3.0.0",
note = "get_native_function() has been renamed to get_typed_function(), just like NativeFunc has been renamed to TypedFunction."
)]
/// Get an export as a `TypedFunction`.
pub fn get_native_function<Args, Rets>(
&self,
ctx: &impl AsContextRef,
name: &str,
) -> Result<TypedFunction<Args, Rets>, ExportError>
where
Args: WasmTypeList,
Rets: WasmTypeList,
{
self.get_typed_function(ctx, name)
}

/// Get an export as a `TypedFunction`.
pub fn get_typed_function<Args, Rets>(
&self,
ctx: &impl AsContextRef,
name: &str,
) -> Result<TypedFunction<Args, Rets>, ExportError>
where
Args: WasmTypeList,
Rets: WasmTypeList,
Expand Down
6 changes: 3 additions & 3 deletions lib/api/tests/js_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ mod js {
let instance = Instance::new(&module, &import_object).unwrap();

let add_one: TypedFunction<i32, i32> =
instance.exports.get_native_function("add_one").unwrap();
instance.exports.get_typed_function("add_one").unwrap();
assert_eq!(add_one.call(1), Ok(2));
}

Expand Down Expand Up @@ -646,7 +646,7 @@ mod js {
let instance = Instance::new(&module, &import_object).unwrap();

let run_func: TypedFunction<(i32, i32), i32> =
instance.exports.get_native_function("run").unwrap();
instance.exports.get_typed_function("run").unwrap();

assert!(run_func.call(1, 7).is_err(), "Expected early termination",);
let run_func = instance.exports.get_function("run").unwrap();
Expand Down Expand Up @@ -725,7 +725,7 @@ mod js {
}

let run_func: TypedFunction<(i32, i32), i32> =
instance.exports.get_native_function("run").unwrap();
instance.exports.get_typed_function("run").unwrap();
test_result(run_func.call(1, 7));

let run_func = instance.exports.get_function("run").unwrap();
Expand Down
16 changes: 8 additions & 8 deletions lib/api/tests/js_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,35 +251,35 @@ mod js {

// let f1: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func1")
// .get_typed_function("call_host_func1")
// .unwrap();
// let f2: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func2")
// .get_typed_function("call_host_func2")
// .unwrap();
// let f3: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func3")
// .get_typed_function("call_host_func3")
// .unwrap();
// let f4: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func4")
// .get_typed_function("call_host_func4")
// .unwrap();
// let f5: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func5")
// .get_typed_function("call_host_func5")
// .unwrap();
// let f6: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func6")
// .get_typed_function("call_host_func6")
// .unwrap();
// let f7: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func7")
// .get_typed_function("call_host_func7")
// .unwrap();
// let f8: TypedFunction<(), ()> = instance
// .exports
// .get_native_function("call_host_func8")
// .get_typed_function("call_host_func8")
// .unwrap();

// f1.call().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions lib/api/tests/sys_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod sys {
assert_eq!(is_memory_instance_ref_strong(mem), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
f.call()?;
f
};
Expand Down Expand Up @@ -183,7 +183,7 @@ mod sys {
assert_eq!(is_global_instance_ref_strong(global), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
f.call()?;
f
};
Expand Down Expand Up @@ -227,7 +227,7 @@ mod sys {
assert_eq!(is_table_instance_ref_strong(table), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
f.call()?;
f
};
Expand Down Expand Up @@ -271,7 +271,7 @@ mod sys {
assert_eq!(is_function_instance_ref_strong(function), Some(true));
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
f.call()?;
f
};
Expand Down Expand Up @@ -321,14 +321,14 @@ mod sys {

{
let function: TypedFunction<(), ()> =
instance.exports.get_native_function("call_host_fn")?;
instance.exports.get_typed_function("call_host_fn")?;
assert_eq!(
is_native_function_instance_ref_strong(&function),
Some(true)
);
}

let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
f.call()?;
f
};
Expand Down
2 changes: 1 addition & 1 deletion lib/api/tests/sys_externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ mod sys {
let f = {
let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?;
let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("sum")?;
let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function("sum")?;

assert_eq!(f.call(4, 5)?, 9);
f
Expand Down
16 changes: 8 additions & 8 deletions lib/api/tests/sys_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ mod sys {
};
let instance = Instance::new(&module, &imports)?;

let f1: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func1")?;
let f2: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func2")?;
let f3: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func3")?;
let f4: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func4")?;
let f5: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func5")?;
let f6: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func6")?;
let f7: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func7")?;
let f8: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func8")?;
let f1: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func1")?;
let f2: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func2")?;
let f3: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func3")?;
let f4: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func4")?;
let f5: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func5")?;
let f6: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func6")?;
let f7: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func7")?;
let f8: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func8")?;

f1.call()?;
f2.call()?;
Expand Down
26 changes: 12 additions & 14 deletions lib/api/tests/sys_reference_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod sys {
{
let f: TypedFunction<(), i32> = instance
.exports
.get_native_function("call_host_func_with_wasm_func")?;
.get_typed_function("call_host_func_with_wasm_func")?;
let result = f.call()?;
assert_eq!(result, 63);
}
Expand Down Expand Up @@ -183,7 +183,7 @@ mod sys {
panic!("result is not an extern ref!");
}

let f: TypedFunction<(), ExternRef> = instance.exports.get_native_function(run)?;
let f: TypedFunction<(), ExternRef> = instance.exports.get_typed_function(run)?;
let result: ExternRef = f.call()?;
assert!(result.is_null());
}
Expand All @@ -200,7 +200,7 @@ mod sys {
}

let f: TypedFunction<(), ExternRef> =
instance.exports.get_native_function(get_hashmap)?;
instance.exports.get_typed_function(get_hashmap)?;

let result: ExternRef = f.call()?;
let inner: &HashMap<String, String> = result.downcast().unwrap();
Expand All @@ -222,7 +222,7 @@ mod sys {
)"#;
let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?;
let f: TypedFunction<ExternRef, ()> = instance.exports.get_native_function("drop")?;
let f: TypedFunction<ExternRef, ()> = instance.exports.get_typed_function("drop")?;

let er = ExternRef::new(3u32);
f.call(er.clone())?;
Expand Down Expand Up @@ -316,7 +316,7 @@ mod sys {
let instance = Instance::new(&module, &imports! {})?;

let f: TypedFunction<(ExternRef, i32), ExternRef> =
instance.exports.get_native_function("insert_into_table")?;
instance.exports.get_typed_function("insert_into_table")?;

let er = ExternRef::new(3usize);

Expand Down Expand Up @@ -359,7 +359,7 @@ mod sys {
assert_eq!(er.strong_count(), 2);
}
let get_from_global: TypedFunction<(), ExternRef> =
instance.exports.get_native_function("get_from_global")?;
instance.exports.get_typed_function("get_from_global")?;

let er = get_from_global.call()?;
assert_eq!(er.strong_count(), 2);
Expand All @@ -383,7 +383,7 @@ mod sys {
let instance = Instance::new(&module, &imports! {})?;

let pass_extern_ref: TypedFunction<ExternRef, ()> =
instance.exports.get_native_function("pass_extern_ref")?;
instance.exports.get_typed_function("pass_extern_ref")?;

let er = ExternRef::new(3usize);
assert_eq!(er.strong_count(), 1);
Expand Down Expand Up @@ -411,14 +411,12 @@ mod sys {
let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &imports! {})?;

let grow_table_with_ref: TypedFunction<(ExternRef, i32), i32> = instance
.exports
.get_native_function("grow_table_with_ref")?;
let fill_table_with_ref: TypedFunction<(ExternRef, i32, i32), ()> = instance
.exports
.get_native_function("fill_table_with_ref")?;
let grow_table_with_ref: TypedFunction<(ExternRef, i32), i32> =
instance.exports.get_typed_function("grow_table_with_ref")?;
let fill_table_with_ref: TypedFunction<(ExternRef, i32, i32), ()> =
instance.exports.get_typed_function("fill_table_with_ref")?;
let copy_into_table2: TypedFunction<(), ()> =
instance.exports.get_native_function("copy_into_table2")?;
instance.exports.get_typed_function("copy_into_table2")?;
let table1: &Table = instance.exports.get_table("table1")?;
let table2: &Table = instance.exports.get_table("table2")?;

Expand Down
Loading

0 comments on commit 6c57aee

Please sign in to comment.