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

Transformations: ResolveAssociateTransformer re-write to in-place substitution #387

Merged
merged 5 commits into from
Oct 10, 2024

Conversation

mlange05
Copy link
Collaborator

@mlange05 mlange05 commented Oct 2, 2024

Note: This PR sits on top of PR #372 and requires this to be merged first.

This PR re-writes the ResolveAssociateTransformer and switches it to acting entirely in-place. For this, instead of finding all symbols and substituting them with their inverse-association, we now simply run over each symbol, find its inverse from the .scope and apply in-place. This requires the substitution to be written as a symbol mapper.

As an addition feature, we can now do partial resolution in associate bodies, where only a select sub-region of the code has its associated symbols resolved. I've added a test to this extend.

And on top of that I've refactored the imports in the associated test.

Edit: I've also had a to introduce "auto-fixer" behaviour for CallStatement nodes and a corresponding test. This now ensure that call.arguments and call.kwarguments are always (possibly empty) tuples and can thus safely be iterated. This fixed some fallout in the transpile tests.

@mlange05 mlange05 changed the title Naml resolve assoc new Transformations: ResolveAssociateTransformer re-write to in-place susbtitution Oct 2, 2024
Copy link

github-actions bot commented Oct 2, 2024

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

@mlange05 mlange05 changed the title Transformations: ResolveAssociateTransformer re-write to in-place susbtitution Transformations: ResolveAssociateTransformer re-write to in-place substitution Oct 3, 2024
@mlange05 mlange05 force-pushed the naml-resolve-assoc-new branch 3 times, most recently from 61d511a to 78f1241 Compare October 6, 2024 11:13
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 98.51852% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.52%. Comparing base (a4b1df9) to head (4445dd0).
Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
loki/ir/nodes.py 93.75% 1 Missing ⚠️
loki/transformations/sanitise.py 97.36% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #387   +/-   ##
=======================================
  Coverage   95.52%   95.52%           
=======================================
  Files         186      186           
  Lines       38894    38977   +83     
=======================================
+ Hits        37152    37234   +82     
- Misses       1742     1743    +1     
Flag Coverage Δ
lint_rules 96.39% <ø> (ø)
loki 95.51% <98.51%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Instead of finding all symbols and substituting them with their
inverse-association, we now simply run over each symbol, find its
inverse from the `.scope` and apply in-place. This requires the
substitution to be written as a symbol mapper.

As an addition feature, we can now do partial resolution in associate
bodies, where only a select sub-region of the code has its associated
symbols resolved. I've added a test to this extend.
This adds "auto-fixer" behaviour for call.arguments and
call.kwarguments, which makes it safe to always iterate them.
@mlange05 mlange05 marked this pull request as ready for review October 7, 2024 15:32
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.

Very neat trick and nicely implemented and tested!

I left a question but that's likely fine, so happy to merge as is.

"""
An :any:`collections.OrderedDict` of associated expressions.
"""
return CaseInsensitiveDict((str(v), k) for k, v in self.associations)
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 simply "stringify" v here, considering that an association can in theory be a rather complex expression?

@reuterbal reuterbal added the ready for merge This PR has been approved and is ready to be merged label Oct 8, 2024
@reuterbal reuterbal merged commit fe7413b into main Oct 10, 2024
13 checks passed
@reuterbal reuterbal deleted the naml-resolve-assoc-new branch October 10, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge This PR has been approved and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants