Skip to content

Commit 6c57aee

Browse files
committed
Renamed get_native_function to get_typed_function, marked former as deprecated.
1 parent f9ce65a commit 6c57aee

20 files changed

+159
-136
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
1111
### Changed
1212
- #2946 Remove dylib,staticlib engines in favor of a single Universal engine
1313
- [#2949](https://github.com/wasmerio/wasmer/pull/2949) Switch back to using custom LLVM builds on CI
14+
- #2892 Renamed `get_native_function` to `get_typed_function`, marked former as deprecated.
1415

1516
### Fixed
1617
- [#2963](https://github.com/wasmerio/wasmer/pull/2963) Remove accidental dependency on libwayland and libxcb in ClI

examples/early_exit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn main() -> anyhow::Result<()> {
8282
//
8383
// Get the `run` function which we'll use as our entrypoint.
8484
println!("Calling `run` function...");
85-
let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("run")?;
85+
let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function("run")?;
8686

8787
// When we call a function it can either succeed or fail. We expect it to fail.
8888
match run_func.call(1, 7) {

examples/exports_memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5252

5353
let load = instance
5454
.exports
55-
.get_native_function::<(), (WasmPtr<u8>, i32)>("load")?;
55+
.get_typed_function::<(), (WasmPtr<u8>, i32)>("load")?;
5656

5757
// Here we go.
5858
//

examples/hello_world.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn main() -> anyhow::Result<()> {
8282
// Recall that the Wasm module exported a function named "run", this is getting
8383
// that exported function from the `Instance`.
8484
let run_func: TypedFunction<(), ()> =
85-
instance.exports.get_native_function(&mut context, "run")?;
85+
instance.exports.get_typed_function(&mut context, "run")?;
8686

8787
// Finally, we call our exported Wasm function which will call our "say_hello"
8888
// function and return.

examples/memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ fn main() -> anyhow::Result<()> {
7373
// The module exports some utility functions, let's get them.
7474
//
7575
// These function will be used later in this example.
76-
let mem_size: TypedFunction<(), i32> = instance.exports.get_native_function("mem_size")?;
77-
let get_at: TypedFunction<i32, i32> = instance.exports.get_native_function("get_at")?;
78-
let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_native_function("set_at")?;
76+
let mem_size: TypedFunction<(), i32> = instance.exports.get_typed_function("mem_size")?;
77+
let get_at: TypedFunction<i32, i32> = instance.exports.get_typed_function("get_at")?;
78+
let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_typed_function("set_at")?;
7979
let memory = instance.exports.get_memory("memory")?;
8080

8181
// We now have an instance ready to be used.

examples/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn main() -> anyhow::Result<()> {
6262
// The first argument is the table index and the next 2 are the 2 arguments
6363
// to be passed to the function found in the table.
6464
let call_via_table: TypedFunction<(i32, i32, i32), i32> =
65-
instance.exports.get_native_function("call_callback")?;
65+
instance.exports.get_typed_function("call_callback")?;
6666

6767
// And then call it with table index 1 and arguments 2 and 7.
6868
let result = call_via_table.call(1, 2, 7)?;

lib/api/src/js/exports.rs

+16
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,27 @@ impl Exports {
134134
self.get(name)
135135
}
136136

137+
#[deprecated(
138+
since = "3.0.0",
139+
note = "get_native_function() has been renamed to get_typed_function(), just like NativeFunc has been renamed to TypedFunction."
140+
)]
137141
/// Get an export as a `TypedFunction`.
138142
pub fn get_native_function<Args, Rets>(
139143
&self,
140144
name: &str,
141145
) -> Result<TypedFunction<Args, Rets>, ExportError>
146+
where
147+
Args: WasmTypeList,
148+
Rets: WasmTypeList,
149+
{
150+
self.get_typed_function(name)
151+
}
152+
153+
/// Get an export as a `TypedFunction`.
154+
pub fn get_typed_function<Args, Rets>(
155+
&self,
156+
name: &str,
157+
) -> Result<TypedFunction<Args, Rets>, ExportError>
142158
where
143159
Args: WasmTypeList,
144160
Rets: WasmTypeList,

lib/api/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
//! # fn exports_example(instance: &Instance) -> anyhow::Result<()> {
171171
//! let memory = instance.exports.get_memory("memory")?;
172172
//! let memory: &Memory = instance.exports.get("some_other_memory")?;
173-
//! let add: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?;
173+
//! let add: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function("add")?;
174174
//! let result = add.call(5, 37)?;
175175
//! assert_eq!(result, 42);
176176
//! # Ok(())

lib/api/src/sys/exports.rs

+17
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,29 @@ impl Exports {
134134
self.get(name)
135135
}
136136

137+
#[deprecated(
138+
since = "3.0.0",
139+
note = "get_native_function() has been renamed to get_typed_function(), just like NativeFunc has been renamed to TypedFunction."
140+
)]
137141
/// Get an export as a `TypedFunction`.
138142
pub fn get_native_function<Args, Rets>(
139143
&self,
140144
ctx: &impl AsContextRef,
141145
name: &str,
142146
) -> Result<TypedFunction<Args, Rets>, ExportError>
147+
where
148+
Args: WasmTypeList,
149+
Rets: WasmTypeList,
150+
{
151+
self.get_typed_function(ctx, name)
152+
}
153+
154+
/// Get an export as a `TypedFunction`.
155+
pub fn get_typed_function<Args, Rets>(
156+
&self,
157+
ctx: &impl AsContextRef,
158+
name: &str,
159+
) -> Result<TypedFunction<Args, Rets>, ExportError>
143160
where
144161
Args: WasmTypeList,
145162
Rets: WasmTypeList,

lib/api/tests/js_instance.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ mod js {
610610
let instance = Instance::new(&module, &import_object).unwrap();
611611

612612
let add_one: TypedFunction<i32, i32> =
613-
instance.exports.get_native_function("add_one").unwrap();
613+
instance.exports.get_typed_function("add_one").unwrap();
614614
assert_eq!(add_one.call(1), Ok(2));
615615
}
616616

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

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

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

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

731731
let run_func = instance.exports.get_function("run").unwrap();

lib/api/tests/js_module.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -251,35 +251,35 @@ mod js {
251251

252252
// let f1: TypedFunction<(), ()> = instance
253253
// .exports
254-
// .get_native_function("call_host_func1")
254+
// .get_typed_function("call_host_func1")
255255
// .unwrap();
256256
// let f2: TypedFunction<(), ()> = instance
257257
// .exports
258-
// .get_native_function("call_host_func2")
258+
// .get_typed_function("call_host_func2")
259259
// .unwrap();
260260
// let f3: TypedFunction<(), ()> = instance
261261
// .exports
262-
// .get_native_function("call_host_func3")
262+
// .get_typed_function("call_host_func3")
263263
// .unwrap();
264264
// let f4: TypedFunction<(), ()> = instance
265265
// .exports
266-
// .get_native_function("call_host_func4")
266+
// .get_typed_function("call_host_func4")
267267
// .unwrap();
268268
// let f5: TypedFunction<(), ()> = instance
269269
// .exports
270-
// .get_native_function("call_host_func5")
270+
// .get_typed_function("call_host_func5")
271271
// .unwrap();
272272
// let f6: TypedFunction<(), ()> = instance
273273
// .exports
274-
// .get_native_function("call_host_func6")
274+
// .get_typed_function("call_host_func6")
275275
// .unwrap();
276276
// let f7: TypedFunction<(), ()> = instance
277277
// .exports
278-
// .get_native_function("call_host_func7")
278+
// .get_typed_function("call_host_func7")
279279
// .unwrap();
280280
// let f8: TypedFunction<(), ()> = instance
281281
// .exports
282-
// .get_native_function("call_host_func8")
282+
// .get_typed_function("call_host_func8")
283283
// .unwrap();
284284

285285
// f1.call().unwrap();

lib/api/tests/sys_export.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ mod sys {
139139
assert_eq!(is_memory_instance_ref_strong(mem), Some(true));
140140
}
141141

142-
let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
142+
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
143143
f.call()?;
144144
f
145145
};
@@ -183,7 +183,7 @@ mod sys {
183183
assert_eq!(is_global_instance_ref_strong(global), Some(true));
184184
}
185185

186-
let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
186+
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
187187
f.call()?;
188188
f
189189
};
@@ -227,7 +227,7 @@ mod sys {
227227
assert_eq!(is_table_instance_ref_strong(table), Some(true));
228228
}
229229

230-
let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
230+
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
231231
f.call()?;
232232
f
233233
};
@@ -271,7 +271,7 @@ mod sys {
271271
assert_eq!(is_function_instance_ref_strong(function), Some(true));
272272
}
273273

274-
let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
274+
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
275275
f.call()?;
276276
f
277277
};
@@ -321,14 +321,14 @@ mod sys {
321321

322322
{
323323
let function: TypedFunction<(), ()> =
324-
instance.exports.get_native_function("call_host_fn")?;
324+
instance.exports.get_typed_function("call_host_fn")?;
325325
assert_eq!(
326326
is_native_function_instance_ref_strong(&function),
327327
Some(true)
328328
);
329329
}
330330

331-
let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?;
331+
let f: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_fn")?;
332332
f.call()?;
333333
f
334334
};

