-
Notifications
You must be signed in to change notification settings - Fork 13
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
POC - linter: missing kind specifier for real literals and possible fix via git patch #334
base: main
Are you sure you want to change the base?
Conversation
…ia automatically generated git patch (file)
Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/334/index.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, so this looks great and I really like the overall concept. As discussed offline, I think there are a few "next steps" to generalise this and make this a bit more usable in practice:
- A generalisation of the diff-regex-per-node mechanism to generate patches should be provided, likely as part of the loki.lint sub-package
- The false-positive generated by the
.true.
vs..TRUE.
in the adjoining lines shows that we need to make thefgen
backend a bit more configurable (eg. via something like a pre-defined "style" dict; with this we could have a dedicated IFS-style that keeps the noise in the diffs low. - The per-node expression-substitution limits this to only local changes like the kind-identifier, but in general this should be fine for now. Further extension can come later (if needed).
As a proof-of-concept this looks great though -very cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 like
and 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