Skip to content

Conversation

@onbjerg
Copy link
Contributor

@onbjerg onbjerg commented Dec 22, 2025

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

Unblocks #647 #648 #649

@onbjerg onbjerg requested a review from DaniPopes as a code owner December 22, 2025 02:34
@onbjerg onbjerg added A-sema Area: semantic analysis A-parser Area: parsing source code to an AST and removed A-sema Area: semantic analysis labels Dec 22, 2025
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
#[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 }
Copy link
Member

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())
Copy link
Member

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(),
Copy link
Member

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

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

Labels

A-parser Area: parsing source code to an AST

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeSize is not granular enough

3 participants