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

Add HashableValue as part of ConstValue, and ContainerValue #322

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jul 31, 2023

  • No additional sharing of code with TypeParam/TypeArg yet, but the idea is that we will be able to
  • Still have both serde_yaml::Value and Box<dyn CustomConst> in different places
  • typecheck.rs remains, as the code that's used by both the new and the old, not-yet-updated (TypeParam/TypeArg) code. When we update the latter, the classes/routines in typecheck.rs should only have one caller (in values.rs) and then they can be moved into values.rs. [So, this is kinda in the wrong place now, if we want to move it.]

}
}

#[cfg(test)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These have gone to ops/constant.rs. I could write some HashableValue-specific ones in values.rs...

@@ -87,132 +54,3 @@ pub(crate) fn check_int_fits_in_width(
Err(ConstIntError::IntWidthInvalid(width))
}
}

fn map_vals<T: PrimType, T2: PrimType>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has moved to values.rs

}

/// Typecheck a constant value
pub(super) fn typecheck_const(typ: &ClassicType, val: &ConstValue) -> Result<(), ConstTypeError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been split into values.rs and constant.rs parts

@acl-cqc acl-cqc marked this pull request as ready for review August 1, 2023 15:19
@acl-cqc acl-cqc changed the title [WIP] Add HashableValue (checkable), add all containers to ConstValue Add HashableValue as part of ConstValue, and ContainerValue Aug 1, 2023
/// An arbitrary length integer constant.
Int(HugrIntValueStore),
Hashable(HashableValue),
/// A collection of constant values (at least some of which are not [ConstValue::Hashable])
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 known to be", perhaps

match ty {
ClassicType::Container(cty) => return vals.check_container(cty),
// We might also fail to deduce a container *value* was hashable,
// because it contains opaque values which don't synthesize their type.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment might need rewording given #325 provides no way for a value "to synthesize its type". Perhaps it motivates allowing such a way?

@@ -145,57 +149,128 @@ impl PartialEq for dyn CustomConst {

impl Default for ConstValue {
fn default() -> Self {
Self::Int(0)
Self::Hashable(HashableValue::Int(0))
Copy link
Member

Choose a reason for hiding this comment

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

i think a default no longer makes sense

src/values.rs Outdated
}
ContainerValue::Map(_) => "a map".to_string(),
ContainerValue::Sum(tag, val) => format!("const:sum:{{tag:{tag}, val:{}}}", val.name()),
ContainerValue::Opaque(c) => format!("const:{:?}", c),
Copy link
Member

Choose a reason for hiding this comment

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

worth saying opaque here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used const:custom: and const:yaml: for the two different forms that we still have ATM

src/values.rs Outdated
Comment on lines 220 to 222
/*/// Expected width (packed with const int) doesn't match type
#[error("Type mismatch for int: expected I{0}, but found I{1}")]
IntWidthMismatch(HugrIntWidthStore, HugrIntWidthStore),*/
Copy link
Member

Choose a reason for hiding this comment

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

delete

Add src/values.rs w/new {Hashable,Container}Value, also move ConstTypeError etc.
  +trait ValueOfType defines 'check_type' method breaking up old typecheck_const
src/ops/constant.rs contains ConstValue (which uses HashableValue)
src/ops/constant/typecheck.rs contains bits still shared with TypeArg/TypeParam
@acl-cqc acl-cqc enabled auto-merge August 2, 2023 10:30
@acl-cqc acl-cqc added this pull request to the merge queue Aug 2, 2023
Merged via the queue into main with commit 7b927eb Aug 2, 2023
5 checks passed
@acl-cqc acl-cqc deleted the new/values branch August 2, 2023 10:32
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