-
Notifications
You must be signed in to change notification settings - Fork 77
feat(ast): change TypeSize to store bits instead of bytes #671
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
base: main
Are you sure you want to change the base?
Conversation
This enables distinguishing edge cases like 127 (fits in int8) from 128 (doesn't fit), which is needed for correct implicit and explicit integer conversions. - Changed internal storage from u8 (bytes 0-32) to u16 (bits 0-256) - TypeSize::new() now takes bits directly - Added new_fb_bytes() for fixed-bytes types that take byte counts - bits() returns stored value, bytes() computes ceil(bits/8) - mk_ty_int_literal no longer rounds to multiples of 8 Closes #650
865b24d to
7df76e4
Compare
| #[inline] | ||
| pub const fn bytes(self) -> u8 { | ||
| if self.0 == 0 { Self::MAX } else { self.0 } | ||
| if self.0 == 0 { 32 } else { self.0.div_ceil(8) as u8 } |
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.
max/8
| #[track_caller] | ||
| pub const fn bytes_keyword(self) -> Symbol { | ||
| kw::fixed_bytes(self.0) | ||
| kw::fixed_bytes(self.bytes()) |
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.
these should be bytes_raw so that 0 maps to the int uint kw without a bit size
| self.mk_ty(TyKind::StringLiteral( | ||
| std::str::from_utf8(s).is_ok(), | ||
| TypeSize::new(s.len().min(32) as u8).unwrap(), | ||
| TypeSize::new(s.len().min(32) as u16 * 8).unwrap(), |
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.
we should just rm fn new and use from_bytes from_bits instead
This enables distinguishing edge cases like 127 (fits in int8) from 128 (doesn't fit), which is needed for correct implicit and explicit integer conversions.
u8(bytes 0-32) tou16(bits 0-256)TypeSize::new()now takes bits directlynew_fb_bytes()for fixed-bytes types that take byte countsbits()returns stored value,bytes()computesceil(bits/8)mk_ty_int_literalno longer rounds to multiples of 8Closes #650
Unblocks #647 #648 #649