-
Notifications
You must be signed in to change notification settings - Fork 7
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
+97
−189
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8560156
Update spec to use a 64-bit USize as the sole integer type in the core.
cqc-alec 55b6672
Use USize as the sole integer type in the core.
cqc-alec 0fddb29
Merge branch 'main' into usize.1
cqc-alec 81fa635
Rename "int()" to "usize()".
cqc-alec 709962e
Remove ClassicType::bit() and use usize() instead.
cqc-alec a1ed3a9
Change Display string for USize.
cqc-alec f9e2075
Add some tests for get_width().
cqc-alec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,10 +1,10 @@ | ||||||
//! Dataflow types | ||||||
|
||||||
use std::fmt::{self, Display, Formatter, Write}; | ||||||
use std::fmt::{self, Display, Formatter}; | ||||||
|
||||||
use super::type_row::{TypeRow, TypeRowElem}; | ||||||
use super::{custom::CustomType, AbstractSignature}; | ||||||
use crate::{classic_row, ops::constant::HugrIntWidthStore}; | ||||||
use crate::classic_row; | ||||||
use itertools::Itertools; | ||||||
use serde_repr::{Deserialize_repr, Serialize_repr}; | ||||||
use smol_str::SmolStr; | ||||||
|
@@ -193,8 +193,8 @@ pub enum HashableType { | |||||
/// TODO of course this is not necessarily hashable, or even classic, | ||||||
/// depending on how it is instantiated... | ||||||
Variable(SmolStr), | ||||||
/// An arbitrary size integer. | ||||||
Int(HugrIntWidthStore), | ||||||
/// A 64-bit unsigned integer. | ||||||
USize, | ||||||
/// An arbitrary length string. | ||||||
String, | ||||||
/// A container (all of whose elements can be hashed) | ||||||
|
@@ -216,22 +216,22 @@ impl ClassicType { | |||||
ClassicType::Graph(Box::new(signature)) | ||||||
} | ||||||
|
||||||
/// Returns a new integer type with the given number of bits. | ||||||
/// Returns a new integer type. | ||||||
#[inline] | ||||||
pub const fn int<const N: HugrIntWidthStore>() -> Self { | ||||||
Self::Hashable(HashableType::Int(N)) | ||||||
pub const fn int() -> Self { | ||||||
Self::Hashable(HashableType::USize) | ||||||
} | ||||||
|
||||||
/// 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 { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this method and use |
||||||
Self::int::<1>() | ||||||
Self::int() | ||||||
} | ||||||
|
||||||
/// New unit type, defined as an empty Tuple. | ||||||
|
@@ -294,10 +294,7 @@ impl Display for HashableType { | |||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||||||
match self { | ||||||
HashableType::Variable(x) => f.write_str(x), | ||||||
HashableType::Int(i) => { | ||||||
f.write_char('I')?; | ||||||
f.write_str(&i.to_string()) | ||||||
} | ||||||
HashableType::USize => f.write_str("I64"), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
HashableType::String => f.write_str("String"), | ||||||
HashableType::Container(c) => c.fmt(f), | ||||||
} | ||||||
|
@@ -496,7 +493,7 @@ mod test { | |||||
); | ||||||
|
||||||
let hash = vec![ | ||||||
SimpleType::Classic(ClassicType::Hashable(HashableType::Int(8))), | ||||||
SimpleType::Classic(ClassicType::Hashable(HashableType::USize)), | ||||||
SimpleType::Classic(ClassicType::Hashable(HashableType::String)), | ||||||
]; | ||||||
let ty = SimpleType::new_tuple(hash); | ||||||
|
@@ -523,7 +520,7 @@ mod test { | |||||
SimpleType::Classic(ClassicType::Container(Container::Sum(_))) | ||||||
); | ||||||
|
||||||
let hash: TypeRow<HashableType> = vec![HashableType::Int(4), HashableType::String].into(); | ||||||
let hash: TypeRow<HashableType> = vec![HashableType::USize, HashableType::String].into(); | ||||||
let ty = SimpleType::new_sum(hash.map_into()); | ||||||
assert_matches!( | ||||||
ty, | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
probably worth renaming this method at this point