Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jan 24, 2025
1 parent 44f0691 commit 3e43193
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 24 deletions.
51 changes: 34 additions & 17 deletions turbopack/crates/turbo-tasks-macros/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,13 +1051,14 @@ pub struct NativeFn {
pub function_path_string: String,
pub function_path: ExprPath,
pub is_method: bool,
pub filter_trait_call_args: Option<TokenStream>,
pub local: bool,
pub local_cells: bool,
}

impl NativeFn {
pub fn ty(&self) -> Type {
parse_quote! { turbo_tasks::NativeFunction }
parse_quote! { turbo_tasks::macro_helpers::NativeFunction }
}

pub fn definition(&self) -> TokenStream {

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / build / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / build / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / build-native / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / build-wasm (web)

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / build-wasm (nodejs)

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / build-native / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / test unit (20) / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / test unit (20) / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / test devlow package / build

mismatched types

Check failure on line 1064 in turbopack/crates/turbo-tasks-macros/src/func.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu - node@16

mismatched types
Expand All @@ -1070,24 +1071,40 @@ impl NativeFn {
} = self;

let constructor = if *is_method {
quote! { new_method }
let arg_meta = if let Some(filter) = self.filter_trait_call_args {
quote! { turbo_tasks::macro_helpers::ArgMeta::with_filter_trait_call_args(#filter) }
} else {
quote! { turbo_tasks::macro_helpers::ArgMeta::new() }
};
quote! {
{
#[allow(deprecated)]
turbo_tasks::macro_helpers::NativeFunction::new_method(
#function_path_string.to_owned(),
turbo_tasks::macro_helpers::FunctionMeta {
local: #local,
local_cells: #local_cells,
},
turbo_tasks::macro_helpers::ArgMeta::new(),
#function_path,
)
}
}
} else {
quote! { new_function }
};

quote! {
{
#[allow(deprecated)]
turbo_tasks::NativeFunction::#constructor(
#function_path_string.to_owned(),
turbo_tasks::FunctionMeta {
local: #local,
local_cells: #local_cells,
},
#function_path,
)
quote! {
{
#[allow(deprecated)]
turbo_tasks::macro_helpers::NativeFunction::new_function(
#function_path_string.to_owned(),
turbo_tasks::macro_helpers::FunctionMeta {
local: #local,
local_cells: #local_cells,
},
#function_path,
)
}
}
}
};
}

pub fn id_ty(&self) -> Type {
Expand Down
1 change: 0 additions & 1 deletion turbopack/crates/turbo-tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub use manager::{
CurrentCellRef, ReadConsistency, TaskPersistence, TurboTasks, TurboTasksApi,
TurboTasksBackendApi, TurboTasksBackendApiExt, TurboTasksCallApi, Unused, UpdateInfo,
};
pub use native_function::{FunctionMeta, NativeFunction};
pub use output::OutputContent;
pub use raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError};
pub use read_ref::ReadRef;
Expand Down
7 changes: 5 additions & 2 deletions turbopack/crates/turbo-tasks/src/macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ pub use super::{
manager::{find_cell_by_type, notify_scheduled_tasks, spawn_detached_for_testing},
};
use crate::{
debug::ValueDebugFormatString, shrink_to_fit::ShrinkToFit, task::TaskOutput, NonLocalValue,
RawVc, TaskInput, TaskPersistence, Vc,
debug::ValueDebugFormatString,
native_function::{ArgMeta, FunctionMeta, NativeFunction},
shrink_to_fit::ShrinkToFit,
task::TaskOutput,
NonLocalValue, RawVc, TaskInput, TaskPersistence, Vc,
};

#[inline(never)]
Expand Down
5 changes: 3 additions & 2 deletions turbopack/crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
},
id_factory::{IdFactory, IdFactoryWithReuse},
magic_any::MagicAny,
native_function::FunctionMeta,
raw_vc::{CellId, RawVc},
registry::{self, get_function},
serialization_invalidation::SerializationInvalidator,
Expand All @@ -48,8 +49,8 @@ use crate::{
trait_helpers::get_trait_method,
util::StaticOrArc,
vc::ReadVcFuture,
Completion, FunctionMeta, InvalidationReason, InvalidationReasonSet, ResolvedVc,
SharedReference, TaskId, TaskIdSet, ValueTypeId, Vc, VcRead, VcValueTrait, VcValueType,
Completion, InvalidationReason, InvalidationReasonSet, ResolvedVc, SharedReference, TaskId,
TaskIdSet, ValueTypeId, Vc, VcRead, VcValueTrait, VcValueType,
};

pub trait TurboTasksCallApi: Sync + Send {
Expand Down
17 changes: 16 additions & 1 deletion turbopack/crates/turbo-tasks/src/native_function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Debug, hash::Hash, pin::Pin};
use std::{env::args, fmt::Debug, hash::Hash, pin::Pin};

use anyhow::{Context, Result};
use futures::Future;
Expand All @@ -23,15 +23,28 @@ type ResolveFunctor =

type IsResolvedFunctor = fn(&dyn MagicAny) -> bool;

type FilterArgsFunctor = for<'a> fn(Box<dyn MagicAny>) -> Box<dyn MagicAny>;

pub struct ArgMeta {
serializer: MagicAnySerializeSeed,
deserializer: MagicAnyDeserializeSeed,
is_resolved: IsResolvedFunctor,
resolve: ResolveFunctor,
filter_trait_call_args: FilterArgsFunctor,
}

impl ArgMeta {
pub fn new<T>() -> Self
where
T: TaskInput + Serialize + for<'de> Deserialize<'de> + 'static,
{
fn noop_filter_args(args: Box<dyn MagicAny>) -> Box<dyn MagicAny> {
args
}
Self::with_filter_trait_call_args::<T>(noop_filter_args)
}

pub fn with_filter_trait_call_args<T>(filter_trait_call_args: FilterArgsFunctor) -> Self
where
T: TaskInput + Serialize + for<'de> Deserialize<'de> + 'static,
{
Expand Down Expand Up @@ -64,6 +77,7 @@ impl ArgMeta {
Ok(Box::new(resolved) as Box<dyn MagicAny>)
})
},
filter_trait_call_args,
}
}

Expand Down Expand Up @@ -144,6 +158,7 @@ impl NativeFunction {
pub fn new_method<Mode, This, Inputs, I>(
name: String,
function_meta: FunctionMeta,
arg_meta: ArgMeta,
implementation: I,
) -> Self
where
Expand Down
3 changes: 2 additions & 1 deletion turbopack/crates/turbo-tasks/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use rustc_hash::FxHasher;
use crate::{
id::{FunctionId, TraitTypeId, ValueTypeId},
id_factory::IdFactory,
native_function::NativeFunction,
no_move_vec::NoMoveVec,
NativeFunction, TraitType, ValueType,
TraitType, ValueType,
};

type FxDashMap<K, V> = DashMap<K, V, BuildHasherDefault<FxHasher>>;
Expand Down

0 comments on commit 3e43193

Please sign in to comment.