Add formatter for the parse AST#820
Conversation
|
So, overall, I think I've managed to get rid of a bunch of overrides, thanks for the hints, they helped a lot! :D However, there still are quite a few remaining but I think it will be rather hard to remove those... :/ I'll try to add explanations for some of them below. Some other notes: Regarding some of the overridden
Similar problems apply to the remaining ones. Regarding your comments:
I changed that!
I tried this, unfortunately this doesn't seem to work very well in my case... The problem is that I had to implement a somewhat sophisticated logic to preserve newlines in the existing program while also respecting the intended formatting, and it doesn't work well if I just always prepend a newline. Just to give you an idea, if you have for example: After reformatting, it should preferably stay the same, while if you have something like: The reformatted result will now look like: instead of: Things get even more complicated if there are comments in between the members where I need to look at the whitespaces before and after the outer comments, so this is why the logic for reformatting is pretty delicate, and just prepending a newline before each members unfortunately trips it up.
Yes I have the Let me know what you think, I hope it's at least an improvement to before. |
|
@LaurenzV Jonas and I discussed this and we think we should not remove the pretty() calls (which would break ViperServer) but wherever possible, have pretty() just call reformat() internally so that we do not have to parallel implementations of almost the same thing. Could you take a look at that? |
|
That's already what happens, see here: https://github.com/LaurenzV/silver/blob/063279a982dfd0d1c2af49c0e009610f290e7500/src/main/scala/viper/silver/parser/ParseAst.scala#L41-L47. All of the remaining overrides are (as mentioned above) more complex and thus I'm not really sure how I can remove them without sacrificing the output quality of the reformatter. |
|
Ah, sorry. I thought you meant |
|
Ah sorry, I misunderstood that. It looks like reformat calls pretty and not the other way around? But that is also fine. So then this is ready from your point of view? |
|
Yes, right now, Otherwise, this would be ready from my side. :) |
|
Yeah I think you can leave it as is, the main goal is to not have duplicate stuff, the direction does not matter too much to me. |
|
@LaurenzV see my last commit. I've changed things to be even more in the direction that I suggested. The expected formatting changed a tiny bit (check that it looks reasonable, or revert it as you wish). There is still one failing test that I couldn't figure out - maybe you could have a look. If there are parts you don't like about this version, I'm happy to discuss alternative solutions :) |
This reverts commit ae824da.
|
Thanks a lot! Seems like you had to change a lot, sorry about that, I didn't have any experience with Scala or Viper before, so I imagine a lot of the code was unidiomatic. 😅 I have fixed the issue with the failing silver test, though it seems like your changes to the parsing and macro expansion logic are causing CI failures, I thought this would fix it, but looks like it doesn't fully solve the issue, so I've reverted it for now. Any idea what the best solution to the problem is? I can try to look into it again tomorrow or so, but given that I'm not at all familiar with that part of the code base, I'm not sure I would be able to figure out the right solution fast. Other then that, I don't have any objections to your changes, especially since the test cases still pass, which do have a pretty wide coverage. |
|
Since some of them are match errors, it might mean we need to make changes in the Silicon test suite? Not sure if that's acceptable to change, though. |
|
I think that most of the errors are stemming from the change to I couldn't find the parse error. Could you send a link to the CI of that one? Regarding changing the SIlicon test suite, it's a bit annoying but definitely in scope for this PR. |
Ah no, I didn't mean that there is a specific error related to parsing, just that as part of those changes the CI failures appeared. It's possible that they are all just related to the Okay, in this case I will give it another shot a bit later and try to fix the failures. Thanks again! |
|
Okay, I've figured the Carbon stuff out, only the match problem remaining. I've opened a PR, with that those tests pass locally for me: viperproject/silicon#908 Once that's merged, we can rerun CI and hopefully merge this PR. |
|
@JonasAlaif are you happy with this now? You still have "requested changes" but I think everything has been addressed. |
No description provided.