next.js
afddbe7a - refactor(turbo-tasks): Make State require OperationValue (#73876)

Commit
1 year ago
refactor(turbo-tasks): Make State require OperationValue (#73876) I started writing this PR by requiring `OperationValue` in `State`: ```diff impl<T> State<T> { - pub fn new(value: T) -> Self { + pub fn new(value: T) -> Self + where + T: OperationValue, + { ``` And then went through changing every compilation error that occurred as a result. ## Hacks **There are some hacks in a number of places here where we incorrectly convert `ResolvedVc` to `OperationValue`.** Unfortunately these have to exist because it's impractical to convert everything to `OperationValue`. `OperationValues` are harder to construct as they must be created directly from the return value of an unresolved function call. ## Why does `State<T>` need `T: OperationValue`? `OperationVc` types require that `.connect()` is called before their value can be read. As an internally-mutable type, `State` allows `Vc`s to be passed in ways that we cannot track. `.connect()` re-connects the `Vc` to the dependency graph so that strong resolution is possible. Without this, you might end up with stale results when reading a `Vc` inside of `State`, which can be very hard to debug. Fundamentally, I think `State` is unsound, but this is a band-aid on it until we can migrate to a better solution (likely effect-style `Collectibles` for `VersionedContentMap`).
Author
bgw bgw
Parents
Loading