next.js
548fbca6 - turbopack: Remove Vc::resolve(), migrate all callsites to Vc::to_resolved() (#91725)

Commit
7 days ago
turbopack: Remove Vc::resolve(), migrate all callsites to Vc::to_resolved() (#91725) ### What? Remove the `Vc::resolve()` method and migrate all ~37 callsites across the turbopack and next crates to use `Vc::to_resolved()` instead. ### Why? `Vc::resolve()` returned `Result<Vc<T>>` — a resolved `Vc` with no static guarantee that it is resolved. This is a footgun: the type is indistinguishable from any other unresolved `Vc<T>`, so it's easy to accidentally lose the "resolved" property at a type boundary or store it in a struct without the compiler enforcing invariants. `Vc::to_resolved()` returns `Result<ResolvedVc<T>>`, which statically encodes the resolved guarantee in the type. `ResolvedVc<T>` implements `Deref<Target = Vc<T>>`, so it coerces seamlessly to `Vc<T>` at call sites that still need the plain type. Removing `Vc::resolve()` eliminates this footgun entirely and pushes callers toward the type-safe API. ### How? - Removed the `Vc::resolve()` method from `turbo-tasks/src/vc/mod.rs`. - Updated `Vc::to_resolved()` to construct the inner `Vc` directly via `self.node.resolve()` rather than calling `self.resolve()`. - Updated `Vc::debug_identifier` to go through `to_resolved()`. - Updated `TaskInput::resolve_input` for `Vc<T>` to use `to_resolved()`. - Updated all callsites across turbopack-core, turbopack-ecmascript, turbopack-resolve, turbopack-browser, turbopack-css, turbopack-node, turbopack-ecmascript-runtime, next-api, next-core, and test/fuzz files: - Where `ResolvedVc<T>` is usable (deref coercion handles method calls, or the value is stored in a `HashMap` etc.), simply replaced `.resolve()` with `.to_resolved()`. - Where a plain `Vc<T>` is strictly required by a callee signature, dereferenced with `*x.to_resolved().await?`. - Updated the `AfterResolvePluginWithCondition` type alias in `resolve/mod.rs` to use `ResolvedVc<AfterResolvePluginCondition>` now that the tuple member is produced by `to_resolved()`. - Updated doc comments referencing `Vc::resolve` to point to `Vc::to_resolved`. Verified with `cargo check --all-targets` — compiles cleanly with no errors. --------- Co-authored-by: Tobias Koppers <sokra@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
Author
Parents
Loading