Skip to content

[SharedCache] Make MetadataSerializable::Load static#6403

Closed
bdash wants to merge 1 commit into
Vector35:devfrom
bdash:dsc-load-as-factory
Closed

[SharedCache] Make MetadataSerializable::Load static#6403
bdash wants to merge 1 commit into
Vector35:devfrom
bdash:dsc-load-as-factory

Conversation

@bdash
Copy link
Copy Markdown
Contributor

@bdash bdash commented Feb 8, 2025

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.

This is a prerequisite of #6393.

@0cyn 0cyn requested a review from emesare February 11, 2025 10:41
`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.
@bdash bdash force-pushed the dsc-load-as-factory branch from e86c67b to 3d203ce Compare February 12, 2025 01:25
@CouleeApps
Copy link
Copy Markdown
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.

@CouleeApps
Copy link
Copy Markdown
Member

On further inspection, seems like Mason already beat me to it in 360160b

@bdash
Copy link
Copy Markdown
Contributor Author

bdash commented Feb 13, 2025

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.

@bdash
Copy link
Copy Markdown
Contributor Author

bdash commented Feb 13, 2025

Looks like this was cherry-picked into dev as c20bf35.

@bdash bdash closed this Feb 13, 2025
@bdash bdash deleted the dsc-load-as-factory branch February 13, 2025 17:48
@emesare emesare added this to the Gallifrey milestone Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants