-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconsider Raw
pattern
#7479
Comments
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2022-12-19-nix-team-meeting-minutes-18/24121/1 |
My thoughts on the raw pattern are basically:
|
We weren't because this ancient PR predated it! This is actually a new version of the pattern which addresses some issues identified in NixOS#7479.
My friend @jhartzell42 taught me about The example in the issue would be rewritten: struct OutputsSpec {
struct Names { ... };
struct All { ... };
typedef std::variant<AllOutputs, OutputNames> Raw;
Raw raw;
/* The moral equivalent of `using Raw::Raw;` */
OutputsSpec(auto &&... arg)
: raw(std::forward<decltype(arg)>(arg)...)
{ } Note how there are no more bad I have given this new version a spin in c51d554; it is working well. I hope we can convert the other sum types in the codebase soon! |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-04-03-nix-team-meeting-minutes-46/27008/1 |
See that issue for details.
See that issue for details.
See that issue for details on the general goal. The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think NixOS#8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`.
Types converted: - `NixStringContextElem` - `OutputsSpec` - `ExtendedOutputsSpec` - `DerivationOutput` - `DerivationType` The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think NixOS#8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`. See that issue (NixOS#7479) for details on the general goal. `git grep 'Raw::Raw'` indicates the two types I didn't yet convert `DerivedPath` and `BuiltPath` (and their `Single` variants) . This is because @roberth and I (can't find issue right now...) plan on reworking them somewhat, so I didn't want to churn them more just yet.
Types converted: - `NixStringContextElem` - `OutputsSpec` - `ExtendedOutputsSpec` - `DerivationOutput` - `DerivationType` The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think NixOS#8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`. See that issue (NixOS#7479) for details on the general goal. `git grep 'Raw::Raw'` indicates the two types I didn't yet convert `DerivedPath` and `BuiltPath` (and their `Single` variants) . This is because @roberth and I (can't find issue right now...) plan on reworking them somewhat, so I didn't want to churn them more just yet. Co-authored-by: Eelco Dolstra <[email protected]>
Types converted: - `NixStringContextElem` - `OutputsSpec` - `ExtendedOutputsSpec` - `DerivationOutput` - `DerivationType` Existing ones mostly conforming the pattern cleaned up: - `ContentAddressMethod` - `ContentAddressWithReferences` The `DerivationGoal::derivationType` field had a bogus initialization, now caught, so I made it `std::optional`. I think NixOS#8829 can make it non-optional again because it will ensure we always have the derivation when we construct a `DerivationGoal`. See that issue (NixOS#7479) for details on the general goal. `git grep 'Raw::Raw'` indicates the two types I didn't yet convert `DerivedPath` and `BuiltPath` (and their `Single` variants) . This is because @roberth and I (can't find issue right now...) plan on reworking them somewhat, so I didn't want to churn them more just yet. Co-authored-by: Eelco Dolstra <[email protected]>
Refactor Raw pattern, part of #7479
We discussed in Nix team meeting on 2022-12-19, that there are multiple instances in the code which follow this pattern:
@edolstra asks whether we should do it that way, because it's quite verbose. Also adding aliases like in this case keeps both names around in the codebase.
@Ericson2314 do we have alternatives that are as convenient to use at the call site? Does there speak anything against having the variants as fields?
The text was updated successfully, but these errors were encountered: