Skip to content

Commit a1cb4f6

Browse files
committed
And even when embedded in a Vc/ReadRef
1 parent 9df6dc7 commit a1cb4f6

File tree

5 files changed

+25
-52
lines changed

5 files changed

+25
-52
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use turbo_tasks::{
3636
},
3737
event::{Event, EventListener},
3838
message_queue::TimingEvent,
39-
registry::{self, get_value_type_global_name},
39+
registry::get_value_type_global_name,
4040
task_statistics::TaskStatisticsApi,
4141
trace::TraceRawVcs,
4242
turbo_tasks,
@@ -867,7 +867,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
867867

868868
let _span = tracing::trace_span!(
869869
"recomputation",
870-
cell_type = registry::get_value_type_global_name(cell.type_id),
870+
cell_type = get_value_type_global_name(cell.type_id),
871871
cell_index = cell.index
872872
)
873873
.entered();

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ mod ser {
127127
None
128128
};
129129
let mut state = serializer.serialize_tuple(3)?;
130-
state.serialize_element(registry::get_value_type_global_name(self.0))?;
130+
state.serialize_element(&self.0)?;
131131
if let Some(serializable) = serializable {
132132
state.serialize_element(&true)?;
133133
state.serialize_element(serializable)?;
@@ -157,11 +157,9 @@ mod ser {
157157
where
158158
A: de::SeqAccess<'de>,
159159
{
160-
let value_type = seq
160+
let value_type: ValueTypeId = seq
161161
.next_element()?
162162
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
163-
let value_type = registry::get_value_type_id_by_global_name(value_type)
164-
.ok_or_else(|| de::Error::custom("Unknown value type"))?;
165163
let has_value: bool = seq
166164
.next_element()?
167165
.ok_or_else(|| de::Error::invalid_length(1, &self))?;

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl TaskId {
160160
}
161161

162162
macro_rules! make_serializable {
163-
($ty:ty, $get_global_name:path, $visitor_name:ident) => {
163+
($ty:ty, $get_object:path, $visitor_name:ident) => {
164164
impl Serialize for $ty {
165165
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
166166
where
@@ -201,20 +201,12 @@ macro_rules! make_serializable {
201201
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
202202
f.debug_struct(stringify!($ty))
203203
.field("id", &self.id)
204-
.field("name", &$get_global_name(*self))
204+
.field("name", &$get_object(*self))
205205
.finish()
206206
}
207207
}
208208
};
209209
}
210210

211-
make_serializable!(
212-
ValueTypeId,
213-
registry::get_value_type_global_name,
214-
ValueTypeVisitor
215-
);
216-
make_serializable!(
217-
TraitTypeId,
218-
registry::get_trait_type_global_name,
219-
TraitTypeVisitor
220-
);
211+
make_serializable!(ValueTypeId, registry::get_value_type, ValueTypeVisitor);
212+
make_serializable!(TraitTypeId, registry::get_trait, TraitTypeVisitor);

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub fn get_function_by_global_name(global_name: &str) -> &'static NativeFunction
3535
struct Values {
3636
id_to_value: Box<[&'static ValueType]>,
3737
value_to_id: FxHashMap<&'static ValueType, ValueTypeId>,
38-
global_name_to_value: FxHashMap<&'static str, (ValueTypeId, &'static ValueType)>,
3938
}
4039

4140
static VALUES: Lazy<Values> = Lazy::new(|| {
@@ -67,11 +66,9 @@ static VALUES: Lazy<Values> = Lazy::new(|| {
6766
}
6867

6968
value_to_id.shrink_to_fit();
70-
global_name_to_value.shrink_to_fit();
7169
Values {
7270
value_to_id,
7371
id_to_value: all_values.into_boxed_slice(),
74-
global_name_to_value,
7572
}
7673
});
7774

@@ -82,13 +79,6 @@ pub fn get_value_type_id(value: &'static ValueType) -> ValueTypeId {
8279
}
8380
}
8481

85-
pub fn get_value_type_id_by_global_name(global_name: &str) -> Option<ValueTypeId> {
86-
VALUES
87-
.global_name_to_value
88-
.get(global_name)
89-
.map(|(id, _)| *id)
90-
}
91-
9282
pub fn get_value_type(id: ValueTypeId) -> &'static ValueType {
9383
VALUES.id_to_value[*id as usize - 1]
9484
}
@@ -100,7 +90,6 @@ pub fn get_value_type_global_name(id: ValueTypeId) -> &'static str {
10090
struct Traits {
10191
id_to_trait: Box<[&'static TraitType]>,
10292
trait_to_id: FxHashMap<&'static TraitType, TraitTypeId>,
103-
global_name_to_trait: FxHashMap<&'static str, (TraitTypeId, &'static TraitType)>,
10493
}
10594

10695
static TRAITS: Lazy<Traits> = Lazy::new(|| {
@@ -130,11 +119,9 @@ static TRAITS: Lazy<Traits> = Lazy::new(|| {
130119
);
131120
}
132121
trait_to_id.shrink_to_fit();
133-
global_name_to_trait.shrink_to_fit();
134122
Traits {
135123
trait_to_id,
136124
id_to_trait: all_traits.into_boxed_slice(),
137-
global_name_to_trait,
138125
}
139126
});
140127

turbopack/crates/turbo-tasks/src/task/shared_reference.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Serialize for TypedSharedReference {
110110
let value_type = registry::get_value_type(*ty);
111111
if let Some(serializable) = value_type.any_as_serializable(arc) {
112112
let mut t = serializer.serialize_tuple(2)?;
113-
t.serialize_element(registry::get_value_type_global_name(*ty))?;
113+
t.serialize_element(ty)?;
114114
t.serialize_element(serializable)?;
115115
t.end()
116116
} else {
@@ -156,29 +156,25 @@ impl<'de> Deserialize<'de> for TypedSharedReference {
156156
where
157157
A: serde::de::SeqAccess<'de>,
158158
{
159-
if let Some(global_name) = seq.next_element()? {
160-
if let Some(ty) = registry::get_value_type_id_by_global_name(global_name) {
161-
if let Some(seed) = registry::get_value_type(ty).get_any_deserialize_seed()
162-
{
163-
if let Some(value) = seq.next_element_seed(seed)? {
164-
let arc = triomphe::Arc::<dyn Any + Send + Sync>::from(value);
165-
Ok(TypedSharedReference {
166-
type_id: ty,
167-
reference: SharedReference(arc),
168-
})
169-
} else {
170-
Err(serde::de::Error::invalid_length(
171-
1,
172-
&"tuple with type and value",
173-
))
174-
}
159+
if let Some(type_id) = seq.next_element()? {
160+
let value_type = registry::get_value_type(type_id);
161+
if let Some(seed) = value_type.get_any_deserialize_seed() {
162+
if let Some(value) = seq.next_element_seed(seed)? {
163+
let arc = triomphe::Arc::<dyn Any + Send + Sync>::from(value);
164+
Ok(TypedSharedReference {
165+
type_id,
166+
reference: SharedReference(arc),
167+
})
175168
} else {
176-
Err(serde::de::Error::custom(format!(
177-
"{ty} is not deserializable"
178-
)))
169+
Err(serde::de::Error::invalid_length(
170+
1,
171+
&"tuple with type and value",
172+
))
179173
}
180174
} else {
181-
Err(serde::de::Error::unknown_variant(global_name, &[]))
175+
Err(serde::de::Error::custom(format!(
176+
"{value_type} is not deserializable"
177+
)))
182178
}
183179
} else {
184180
Err(serde::de::Error::invalid_length(

0 commit comments

Comments
 (0)