Skip to content

Conversation

@LonelyCat124
Copy link
Collaborator

Could be closes, not sure, up to review.

Work in progress on doing this, remaining steps I have for this PR:

  1. Swap fparser2.py to use create when creating Intrinsics where possible (often I think it won't be). If not possible, we could canonicalise, I'll try that and see how it goes.
  2. Fix remaining tests.

@LonelyCat124
Copy link
Collaborator Author

LonelyCat124 commented Sep 24, 2025

I think we could also delete the IAttr class entirely and replace it with __new__ on the Intrinsic Enum, any preferences @sergisiso

@LonelyCat124
Copy link
Collaborator Author

I think we could also delete the IAttr class entirely and replace it with __new__ on the Intrinsic Enum, any preferences @sergisiso

I quickly tried this and decided its worse because you can't pass named arguments to __new__, meaning we'd be stuck again with the non-named Enum argument lists which are getting too long now to be readable.

@LonelyCat124
Copy link
Collaborator Author

I've fixed the remaining problems with the test suite. I expect there will be some coverage changes I need to look at next, notably I expect there are now unreachable sections of fparser2.py that I can remove, but I will wait to see what pycov says and go from there in case there are other sections I either miss testing or that can now be removed.

One option I leave up to the review is whether to add something to the backend to not output argument names, as we will now be very explicit and add argument names wherever possible (assuming an IntrinsicCall has been canonicalised).

@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.90%. Comparing base (5ee8752) to head (be08a53).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #3150    +/-   ##
========================================
  Coverage   99.90%   99.90%            
========================================
  Files         374      374            
  Lines       53011    53164   +153     
========================================
+ Hits        52958    53111   +153     
  Misses         53       53            

☔ 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.

@LonelyCat124
Copy link
Collaborator Author

@arporter @sergisiso This is ready for a first look now.

@LonelyCat124 LonelyCat124 marked this pull request as ready for review September 26, 2025 13:39
@LonelyCat124
Copy link
Collaborator Author

I broke all the sympy stuff again when switching the default behaviour :'(

@LonelyCat124
Copy link
Collaborator Author

Hopefully integration works now, there was one badly defined intrinsic (capitalized argument names which docs say we shouldn't have) that I've fixed and I'm hoping was the remaining issue.

@LonelyCat124
Copy link
Collaborator Author

@arporter I think this is ready for another look now - I've fixed the issues discussed and the NEMO4 integration tests work - I'm waiting on the others to finish running but the first LFRic attempt had the signal 11 issue from the Nvidia compiler so I've set it rerunning.

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 Aidan. Pretty much there now, just needs some tidying and perhaps a little refactor in the FortranWriter/SympyWriter handlers for IntrinsicCall.

fails, then PSyclone will not create an ``IntrinsicCall`` corresponding to
the input. This canonicalisation is required to guarantee correct behaviour
when computing reference_accesses or the return type of an Intrinsic.
will convert all of the arguments to be named arguments. If canonicalisation
Copy link
Member

Choose a reason for hiding this comment

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

Please could you reword this whole section (L597-) as I think we've agreed that we're not calling it "canonicalisation" any more?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

# By default, the PSyIR backends output argument names on (most)
# IntrinsicCalls. This option enables control of that behaviour.
self._backend_intrinsic_named_kwargs = True
self._backend_intrinsic_named_kwargs = False
Copy link
Member

Choose a reason for hiding this comment

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

Comment above needs changing as the default is now not to put unnecessary argument names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

# Record any intrinsic output format settings.
if "disable_named_intrinsic_args" in args:
if "backend_add_all_intrinsic_arg_names" in args:
# The backend won't attempt to add names to required
Copy link
Member

Choose a reason for hiding this comment

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

Pls update this comment too :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Config.get().backend_indentation_disabled = True
# A command-line flag overrides the setting in the Config file (if
# any).
if "backend_disable_validation" in args:
Copy link
Member

Choose a reason for hiding this comment

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

Please could you group this with the bit setting backend_intrinsic_named_kwargs above so that all the 'backend' options are in one place in the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved.

# Config says to avoid outputting argument names where
# possible.
try:
# Canonicalisation handles any error checking we might
Copy link
Member

Choose a reason for hiding this comment

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

s/Canonicalisation/compute_argument_names()/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

:returns: the SymPy representation for the Intrinsic.
'''
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this list of special routines (and if so, please add a comment)?

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 think so yes - these are the intrinsics that require a Call XXXX format, so they need to be handled differently. I think the sympy stuff doesn't work for them, but we should still be precise I think.

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 could be wrong here maybe, I don't really understand the goal of the sympy output for intrinsics that sympy doesn't recognize)

:returns: A symbol object with the same properties as this
symbol object.
:rtype: :py:class:`psyclone.psyir.symbols.IntrinsicSymbol`
Copy link
Member

Choose a reason for hiding this comment

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

Typehint instead pls (may need a from __future__ import annotations)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added


def test_sym_writer_intrinsiccall_node(fortran_reader):
'''Handle unlikely edge cases for intrinsiccall node.'''
code = """subroutine test
Copy link
Member

Choose a reason for hiding this comment

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

Please could you specify what the 'unlikely edge cases' are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

# Author A. B. G. Chalk, STFC Daresbury Lab
# -----------------------------------------------------------------------------

''' Perform py.test tests on the psygen.psyir.symbols.intrinsicsymbol file '''
Copy link
Member

Choose a reason for hiding this comment

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

This should say "....intrinsic_symbol file" and this file should be named "intrinsic_symbol_test.py".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

intrinsic = psyir.walk(IntrinsicCall)[0]
assert isinstance(intrinsic.routine.symbol, IntrinsicSymbol)
isym = intrinsic.routine.symbol
copy = isym.copy()
Copy link
Member

Choose a reason for hiding this comment

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

Pls could you check that we do have a copy, i.e.:

    assert copy is not isym
    assert isym.datatype is not copy.datatype
    etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

@LonelyCat124
Copy link
Collaborator Author

@arporter I've addressed the comments now - the only one I'm not sure about is the sympy writer one (w.r.t what the sympy writer should output for these things it doesn't support). Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants