Skip to content

[turbopack] Split IsTransient out of TaskInput trait#94136

Draft
lukesandberg wants to merge 2 commits into
lukesandberg/shrink-futuresfrom
lukesandberg/clone_ready_task_input
Draft

[turbopack] Split IsTransient out of TaskInput trait#94136
lukesandberg wants to merge 2 commits into
lukesandberg/shrink-futuresfrom
lukesandberg/clone_ready_task_input

Conversation

@lukesandberg
Copy link
Copy Markdown
Contributor

No description provided.

Adds a new `IsTransient` trait with a single method `fn is_transient(&self) -> bool`
defaulting to `false`. Makes `TaskInput: IsTransient` (supertrait), removes
`is_transient` from `TaskInput` itself, and adds a derive proc-macro for `IsTransient`
that emits a field-walking implementation.

This is pure cleanup with two benefits:

1. **Decoupled concern.** Transience checking is orthogonal to whether a type can be
   passed as a `#[turbo_tasks::function]` argument. Splitting it out makes the trait
   surface cleaner and lets non-`TaskInput` types check transience without adopting
   the full TaskInput contract.

2. **Sets up a future blanket impl.** Every `#[derive(NonLocalValue)]` type carries the
   property "contains no unresolved Vcs" — exactly the precondition for treating
   `TaskInput::resolve_input` as a no-op clone (the `CloneReady` future). A follow-up
   commit can have the `NonLocalValue` derive emit the optimized `TaskInput` impl
   directly, eliminating the async-fn envelope for ~92 types.

Also switches the default `TaskInput::resolve_input` body from an opaque async block to
the named `CloneReady` future (8 B, no enum discriminant) — small but consistent win
on every primitive impl.

The 144 sites that derive `TaskInput` now also derive `IsTransient`. The handful of
manual `impl TaskInput` blocks (`Pattern`, `Query`, `WebpackLoaderItem`, etc.) drop
the now-orphan `is_transient` method body and gain a trivial `impl IsTransient for X {}`.
…eReady TaskInput

Most #[turbo_tasks::value] types are cell-output types — produced by tasks and never
passed as task arguments — so they don't satisfy TaskInput's supertrait bounds
(`Clone + Eq + Hash + Encode + Decode + ...`). A small fraction (FileSystemPath,
AssetIdent, NextMode, etc.) are intended as function arguments.

This commit adds a `task_input` opt-in flag to #[turbo_tasks::value(...)]:

  #[turbo_tasks::value(shared, task_input)]
  pub struct FileSystemPath { ... }

When set, the macro:
- Adds `#[derive(turbo_tasks::IsTransient)]` to the struct.
- Emits `impl turbo_tasks::TaskInput for X {}`, using the trait defaults
  (`is_resolved = true`, `resolve_input` returns a CloneReady future — 8 bytes,
  no async-fn envelope).

Concrete tags applied to high-leverage task-input types: AssetIdent, BatchingConfig,
ClientContextType, EcmascriptModuleAssetType, ExecutionEnvironment, FileSystemPath,
IssueSeverity, NextFontGoogleOptions, NextFontLocalOptions, NextMode, Pattern,
RequestKey, ResolveErrorMode, ServerContextType, SourceMapsType, StyleGroupsAlgorithm.

Measured workspace impact (next-napi-bindings, -Zprint-type-sizes):
- Default change to CloneReady future:    -10,760 B (-0.60%)
- task_input opt-in on ~16 types:         -17,368 B (-0.96%)
- Combined:                               -28,128 B (-1.56%)

Follow-ups can tag more leaderboard candidates incrementally as their value justifies.
Copy link
Copy Markdown
Contributor Author

lukesandberg commented May 26, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Stats skipped

Commit: 4a4c522
View workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant