next.js
cd6a9bc7 - Replace mark_root() with #[turbo_tasks::function(root)] flag (#90512)

Commit
1 day ago
Replace mark_root() with #[turbo_tasks::function(root)] flag (#90512) ## Summary Replaces the runtime `mark_root()` call with a declarative `root` flag on the `#[turbo_tasks::function]` attribute macro. This moves root task aggregation number assignment from an imperative runtime call to a compile-time declaration, making the intent clearer and applying the aggregation number at task creation time rather than during execution. ### What changed - **Macro parsing**: Added `root` as a new flag option for `#[turbo_tasks::function(root)]` (can be combined with other flags, e.g. `#[turbo_tasks::function(operation, root)]`) - **NativeFunction**: Added `is_root: bool` field and parameter to all three constructors (`new_function`, `new_method`, `new_method_without_this`) - **Backend**: In `get_or_create_persistent_task` and `get_or_create_transient_task`, checks `native_fn.is_root` on brand-new task creation (not cache hits or backing storage restores) and sets `UpdateAggregationNumber` with `u32::MAX` - **Usage site**: Changed `whole_app_module_graph_operation` in `crates/next-api/src/project.rs` from `#[turbo_tasks::function(operation)]` + `mark_root()` to `#[turbo_tasks::function(operation, root)]` - **Cleanup**: Removed `mark_root()`, `set_own_task_aggregation_number` from `TurboTasksApi` trait, `Backend` trait, and all implementations (turbo-tasks-backend, turbo-tasks-testing) ### Key design decisions - Root aggregation number is only set on **brand-new task creation** (Vacant entry in the task cache when not found in backing storage either), not on cache hits or when restoring from backing storage - The `root` flag is stored on `NativeFunction` (which is a static singleton per function), so it's accessible via `CachedTaskType.native_fn.is_root` in the backend without any additional runtime overhead ## Test Plan - `cargo check -p turbo-tasks-macros -p turbo-tasks -p turbo-tasks-backend -p next-api` passes - `cargo test -p turbo-tasks-backend` passes - `pnpm swc-build-native` builds successfully
Author
Parents
Loading