-
Notifications
You must be signed in to change notification settings - Fork 116
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
Type-checker confused about what constitutes a binding or a reference in mapping patterns #244
Comments
All these mappings should be rejected I think. The left and right hand sides of a mapping should bind the same set of identifiers, and none should be duplicated. Referring to external let-bound variables should not be allowed. Here the forwards case binds (shadows) zeros_3 but it doesn't appear on the rhs:
The second case (BAD1) should fail for the same reason. For BAD2 this should fail because the forwards case becomes
which binds zeros_3 twice. BAD4 has the same problem. BAD3 and the case between BAD2 and BAD3 should fail because they have the same problem as BAD1 in reverse. I think in these cases what you really want are functions, not mappings. In general mappings should be total in both directions. The semantics for partial mappings were not adequately considered when they were implemented, and I don't see any real way to fix them in a backwards compatible way. Realistically the mapping code needs a full re-write, when I do go in to patch issues I just find more wrong with it - like the fix the other day was replacing OCaml's polymorphic equality with an |
Hm. Partiality of mappings is very convenient as a sail user, but I am willing to believe that it's painful for sail's authors. I'm not quite sure that this particular issue comes from partiality, though, but I could be convinced. Concretely, this case comes about in my model because I am using a
than
and that means referring to values in the environment. I can try using |
Oh, hah, I just thought up the following terrible hack.
works just fine. |
Yes, there's no way with mapping patterns to distinguish between a new variable in the mapping and a reference to a constant. In a regular pattern you would have to introduce a new variable and do:
but you can't do that for all guards expressions in a bi-directional way. To support that we would need either need new syntax for a pattern that means "check the matched value is equal to this expression", or a special toplevel
and use it in patterns. It might be good to enforce some style like ALL_CAPS to distinguish from regular variables there though. |
Your hack also really isn't that terrible imho |
Another thing is having a way to name the bitvectors in patterns is something I want for documentation generation, so worth thinking about the right way to go about this. |
Unfortunately, it doesn't actually work due to #245. The code generated for the outer pattern's
|
Original issue should be addressed by #253 I'll look into the thing with the register_selector_bits_zero |
I added a test for |
…_manifest, sail_lem_backend, sail_latex_backend, sail_doc_backend, sail_coq_backend, sail_c_backend, sail and libsail (0.16) CHANGES: ##### New documentation backend A new documentation backend for integrating with Asciidoctor has been added. ##### Automatic formatting (EXPERIMENTAL) The `sail -fmt` option can be used to automatically format Sail source. This currently misses some features and can produce ugly output in some known cases, so is not ready for serious usage yet. ##### Fixes Various bugfixes including: * Issue 203: rems-project/sail#203 * Issue 202: rems-project/sail#202 * Issue 188: rems-project/sail#188 * Issue 187: rems-project/sail#187 * Issue 277: rems-project/sail#277 Various mapping issues such as: * Issue 244: rems-project/sail#244 As well as other minor issues The `val cast` syntax and support for implict casts is now entirely removed, as mentioned in the previous release changes. The flags are still allowed (to avoid breaking Makefiles) but no longer do anything. The pattern completeness checker has been improved and is now context sensitive in some cases.
…_manifest, sail_lem_backend, sail_latex_backend, sail_doc_backend, sail_coq_backend, sail_c_backend, sail and libsail (0.16) CHANGES: ##### New documentation backend A new documentation backend for integrating with Asciidoctor has been added. ##### Automatic formatting (EXPERIMENTAL) The `sail -fmt` option can be used to automatically format Sail source. This currently misses some features and can produce ugly output in some known cases, so is not ready for serious usage yet. ##### Fixes Various bugfixes including: * Issue 203: rems-project/sail#203 * Issue 202: rems-project/sail#202 * Issue 188: rems-project/sail#188 * Issue 187: rems-project/sail#187 * Issue 277: rems-project/sail#277 Various mapping issues such as: * Issue 244: rems-project/sail#244 As well as other minor issues The `val cast` syntax and support for implict casts is now entirely removed, as mentioned in the previous release changes. The flags are still allowed (to avoid breaking Makefiles) but no longer do anything. The pattern completeness checker has been improved and is now context sensitive in some cases.
Whether a variable in a pattern is in reference to a value in scope or is, instead, a binder introduced by the pattern is inconsistently handled. This results in confusion when one attempts to use a value (that is, a variable in the former case) twice in a pattern.
Here's a reasonably minimal test program. Compile with
-D BAD1
through-D BAD4
to elicit different cases. It is not necessary to do more than type-check to tickle this behavior (that is,-just_check
suffices, without need of-c
or-ocaml
or any such).The text was updated successfully, but these errors were encountered: