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

implement IpAddrs #64

Merged
merged 9 commits into from
Sep 30, 2024
Merged

implement IpAddrs #64

merged 9 commits into from
Sep 30, 2024

Conversation

tertsdiepraam
Copy link
Contributor

No description provided.

@tertsdiepraam tertsdiepraam marked this pull request as draft September 13, 2024 08:13
@tertsdiepraam tertsdiepraam marked this pull request as ready for review September 13, 2024 10:27
@tertsdiepraam
Copy link
Contributor Author

@bal-e looks like I can't request review from you, but feel free to!

Copy link

@bal-e bal-e left a comment

Choose a reason for hiding this comment

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

Looking great! Just had a few questions.

Literal::IpAddress(addr) => {
let to = self.new_tmp();
const SIZE: usize = std::mem::size_of::<IpAddr>();
let x: [u8; SIZE] = unsafe { std::mem::transmute_copy(addr) };
Copy link

Choose a reason for hiding this comment

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

Is this safe? The layout of IpAddr is not guaranteed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not safe no. Well, I mean, some parts aren't. Transmuting into some bytes and then transmuting back should be fine, but combined with my own equality checking and all that it becomes unsafe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that means that I either need to call out for any operation or implement my own ip addr type with stable ABI that hopefully converts back and forth with a no-op. I'd love it if I could just fail to compile if the layout changes lol.

src/lower/mod.rs Outdated
Comment on lines 943 to 948
// For an ip addr, we need to be clever, because we can
// only compare the bytes that are used the current
// variant. Therefore, we read the discriminant of the
// left value. If that's 0, we compare 5 bytes,
// otherwise, we compare 17 bytes. In other words we
// compare 5 + 12 * discriminant bytes.
Copy link

Choose a reason for hiding this comment

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

This is interesting, but I think a branch condition would be simpler and faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not simpler, because branching is a bit hard to add at this level (with the current API). Also keep in mind that cranelift optimizes branches very poorly at the moment, that being said, faster is not even on my mind right now.

@tertsdiepraam tertsdiepraam changed the base branch from main to function-macro September 25, 2024 17:12
@tertsdiepraam tertsdiepraam merged commit c45f7e1 into function-macro Sep 30, 2024
12 checks passed
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