feat: add TaskStorage derive macro and schema infrastructure (#88338)
Add a new derive macro for `TaskStorage` a replacement for `InnerStorage` and `CachedDataItem`, currently it is unused outside of tests.
## What
* add a new derive macro that generates code from the 'schema' in `storage_schema.rs`
* `storage_schema.rs` defines the layout of our new struct, for each field we specify
* type and name
* category ('data' 'meta' or 'transient')
* location (inline or lazy or flags for bitfields)
* whether we should `filter_transient` when encoding (not everything can contain transient data)
* Logically this is a replacement for `CachedDataItem`
* From that we generate a few things
* `TaskFlags` a bitfield to hold some data items as well as 'meta' information like the 'snapshot' and 'restore' bits replacing `InnerStorageState`
* `LazyField` enum, defines tall the fields that we dynamically allocate
* `TaskStorage` the main storage struct, along with basic accessors for all the datatypes (which helps encapsualte storage strategy)
* `TaskStorageAccessors` a trait with default implementations of every accessor which also handle
* access checking, via `check_access`
* mutation tracking via `track_mutation`
* putting these behaviors in a trait allows some of the business logic around snapshotting to remain in normal rust code that implements the trait, while all the field updating logic can be autogenerated
* Serialization and encoding infrastructure
* routines to encode and decode the 'meta' or 'data' subsets
* routines to create partial 'snapshots' of `meta` or `data` subsets
* routines to restore data from deserialized snapshots
See https://gist.github.com/lukesandberg/ea35f0e92c1cdeddf80d0498f2978144 for a fully expanded version of the macro
### Why
There are a few goals from this redesign of `InnerStorage`
* (speculative) a single large `derive` macro will be easier to maintain than the current mix of `macro_rules` and derive macros we use for `CacheDataItem`
* There is one macro to expand when inspecting and the macro generation code is pretty straightforward if voluminous
* We eliminate many `match` operations on `CachedDataItem`
* Today to lookup a piece of data we need to execute several matches to get the the data category and find the storage location. With this new approach those are handled by just calling the correct accessor which statically addresses the storage location
* serialization performance
* we don't need to 'explode' the storage into `Vec<CachedDataItem>` anymore and instead can either directly snapshot the storage or encode directly to a buffer. This should eliminate some temporary allocations and should enable a smaller serialization format
* more flexibility
* mostly this is the same approach as before with a few small improvements, notably `invalidator` and `immutable` are now stored as single inline bits reducing lookupcosts and memory for tasks that have these.
### How
Most of the code was written by Claude with obviously a ton of feedback, so please review carefully. For now all this code is unused but future PRs will integrate it into the backend
Showing
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Please
register
or
sign in
to comment