Skip to content

Commit b8baa89

Browse files
committed
comments and simplifications
1 parent e4312ac commit b8baa89

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

turbopack/crates/turbo-tasks-build/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub fn generate_register() {
154154
entry.global_name,
155155
)
156156
.unwrap();
157+
// Register all the trait items for each impl so we can dispatch to them as turbotasks
157158
for trait_ident in &entry.trait_idents {
158159
writeln!(
159160
values_code,
@@ -164,6 +165,8 @@ pub fn generate_register() {
164165
.unwrap();
165166
}
166167
writeln!(values_code, "}}, #[allow(unused_variables)] |value_id| {{").unwrap();
168+
// Register all the vtables for the impls so we can dispatch to them as normal indirect
169+
// trait calls.
167170
for trait_ident in &entry.trait_idents {
168171
writeln!(
169172
values_code,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ impl<T: ?Sized> VTableRegistry<T> {
9191
debug_assert!(prev.is_none(), "{id} was already registered");
9292
}
9393

94-
pub(crate) fn get(&self, id: &ValueTypeId) -> Option<DynMetadata<T>> {
95-
self.map.get(id).map(|r| *r.value())
94+
pub(crate) fn get(&self, id: ValueTypeId) -> DynMetadata<T> {
95+
*self.map.get(&id).unwrap().value()
9696
}
9797
}
9898

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ where
9797
type Target = U;
9898

9999
fn deref(&self) -> &Self::Target {
100-
// This lookup will fail if the valuye type stored does not actually implement the trait,
100+
// This lookup will fail if the value type stored does not actually implement the trait,
101101
// which implies a bug in either the registry code or the macro code.
102-
let metadata = <Box<U> as VcValueTrait>::get_impl_vtables()
103-
.get(&self.shared_reference.type_id)
104-
.unwrap();
102+
let metadata =
103+
<Box<U> as VcValueTrait>::get_impl_vtables().get(self.shared_reference.type_id);
105104
let downcast_ptr = std::ptr::from_raw_parts(
106105
self.shared_reference.reference.0.as_ptr() as *const (),
107106
metadata,

0 commit comments

Comments
 (0)