next.js
394c97a2 - Add a resolved argument to `#[turbo_tasks::function]` (#68422)

Commit
1 year ago
Add a resolved argument to `#[turbo_tasks::function]` (#68422) ### What & Why? We want to enforce that values that functions return contain only `ResolvedVc` and not `Vc` (though the outermost `Vc` is okay). We can do that using the `ResolvedValue` marker trait (https://github.com/vercel/turbo/pull/8678). This PR allows enforcing that by passing a `resolved` argument to the `#[turbo_tasks::function(...)]` macro. This enforcement behavior is currently opt-in, but the goal is eventually to make it opt-out, so that most functions can easily be converted to use local tasks. Bigger picture: https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff ### How? The key part of the macro is this bit: ``` fn assert_returns_resolved_value< ReturnType, Rv, >() where ReturnType: turbo_tasks::task::TaskOutput<Return = Vc<Rv>>, Rv: turbo_tasks::ResolvedValue + Send, {} assert_returns_resolved_value::<#return_type, _>() ``` That creates no-op code that successfully compiles when the return value (inside of the outermost `Vc`) is a `ResolvedValue`, but fails when it isn't. This is the same trick that the [`static_assertions` library](https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_eq_all.html) uses. ### Test Plan Lots of [trybuild](https://github.com/dtolnay/trybuild) tests! ``` cargo nextest r -p turbo-tasks-macros-tests ``` **Hint:** Use `TRYBUILD=overwrite` when intentionally changing the tests.
Author
bgw bgw
Parents
Loading