-
Notifications
You must be signed in to change notification settings - Fork 14
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
Array shadowing bugfix for inliner #202
Array shadowing bugfix for inliner #202
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #202 +/- ##
=======================================
Coverage 92.26% 92.26%
=======================================
Files 96 96
Lines 17092 17092
=======================================
Hits 15770 15770
Misses 1322 1322
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thank you very much for finding this and supplying test and fix. However, I think all that's missing here is a call to recursive_expression_map_update before applying the |
… added import for it, remove local import found in same file to avoid duplicate imports
…/loki into inliner-array-indexing-bugfix
Thanks @reuterbal, that's a lot simpler and works! Note that there was an additional local import for |
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.
Fantastic, many thanks!
I don't remember what the history of the local import was, but the pylint annotations next to it suggest this may have been to break a cyclic import in the past. However, this does not seem to be a problem any more. Thanks for changing this!
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.
Many thanks for catching this @skarppinen and apologies, I must have dropped this in the recent refactoring. GTG from me.
Hello.
This PR fixes a bug in
inline_subroutine_calls
.Consider the following example (here demonstrating with
inline_member_procedures
, which eventually calls the above):On the main branch, this prints:
Inside the double loop, note the wrong
jlon
andjg
.This occurs because the inliner renames shadowing variables only by "name", i.e
arr(jlon, jg)
is transformed only toinner_arr(jlon, jg)
even thoughjlon
andjg
should also be renamed as they are shadowed as well.This occurs here (
var_map
only changes name):loki/loki/transform/transform_inline.py
Lines 337 to 342 in 556db2e
This PR fixes the above issue by first building a transformation map for renaming nonarray variables, and then a transformation map for renaming array variables. In the construction of the latter, the
dimensions
attribute is transformed using the transformation map for nonarray variables. There may be a more elegant way to achieve this.There is also a new test to check that this remains fixed.