Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Fix parsing of defaults in generics#94

Open
bgw wants to merge 1 commit intobincode-org:trunkfrom
bgw:bgw/fix-generic-default-parsing
Open

Fix parsing of defaults in generics#94
bgw wants to merge 1 commit intobincode-org:trunkfrom
bgw:bgw/fix-generic-default-parsing

Conversation

@bgw
Copy link

@bgw bgw commented Oct 31, 2025

I ran into this while using the bincode derive macros.

There were two bugs:

  • Defaults used in combination with constraints would get parsed as part of the constraints because we didn't stop consuming tokens when encountering =.
  • Defaults used in const generics weren't handled at all.

API changes:

  • This add a new field to the ConstGeneric struct.

There were two bugs:
- Defaults used in combination with constraints would get parsed as part
  of the constraints because we didn't stop consuming tokens when
  encountering `=`.
- Defaults used in const generics weren't handled at all.
bgw added a commit to vercel/next.js that referenced this pull request Dec 5, 2025
…bo task values (#85580)

It looks like bincode should reduce the filesystem cache size by ~10% versus pot, because its not a self-describing format. This attempts to add the `bincode::Encode`/`bincode::Decode` traits everywhere, so that we can use those instead of serde.

## Why not use bincode's serde compatibility feature?

- Unfortunately, serde has some bugs/incompatibilities/footguns with non-self-describing formats. `bincode`'s traits avoid this by not exposing features that would be incompatible with a self-describing format. https://docs.rs/bincode/latest/bincode/serde/index.html#known-issues
- `bincode::Encode`/`Decode` are much simpler traits than serde's equivalents, so we'll probably get some rustc build performance and turbopack binary size benefits from using the bincode versions. In cases where we do have to implement these traits by hand, it's much easier than implementing the serde equivalents.
- I'd like to kill `erased-serde` anyways because we're probably paying some performance cost from the large amounts of dynamic dispatch it performs, and we're not getting any benefits from it if we only ever serialize to a single format.

## Forks of Upstream Crates

- I've forked `bincode` here: https://github.com/bgw/bincode/commits/bgw/patches/
  - I submitted a patch via email to the maintainer via sourcehut
    - Upstream: https://git.sr.ht/~stygianentity/bincode
    - Fork: https://git.sr.ht/~bgw/bincode
  - This adds a few extra derive features and fixes type bounds on `PhantomData`.
  - The type bounds on `PhantomData` aren't very important, and we could work around it in our code.
  - We could just fork the derive crate if upstream doesn't want to accept the patches.
- And `virtue` here: bgw/virtue@e386f35
  - I've submitted a PR to `virtue` here: bincode-org/virtue#94
  - This fixes a bug in the parsing of const enums and generics with defaults.
  - We don't hit this very often as most of our types are not generics, so we could work around it in our code if upstream doesn't want to accept the patch.

## Other Notes

- Depends on a patched version of the `bincode` and `virtue` crates to fix a few bugs and add a few new features. I'll work on upstreaming these changes.
- This implements `BorrowDecode` everywhere because the `bincode::Decode` derive macro requires it. I plan to add an attribute in my bincode fork to allow disabling this, and then we can get rid of all of the `BorrowDecode` impls. We don't want/need `BorrowDecode` for turbo task values because everything needs to be owned anyways.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant