Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Turbopack] serialization fixups #68715

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ tokio = "1.25.0"
tokio-util = { version = "0.7.7", features = ["io"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
triomphe = "0.1.13"
triomphe = { git = "https://github.com/sokra/triomphe", branch = "sokra/unstable" }
unicode-segmentation = "1.10.1"
unsize = "1.1.0"
url = "2.2.2"
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbo-tasks-macros/src/value_trait_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
});

trait_methods.push(quote! {
trait_type.register_default_trait_method::<(#(#arg_types),*)>(stringify!(#ident).into(), *#native_function_id_ident);
trait_type.register_default_trait_method::<(#(#arg_types,)*)>(stringify!(#ident).into(), *#native_function_id_ident);
});

native_functions.push(quote! {
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
Some(turbo_fn.static_block(&native_function_id_ident))
} else {
trait_methods.push(quote! {
trait_type.register_trait_method::<(#(#arg_types),*)>(stringify!(#ident).into());
trait_type.register_trait_method::<(#(#arg_types,)*)>(stringify!(#ident).into());
});
None
};
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ serde_regex = "1.1.0"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
triomphe = { workspace = true, features = ["unsize"] }
triomphe = { workspace = true, features = ["unsize", "unstable"] }
turbo-tasks-hash = { workspace = true }
turbo-tasks-macros = { workspace = true }
turbo-tasks-malloc = { workspace = true }
Expand Down
11 changes: 4 additions & 7 deletions turbopack/crates/turbo-tasks/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::{
task::shared_reference::TypedSharedReference,
trait_helpers::{get_trait_method, has_trait, traits},
triomphe_utils::unchecked_sidecast_triomphe_arc,
FunctionId, RawVc, ReadRef, SharedReference, TaskId, TaskIdProvider, TaskIdSet, TraitRef,
TraitTypeId, ValueTypeId, VcRead, VcValueTrait, VcValueType,
FunctionId, RawVc, ReadRef, SharedReference, TaskId, TaskIdSet, TraitRef, TraitTypeId,
ValueTypeId, VcRead, VcValueTrait, VcValueType,
};

pub enum TaskType {
Expand Down Expand Up @@ -188,7 +188,7 @@ mod ser {
s.serialize_element::<u8>(&1)?;
s.serialize_element(&FunctionAndArg::Borrowed {
fn_type: *fn_type,
arg,
arg: &**arg,
})?;
s.serialize_element(this)?;
s.end()
Expand All @@ -207,7 +207,7 @@ mod ser {
let arg = if let Some(method) =
registry::get_trait(*trait_type).methods.get(method_name)
{
method.arg_serializer.as_serialize(arg)
method.arg_serializer.as_serialize(&**arg)
} else {
return Err(serde::ser::Error::custom("Method not found"));
};
Expand Down Expand Up @@ -428,9 +428,6 @@ impl TryFrom<CellContent> for SharedReference {
pub type TaskCollectiblesMap = AutoMap<RawVc, i32, BuildHasherDefault<FxHasher>, 1>;

pub trait Backend: Sync + Send {
#[allow(unused_variables)]
fn initialize(&mut self, task_id_provider: &dyn TaskIdProvider) {}

#[allow(unused_variables)]
fn startup(&self, turbo_tasks: &dyn TurboTasksBackendApi<Self>) {}

Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-tasks/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,6 @@ impl<'de> Deserialize<'de> for TaskId {
}
}

deserializer.deserialize_u64(V)
deserializer.deserialize_u32(V)
}
}
3 changes: 1 addition & 2 deletions turbopack/crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ impl<B: Backend + 'static> TurboTasks<B> {
// that should be safe as long tasks can't outlife turbo task
// so we probably want to make sure that all tasks are joined
// when trying to drop turbo tasks
pub fn new(mut backend: B) -> Arc<Self> {
pub fn new(backend: B) -> Arc<Self> {
let task_id_factory = IdFactoryWithReuse::new();
backend.initialize(&task_id_factory);
let this = Arc::new_cyclic(|this| Self {
this: this.clone(),
backend,
Expand Down
3 changes: 2 additions & 1 deletion turbopack/crates/turbo-tasks/src/task/shared_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ impl<'de> Deserialize<'de> for TypedSharedReference {
if let Some(seed) = registry::get_value_type(ty).get_any_deserialize_seed()
{
if let Some(value) = seq.next_element_seed(seed)? {
Ok(TypedSharedReference(ty, SharedReference::new(value.into())))
let arc = triomphe::Arc::<dyn Any + Send + Sync>::from(value);
Ok(TypedSharedReference(ty, SharedReference(arc)))
} else {
Err(serde::de::Error::invalid_length(
1,
Expand Down
Loading