lib/api/tests/sys_externals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ mod sys {
396396
let f = {
397397
let module = Module::new(&store, wat)?;
398398
let instance = Instance::new(&module, &imports! {})?;
399-
let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("sum")?;
399+
let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function("sum")?;
400400

401401
assert_eq!(f.call(4, 5)?, 9);
402402
f

lib/api/tests/sys_module.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ mod sys {
228228
};
229229
let instance = Instance::new(&module, &imports)?;
230230

231-
let f1: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func1")?;
232-
let f2: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func2")?;
233-
let f3: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func3")?;
234-
let f4: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func4")?;
235-
let f5: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func5")?;
236-
let f6: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func6")?;
237-
let f7: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func7")?;
238-
let f8: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func8")?;
231+
let f1: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func1")?;
232+
let f2: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func2")?;
233+
let f3: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func3")?;
234+
let f4: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func4")?;
235+
let f5: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func5")?;
236+
let f6: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func6")?;
237+
let f7: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func7")?;
238+
let f8: TypedFunction<(), ()> = instance.exports.get_typed_function("call_host_func8")?;
239239

240240
f1.call()?;
241241
f2.call()?;

lib/api/tests/sys_reference_types.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ mod sys {
116116
{
117117
let f: TypedFunction<(), i32> = instance
118118
.exports
119-
.get_native_function("call_host_func_with_wasm_func")?;
119+
.get_typed_function("call_host_func_with_wasm_func")?;
120120
let result = f.call()?;
121121
assert_eq!(result, 63);
122122
}
@@ -183,7 +183,7 @@ mod sys {
183183
panic!("result is not an extern ref!");
184184
}
185185

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

202202
let f: TypedFunction<(), ExternRef> =
203-
instance.exports.get_native_function(get_hashmap)?;
203+
instance.exports.get_typed_function(get_hashmap)?;
204204

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

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

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

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

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

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

385385
let pass_extern_ref: TypedFunction<ExternRef, ()> =
386-
instance.exports.get_native_function("pass_extern_ref")?;
386+
instance.exports.get_typed_function("pass_extern_ref")?;
387387

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

414-
let grow_table_with_ref: TypedFunction<(ExternRef, i32), i32> = instance
415-
.exports
416-
.get_native_function("grow_table_with_ref")?;
417-
let fill_table_with_ref: TypedFunction<(ExternRef, i32, i32), ()> = instance
418-
.exports
419-
.get_native_function("fill_table_with_ref")?;
414+
let grow_table_with_ref: TypedFunction<(ExternRef, i32), i32> =
415+
instance.exports.get_typed_function("grow_table_with_ref")?;
416+
let fill_table_with_ref: TypedFunction<(ExternRef, i32, i32), ()> =
417+
instance.exports.get_typed_function("fill_table_with_ref")?;
420418
let copy_into_table2: TypedFunction<(), ()> =
421-
instance.exports.get_native_function("copy_into_table2")?;
419+
instance.exports.get_typed_function("copy_into_table2")?;
422420
let table1: &Table = instance.exports.get_table("table1")?;
423421
let table2: &Table = instance.exports.get_table("table2")?;
424422

0 commit comments

Comments
 (0)