Open MichaelSt98 opened 4 months ago
Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/334/index.html
As discussed offline: This is fantastic and I'm positively surprised how relatively straightforward the implementation appears to be. The testing on our Fortran codes also makes this look very promising.
In terms of the implementation:
- I think we might want to think a little more about the association of IR containers with the corresponding Sourcefile object. We should try to somehow provide a mechanism of providing this upward link, to make the additional argument that you had to introduce unnecessary. Moreover, the
source
object of the Sourcefile should also have the full string already, which would make it redundant to read the file again.- The mechanics of creating a diff from replacing individual source lines should likely become a set of independent utilities. Maybe we need to add a second use case to trial what the interface of such utilities should look like in a more generic sense?
- We should think of how we are going to embed this in the larger linter control flow. Right now you've hijacked the fixer method, which was originally intended for editing the IR and later dumping the IR to file. We could make the "generate a diff instead"-mode a generic variant of that, or create a secondary fixer workflow side-by-side, or switch the entire fixer workflow to the diff methodology. I don't have a strong opinion on this (yet?) but probably worth a discussion, also with @mlange05 .
Thanks for having a look and I completely agree. The "hijacking fixer method"-approach was appropriate to test the idea/approach, but was never intended to be a proper solution.
I also don't have a strong opinion on whether we should introduce a "generate a diff instead"-mode or whether we should create a secondary fixed workflow ... or rather I can think of advantages and disadvantages for both.
What it does/How it works:
with_ir_node=True
)literal.kind is None
: fix kind and save in dictSubstituteExpressions
to the relevant node (only!)node.source.string
)difflib
and write to fileDemonstration with CLOUDSC:
With this config file
applied to the CLOUDSC dwarf via e.g.,
loki-lint.py check -c lint_config.yml --fix --worker 4
generates a file "loki_lint_CLOUDSC.patch" which looks likeand can be applied via
git apply --whitespace=fix loki_lint_*.patch
resulting in
git diff
Also tested for "ifs-source" with "include: arpifs/phys_ec/*/.F90".
Some notes:
Current limitations:
SubstituteExpressions