Unverified Commit b8a14cd8 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: add track_caller to improve panics (#85565)

### What?

Helps finding Item does not exist or access type errors
parent 3b0af3ce
...@@ -382,6 +382,7 @@ impl<B: BackingStorage> TaskGuardImpl<'_, B> { ...@@ -382,6 +382,7 @@ impl<B: BackingStorage> TaskGuardImpl<'_, B> {
/// Verify that the task guard restored the correct category /// Verify that the task guard restored the correct category
/// before accessing the data. /// before accessing the data.
#[inline] #[inline]
#[track_caller]
fn check_access(&self, category: TaskDataCategory) { fn check_access(&self, category: TaskDataCategory) {
{ {
match category { match category {
...@@ -434,6 +435,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -434,6 +435,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task_id self.task_id
} }
#[track_caller]
fn add(&mut self, item: CachedDataItem) -> bool { fn add(&mut self, item: CachedDataItem) -> bool {
let category = item.category(); let category = item.category();
self.check_access(category); self.check_access(category);
...@@ -446,12 +448,14 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -446,12 +448,14 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.add(item) self.task.add(item)
} }
#[track_caller]
fn add_new(&mut self, item: CachedDataItem) { fn add_new(&mut self, item: CachedDataItem) {
self.check_access(item.category()); self.check_access(item.category());
let added = self.add(item); let added = self.add(item);
assert!(added, "Item already exists"); assert!(added, "Item already exists");
} }
#[track_caller]
fn insert(&mut self, item: CachedDataItem) -> Option<CachedDataItemValue> { fn insert(&mut self, item: CachedDataItem) -> Option<CachedDataItemValue> {
let category = item.category(); let category = item.category();
self.check_access(category); self.check_access(category);
...@@ -461,6 +465,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -461,6 +465,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.insert(item) self.task.insert(item)
} }
#[track_caller]
fn update( fn update(
&mut self, &mut self,
key: CachedDataItemKey, key: CachedDataItemKey,
...@@ -474,6 +479,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -474,6 +479,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.update(key, update); self.task.update(key, update);
} }
#[track_caller]
fn remove(&mut self, key: &CachedDataItemKey) -> Option<CachedDataItemValue> { fn remove(&mut self, key: &CachedDataItemKey) -> Option<CachedDataItemValue> {
let category = key.category(); let category = key.category();
self.check_access(category); self.check_access(category);
...@@ -488,6 +494,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -488,6 +494,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.get(key) self.task.get(key)
} }
#[track_caller]
fn get_mut(&mut self, key: &CachedDataItemKey) -> Option<CachedDataItemValueRefMut<'_>> { fn get_mut(&mut self, key: &CachedDataItemKey) -> Option<CachedDataItemValueRefMut<'_>> {
let category = key.category(); let category = key.category();
self.check_access(category); self.check_access(category);
...@@ -497,6 +504,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -497,6 +504,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.get_mut(key) self.task.get_mut(key)
} }
#[track_caller]
fn get_mut_or_insert_with( fn get_mut_or_insert_with(
&mut self, &mut self,
key: CachedDataItemKey, key: CachedDataItemKey,
...@@ -510,11 +518,13 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -510,11 +518,13 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.get_mut_or_insert_with(key, insert) self.task.get_mut_or_insert_with(key, insert)
} }
#[track_caller]
fn has_key(&self, key: &CachedDataItemKey) -> bool { fn has_key(&self, key: &CachedDataItemKey) -> bool {
self.check_access(key.category()); self.check_access(key.category());
self.task.contains_key(key) self.task.contains_key(key)
} }
#[track_caller]
fn count(&self, ty: CachedDataItemType) -> usize { fn count(&self, ty: CachedDataItemType) -> usize {
self.check_access(ty.category()); self.check_access(ty.category());
self.task.count(ty) self.task.count(ty)
...@@ -532,6 +542,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> { ...@@ -532,6 +542,7 @@ impl<B: BackingStorage> TaskGuard for TaskGuardImpl<'_, B> {
self.task.shrink_to_fit(ty) self.task.shrink_to_fit(ty)
} }
#[track_caller]
fn extract_if<'l, F>( fn extract_if<'l, F>(
&'l mut self, &'l mut self,
ty: CachedDataItemType, ty: CachedDataItemType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment