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

Support constant attribute for function variable #192

Open
katat opened this issue Sep 23, 2024 · 1 comment
Open

Support constant attribute for function variable #192

katat opened this issue Sep 23, 2024 · 1 comment

Comments

@katat
Copy link
Collaborator

katat commented Sep 23, 2024

We may need to instruct if a variable is a constant during assignment, as the assigned value can't represent itself as a constant at type checking phase until synthesizer phase in some cases.

For example:

// this value being assigned should be a constant
let size_bit_len = bits::bit_len(SIZE);

But the return signature bits::bit_len can't reflect it is a constant:

fn bit_len(const SIZE: Field) -> Field;

To instruct the size_bit_len to be a constant field in order to bypass certain type checks, we would:

const size_bit_len = bits::bit_len(SIZE);

This would bypass the checks in the case:

comparator::less_than(size_bit_len, ii, 2)

where the less_than signature is

fn less_than(const LEN: Field, lhs: Field, rhs: Field) -> Field

At synthesizer phase, the assignment can check if the value being assigned is a constant based on the ConstOrVar struct.

@katat
Copy link
Collaborator Author

katat commented Sep 27, 2024

Maybe the better way would delay this type check to the MAST phase where it can propagate the constant values.
So it can just check if the argument being propagated is a constant.

To do so, we will need to propagate constant values from both builtins and native functions.

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

No branches or pull requests

1 participant