Skip to content

Revert "Revert "Use template structs instead of phantoms""#8365

Merged
thufschmitt merged 1 commit intoNixOS:masterfrom
obsidiansystems:proto-structs
May 22, 2023
Merged

Revert "Revert "Use template structs instead of phantoms""#8365
thufschmitt merged 1 commit intoNixOS:masterfrom
obsidiansystems:proto-structs

Conversation

@Ericson2314
Copy link
Member

Motivation

This is the more typically way to do Argument-dependent lookup-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.

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 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.

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • documentation in the internal API docs
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or incompatible change: updated release notes

Priorities

Add 👍 to pull requests you find important.

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.
@Ericson2314 Ericson2314 requested a review from thufschmitt as a code owner May 18, 2023 02:48
@Ericson2314 Ericson2314 requested a review from edolstra as a code owner May 18, 2023 02:48
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label May 18, 2023
@Ericson2314 Ericson2314 added the protocol Things involving the daemon protocol & compatibility issues label May 18, 2023
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections.

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! That fells so much nicer and idiomatic than the old Phantom-based solution

@thufschmitt thufschmitt merged commit 673fe85 into NixOS:master May 22, 2023
@Ericson2314 Ericson2314 deleted the proto-structs branch May 22, 2023 11:07
@nixos-discourse
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

protocol Things involving the daemon protocol & compatibility issues store Issues and pull requests concerning the Nix store

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants