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 patterns on arrays and opaque types. #878

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

maximebuyse
Copy link
Contributor

@maximebuyse maximebuyse commented Sep 4, 2024

Closes #464 , #804

We add a phase to rewrite array patterns and usize/isize/i128/u128 patterns.

The phase rewrites them with if let guards.

For integer types the idea is to rewrite:

match x {
  1 => ...
}

as

match x {
  x if let true = (x == 1) => ...
}

For array/slice patterns, the idea is to rewrite:

match x {
  [a, b] => ...
}

as

match x {
 t if let (a, b) = (t[0], t[1]) => ...
}

In the case of slice patterns we also test the length of the slice in the condition:

match x {
  [a,.., b] => ...
}

becomes

match x {
 t if let Some(a, b) = if t.len() >= 2 then Some(t[0], t[t.len()-1]) else None => ...
}

In case the subpatterns of an array also need a guard to be rewritten, we rewrite using a pattern matching.

In case there is a disjunctive pattern with guards in the subpatterns, we try to take a boolean disjunction of the guards. When it is not possible we call the phase hoist_disjunctive_patterns and separate the arm into one arm for each case of the disjunction.

@maximebuyse maximebuyse marked this pull request as ready for review September 18, 2024 15:10
@maximebuyse
Copy link
Contributor Author

@W95Psp Not sure that you got notified but this now ready for review!

@W95Psp
Copy link
Collaborator

W95Psp commented Sep 19, 2024

I started to look at this a bit, there are issues with fresh vars I think https://hax-playground.cryspen.com/#fstar/7ec551634b/gist=898efdab8cc9c41469c5f28e72216b6e

@maximebuyse
Copy link
Contributor Author

I started to look at this a bit, there are issues with fresh vars I think https://hax-playground.cryspen.com/#fstar/7ec551634b/gist=898efdab8cc9c41469c5f28e72216b6e

Good catch, I pushed a fix.

@franziskuskiefer franziskuskiefer added the waiting-on-author Status: This is awaiting some action from the author. label Oct 8, 2024
@franziskuskiefer
Copy link
Member

Looks like there are conflicts that need to get resolved.

@franziskuskiefer franziskuskiefer linked an issue Oct 10, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-author Status: This is awaiting some action from the author.
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Array/Slice Patterns are not supported F*: pattern matching is disallowed on usizes, isizes (+u128/i128)
3 participants