facts: add flat binary schema and writer - #251
Open
zoogies wants to merge 2 commits into
Open
Conversation
rjsmith1999
reviewed
Sep 3, 2026
Comment on lines
+8
to
+10
| pub(crate) fn from_words(words: Vec<u32>) -> Self { | ||
| Self(words) | ||
| } |
Collaborator
There was a problem hiding this comment.
I don't understand the purpose of this data structure yet. It's just a vector for words with a byte view?
Comment on lines
+54
to
+55
| let builder = unsafe { Box::from_raw(builder) }; | ||
| Box::into_raw(Box::new(builder.freeze())) |
Collaborator
There was a problem hiding this comment.
This seems weird... why do we call box from raw before calling freeze?
Comment on lines
+30
to
+32
| pub extern "C" fn facts_buf_len(b: *const FactsBuf) -> usize { | ||
| unsafe { b.as_ref() }.map_or(0, |buf| buf.as_bytes().len()) | ||
| } |
Collaborator
There was a problem hiding this comment.
I think this works... let else is I a bit more wordy, but I like separating out the error handling. It makes it clearer what you are trying to.
Suggested change
| pub extern "C" fn facts_buf_len(b: *const FactsBuf) -> usize { | |
| unsafe { b.as_ref() }.map_or(0, |buf| buf.as_bytes().len()) | |
| } | |
| pub extern "C" fn facts_buf_len(buf: *const FactsBuf) -> usize { | |
| let Some(buf) = unsafe { b.as_ref() } else { return 0 } | |
| buf.as_bytes().len() | |
| } |
Comment on lines
+30
to
+32
| pub extern "C" fn facts_buf_len(b: *const FactsBuf) -> usize { | ||
| unsafe { b.as_ref() }.map_or(0, |buf| buf.as_bytes().len()) | ||
| } |
Collaborator
There was a problem hiding this comment.
Alternative:
Suggested change
| pub extern "C" fn facts_buf_len(b: *const FactsBuf) -> usize { | |
| unsafe { b.as_ref() }.map_or(0, |buf| buf.as_bytes().len()) | |
| } | |
| pub extern "C" fn facts_buf_len(buf: *const FactsBuf) -> usize { | |
| if let Some(buf) = unsafe { buf.as_ref() } { | |
| buf.as_bytes().let() | |
| } else { | |
| 0 | |
| } | |
| } |
Comment on lines
+35
to
+37
| pub extern "C" fn facts_buf_data(b: *const FactsBuf) -> *const u8 { | ||
| unsafe { b.as_ref() }.map_or(std::ptr::null(), |buf| buf.as_bytes().as_ptr()) | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| pub extern "C" fn facts_buf_data(b: *const FactsBuf) -> *const u8 { | |
| unsafe { b.as_ref() }.map_or(std::ptr::null(), |buf| buf.as_bytes().as_ptr()) | |
| } | |
| pub extern "C" fn facts_buf_data(buf: *const FactsBuf) -> *const u8 { | |
| let Some(buf) = unsafe { buf.as_ref() } else { return std::ptr::null(); } | |
| buf.as_bytes().as_ptr() | |
| } |
Comment on lines
+40
to
+47
| pub extern "C" fn facts_buf_free(b: *mut FactsBuf) { | ||
| if !b.is_null() { | ||
| unsafe { | ||
| drop(Box::from_raw(b)); | ||
| } | ||
| } | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
Suggested change
| pub extern "C" fn facts_buf_free(b: *mut FactsBuf) { | |
| if !b.is_null() { | |
| unsafe { | |
| drop(Box::from_raw(b)); | |
| } | |
| } | |
| } | |
| pub extern "C" fn facts_buf_free(b: *mut FactsBuf) { | |
| if b.is_null() { return; } | |
| drop(unsafe { Box::from_raw(b) }); | |
| } | |
| } | ||
|
|
||
| fn add_node(&mut self, ty: NodeType) -> NodeID { | ||
| let dense_id = u32::try_from(self.nodes.len()).expect("module has too many nodes"); |
Collaborator
There was a problem hiding this comment.
Doesn't this need to error when self.nodes.len() == INVALID_ID/u32::MAX?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack created with GitHub Stacks CLI • Give Feedback 💬