Skip to content

Commit e4a2758

Browse files
sokrahuozhi
authored andcommitted
Turbopack: add track_caller to improve panics (#85565)
### What? Helps finding Item does not exist or access type errors
1 parent cf7ddfc commit e4a2758

File tree

1 file changed

+11
-0
lines changed
  • turbopack/crates/turbo-tasks-backend/src/backend/operation

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ impl<B: BackingStorage> TaskGuardImpl<'_, B> {
382382
/// Verify that the task guard restored the correct category
383383
/// before accessing the data.
384384
#[inline]
385+
#[track_caller]
385386
fn check_access(&self, category: TaskDataCategory) {
386387
{
387388
match category {
@@ -434,6 +435,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
434435
self.task_id
435436
}
436437

438+
#[track_caller]
437439
fn add(&mut self, item: CachedDataItem) -> bool {
438440
let category = item.category();
439441
self.check_access(category);
@@ -446,12 +448,14 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
446448
self.task.add(item)
447449
}
448450

451+
#[track_caller]
449452
fn add_new(&mut self, item: CachedDataItem) {
450453
self.check_access(item.category());
451454
let added = self.add(item);
452455
assert!(added, "Item already exists");
453456
}
454457

458+
#[track_caller]
455459
fn insert(&mut self, item: CachedDataItem) -> Option<CachedDataItemValue> {
456460
let category = item.category();
457461
self.check_access(category);
@@ -461,6 +465,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
461465
self.task.insert(item)
462466
}
463467

468+
#[track_caller]
464469
fn update(
465470
&mut self,
466471
key: CachedDataItemKey,
@@ -474,6 +479,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
474479
self.task.update(key, update);
475480
}
476481

482+
#[track_caller]
477483
fn remove(&mut self, key: &CachedDataItemKey) -> Option<CachedDataItemValue> {
478484
let category = key.category();
479485
self.check_access(category);
@@ -488,6 +494,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
488494
self.task.get(key)
489495
}
490496

497+
#[track_caller]
491498
fn get_mut(&mut self, key: &CachedDataItemKey) -> Option<CachedDataItemValueRefMut<'_>> {
492499
let category = key.category();
493500
self.check_access(category);
@@ -497,6 +504,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
497504
self.task.get_mut(key)
498505
}
499506

507+
#[track_caller]
500508
fn get_mut_or_insert_with(
501509
&mut self,
502510
key: CachedDataItemKey,
@@ -510,11 +518,13 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
510518
self.task.get_mut_or_insert_with(key, insert)
511519
}
512520

521+
#[track_caller]
513522
fn has_key(&self, key: &CachedDataItemKey) -> bool {
514523
self.check_access(key.category());
515524
self.task.contains_key(key)
516525
}
517526

527+
#[track_caller]
518528
fn count(&self, ty: CachedDataItemType) -> usize {
519529
self.check_access(ty.category());
520530
self.task.count(ty)
@@ -532,6 +542,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
532542
self.task.shrink_to_fit(ty)
533543
}
534544

545+
#[track_caller]
535546
fn extract_if<'l, F>(
536547
&'l mut self,
537548
ty: CachedDataItemType,

0 commit comments

Comments
 (0)