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 support for numeric match at runtime #143

Merged
merged 7 commits into from
Sep 26, 2024

Conversation

wingertge
Copy link
Contributor

Parses match statements with only numeric and wildcard arms as switch statements.
Or match arms are unrolled into their component elements for simplicity. Could theoretically use fallthrough or multiple selectors in cuda and wgsl respectively, but this also works.
Works the same as if else when the value is used as an expression.

Testing

Adds several runtime tests for the new switch statements.

Comment on lines +463 to +468
pub struct SwitchExpandExpr<I: Int, C: CubePrimitive> {
value: ExpandElementTyped<I>,
out: ExpandElementTyped<C>,
default: CubeContext,
cases: Vec<(ExpandElementTyped<I>, CubeContext)>,
}
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 difference between the SwitchExpand and SwitchExpandExpr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SwitchExpandExpr creates an outer output variables and adds an assign statement to each branch to assign the return to the outer variable. It's the same as the IfExpandExpr, it's used to emulate Rust behaviour that allows using match as value in assignments. For typing reasons and to avoid a pointless assign in every branch, the two are split based on whether the match has a return value.

@nathanielsimard nathanielsimard merged commit d509fbd into tracel-ai:main Sep 26, 2024
5 checks passed
@wingertge wingertge deleted the switch branch September 26, 2024 12:49
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