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

[new] Typechecking for Const nodes #103

Merged
merged 22 commits into from
Jun 8, 2023
Merged

[new] Typechecking for Const nodes #103

merged 22 commits into from
Jun 8, 2023

Conversation

croyzor
Copy link
Contributor

@croyzor croyzor commented May 30, 2023

Add a validation check that const values match the type of the wires coming out of them

@croyzor croyzor force-pushed the draft/const-types branch from 640d1d5 to 653a366 Compare June 1, 2023 08:42
@croyzor croyzor changed the title [draft] Provide types when building const nodes [new] Provide types when building const nodes Jun 1, 2023
@croyzor croyzor requested a review from ss2165 June 1, 2023 09:46
@croyzor croyzor marked this pull request as ready for review June 1, 2023 09:46
@ss2165
Copy link
Member

ss2165 commented Jun 5, 2023

This PR does a few things to work around the fact that a ConstValue::Int doesn't actually know what type it is. I think this is worth fixing (values should be able to say what type they are), so this is done in #118 .
I think basing the validation in this PR on the changes in that one is the way to go.
This should mean hopefully that the changes to builder in this PR are not required.

@croyzor croyzor force-pushed the draft/const-types branch from 035215f to 0457711 Compare June 6, 2023 08:44
check_valid_width(*width)?;
// Check that the terms make sense against the types
if exp_width == width {
let max_value = u128::pow(2, *width as u32);
Copy link
Member

Choose a reason for hiding this comment

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

the compiler/stdlib might optimise using this anyway, but use 1<<pow in general to do powers of two

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just updated the logic here a bit, but it seems good to me to have HugrIntValueStore::powwhen we're being generic over what output type is

Err(TypeError::IntWidthMismatch(*exp_width, *width))
}
}
(ty @ ClassicType::F64, _) => Err(TypeError::Unimplemented(ty.clone())),
Copy link
Member

Choose a reason for hiding this comment

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

what's the trouble with floats?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have any float constructor for ConstValue yet!

@croyzor croyzor requested a review from ss2165 June 8, 2023 09:35
@croyzor croyzor changed the title [new] Provide types when building const nodes [new] Typechecking for Const nodes Jun 8, 2023
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.

Looks good, just spotted a couple of things (mainly just need to change ConstConst)

@croyzor croyzor requested a review from ss2165 June 8, 2023 09:58
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.

🙏

@croyzor croyzor merged commit 45eb06b into main Jun 8, 2023
@croyzor croyzor deleted the draft/const-types branch June 8, 2023 10:07
doug-q added a commit that referenced this pull request Oct 21, 2024
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