Fmt: optimize format rule of let_binder, if_stmt, [x..y]#636
Fmt: optimize format rule of let_binder, if_stmt, [x..y]#636trdthg wants to merge 2 commits intorems-project:sail2from
Conversation
Test Results 9 files ±0 21 suites ±0 0s ⏱️ ±0s Results for commit 85d3347. ± Comparison against base commit 5d35b1a. This pull request removes 1 and adds 3 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
f03a08a to
61573b9
Compare
|
I had another look at the diff and a lot of it is definitely an improvement, but there is a bit of weirdness with more complex expressions inside the |
|
Update
all these can be collapsed into one line now I put some restrictions on purpose before. For example, a maximum of two levels of nesting And I found that you can configure |
|
Update:
|
|
Update:
|
7b606a1 to
2bb72e7
Compare
|
Can't comment on the OCaml code, but the resulting sail formatting is IMO a big improvement. Mostly unrelated note: Some of the one-line if/else clauses are a bit complicated and I'd personally add line breaks or maybe set the column limit lower. Is there a way to force multiline if/else? Maybe there should be a config option to say don't merge if/else into a single line unless it's part of a let/other expression? So basically this is good in one line: should be |
|
Thank you for your review. I agree, in fact the comment above mentions a restriction, and it was used to solve this issue (but didn't work well at last)
This seems to be good and should solve the problem here, I'll give it a try function hex_bits_signed_forwards bv = {
if signed(bv) < 0 then { (length(bv), concat_str("-", hex_str(unsigned(not_vec(bv) + 1)))) } else {
(length(bv), hex_str(unsigned(bv)))
}
}The reason it's formatted this way now is that this line is wider than 120, so If there's a way to make it do the same after Anyway, I'll try both. |
- new module - WrapChecker: check if `chunk[s]` must wrap - new function - doc_chunks_nowrap_or_surround: check nowrap, if not, then surround - doc_chunks_rhs: check wrap, if true then prefix hardline - format rule updates - if_stmt will be prefix a hardline and nested if wrap - force foreach wrap
2bb72e7 to
9ac6d52
Compare
81b2276 to
85d3347
Compare
|
May need to refactor, so turning it into a Draft for now |
let_binder,if_stmt,[x.... .y]... and their combinationsI also tested it on sail-riscv/model/*.sail
You can see the formatting results compared to sail2 branch at trdthg/sail-riscv#2
There's still a lot of work to be done, but that will be next time