chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.79k stars 421 forks source link

Prevent chplcheck fixits from being misapplied #24846

Open jabraham17 opened 7 months ago

jabraham17 commented 7 months ago

In #24663 and #24744, I have been implementing automatic fixits for chplcheck. This allows users to automatically fix issues in their code. However, fixits cannot be applied blindly as they may break code. This is somewhat mitigated by #24744 where users can use --interactive to selectively apply fixits, but this provides no protection to users who blindly apply --fixit

For example, the following code cause chplcheck --fixit to break code

for i in (1..10) {}

After applying the fixit for an unused loop index, the code will look like the following

for 1..10) {}

This is due to how the locations work in the current parser, and this is not an easy fix (that I can think of). However, if a user blindly applies the fixits, there code will no longer compile.

Another example occurs when multiple fixits are applied on top of each other

for i in 1..10 do {}

In this case, 2 fixits will be applied (unused loop index and unnecessary do keyword). However, because these overlap on the same lines chplcheck --fixit will create a very garbled loop.

I think there are two things to improve here:

  1. support overlapping fixits
  2. when a fixit will cause code to no longer parse/resolve, do not apply the fixit and warn the user
jabraham17 commented 6 months ago

As a part of this, there should be a --dryrun flag which shows essential a patch file for what changes will be made.

A further user experience improvement would be to have the interactive mode print out what changes are actually going to be made, rather than just the fixit description