fix: handle all values for buffers in turbocall codegen (#28170)

Now that ArrayBuffer/ArrayBufferView is a generic Value type, we have to
handle it being passed any value. To do this, thread
FastApiCallbackOptions through the function, and add error raising
logic.

If we run conversion and the value is not valid, we return `isize::MAX`,
and then in cranelift we use this value to know that we should branch to
the error logic.

An example compilation looks like this:
```rust
extern "C" fn print_buffer(ptr: *const u8, len: usize);
```

```clif
function %print_buffer_wrapper(i64, i64, i64, i64) system_v {
    sig0 = (i64, i64) system_v
    sig1 = (i64) -> i64 system_v
    sig2 = (i64) system_v

block0(v0: i64, v1: i64, v2: i64, v3: i64):
    v4 = iconst.i64 0x6525_9198_2d00 ; turbocall_ab_contents
    v5 = call_indirect sig1, v4(v1)
    v6 = iconst.i64 0x7fff_ffff_ffff_ffff
    v7 = icmp eq v5, v6
    brif v7, block1, block2

block2:
    v8 = iconst.i64 0x7558_4c0c_0700 ; sym.ptr
    call_indirect sig0, v8(v5, v2)
    return

block1 cold:
    v9 = iconst.i64 0x6525_9198_2d70 ; turbocall_raise
    call_indirect sig2, v9(v3)
    return
}
```

Also cleaned up all the `unwrap`s and added some logging.
This commit is contained in:
snek 2025-02-18 17:24:25 +01:00 committed by GitHub
parent 4ab380e0a7
commit 6206343b54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 265 additions and 103 deletions

View file

@ -95,6 +95,8 @@ pub fn init<
.filter_module("opentelemetry_sdk", log::LevelFilter::Off)
// for deno_compile, this is too verbose
.filter_module("editpe", log::LevelFilter::Error)
// too verbose
.filter_module("cranelift_codegen", log::LevelFilter::Off)
.format(|buf, record| {
let mut target = record.target().to_string();
if let Some(line_no) = record.line() {