Skip to content

Commit

Permalink
[Turbopack] serialization fixups (#68715)
Browse files Browse the repository at this point in the history
### What?

Fix some incorrect serialization code that has never been tested
Need to use fork of triomphe to convert `Box<dyn Any>` to `Arc<dyn
Any>`.
remove unused initializate function from backend
  • Loading branch information
sokra authored Aug 13, 2024
1 parent 6b77d56 commit ce48d7c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 18 deletions.
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

0 comments on commit ce48d7c

Please sign in to comment.