next.js
3a323194 - Turbopack: bincode: Add traits for types that require `TurboBincodeEncoder` or `TurboBincodeDecoder` (#86633)

Commit
19 days ago
Turbopack: bincode: Add traits for types that require `TurboBincodeEncoder` or `TurboBincodeDecoder` (#86633) **Example usage:** See `CachedTaskType`​ in `turbopack/crates/turbo-tasks/src/backend.rs`​ on https://github.com/vercel/next.js/pull/86631 for an example of how this is used. That needs to call the encoder/decoder function pointer stored on `native_fn.arg_meta.bincode` with a concrete `TurboBincodeEncoder`/`TurboBincodeDecoder`, so it uses this trait. --- For `SharedReference` (value cell contents) and `TaskInput`s, we need to generate function pointers to functions that can encode/decode the type. Those generated functions cannot contain generics, so they require `TurboBincodeEncoder` or `TurboBincodeDecoder<()>` as arguments. That's okay because we don't want to use multiple encoders/decoders anyways, because that would be really bad for binary size and compilation time. However, `SharedReference` and `TaskInput`s are wrapped in other container types that need to be encoded/decoded (e.g. `TypedSharedReference`. In these cases, the wrapper types need to be able to implement `Encode`/`Decode`, but can't because of the fixed `Encoder`/`Decoder` implementations. So this provides a way to do that, by panicking at runtime if the type doesn't match. This uses the `unty` crate which is part of the bincode project: https://github.com/bincode-org/unty
Author
bgw bgw
Parents
Loading