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

Policy VM: Change Enum representation to be orderable #73

Open
apetkov-so opened this issue Jan 22, 2025 · 2 comments · May be fixed by #95
Open

Policy VM: Change Enum representation to be orderable #73

apetkov-so opened this issue Jan 22, 2025 · 2 comments · May be fixed by #95
Assignees
Labels
policy-compiler Policy language compiler vm Aranya policy lang VM

Comments

@apetkov-so
Copy link
Contributor

We want to use enums in fact keys, and there shouldn't be any reason why you can't do that, except enum values are internally string pairs instead of integers (IIRC this was done to ease interface generation).

I think it would make more sense to indirect enums through a definition stored in the machine. The actual value stores a type name and an index into that definition. That index will be naturally orderable, then it can be used in fact keys.

@apetkov-so apetkov-so added policy-compiler Policy language compiler vm Aranya policy lang VM labels Jan 22, 2025
@apetkov-so apetkov-so added this to the Policy Lang v2 Features milestone Jan 22, 2025
@apetkov-so apetkov-so self-assigned this Jan 22, 2025
@apetkov-so
Copy link
Contributor Author

apetkov-so commented Feb 3, 2025

@chip-so, @jdygert-spok There's a macro, value, that tries to parse a string into an enum.

#[value]
#[derive(Default)]
pub enum TestEnum {
    #[default]
    A,
    B,
    C,
}

This now requires access to the RunState to lookup the enum value identifier. I'm not sure how we can make it work.

EDIT: Actually, I don't think it does. We can just use the value indices. Only enum validation requires access to the RunState.

@apetkov-so
Copy link
Contributor Author

apetkov-so commented Feb 6, 2025

@chip-so @jdygert-spok Can I get some help with the value macro? I just can't figure out how to map the identifiers to their indices.

@apetkov-so apetkov-so linked a pull request Feb 6, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
policy-compiler Policy language compiler vm Aranya policy lang VM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant