-
Notifications
You must be signed in to change notification settings - Fork 126
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
Lean: Manage when
clauses in match_bv
#1179
Conversation
The only semantic change this PR proposes is to not assert on argument pattern that we cannot yet translate, but instead to record them as `TODO_ARG_PATTERN`. This is sufficient to build the full RISC-V Sail model without assertions and with about 3500 warnings and errors remaining. This PR also introduces a GitHub action to validate that the RISC-V model builds. The RISC-V model currently requires two patches (one in Ryan's repository and one applied through this patch). Over time, we expect to switch to the main RISC-V repo. Co-authored-by: Léo Stefanesco <[email protected]>
Test Results 13 files 27 suites 0s ⏱️ For more details on these errors, see this check. Results for commit 13bdc46. ♻️ This comment has been updated with latest results. |
when
clauses in match_bvwhen
clauses in match_bv
I just tested this. While the code looks great, I am getting 10 syntax and type errors on the full sail model and lean hangs at I currently get the error def csr_name_map_forwards (arg_ : (BitVec 12)) : SailM String := do
match_bv arg_ with
| 001100000001 => do (pure "misa")
[...]
| reg => do (hex_bits_12_forwards reg) On the positive side, the bv_match model has 82000 lines vs the current model's 105000 lines. |
I guess I did mess something up before putting up the PR then. Thanks for taking the time to run this on your end, I'll have it hopefully fixed soon. |
Would we assume this to be exhaustive because the expression syntactically matches a constructor? I'm not sure I'd count on this being changed. OCaml also gives me a non-exhaustiveness warning on the same match block. |
That's to do with literals 🤔 In the second match block it matches an |
Sail also considers such a match statement as incomplete:
But it's just a warning in Sail not an error, so you might have to add |
@arthur-adjedj: Pushed a fix for |
One idea to sidestep the issues generally for now: We could add a pragma to Sail to mark functions in which |
This PR re-enables
match_bv
, and makes an attempt at managingwhen
clauses correctly. This PR currently compiles RISC-V, but fails on a few C tests because of different limitations from the implementation:encdec
andencdec_subrange
: The elaboration of bitvector pattern-matching inside another (non-bitvector) pattern such as here currently fails, and leads to ill-formed syntax.option_nest
andspecial_annot
: some exhaustive patterns appear aslet <pat> := <term>
, but Lean does not manage to prove the exhaustiveness. A MWE of this issue is the following:This probably warrants a RFC on the Lean repo.
vector_init
: The output differs from the expected output:Expected:
Actual output (it's missing the first
ok
):vector_subrange_pattern
: someTODO_ARG_PATTERN
s appear in a few places. My initial guess is that subrange patterns in function clauses are not deleted correctly by theremove_vector_subrange_pats
rewrite pass, though I have not investigated this any further.Furthermore, the
make_cases_exhaustive
rewrite pass does not work in the presence of patterns withwhen
clauses, andfailwith
s when it encounters one, so I had to turn it off for now, leading to somematch
es getting an additional superfluous wildcard pattern-match here and there. It could probably be tweaked to simply give-up on the exhaustiveness checks whenever it encounters awhen
pattern.I do not have more time to dedicate to this PR, so I will leave this here as is. Anyone feel free to try and fix these errors, or consider them to not matter too much and skip them in the test suite altogether.