1use std::{
2 borrow::Borrow,
3 env,
4 path::PathBuf,
5 sync::{Arc, LazyLock, Mutex, PoisonError, Weak},
6};
7
8use anyhow::{Context, Result};
9use turbo_bincode::{
10 TurboBincodeBuffer, new_turbo_bincode_decoder, new_turbo_bincode_encoder, turbo_bincode_decode,
11 turbo_bincode_encode, turbo_bincode_encode_into,
12};
13use turbo_tasks::{
14 TaskId,
15 backend::CachedTaskType,
16 panic_hooks::{PanicHookGuard, register_panic_hook},
17 parallel,
…lines 18–246 unchanged (229 lines)
247 let operations = turbo_bincode_decode(operations.borrow())?;
248 Ok(operations)
249 }
250 get(&self.inner.database).context("Unable to read uncompleted operations from database")
251 }
252
253 fn serialize(
254 &self,
255 task: TaskId,
256 data: &TaskStorage,
257 category: SpecificTaskDataCategory,
258 ) -> Result<TurboBincodeBuffer> {
259 encode_task_data(task, data, category)
260 }
261
262 fn save_snapshot<I>(
263 &self,
264 operations: Vec<Arc<AnyOperation>>,
265 task_cache_updates: Vec<ChunkedVec<(Arc<CachedTaskType>, TaskId)>>,
266 snapshots: Vec<I>,
…lines 267–794 unchanged (528 lines)
795 }
796
797 Ok(result)
798 })
799}
800
801fn encode_task_data(
802 task: TaskId,
803 data: &TaskStorage,
804 category: SpecificTaskDataCategory,
805) -> Result<TurboBincodeBuffer> {
806 // TODO: see if the caller can pass us a buffer instead of us allocating a new one.
807 // This should be possible and save a lot of small allocations.
808 let mut buffer = TurboBincodeBuffer::new();
809 let mut encoder = new_turbo_bincode_encoder(&mut buffer);
810 data.encode(category, &mut encoder)?;
811
812 if !cfg!(feature = "verify_serialization") {
813 return Ok(buffer);
814 }
815
816 TaskStorage::new()
817 .decode(category, &mut new_turbo_bincode_decoder(buffer.borrow()))
818 .with_context(|| {
819 format!(
820 "expected to be able to decode serialized data for '{category:?}' information for \
821 {task}"
822 )
823 })?;
824
825 Ok(buffer)
826}
827