Skip to content

Support optional and named arguments in inlining#2801

Closed
schreiberx wants to merge 25 commits intomasterfrom
martin_2_issue_inline_optional_args_2525
Closed

Support optional and named arguments in inlining#2801
schreiberx wants to merge 25 commits intomasterfrom
martin_2_issue_inline_optional_args_2525

Conversation

@schreiberx
Copy link
Collaborator

This PR would solve issue #2525

@schreiberx schreiberx added the NEMO Issue relates to the NEMO domain label Nov 23, 2024
@codecov
Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.89%. Comparing base (e95eefe) to head (f1ec7b7).
Report is 1269 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #2801    +/-   ##
========================================
  Coverage   99.89%   99.89%            
========================================
  Files         362      363     +1     
  Lines       51685    51858   +173     
========================================
+ Hits        51633    51806   +173     
  Misses         52       52            

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@schreiberx schreiberx requested a review from arporter November 24, 2024 19:16
@schreiberx schreiberx added ready for review PSyIR Core PSyIR functionality labels Nov 24, 2024
@schreiberx schreiberx marked this pull request as ready for review November 24, 2024 19:18
@schreiberx
Copy link
Collaborator Author

Hi @arporter , this is now ready for review.

It's on supporting the optional arguments using the previous pull request on the argument matching.
I also took out all parts from the call.py related to other routines and put them into a dedicated file, psyir/tools/call_routine_matcher.py, which keeps things tidy and better configurable with respect to the options.

Regarding the options dictionary, I'm now using a set_option(...) for some classes. This makes "override" options IMHO much clearer rather than using some dictionary that can have arbitrary strings in it. (@hiker , I think that's also what you wanted).

@schreiberx
Copy link
Collaborator Author

This PR depends on PR #2775

@schreiberx schreiberx self-assigned this Nov 28, 2024
@schreiberx schreiberx requested a review from sergisiso December 23, 2024 21:38
@schreiberx
Copy link
Collaborator Author

@arporter @sergisiso @hiker I thought it would be good to have you all informed about this PR because of some restructuring of the callee detection and I guess this is getting more and more important for other use cases of psyclone.

We have the following two different situations:

  • We like to create a call trace. However, we don't want to use the inline transformation for a call trace. What we would like to have is to find the callee.
  • If we like to inline, we need to find the callee as well.
    Since finding the matching callee for interfaced calls/subroutines is part of these two situations, and since adding the feature of supporting optional and named arguments added quite a lot of lines of codes, I put the functionality to find the matching calls/subroutine into the file in
    psyir/tools/call_routine_matcher.py
    To do the coverage tests in the Andy style (Each test has to cover 100% of the corresponding file), I moved over various test cases which have been formerly part of the call_tests.py and inline_trans_tests.py to the new test file call_routine_matcher_tests.py .
    All three test files now result in 100% coverage of the respective python file.

Copy link
Member

@arporter arporter left a comment

Choose a reason for hiding this comment

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

Thanks very much Martin, this is exciting functionality. However, there are a couple of biggish issues that I want to tackle before I go any further with the review. First, you have implemented a different way of handling options for InlineTrans. We need project-wide agreement on how we do this so that we can adopt a uniform approach (#2668 ). We should use #2668 to come to some agreement and then you can implement that here. Second, you have cool new functionality to remove branching when the condition is a literal and I think that should be broken out as a separate transformation with an associated PR.
Finally, there are some files with non-functional changes that you can just revert to master to shrink this PR.

'OMPSharedClause',
'OMPDependClause'
]
'OMPDependClause',
Copy link
Member

Choose a reason for hiding this comment

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

Please revert (since there's no functional change to this file).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK.

@@ -0,0 +1,18 @@

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding this. Please could you add the usual licence/copyright header (with appropriate year).

Copy link
Member

Choose a reason for hiding this comment

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

Also, please add a comment saying it builds the html versions of all of the docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm working on the proposed changes quite late. There have been huge updates on this Makefile. I'll remove my suggested changes since the new version from master is much better.

make -C developer_guide html SPHINXOPTS="-W --keep-going"

reference_guide:
make -C reference_guide html SPHINXOPTS="-W --keep-going"
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this gives:

build finished with problems, 2 warnings (with warnings treated as errors).
make[1]: *** [Makefile:19: html] Error 1
make[1]: Leaving directory '/home/me/Projects/PSyclone/doc/reference_guide'
make: *** [Makefile:9: reference_guide] Error 2

Possibly the simplest thing to do is not to "treat warnings as errors" for the Reference Guide.

Copy link
Collaborator Author

@schreiberx schreiberx Jul 16, 2025

Choose a reason for hiding this comment

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

I'm working on the proposed changes quite late. There have been huge updates on this Makefile. I'll remove my suggested changes since the new version from master is much better.

Copy link
Member

Choose a reason for hiding this comment

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

Please remove this - I don't think we need a script to wrap around pytest -n x blah. Especially since running the whole test suite takes a few minutes.

sym.interface.container_symbol._reference = test_kernel_mod
trans = OMPTaskTrans()
trans: OMPTaskTrans = OMPTaskTrans()
trans.set_option(check_matching_arguments_of_callee=False)
Copy link
Member

Choose a reason for hiding this comment

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

This change to the way we set options for a transformation needs to be agreed with everyone and done as a separate PR. Please revert it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK


def __init__(self):
# List of call-to-subroutine argument indices
self._ret_arg_match_list: List[int] = None
Copy link
Member

Choose a reason for hiding this comment

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

Why is this Transformation class now holding state? I wouldn't expect this to be necessary...

:type node: :py:class:`psyclone.psyir.nodes.Routine`
:param call_node: target PSyIR node.
:type call_node: :py:class:`psyclone.psyir.nodes.Call`
:param routine: PSyIR subroutine to be inlined.
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for adding this argument?


# Validate that the inlining can also be accomplish.
# This routine will also update
# self.node_routine and self._ret_arg_match_list
Copy link
Member

Choose a reason for hiding this comment

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

Ah, so that's why there's state? Please update the comments on the declarations of these member variables.

# This routine will also update
# self.node_routine and self._ret_arg_match_list
# with the routine to be inlined and the relation between the
# arguments and to which routine arguments they are matched to.
Copy link
Member

Choose a reason for hiding this comment

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

"...and which routine arguments..."

# - `True`: Replace If-Block with If-Body
# - `False`: Replace If-Block with Else-Body. If it doesn't exist
# just delete the if statement.
self._optional_arg_eliminate_ifblock_if_const_condition()
Copy link
Member

Choose a reason for hiding this comment

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

Nice. However, I think this should be a separate transformation. That way, it can be used after @hbrunie 's new ReplaceReferenceByLiteralTrans (#2828) to eliminate branching. For preference I think this should be done as a separate PR to avoid us ending up with a massive review again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. I'll open first an issue and then we'll see. Not sure if I can do this in the near future.

hbrunie added a commit to hbrunie/PSyclone that referenced this pull request Jan 23, 2025
@hbrunie hbrunie mentioned this pull request Jan 23, 2025
hbrunie added a commit to hbrunie/PSyclone that referenced this pull request May 6, 2025
@schreiberx
Copy link
Collaborator Author

@arporter I'll close this one and reopen another one.

@schreiberx schreiberx closed this Jul 18, 2025
@schreiberx
Copy link
Collaborator Author

For reference, this is the new PR: #3067

@schreiberx schreiberx deleted the martin_2_issue_inline_optional_args_2525 branch July 18, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NEMO Issue relates to the NEMO domain PSyIR Core PSyIR functionality reviewed with actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants