Skip to content

Commit e622d5a

Browse files
authored
[turbopack] Remove LocalTaskType::Native, it is dead (#85480)
### What Remove `LocalTaskType::Native` and supporting infrastructure. Simplify schedule_local_task to remove an allocation and `CaptureFuture`. ### Why? local tasks for things other than 'resolve' tasks have been proven to not be a very useful idea. However, for resolve tasks they do still make sense. We can use the small amount of indirection provided by `LocalTask` to optimize how we launch other turbotasks. Now that the local task implementation is clearly just about turbo-tasks infrastructure (rather than calling arbitrary 'user code') we can simplify dispatching a bit.
1 parent 13bf3d9 commit e622d5a

File tree

13 files changed

+81
-294
lines changed

13 files changed

+81
-294
lines changed

turbopack/crates/turbo-tasks-backend/tests/local_tasks.rs

Lines changed: 0 additions & 74 deletions
This file was deleted.

turbopack/crates/turbo-tasks-macros-tests/tests/function/fail_attribute_invalid_args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unexpected token, expected one of: "fs", "network", "operation", "local"
1+
error: unexpected token, expected one of: "fs", "network", or "operation"
22
--> tests/function/fail_attribute_invalid_args.rs:10:25
33
|
44
10 | #[turbo_tasks::function(invalid_argument)]

turbopack/crates/turbo-tasks-macros-tests/tests/function/fail_attribute_invalid_args_inherent_impl.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unexpected token, expected one of: "fs", "network", "operation", "local"
1+
error: unexpected token, expected one of: "fs", "network", or "operation"
22
--> tests/function/fail_attribute_invalid_args_inherent_impl.rs:15:29
33
|
44
15 | #[turbo_tasks::function(invalid_argument)]

turbopack/crates/turbo-tasks-macros/src/func.rs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ pub struct TurboFn<'a> {
3030
exposed_inputs: Vec<Input>,
3131
/// Should we return `OperationVc` and require that all arguments are `NonLocalValue`s?
3232
operation: bool,
33-
/// Should this function use `TaskPersistence::LocalCells`?
34-
local: bool,
3533
}
3634

3735
#[derive(Debug)]
@@ -206,7 +204,6 @@ impl TurboFn<'_> {
206204
this,
207205
exposed_inputs,
208206
operation: args.operation.is_some(),
209-
local: args.local.is_some(),
210207
inline_ident,
211208
})
212209
}
@@ -494,26 +491,14 @@ impl TurboFn<'_> {
494491
}
495492

496493
pub fn persistence(&self) -> impl ToTokens {
497-
if self.local {
498-
quote! {
499-
turbo_tasks::TaskPersistence::Local
500-
}
501-
} else {
502-
quote! {
503-
turbo_tasks::macro_helpers::get_non_local_persistence_from_inputs(&*inputs)
504-
}
494+
quote! {
495+
turbo_tasks::macro_helpers::get_persistence_from_inputs(&*inputs)
505496
}
506497
}
507498

508499
pub fn persistence_with_this(&self) -> impl ToTokens {
509-
if self.local {
510-
quote! {
511-
turbo_tasks::TaskPersistence::Local
512-
}
513-
} else {
514-
quote! {
515-
turbo_tasks::macro_helpers::get_non_local_persistence_from_inputs_and_this(this, &*inputs)
516-
}
500+
quote! {
501+
turbo_tasks::macro_helpers::get_persistence_from_inputs_and_this(this, &*inputs)
517502
}
518503
}
519504

@@ -748,10 +733,6 @@ pub struct FunctionArguments {
748733
///
749734
/// If there is an error due to this option being set, it should be reported to this span.
750735
pub operation: Option<Span>,
751-
/// Does not run the function as a real task, and instead runs it inside the parent task using
752-
/// task-local state. The function call itself will not be cached, but cells will be created on
753-
/// the parent task.
754-
pub local: Option<Span>,
755736
}
756737

757738
impl Parse for FunctionArguments {
@@ -776,24 +757,15 @@ impl Parse for FunctionArguments {
776757
("operation", Meta::Path(_)) => {
777758
parsed_args.operation = Some(meta.span());
778759
}
779-
("local", Meta::Path(_)) => {
780-
parsed_args.local = Some(meta.span());
781-
}
782760
(_, meta) => {
783761
return Err(syn::Error::new_spanned(
784762
meta,
785-
"unexpected token, expected one of: \"fs\", \"network\", \"operation\", \
786-
\"local\"",
763+
"unexpected token, expected one of: \"fs\", \"network\", or \"operation\"",
787764
));
788765
}
789766
}
790767
}
791-
if let (Some(_), Some(span)) = (parsed_args.local, parsed_args.operation) {
792-
return Err(syn::Error::new(
793-
span,
794-
"\"operation\" is mutually exclusive with the \"local\" option",
795-
));
796-
}
768+
797769
Ok(parsed_args)
798770
}
799771
}
@@ -1111,7 +1083,6 @@ pub struct NativeFn {
11111083
/// Used only if `is_method` is true.
11121084
pub is_self_used: bool,
11131085
pub filter_trait_call_args: Option<FilterTraitCallArgsTokens>,
1114-
pub local: bool,
11151086
}
11161087

