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

Use a 64-bit USize as the sole integer type in the core #376

Merged
merged 7 commits into from
Aug 9, 2023
Merged

Conversation

cqc-alec
Copy link
Collaborator

@cqc-alec cqc-alec commented Aug 8, 2023

Closes #356 .

@cqc-alec cqc-alec requested a review from ss2165 August 8, 2023 13:47
#[inline]
pub const fn int<const N: HugrIntWidthStore>() -> Self {
Self::Hashable(HashableType::Int(N))
pub const fn int() -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

probably worth renaming this method at this point

}

/// Returns a new 64-bit integer type.
#[inline]
pub const fn i64() -> Self {
Self::int::<64>()
Self::int()
}

/// Returns a new 1-bit integer type.
#[inline]
pub const fn bit() -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

remove this method and use int() wherever this is used I think

f.write_char('I')?;
f.write_str(&i.to_string())
}
HashableType::USize => f.write_str("I64"),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
HashableType::USize => f.write_str("I64"),
HashableType::USize => f.write_str("USize"),

Comment on lines -208 to -221
fn check_int_fits_in_width(
value: HugrIntValueStore,
width: HugrIntWidthStore,
) -> Result<(), ConstIntError> {
if width > HUGR_MAX_INT_WIDTH {
return Err(ConstIntError::IntWidthTooLarge(width));
}

if VALID_WIDTHS.contains(&width) {
let max_value = if width == HUGR_MAX_INT_WIDTH {
HugrIntValueStore::MAX
} else {
HugrIntValueStore::pow(2, width as u32) - 1
};
Copy link
Member

Choose a reason for hiding this comment

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

should this code go in the int type resource or is some version already there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add a test in int_types.rs.

@cqc-alec cqc-alec requested a review from ss2165 August 9, 2023 12:23
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

👍

@cqc-alec cqc-alec added this pull request to the merge queue Aug 9, 2023
Merged via the queue into main with commit cb06bc1 Aug 9, 2023
@cqc-alec cqc-alec deleted the usize.1 branch August 9, 2023 12:38
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.

Use size type for integers in core
2 participants