-
Notifications
You must be signed in to change notification settings - Fork 773
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
tracing 0.2: "impl Valuable for Option" is a design bug. None is indistinguishable from Some(None) #2777
Comments
Thank you for opening this issue, and I'm sorry that my response isn't as thorough as your issue, as I am currently on vacation. My opinion is that while I sympathize with your frustration, I think that changing this behavior would undermine interoperability with the systems used for analysis while privileging what some—myself included—would consider to be an uncommon pattern (nested
I alluded to this earlier, but valuable's raison d'être is to support |
@davidbarsky , thanks for answer! Please, read this post to the end, in the end I will propose wonderful way for Yes, now I agree that we should do whatever serde does. If serde_json doesn't distinguish between But But I have a solution. What we need? You just said we need object-safe
I. e. this is exactly object-safe Note: Most importantly, this proposal will make Also: Of course, all this applies to allocations done by |
I'm sorry if I missed any detail in my original response!
I'm really sorry: the disparity you've raising was documented in tokio-rs/valuable#42. We might revisit this behavior in Valuable 0.2, which is what tracing 0.2 would most likely ship with. However, my points concerning code structure and use of enums still stand and I strongly encourage you to restructure your code such that the distinction between
To address the larger, meta-point point of "consider using
Have you read the blog post announcing Valuable, by any chance? If you haven't, I really recommend that you do.
While I get the (legitimate!) frustration in needing to take on another explicit dependency and add another argument to a derive attribute, we weigh the concerns about end-to-end control of public dependencies substantially higher than asking users to make an additive change to their dependencies. |
Thanks again for big answer.
As I said before, serializing code in current version of But... well... while writing this message I looked at erased_serde code again, and now I see that erased_serde actually regularly allocates in latest released version (0.3.31) and doesn't allocate in master (94ab637b3dd75278e22580741ca3aabce0f7ed3e). I'm sorry about confusion. But okay, I agree with your position. You may close the bug |
This report is about tracing 0.2. As well as I understand tracing 0.2 will use valuable. Unfortunately,
impl Valuable for Option
is implemented so ( https://docs.rs/valuable/0.1.0/src/valuable/valuable.rs.html ):In other words,
Some(x)
will be serialized the same way asx
. This is, of course, bad for my taste. This contradicts to Rust's strong type system. I think authors of this code don't understand what is Rust's Option and why it exists. This brings us back to C++ madness, whereT
is implicitly convertible tostd::optional<T>
.You may say, this arguments are unconvincing. Yes, I thought so. So, I spend some time thinking about this. And I came up with (I hope) strong argument: in current model if we have
Option<Option<i32>>
, thenNone
is indistinguishable fromSome(None)
. I. e. consider this code:In valuable branch of tracing 0.2
a
andb
will be serialized same way, and thus we will have data loss. (I didn't test this, but [looking at code] I'm nearly sure this is what we will get. If you want, I can test this.)This is inappropriate. We develop logging system. It must preserve as much information as possible. For later analysis.
You may say: "But serializing with serde_json does the same!" Well, yes. But I have counterarguments:
serde_json
crate, not inserde
crate. Or some alternative toserde_json
should be developed. There is no problem with serde data model. In valuable situation differs. We have problem in data model.impl Valuable for Option
immediately loses information, unlikeimpl Serialize for Option
. (Go look at both implementations, you will see the difference.)None
is indistinguishable fromSome(None)
. OopsSo here are my suggestions. First, we need different representation for Option (i. e. Valuable for Option should be implemented differently). I propose treating
Some(x)
as[x]
andNone
as[]
. Or we can choose serde's approach: add Option to data model. Then consumers of data model (i. e.Visit
) will somehow deal with Option.Okay, so Valuable for Option will be implemented differently. And, of course, we should audit other implementations for Valuable. Also, we will need some Option-like type, which will preserve past Option behavior. Because, it seems, some people still need it (such as this: #2745 ). So we will need our own SkipOption or ThinOption. We also need some trait for converting from Option to our SkipOption, so user will be able to write this:
and get old Option behavior.
You may say: "Why you reported this here, not to valuable?" As I said, tracing has unique needs: it should preserve as much information as possible, and this doesn't matter how exactly. This may differ with needs of other
valuable
users. So my point is this: this should be somehow solved in tracing. One way is to fix valuable. Another way is for tracing to migrate to something elseVersion
valuable
branch of tracing 0.2The text was updated successfully, but these errors were encountered: