@@ -32,7 +32,9 @@ use turbo_bincode::{
3232 TurboBincodeDecode , TurboBincodeDecoder , TurboBincodeEncode , TurboBincodeEncoder ,
3333 impl_decode_for_turbo_bincode_decode, impl_encode_for_turbo_bincode_encode,
3434} ;
35- use turbo_tasks:: { CellId , SharedReference , ShrinkToFit , ValueTypePersistence , registry} ;
35+ use turbo_tasks:: {
36+ CellId , Evictability , SharedReference , ShrinkToFit , ValueTypePersistence , registry,
37+ } ;
3638
3739use crate :: backend:: storage_schema:: { DropPartial , DropPartialOutcome } ;
3840
@@ -50,37 +52,23 @@ impl CellData {
5052}
5153
5254impl DropPartial for CellData {
53- /// Drop cells that can be cheaply reconstructed on next access , retain
54- /// those that cannot . Called by the macro-generated `TaskStorage::drop_partial`
55+ /// Drop cells whose value type is freely evictable , retain those that
56+ /// are not . Called by the macro-generated `TaskStorage::drop_partial`
5557 /// on the data-eviction path.
5658 ///
57- /// Dropped:
58- /// - `Persistable` — restored from disk.
59- /// - `SkipPersist { expensive: false, .. }` — cheap to re-derive by re-running the task .
59+ /// Dropped (`Evictability::Always`): persistable cells (restored from
60+ /// disk on next access), skip cells (re-derived by re-running the task),
61+ /// and hash-only cells ( re-derived; hash gates spurious invalidation) .
6062 ///
6163 /// Retained:
62- /// - `SkipPersist { expensive: true, .. }` — expensive to re-derive.
63- /// - `SessionStateful` — would lose accumulated state if dropped.
64+ /// - `Evictability::Expensive` — re-derivation is non-trivial, prefer keeping in memory.
65+ /// - `Evictability::Never` — value type holds session-scoped state that must not leave memory
66+ /// (`State<>` cells, file watchers, worker pools).
6467 fn drop_partial ( & mut self ) -> DropPartialOutcome {
6568 self . 0 . retain (
66- |cell_id, _| match registry:: get_value_type ( cell_id. type_id ) . persistence {
67- ValueTypePersistence :: Persistable ( _, _)
68- | ValueTypePersistence :: SkipPersist {
69- expensive : false ,
70- hash_only : _,
71- } => {
72- // these are either persisted or determined to not be worth persisting because
73- // they are cheap to re-derive
74- false
75- }
76- ValueTypePersistence :: SkipPersist {
77- expensive : true ,
78- hash_only : _,
79- }
80- | ValueTypePersistence :: SessionStateful => {
81- // These are either impossible to derive or expensive so we retain.
82- true
83- }
69+ |cell_id, _| match registry:: get_value_type ( cell_id. type_id ) . evictability {
70+ Evictability :: Always => false ,
71+ Evictability :: Expensive | Evictability :: Never => true ,
8472 } ,
8573 ) ;
8674 if self . 0 . is_empty ( ) {
@@ -122,9 +110,9 @@ impl ShrinkToFit for CellData {
122110
123111impl TurboBincodeEncode for CellData {
124112 /// Writes `count-of-persistable-entries` followed by each persistable
125- /// `(CellId, encoded-value)`. Entries whose value type is `SkipPersist`
126- /// or `SessionStateful ` (no bincode) are skipped; they will be
127- /// reconstructed on the next task execution after restore.
113+ /// `(CellId, encoded-value)`. Entries whose value type is `Skip` or
114+ /// `HashOnly ` (no bincode codec ) are skipped; they will be reconstructed
115+ /// on the next task execution after restore.
128116 fn encode ( & self , encoder : & mut TurboBincodeEncoder ) -> Result < ( ) , EncodeError > {
129117 // First pass: count persistable entries. One extra O(N) iteration over
130118 // the registry — cold path (snapshot time only) and the registry is a
@@ -185,16 +173,20 @@ impl_decode_for_turbo_bincode_decode!(CellData);
185173
186174#[ cfg( test) ]
187175mod tests {
188- //! `drop_partial` must partition cells by their `ValueTypePersistence` —
189- //! keep the non-recoverable ones, drop the rest. Tests below declare one
190- //! value type per persistence variant and exercise every partition.
176+ //! `drop_partial` must partition cells by their `Evictability` — keep
177+ //! the non-evictable ones, drop the rest. Tests below cover every
178+ //! `(persistence, evictability)` combination the macro currently emits,
179+ //! including the `Persistable + Never` combo (e.g. `DiskFileSystem`).
191180 use turbo_tasks:: { self as turbo_tasks, VcValueType } ;
192181
193182 use super :: * ;
194183
195184 #[ turbo_tasks:: value]
196185 struct PersistableV ( #[ allow( dead_code) ] u32 ) ;
197186
187+ #[ turbo_tasks:: value( evict = "never" ) ]
188+ struct PersistableNeverV ( #[ allow( dead_code) ] u32 ) ;
189+
198190 #[ turbo_tasks:: value( serialization = "skip" ) ]
199191 struct SkipCheapV (
200192 #[ turbo_tasks( trace_ignore) ]
@@ -229,16 +221,18 @@ mod tests {
229221 }
230222
231223 #[ test]
232- fn drop_partial_partitions_by_persistence ( ) {
224+ fn drop_partial_partitions_by_evictability ( ) {
233225 let mut data = CellData :: new ( ) ;
234226 data. insert ( cell_of :: < PersistableV > ( 0 ) , dummy_ref ( ) ) ;
227+ data. insert ( cell_of :: < PersistableNeverV > ( 0 ) , dummy_ref ( ) ) ;
235228 data. insert ( cell_of :: < SkipCheapV > ( 0 ) , dummy_ref ( ) ) ;
236229 data. insert ( cell_of :: < SkipExpensiveV > ( 0 ) , dummy_ref ( ) ) ;
237230 data. insert ( cell_of :: < SessionStatefulV > ( 0 ) , dummy_ref ( ) ) ;
238231 data. insert ( cell_of :: < HashOnlyV > ( 0 ) , dummy_ref ( ) ) ;
239232
240233 assert_eq ! ( data. drop_partial( ) , DropPartialOutcome :: HasResidue ) ;
241- assert_eq ! ( data. len( ) , 2 ) ;
234+ assert_eq ! ( data. len( ) , 3 ) ;
235+ assert ! ( data. contains_key( & cell_of:: <PersistableNeverV >( 0 ) ) ) ;
242236 assert ! ( data. contains_key( & cell_of:: <SkipExpensiveV >( 0 ) ) ) ;
243237 assert ! ( data. contains_key( & cell_of:: <SessionStatefulV >( 0 ) ) ) ;
244238 assert ! ( !data. contains_key( & cell_of:: <PersistableV >( 0 ) ) ) ;
@@ -247,7 +241,7 @@ mod tests {
247241 }
248242
249243 #[ test]
250- fn drop_partial_fully_empties_when_all_recoverable ( ) {
244+ fn drop_partial_fully_empties_when_all_evictable ( ) {
251245 let mut data = CellData :: new ( ) ;
252246 data. insert ( cell_of :: < PersistableV > ( 0 ) , dummy_ref ( ) ) ;
253247 data. insert ( cell_of :: < SkipCheapV > ( 0 ) , dummy_ref ( ) ) ;
@@ -258,13 +252,14 @@ mod tests {
258252 }
259253
260254 #[ test]
261- fn drop_partial_keeps_everything_when_all_non_recoverable ( ) {
255+ fn drop_partial_keeps_everything_when_all_non_evictable ( ) {
262256 let mut data = CellData :: new ( ) ;
257+ data. insert ( cell_of :: < PersistableNeverV > ( 0 ) , dummy_ref ( ) ) ;
263258 data. insert ( cell_of :: < SkipExpensiveV > ( 0 ) , dummy_ref ( ) ) ;
264259 data. insert ( cell_of :: < SessionStatefulV > ( 0 ) , dummy_ref ( ) ) ;
265260
266261 assert_eq ! ( data. drop_partial( ) , DropPartialOutcome :: HasResidue ) ;
267- assert_eq ! ( data. len( ) , 2 ) ;
262+ assert_eq ! ( data. len( ) , 3 ) ;
268263 }
269264
270265 #[ test]
0 commit comments