[SharedCache] Make MetadataSerializable::Load static#6403
Closed
bdash wants to merge 1 commit into
Closed
Conversation
`MetadataSerializable` is updated to allow a subclass to optionally specify the return type of `Load`. If not specified it defaults to the subclass itself. `SharedCache` specifies `std::optional` to represent the case where the serialized metadata is in a format or version it does not recognize. By making `Load` a static member function and having it return a new object it becomes easier to reason about the state of objects when a deserialization failure occurs. It can return `std::optional` to indicate failure and there is no object left in an unknown state. Prior to this, `Load` worked on an existing instance of an object. It was unclear what state the object would be in if a deserialization failure occurred (its original state prior to `Load`? some partially-loaded state? a null state?). The failure itself also had to be communicated out of band.
e86c67b to
3d203ce
Compare
Member
|
FYI this requires /std:c++20 to compile on MSVC due to the use of designated initializers. That's probably fine and we will likely need to be updating the entirety of the binja api to C++20 anyway, but for the moment it's a compile error. You can either rewrite parts of this to not use those, or we can have The Discussion internally for whether that is something we are doing now. |
Member
|
On further inspection, seems like Mason already beat me to it in 360160b |
Contributor
Author
|
Thanks for pointing that out. It's a little annoying that Clang lets C++20 constructs slide in C++17 language mode without so much as a warning. |
Contributor
Author
|
Looks like this was cherry-picked into |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MetadataSerializableis updated to allow a subclass to optionally specify the return type ofLoad. If not specified it defaults to the subclass itself.SharedCachespecifiesstd::optionalto represent the case where the serialized metadata is in a format or version it does not recognize.By making
Loada static member function and having it return a new object it becomes easier to reason about the state of objects when a deserialization failure occurs. It can returnstd::optionalto indicate failure and there is no object left in an unknown state.Prior to this,
Loadworked on an existing instance of an object. It was unclear what state the object would be in if a deserialization failure occurred (its original state prior toLoad? some partially-loaded state? a null state?). The failure itself also had to be communicated out of band.This is a prerequisite of #6393.