Skip to content

Commit bcacc8a

Browse files
committed
Fix global names for values
1 parent bc96526 commit bcacc8a

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use turbo_tasks_testing::{Registration, register, run_without_cache_check};
99
static REGISTRATION: Registration = register!();
1010

1111
const EXPECTED_TRACE: &str = "\
12-
Adder::add_method (read cell of type turbo-tasks::primitives::u64)
12+
Adder::add_method (read cell of type turbo_tasks::primitives::u64)
1313
self:
14-
Adder::new (read cell of type turbo-tasks-backend::Adder)
14+
Adder::new (read cell of type trace_transient::Adder)
1515
args:
16-
unknown transient task (read cell of type turbo-tasks::primitives::unit)
16+
unknown transient task (read cell of type turbo_tasks::primitives::())
1717
args:
18-
unknown transient task (read cell of type turbo-tasks::primitives::u16)
19-
unknown transient task (read cell of type turbo-tasks::primitives::u32)";
18+
unknown transient task (read cell of type turbo_tasks::primitives::u16)
19+
unknown transient task (read cell of type turbo_tasks::primitives::u32)";
2020

2121
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
2222
async fn test_trace_transient() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ pub fn generic_type(input: TokenStream) -> TokenStream {
7575
turbo_tasks::VcCellSharedMode<#ty>
7676
},
7777
quote! {
78-
turbo_tasks::ValueType::new_with_any_serialization::<#repr>()
78+
turbo_tasks::ValueType::new_with_any_serialization::<#repr>(
79+
concat!(module_path!(), "::", stringify!(#repr))
80+
)
7981
},
8082
);
8183

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub fn primitive(input: TokenStream) -> TokenStream {
4444
turbo_tasks::VcCellSharedMode<#ty>
4545
},
4646
quote! {
47-
turbo_tasks::ValueType::new_with_any_serialization::<#ty>()
47+
turbo_tasks::ValueType::new_with_any_serialization::<#ty>(
48+
concat!(module_path!(), "::", stringify!(#ty))
49+
)
4850
},
4951
);
5052

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,15 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
386386

387387
let new_value_type = match serialization_mode {
388388
SerializationMode::None => quote! {
389-
turbo_tasks::ValueType::new::<#ident>()
389+
turbo_tasks::ValueType::new::<#ident>(
390+
concat!(module_path!(), "::", stringify!(#ident))
391+
)
390392
},
391393
SerializationMode::Auto | SerializationMode::Custom => {
392394
quote! {
393-
turbo_tasks::ValueType::new_with_any_serialization::<#ident>()
395+
turbo_tasks::ValueType::new_with_any_serialization::<#ident>(
396+
concat!(module_path!(), "::", stringify!(#ident))
397+
)
394398
}
395399
}
396400
};

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ struct Values {
4141
static VALUES: Lazy<Values> = Lazy::new(|| {
4242
// Inventory does not guarantee an order. So we sort by the global name to get a stable order
4343
// This ensures that assigned ids are also stable.
44+
// We don't currently take advantage of this but we could in the future. The remaining issue is
45+
// ensuring the set of values is the same across runs.
4446
let mut all_values = inventory::iter::<CollectableValueType>
4547
.into_iter()
4648
.map(|t| &**t.0)
4749
.collect::<Vec<_>>();
48-
all_values.sort_by_key(|t| t.name);
50+
all_values.sort_by_key(|t| t.global_name);
4951

5052
let mut value_to_id = FxHashMap::default();
5153
value_to_id.reserve(all_values.len());
@@ -56,11 +58,11 @@ static VALUES: Lazy<Values> = Lazy::new(|| {
5658
// SAFETY: as a usize, usize+1 is definitely non-zero.
5759
let id = unsafe { ValueTypeId::new_unchecked((index + 1).try_into().unwrap()) };
5860
value_to_id.insert(value_type, id);
59-
let prev = global_name_to_value.insert(value_type.name, (id, value_type));
61+
let prev = global_name_to_value.insert(value_type.global_name, (id, value_type));
6062
debug_assert!(
6163
prev.is_none(),
6264
"two traits registered with the same name: {}",
63-
value_type.name
65+
value_type.global_name
6466
);
6567
}
6668

@@ -92,7 +94,7 @@ pub fn get_value_type(id: ValueTypeId) -> &'static ValueType {
9294
}
9395

9496
pub fn get_value_type_global_name(id: ValueTypeId) -> &'static str {
95-
get_value_type(id).name
97+
get_value_type(id).global_name
9698
}
9799

98100
struct Traits {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type RawCellFactoryFn = fn(TypedSharedReference) -> RawVc;
3535
pub struct ValueType {
3636
/// A readable name of the type
3737
pub name: &'static str,
38+
/// The fully qualitifed global name of the type.
39+
pub global_name: &'static str,
3840
/// Set of traits available
3941
traits: AutoSet<TraitTypeId>,
4042
/// List of trait methods available
@@ -105,9 +107,10 @@ pub fn any_as_serialize<T: Any + Serialize + Send + Sync + 'static>(
105107

106108
impl ValueType {
107109
/// This is internally used by `#[turbo_tasks::value]`
108-
pub fn new<T: VcValueType>() -> Self {
110+
pub fn new<T: VcValueType>(global_name: &'static str) -> Self {
109111
Self {
110112
name: std::any::type_name::<T>(),
113+
global_name,
111114
traits: AutoSet::new(),
112115
trait_methods: AutoMap::new(),
113116
magic_serialization: None,
@@ -119,9 +122,12 @@ impl ValueType {
119122
/// This is internally used by `#[turbo_tasks::value]`
120123
pub fn new_with_any_serialization<
121124
T: VcValueType + Any + Serialize + for<'de> Deserialize<'de>,
122-
>() -> Self {
125+
>(
126+
global_name: &'static str,
127+
) -> Self {
123128
Self {
124129
name: std::any::type_name::<T>(),
130+
global_name,
125131
traits: AutoSet::new(),
126132
trait_methods: AutoMap::new(),
127133
magic_serialization: None,

0 commit comments

Comments
 (0)