11171088
impl NativeFn {
@@ -1127,7 +1098,6 @@ impl NativeFn {
11271098
is_method,
11281099
is_self_used,
11291100
filter_trait_call_args,
1130-
local,
11311101
} = self;
11321102

11331103
if *is_method {
@@ -1153,9 +1123,6 @@ impl NativeFn {
11531123
turbo_tasks::macro_helpers::NativeFunction::new_method(
11541124
#function_path_string,
11551125
#function_global_name,
1156-
turbo_tasks::macro_helpers::FunctionMeta {
1157-
local: #local,
1158-
},
11591126
#arg_filter,
11601127
#function_path,
11611128
)
@@ -1168,9 +1135,6 @@ impl NativeFn {
11681135
turbo_tasks::macro_helpers::NativeFunction::new_method_without_this(
11691136
#function_path_string,
11701137
#function_global_name,
1171-
turbo_tasks::macro_helpers::FunctionMeta {
1172-
local: #local,
1173-
},
11741138
#arg_filter,
11751139
#function_path,
11761140
)
@@ -1184,9 +1148,6 @@ impl NativeFn {
11841148
turbo_tasks::macro_helpers::NativeFunction::new_function(
11851149
#function_path_string,
11861150
#function_global_name,
1187-
turbo_tasks::macro_helpers::FunctionMeta {
1188-
local: #local,
1189-
},
11901151
#function_path,
11911152
)
11921153
}

turbopack/crates/turbo-tasks-macros/src/function_macro.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub fn function(args: TokenStream, input: TokenStream) -> TokenStream {
4141
let args = syn::parse::<FunctionArguments>(args)
4242
.inspect_err(|err| errors.push(err.to_compile_error()))
4343
.unwrap_or_default();
44-
let local = args.local.is_some();
4544
let is_self_used = args.operation.is_some() || is_self_used(&block);
4645

4746
let Some(turbo_fn) = TurboFn::new(&sig, DefinitionContext::NakedFn, args) else {
@@ -66,7 +65,6 @@ pub fn function(args: TokenStream, input: TokenStream) -> TokenStream {
6665
is_method: turbo_fn.is_method(),
6766
is_self_used,
6867
filter_trait_call_args: None, // not a trait method
69-
local,
7068
};
7169
let native_function_ident = get_native_function_ident(ident);
7270
let native_function_ty = native_fn.ty();

turbopack/crates/turbo-tasks-macros/src/value_impl_macro.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream {
9797
FunctionArguments::default()
9898
}
9999
};
100-
let local = func_args.local.is_some();
101100
let is_self_used = func_args.operation.is_some() || is_self_used(block);
102101

103102
let Some(turbo_fn) =
@@ -120,7 +119,6 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream {
120119
is_method: turbo_fn.is_method(),
121120
is_self_used,
122121
filter_trait_call_args: None, // not a trait method
123-
local,
124122
};
125123

126124
let native_function_ident = get_inherent_impl_function_ident(ty_ident, ident);
@@ -209,7 +207,6 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream {
209207
continue;
210208
}
211209
};
212-
let local = func_args.local.is_some();
213210
let is_self_used = func_args.operation.is_some() || is_self_used(block);
214211

215212
let Some(turbo_fn) =
@@ -246,7 +243,6 @@ pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream {
246243
is_method: turbo_fn.is_method(),
247244
is_self_used,
248245
filter_trait_call_args: turbo_fn.filter_trait_call_args(),
249-
local,
250246
};
251247

252248
let native_function_ident =

turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,6 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
212212
is_method: turbo_fn.is_method(),
213213
is_self_used,
214214
filter_trait_call_args: turbo_fn.filter_trait_call_args(),
215-
// `local` is currently unsupported here because:
216-
// - The `#[turbo_tasks::function]` macro needs to be present for us to read this
217-
// argument. (This could be fixed)
218-
// - This only makes sense when a default implementation is present.
219-
local: false,
220215
};
221216

222217
let native_function_ident = get_trait_default_impl_function_ident(trait_ident, ident);

turbopack/crates/turbo-tasks/src/macro_helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use crate::{
1616
magic_any::MagicAny,
1717
manager::{find_cell_by_type, spawn_detached_for_testing},
1818
native_function::{
19-
CollectableFunction, FunctionMeta, NativeFunction, downcast_args_owned, downcast_args_ref,
19+
CollectableFunction, NativeFunction, downcast_args_owned, downcast_args_ref,
2020
},
2121
value_type::{CollectableTrait, CollectableValueType},
2222
};
@@ -32,15 +32,15 @@ pub async fn value_debug_format_field(value: ValueDebugFormatString<'_>) -> Stri
3232
}
3333
}
3434

35-
pub fn get_non_local_persistence_from_inputs(inputs: &impl TaskInput) -> TaskPersistence {
35+
pub fn get_persistence_from_inputs(inputs: &impl TaskInput) -> TaskPersistence {
3636
if inputs.is_transient() {
3737
TaskPersistence::Transient
3838
} else {
3939
TaskPersistence::Persistent
4040
}
4141
}
4242

43-
pub fn get_non_local_persistence_from_inputs_and_this(
43+
pub fn get_persistence_from_inputs_and_this(
4444
this: RawVc,
4545
inputs: &impl TaskInput,
4646
) -> TaskPersistence {

0 commit comments

Comments
 (0)