Revert "Revert "Use template structs instead of phantoms""#8365
Merged
thufschmitt merged 1 commit intoNixOS:masterfrom May 22, 2023
Merged
Revert "Revert "Use template structs instead of phantoms""#8365thufschmitt merged 1 commit intoNixOS:masterfrom
thufschmitt merged 1 commit intoNixOS:masterfrom
Conversation
This is the more typically way to do [Argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)-leveraging generic serializers in C++. It makes the relationship between the `read` and `write` methods more clear and rigorous, and also looks more familiar to users coming from other languages that do not have C++'s libertine ad-hoc overloading. I am returning to this because during the review in NixOS#6223, it came up as something that would make the code easier to read --- easier today hopefully already, but definitely easier if we were have multiple codified protocols with code sharing between them as that PR seeks to accomplish. If I recall correctly, the main criticism of this the first time around (in 2020) was that having to specify the type when writing, e.g. `WorkerProto<MyType>::write`, was too verbose and cumbersome. This is now addressed with the `workerProtoWrite` wrapper function. This method is also the way `nlohmann::json`, which we have used for a number of years now, does its serializers, for what its worth. This reverts commit 45a0ed8. That commit in turn reverted 9ab07e9.
thufschmitt
approved these changes
May 22, 2023
Member
thufschmitt
left a comment
There was a problem hiding this comment.
Yes! That fells so much nicer and idiomatic than the old Phantom-based solution
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-05-19-nix-team-meeting-minutes-56/28446/1 |
8 tasks
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.
Motivation
This is the more typically way to do Argument-dependent lookup-leveraging generic serializers in C++. It makes the relationship between the
readandwritemethods more clear and rigorous, and also looks more familiar to users coming from other languages that do not have C++'s libertine ad-hoc overloading.Context
I am returning to this because during the review in #6223, it came up as something that would make the code easier to read --- easier today hopefully already, but definitely easier if we were have multiple codified protocols with code sharing between them as that PR seeks to accomplish.
If I recall correctly, the main criticism of this the first time around (in 2020) was that having to specify the type when writing, e.g.
WorkerProto<MyType>::write, was too verbose and cumbersome. This is now addressed with theworkerProtoWritewrapper function.This method is also the way
nlohmann::json, which we have used for a number of years now, does its serializers, for what its worth.This reverts commit 45a0ed8. That commit in turn reverted 9ab07e9.
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.shsrc/*/teststests/nixos/*Priorities
Add 👍 to pull requests you find important.