-
Notifications
You must be signed in to change notification settings - Fork 256
Open
Labels
gen-cppRelated to the C++ code generatorRelated to the C++ code generatorgen-rustRelated to bindings for Rust-compiled-to-WebAssemblyRelated to bindings for Rust-compiled-to-WebAssembly
Description
If I take a look into the generated Rust code for the tests/runtime/lists test:
pub fn empty_list_param(a: &[u8]) -> () {
unsafe {
let vec0 = a;
let ptr0 = vec0.as_ptr().cast::<u8>();
let len0 = vec0.len();
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "test:lists/to-test")]
unsafe extern "C" {
#[link_name = "empty-list-param"]
fn wit_import1(_: *mut u8, _: usize);
}
#[cfg(not(target_arch = "wasm32"))]
unsafe extern "C" fn wit_import1(_: *mut u8, _: usize) {
unreachable!()
}
wit_import1(ptr0.cast_mut(), len0);
}
}The lowered function could be declared as receiving a const pointer (the host won't free or modify the list. This is also required by the immutable slice argument), this would remove the alarming .cast_mut() call.
(I came to this conclusion while looking into const correctness in the C++ backend)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
gen-cppRelated to the C++ code generatorRelated to the C++ code generatorgen-rustRelated to bindings for Rust-compiled-to-WebAssemblyRelated to bindings for Rust-compiled-to-WebAssembly