Skip to content

facts: add flat binary schema and writer - #251

Open
zoogies wants to merge 2 commits into
mainfrom
feat/facts-flat-core
Open

facts: add flat binary schema and writer#251
zoogies wants to merge 2 commits into
mainfrom
feat/facts-flat-core

Conversation

@zoogies

@zoogies zoogies commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Stack created with GitHub Stacks CLIGive Feedback 💬

@zoogies zoogies self-assigned this Aug 18, 2026
@zoogies zoogies added the enhancement New feature or request label Aug 18, 2026
@zoogies
zoogies marked this pull request as ready for review August 20, 2026 13:38
Comment on lines +8 to +10
pub(crate) fn from_words(words: Vec<u32>) -> Self {
Self(words)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to error when self.nodes.len() == INVALID_ID/u32::MAX?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants