-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Non-exported record fields #1132
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,8 @@ pub struct FieldMetadata { | |
pub annotation: TypeAnnotation, | ||
/// If the field is optional. | ||
pub opt: bool, | ||
/// If the field is serialized. | ||
pub not_exported: bool, | ||
pub priority: MergePriority, | ||
} | ||
|
||
|
@@ -133,6 +135,7 @@ impl FieldMetadata { | |
contracts: outer.annotation.contracts, | ||
}, | ||
opt: outer.opt || inner.opt, | ||
not_exported: outer.not_exported || inner.not_exported, | ||
priority, | ||
} | ||
} | ||
|
@@ -359,22 +362,24 @@ impl RecordData { | |
}) | ||
} | ||
|
||
/// Return an iterator over the fields' values, ignoring optional fields without | ||
/// definition. Fields that aren't optional but yet don't have a definition are mapped to the | ||
/// error `MissingFieldDefError`. | ||
pub fn iter_without_opts( | ||
/// Return an iterator over the fields' values, ignoring optional fields | ||
/// without definition and fields marked as not_exported. Fields that | ||
/// aren't optional but yet don't have a definition are mapped to the error | ||
/// `MissingFieldDefError`. | ||
pub fn iter_serializable( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nitpicky nitpick, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Funnily enough, I had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I fear it might be misleading, but it does iter on fields that don't have values (where value is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vkleen it's not a huge deal either, let's not keep this PR open for that. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave it the way it is (the path of least resistance 😆). The next time someone touches that code, they can see if another name fits better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (late to the party) Naming idea: |
||
&self, | ||
) -> impl Iterator<Item = Result<(&Ident, &RichTerm), MissingFieldDefError>> { | ||
self.fields | ||
.iter() | ||
.filter_map(|(id, field)| match field.value { | ||
Some(ref v) => Some(Ok((id, v))), | ||
self.fields.iter().filter_map(|(id, field)| { | ||
debug_assert!(field.pending_contracts.is_empty()); | ||
match field.value { | ||
Some(ref v) if !field.metadata.not_exported => Some(Ok((id, v))), | ||
None if !field.metadata.opt => Some(Err(MissingFieldDefError { | ||
id: *id, | ||
metadata: field.metadata.clone(), | ||
})), | ||
None => None, | ||
}) | ||
_ => None, | ||
} | ||
}) | ||
Comment on lines
+365
to
+382
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is only used in |
||
} | ||
|
||
/// Get the value of a field. Ignore optional fields without value: trying to get their value | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the correct semantics, especially when considering a program like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, because it means it actually gives a way to "remove" fields via merging, at least as far as serialization is concerned. I don't know if it should be used that way, or if it is a problem at all, but just wanted to point it out. It's probably also morally better than plain removal of a field, because you can still query it, see it when not exporting, etc.