-
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
Inline functions (including multi-line and non-elemental functions) #378
Conversation
Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/378/index.html |
41c4775
to
fca8757
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #378 +/- ##
==========================================
- Coverage 95.53% 95.51% -0.03%
==========================================
Files 186 186
Lines 38974 39140 +166
==========================================
+ Hits 37233 37383 +150
- Misses 1741 1757 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The whole thing got a bit out of hand again and turned out to be a rabbit hole ... Currently (or rather with this PR), nested functions are handled via an iterative approach. We could try to solve this recursively instead. However, I don't think this would be straight-forward and questionable whether this is beneficial. Anyway, I am open for discussing that and other implementation details. Moreover, it would be possible to check whether functions are single-line (or could be reduced to a single line) and inline those at an expression level. |
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.
Looks great, and is very, very useful! Many thanks, this one has been on the todo list for a while! 🙏 🙏 🙏 🙏 🙏 🙏 GTG
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.
Very nicely done, this is a really fantastic addition and nicely executed!
A bunch of nitpick comments but no showstoppers.
.pylintrc
Outdated
@@ -87,6 +87,7 @@ disable=W0511, # Disable TODO warnings | |||
pointless-string-statement, | |||
attribute-defined-outside-init, | |||
protected-access, | |||
too-many-positional-arguments, |
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.
This has also been fixed on the main branch, so we might want to remove the commit from this branch in a rebase.
@@ -367,6 +465,81 @@ def test_inline_member_routines(tmp_path, frontend): | |||
assert (b == [3., 3., 3.]).all() | |||
|
|||
|
|||
@pytest.mark.parametrize('frontend', available_frontends(skip={ | |||
OMNI: "OMNI can't parse the code"})) |
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.
Why? I can't see anything that would usually upset OMNI, and a quick parse with F_Front
was successful for me.
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.
If you execute
from loki import Subroutine, fgen, OMNI, FP
fcode = """
subroutine member_functions
implicit none
integer :: i
real(kind=8) :: a(3)
contains
function add_to_a(b, n)
integer, intent(in) :: n
real(kind=8), intent(in) :: b(n)
real(kind=8) :: add_to_a(n)
do i = 1, n
add_to_a(i) = a(i) + b(i)
end do
end function
end subroutine member_functions
"""
routine = Subroutine.from_source(fcode, frontend=OMNI)
print(fgen(routine))
SUBROUTINE member_functions ()
IMPLICIT NONE
INTEGER :: i
REAL(KIND=8) :: a(3)
CONTAINS
FUNCTION add_to_a (b, n)
IMPLICIT NONE
INTEGER, INTENT(IN) :: n
REAL(KIND=8), INTENT(IN) :: b(n)
! HERE: MISSING DIMENSION !!!
REAL(KIND=8) :: add_to_a
DO i=1,n
add_to_a(i) = a(i) + b(i)
END DO
END FUNCTION add_to_a
END SUBROUTINE member_functions
Same thing for real(kind=8), dimension(n) :: add_to_a
. This doesn't happen for FP
and OFP
.
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.
This does sound like a bug in the Loki frontend, translating the OMNI AST to Loki IR, not a problem with OMNI.
Give me a sec, I'll have a look...
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.
#391 should fix the problem
ec744c3
to
5d7e7b3
Compare
…der certain circumstances
…l is not necessarily explicit (enough)
3be60e1
to
53cc3fa
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.
I have rebased and removed the pylintrc commit. Ready from my side now, many thanks again!
Extending and improving Inline utilities as discussed in #377