1+ use std:: { borrow:: Borrow , path:: PathBuf , sync:: Arc } ;
2+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
13use std:: {
2- borrow:: Borrow ,
34 env,
4- path:: PathBuf ,
5- sync:: { Arc , LazyLock , Mutex , PoisonError , Weak } ,
5+ sync:: { LazyLock , Mutex , PoisonError , Weak } ,
66} ;
77
8- use anyhow:: { Context , Result } ;
8+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
9+ use anyhow:: Context ;
10+ use anyhow:: Result ;
911use smallvec:: SmallVec ;
12+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
1013use turbo_bincode:: { new_turbo_bincode_decoder, turbo_bincode_decode, turbo_bincode_encode} ;
14+ use turbo_tasks:: { DynTaskInputs , RawVc , TaskId , macro_helpers:: NativeFunction } ;
15+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
1116use turbo_tasks:: {
12- DynTaskInputs , RawVc , TaskId ,
13- macro_helpers:: NativeFunction ,
1417 panic_hooks:: { PanicHookGuard , register_panic_hook} ,
1518 parallel,
1619} ;
@@ -19,10 +22,13 @@ use crate::{
1922 GitVersionInfo ,
2023 backend:: { AnyOperation , SpecificTaskDataCategory , storage_schema:: TaskStorage } ,
2124 backing_storage:: { SnapshotItem , SnapshotMeta , compute_task_type_hash_from_components} ,
25+ database:: { db_invalidation:: StartupCacheState , key_value_database:: KeySpace } ,
26+ } ;
27+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
28+ use crate :: {
2229 database:: {
23- db_invalidation:: { StartupCacheState , check_db_invalidation_and_cleanup, invalidate_db} ,
30+ db_invalidation:: { check_db_invalidation_and_cleanup, invalidate_db} ,
2431 db_versioning:: handle_db_versioning,
25- key_value_database:: KeySpace ,
2632 turbo:: { TurboKeyValueDatabase , TurboWriteBatch } ,
2733 write_batch:: WriteBuffer ,
2834 } ,
@@ -32,20 +38,24 @@ use crate::{
3238const META_KEY_OPERATIONS : u32 = 0 ;
3339const META_KEY_NEXT_FREE_TASK_ID : u32 = 1 ;
3440
41+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
3542struct IntKey ( [ u8 ; 4 ] ) ;
3643
44+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
3745impl IntKey {
3846 fn new ( value : u32 ) -> Self {
3947 Self ( value. to_le_bytes ( ) )
4048 }
4149}
4250
51+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
4352impl AsRef < [ u8 ] > for IntKey {
4453 fn as_ref ( & self ) -> & [ u8 ] {
4554 & self . 0
4655 }
4756}
4857
58+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
4959fn as_u32 ( bytes : impl Borrow < [ u8 ] > ) -> Result < u32 > {
5060 let n = u32:: from_le_bytes ( bytes. borrow ( ) . try_into ( ) ?) ;
5161 Ok ( n)
@@ -59,6 +69,7 @@ fn as_u32(bytes: impl Borrow<[u8]>) -> Result<u32> {
5969//
6070// These overrides let us avoid the cache invalidation / error suppression within Vercel so that we
6171// feel these pain points and fix the root causes of bugs.
72+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
6273fn should_invalidate_on_panic ( ) -> bool {
6374 fn env_is_falsy ( key : & str ) -> bool {
6475 env:: var_os ( key)
@@ -70,6 +81,7 @@ fn should_invalidate_on_panic() -> bool {
7081 * SHOULD_INVALIDATE
7182}
7283
84+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
7385struct TurboBackingStorageInner {
7486 database : TurboKeyValueDatabase ,
7587 /// Used when calling [`TurboBackingStorage::invalidate`]. Can be `None` in the
@@ -89,11 +101,16 @@ struct TurboBackingStorageInner {
89101/// backend needs (snapshots, task-candidate lookups, etc.).
90102///
91103/// [`TurboTasksBackend::new`]: crate::TurboTasksBackend::new
104+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
92105pub struct TurboBackingStorage {
93106 // wrapped so that `register_panic_hook` can hold a weak reference to `inner`.
94107 inner : Arc < TurboBackingStorageInner > ,
95108}
96109
110+ #[ cfg( all( target_family = "wasm" , target_os = "unknown" ) ) ]
111+ pub struct TurboBackingStorage ;
112+
113+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
97114impl TurboBackingStorage {
98115 pub ( crate ) fn new_in_memory ( database : TurboKeyValueDatabase ) -> Self {
99116 Self {
@@ -157,6 +174,7 @@ impl TurboBackingStorage {
157174 }
158175}
159176
177+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
160178impl TurboBackingStorageInner {
161179 fn invalidate ( & self , reason_code : & str ) -> Result < ( ) > {
162180 // `base_path` is `None` for in-memory backing storage (see `noop_backing_storage`).
@@ -190,6 +208,7 @@ impl TurboBackingStorageInner {
190208 }
191209}
192210
211+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
193212impl TurboBackingStorage {
194213 /// Called when the database should be invalidated upon re-initialization.
195214 ///
@@ -408,6 +427,75 @@ impl TurboBackingStorage {
408427 }
409428}
410429
430+ #[ cfg( all( target_family = "wasm" , target_os = "unknown" ) ) ]
431+ impl TurboBackingStorage {
432+ pub ( crate ) fn new_in_memory ( ) -> Self {
433+ Self
434+ }
435+
436+ pub ( crate ) fn invalidate ( & self , _reason_code : & str ) -> Result < ( ) > {
437+ Ok ( ( ) )
438+ }
439+
440+ pub ( crate ) fn next_free_task_id ( & self ) -> Result < TaskId > {
441+ Ok ( TaskId :: MIN )
442+ }
443+
444+ pub ( crate ) fn uncompleted_operations ( & self ) -> Result < Vec < AnyOperation > > {
445+ Ok ( Vec :: new ( ) )
446+ }
447+
448+ pub ( crate ) fn save_snapshot < I > (
449+ & self ,
450+ _operations : Vec < Arc < AnyOperation > > ,
451+ _snapshots : Vec < I > ,
452+ ) -> Result < SnapshotMeta >
453+ where
454+ I : IntoIterator < Item = SnapshotItem > + Send + Sync ,
455+ {
456+ Ok ( SnapshotMeta :: default ( ) )
457+ }
458+
459+ pub ( crate ) fn lookup_task_candidates (
460+ & self ,
461+ _native_fn : & ' static NativeFunction ,
462+ _this : Option < RawVc > ,
463+ _arg : & dyn DynTaskInputs ,
464+ ) -> Result < SmallVec < [ TaskId ; 1 ] > > {
465+ Ok ( SmallVec :: new ( ) )
466+ }
467+
468+ pub ( crate ) fn lookup_data (
469+ & self ,
470+ _task_id : TaskId ,
471+ _category : SpecificTaskDataCategory ,
472+ _storage : & mut TaskStorage ,
473+ ) -> Result < ( ) > {
474+ Ok ( ( ) )
475+ }
476+
477+ pub ( crate ) fn batch_lookup_data (
478+ & self ,
479+ task_ids : & [ TaskId ] ,
480+ _category : SpecificTaskDataCategory ,
481+ ) -> Result < Vec < TaskStorage > > {
482+ Ok ( task_ids. iter ( ) . map ( |_| TaskStorage :: new ( ) ) . collect ( ) )
483+ }
484+
485+ pub ( crate ) fn compact ( & self ) -> Result < bool > {
486+ Ok ( false )
487+ }
488+
489+ pub ( crate ) fn shutdown ( & self ) -> Result < ( ) > {
490+ Ok ( ( ) )
491+ }
492+
493+ pub ( crate ) fn has_unrecoverable_write_error ( & self ) -> bool {
494+ false
495+ }
496+ }
497+
498+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
411499fn get_next_free_task_id ( batch : & TurboWriteBatch < ' _ > ) -> Result < u32 , anyhow:: Error > {
412500 Ok (
413501 match batch. get (
@@ -420,6 +508,7 @@ fn get_next_free_task_id(batch: &TurboWriteBatch<'_>) -> Result<u32, anyhow::Err
420508 )
421509}
422510
511+ #[ cfg( not( all( target_family = "wasm" , target_os = "unknown" ) ) ) ]
423512fn save_infra (
424513 batch : & TurboWriteBatch < ' _ > ,
425514 next_task_id : u32 ,
0 commit comments