You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The feature flag `derive_all` is added to the `libc` library that when enabled adds `Debug`, `Eq`, `Hash`, and `PartialEq`traits for all structs. It will default to off.
31
+
Add an `extra_traits` feature to the `libc` library that enables `Debug`, `Eq`, `Hash`, and `PartialEq`implementations for all structs.
The `Debug`, `Eq`, `Hash`, and `PartialEq` traits will be added as automatic derives within the `s!` macro in `src/macros.rs` if the `derive_all` feature
36
+
The `Debug`, `Eq`/`PartialEq`, and `Hash` traits will be added as automatic derives within the `s!` macro in `src/macros.rs` if the corresponding feature
37
37
flag is enabled. This won't work for some types because auto-derive doesn't work for arrays larger than 32 elements, so for these they'll be implemented manually. For `libc`
38
38
as of `bbda50d20937e570df5ec857eea0e2a098e76b2d` on `x86_64-unknown-linux-gnu` these many structs will need manual implementations:
39
39
40
40
*`Debug` - 17
41
-
*`Eq` and `PartialEq` - 46
41
+
*`Eq`/`PartialEq` - 46
42
42
*`Hash` - 17
43
43
44
44
# Drawbacks
45
45
[drawbacks]: #drawbacks
46
46
47
-
The addition of this behind a feature flag does not have a significant effect on build times, but the burden of adding these implementations for new types that
48
-
require manual implementations will be high, possibly hindering new contributors.
47
+
While most structs will be able to derive these implementations automatically, some will not (for example arrays larger than 32 elements). This will make it harder to add
48
+
some structs to `libc`.
49
+
50
+
This extra trait will increase the testing requirements for `libc`.
49
51
50
52
# Rationale and alternatives
51
53
[alternatives]: #alternatives
52
54
53
55
Adding these trait implementations behind a singular feature flag has the best compination of utility and ergonomics out of the possible alternatives listed below:
54
56
55
-
## Always enabled
57
+
## Always enabled with no feature flags
56
58
57
-
This was regarded as unsuitable because it doubles to triples compilation time. Compilation times of `libc` was tested at commit `bbda50d20937e570df5ec857eea0e2a098e76b2d`
58
-
with modifications to add derives for the traits discussed here. Some types failed to have these traits derived because of specific fields, so these were removed from the
59
-
struct declaration. The table below shows the results:
59
+
This was regarded as unsuitable because it increases compilation times by 100-200%. Compilation times of `libc` was tested at commit `bbda50d20937e570df5ec857eea0e2a098e76b2d`
60
+
with modifications to add derives for the traits discussed here under the `extra_traits` feature (with no other features). Some types failed to have these traits
61
+
derived because of specific fields, so these were removed from the struct declaration. The table below shows the compilation times:
For crates that are more than one level above `libc` in the dependency chain it will be impossible for them to opt out. This could also happen with a default-off
75
77
feature flag, but it's more likely the library authors will expose it as a flag as well.
76
78
77
-
## Independent feature flags
79
+
## Multiple feature flags
80
+
81
+
Instead of having a single `extra_traits` feature, have it and feature flags for each trait individually like:
78
82
79
-
It wasn't tested how much compilation times increased per-trait, but further mitigation of slow compilation times could done by exposing all traits mentioned here
80
-
behind individual feature flags. By doing this it becomes harder for downstream crates to pass-through these feature flags, so it's likely not a worthwhile tradeoff.
83
+
*`trait_debug` - Enables `Debug` for all structs
84
+
*`trait_eg` - Enables `Eq` and `PartialEq` for all structs
85
+
*`trait_hash` - Enables `Hash` for all structs
86
+
*`extra_traits` - Enables all of the above through dependent features
87
+
88
+
This change should reduce compilation times when not all traits are desired. The downsides are that it complicates CI. It can be added in a backwards-compatible
89
+
manner later should compilation times or consumer demand changes.
81
90
82
91
# Unresolved questions
83
92
[unresolved]: #unresolved-questions
84
-
85
-
Is `derive_all` a suitable name for this feature flag?
0 commit comments