-
Notifications
You must be signed in to change notification settings - Fork 12
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: Re-organise inline
and extract
sub-packages
#376
Conversation
Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/376/index.html |
16b1623
to
8be5434
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #376 +/- ##
==========================================
+ Coverage 95.54% 95.55% +0.01%
==========================================
Files 188 199 +11
Lines 39468 39584 +116
==========================================
+ Hits 37709 37825 +116
Misses 1759 1759
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
acdd7b6
to
3ef33ed
Compare
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.
Thanks, this is great! Makes for a much cleaner separation of functionality and the clean-up on the side in tests is much appreciated.
I left two minor comments: very minor nitpick and a question about naming.
3ef33ed
to
8fecaae
Compare
This also moves the test and renames the `extract_contained_` to `extract_internal_`, while keeping aliases to the old methods.
8fecaae
to
cc85694
Compare
This also changes the semantics of the associated pragma annotations to `!$loki outline`.
c0477f8
to
4663da6
Compare
@reuterbal Ok, I've rebased this over recent master and renamed the outline method, flags and pragma names. The rebase was quite tricky (esp. splitting the new |
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.
Thanks, I can't spot anything that may have come from the rebasing.
While looking through the changes again, I spotted an outdated docstring and a potentially unnecessary way of instantiating a visitor. Both don't come from this PR but maybe it's easy to fix them here?
Also, I've noticed that the InlineSubstitutionMapper
is very much undertested (https://app.codecov.io/gh/ecmwf-ifs/loki/pull/376/blob/loki/transformations/inline/mapper.py), probably because it is only being used when inlining statement functions (and therefore the other code parts are never hit). I'm wondering if it would be easy to expand the test coverage, e.g., by adding a test with a statement function that uses a scalar and an inline call? I've left a suggestion that uses the existing test and modifies it accordingly, but have not actually tested that this works as expected.
retriever = ExpressionRetrieverSkipInlineCallParameters(lambda e: isinstance(e, sym.InlineCall), | ||
inline_elementals_only=inline_elementals_only, functions=functions) | ||
# override retriever ... | ||
FindInlineCallsSkipInlineCallParameters.retriever = retriever |
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.
I must have missed this before: This shouldn't be necessary, since the FindInlineCallsSkipInlineCallParameters
is declared inside the function, we should be able to directly instantiate the retriever with the provided values for inline_elementals_only
and functions
.
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.
Yes, now I understand. Pushed a fix to this extend.
3239e0c
to
06774ae
Compare
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!
This change creates two new separate transformation sub-packages
loki.transformations.inline
andloki.transformations.extract
that are conceptual complements. For the inline sub-package, this allows us to separate the different types of inlining (constants, small functions and full procedures), and the associated tests. For "extract", this change brings together the two disparate current implementations (formerlyextract_contained
andregion_to_call
), and provides the counter-passes to the respective inlining operations asextract_internals
andextract_marked
. I've also added a wrapperExtractTransformation
class that provides both functionalities for batch processing.Please note that, other than a minor bug-fix, I've left the implementations untouched. Further consolidation and additional features are planned, but I wanted to get the diff-heavy stuff out of the way first.
In some more detail:
loki.transformations.inline
sub-package withconstants
/functions
/mapper
/procedures
modules. Importantly, I also split the test accordingly and localised it!extract_contained
toextract_internals
for consistency and created newloki.transformations.extract
sub-package.region_to_call
toextract_marked
and moved toloki.transformations.extract
.ExtractTransformation
as batch-processing entry point. Importantly, this works onModule
andSourcefile
objects only, as that defines where the newly created procedures go. Also added tests for thisextract_internals
and a few linter-compliance fixes for the transformation standalone tests. (Turns out pylint does not recurse into test directories, as there is no automatic package import 😉 )