Skip to content
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

Always load .roc files with an explicit align 16 #5771

Closed
wants to merge 1 commit into from

Conversation

rtfeldman
Copy link
Contributor

This is potentially relevant in the future when parsing with SIMD.

Also, this centralizes the file loading logic before we parse, which is nice.

This is potentially relevant in the future when
parsing with SIMD.
// vec now owns the allocated memory and will deallocate it when dropped.
// We set the vec's length to be file_len because we're about to read_exact that
// many bytes into it.
let mut vec = unsafe { Vec::from_raw_parts(buffer_ptr, file_len, file_len) };
Copy link
Contributor

Choose a reason for hiding this comment

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

based on https://doc.rust-lang.org/std/vec/struct.Vec.html#method.from_raw_parts, this is UB.

You cannot have a rust Vec<T> with an allocation whose alignment is different from the alignment of T. When rust drops this vector, it only know the alignment of T, which does not match the alignment of the allocation.

also, should we not be using mmap to load files into memory?

@rtfeldman rtfeldman closed this Sep 17, 2023
@rtfeldman rtfeldman deleted the load-with-alignment branch September 17, 2023 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants