Skip to content
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

Linter debug rule fixes #126

Merged
merged 5 commits into from
Sep 5, 2023
Merged

Linter debug rule fixes #126

merged 5 commits into from
Sep 5, 2023

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented Aug 14, 2023

A small PR to fix errors in the linter debug rules:

  • ArgSizeMismatchRule: Check up to a maximum of two indirections for dimension names when comparing arg/dummy-arg sizes
  • DynamicUboundCheckRule: Fixer method returns node_map to trigger source invalidation
  • DynamicUboundCheckRule: Fixer method preserves subroutine signature when updating argument declarations
  • Fortran90OperatorsRule: Class member was added unnecessarily during removal of Expression.source. This is now a local object.

NB: This PR is stacked on top of #118 because the DynamicUboundCheckRule fixer method relies on the removal of Expression.source.

@github-actions
Copy link

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/126/index.html

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #126 (e5d2c6d) into main (4360075) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #126      +/-   ##
==========================================
- Coverage   92.09%   92.07%   -0.03%     
==========================================
  Files          89       89              
  Lines       16540    16537       -3     
==========================================
- Hits        15233    15226       -7     
- Misses       1307     1311       +4     
Flag Coverage Δ
lint_rules 96.12% <100.00%> (+0.10%) ⬆️
loki 92.00% <ø> (-0.03%) ⬇️
transformations 91.59% <ø> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
lint_rules/lint_rules/debug_rules.py 95.12% <100.00%> (+0.41%) ⬆️
lint_rules/lint_rules/ifs_coding_standards_2011.py 97.40% <100.00%> (-0.01%) ⬇️

... and 13 files with indirect coverage changes

@awnawab awnawab marked this pull request as ready for review August 14, 2023 15:07
Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, needs to land after #118, though.

if not stat:
dummy_size = Product(SubstituteExpressions(assign_map).visit(dummy_arg_size))
# we check for a maximum of two indirections for the dummy and arg dimension names
for _ in range(2):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this indirection depth a config value? That would allow overwriting the value from outside if necessary. See for example

config = {
'max_nesting_depth': 3,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah that is a great idea! Please wait to merge until I've added this.

op_str = op if op != '!=' else '/='
line = [line for line in lines if op_str in strip_inline_comments(line.string)]
if not line:
_op_map = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: any particular reason for moving the map here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained in #118, this ended up here because I misunderstood one of your earlier comments 😅

@@ -284,13 +303,24 @@ def fix_subroutine(cls, subroutine, rule_report, config):
vtype = arg.type.clone(shape=new_shape, scope=subroutine)
new_vars += as_tuple(arg.clone(type=vtype, dimensions=new_shape, scope=subroutine))

#TODO: add 'VariableDeclaration.symbols' should be of type 'Variable' rather than 'Expression'
# simplify variable declarations
single_variable_declaration(subroutine)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, apologies if I'm misreading this, but from what I understand, fix_subroutine is the auto that is intended to "correct" small violations for code that gets put back into source, right? With that in mind, splitting variable declarations looks like a very invasive change for a linter! I know we like these for GPU-specific transformations, but forcing this into every file of a large code base for mere convenience seems like a pretty hard no, if we want to bring "fixed" code back into any repo. Is this really intended here, or am I misunderstanding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your understanding is correct....this was an easy yet robust way to deal with any potential corner case of array declarations. I thought it would be ok given how invasive this fixer method is already.

Thanks a lot for pointing this out, I'll stop being lazy and make the fixer method more sophisticated 😅

Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for addressing my previous comment. All looks ok form my end now. GTG :shipit:

@reuterbal reuterbal merged commit 400ebbb into main Sep 5, 2023
11 checks passed
@reuterbal reuterbal deleted the naan-debugrules-fix branch September 5, 2023 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants