Skip to content

(Closes #2612) add support for length and precision attributes in character type#3377

Open
arporter wants to merge 30 commits intomasterfrom
2612_add_len_to_scalartype
Open

(Closes #2612) add support for length and precision attributes in character type#3377
arporter wants to merge 30 commits intomasterfrom
2612_add_len_to_scalartype

Conversation

@arporter
Copy link
Copy Markdown
Member

No description provided.

@arporter arporter marked this pull request as draft March 16, 2026 19:37
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.96%. Comparing base (7b6d98a) to head (5508155).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #3377    +/-   ##
========================================
  Coverage   99.95%   99.96%            
========================================
  Files         387      388     +1     
  Lines       54317    54485   +168     
========================================
+ Hits        54295    54465   +170     
+ Misses         22       20     -2     

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

@arporter
Copy link
Copy Markdown
Member Author

This is a little bigger than I'd have liked because, in quite a few tests, we use character as a "type that we don't support". I've kicked this can down the road a bit by switching to complex but we will also want to add support for that soon. Perhaps at that point there will be no basic type that we don't support?

@arporter arporter added enhancement PSyIR Core PSyIR functionality labels Mar 23, 2026
@arporter arporter marked this pull request as ready for review March 23, 2026 17:08
@arporter
Copy link
Copy Markdown
Member Author

Something goes very wrong in the NEMO ITs:
image
I don't have a test with len=some_intrinsic(arg)...

@arporter
Copy link
Copy Markdown
Member Author

(Pdb) print(sym)
cd_mpp: DataSymbol<UnsupportedFortranType('CHARACTER(LEN = 3), OPTIONAL, INTENT(IN) :: cd_mpp'), Argument(Access.UNKNOWN)>

@arporter
Copy link
Copy Markdown
Member Author

NEMO v4 IT still fails:

psyclone/psyir/transformations/acc_kernels_trans.py", line 274, in validate
3198
    if sym.datatype.intrinsic != ScalarType.Intrinsic.CHARACTER:
3199
       ^^^^^^^^^^^^^^^^^^^^^^
psyclone/psyir/symbols/datatypes.py", line 325, in intrinsic
    return self.partial_datatype.intrinsic
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DataTypeSymbol' object has no attribute 'intrinsic'

@arporter
Copy link
Copy Markdown
Member Author

I declare this one ready for review too. I haven't yet had a green run on the NEMOv4 integration tests but I've tried it manually and I think it's OK. We can run the ITs once Aidan's benchmarking is done.

@arporter arporter changed the title (Closes #2612) add support for length attribute in character type (Closes #2612) add support for length and precision attributes in character type Mar 31, 2026
@sergisiso sergisiso deployed to integration April 9, 2026 11:23 — with GitHub Actions Active
Copy link
Copy Markdown
Collaborator

@sergisiso sergisiso left a comment

Choose a reason for hiding this comment

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

Thanks @arporter it's good to see additional symbols have a proper datatype. See mostly minor comments but the NEMOv4 integration test has also failed.

Comment on lines +102 to +103
|Initialisation |Explicit | Implicit loops, |
|expressions |initialisation | array constructors |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I suppose by supported we mean that it produces an ArrayType datasymbol with the initialisation expression being a CodeBlock?

I am ok with it if that's the case, but to be sure they work, can you add an example of each in src/psyclone/tests/psyir/frontend/fparser2_test.py, in test_process_array_declarations or test_declarations_with_initialisations (unless it is already tested somewhere else, but I couldn't find it)

Comment on lines +184 to +186
# TODO #3240 - sometimes we have an ArrayReference that is
# actually a character sub-string.
base_type = self.symbol.datatype.copy()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add a test in src/psyclone/tests/psyir/nodes/array_reference_test.py::test_array_datatype


def debug_string(self) -> str:
''':returns: the name of the Enum item.'''
return self.name
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pylint says "Instance of 'ScalarTypeAttribute' has no 'name' member"

Can we make ScalarTypeAttribute inherit from Enum, instead of each subclass having multiple-inheritance?

Comment on lines +404 to +406
class CharLengthParameter(ScalarTypeAttribute, Enum):
ASTERISK = 1
COLON = 2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pylint wants a docstring.

Also, can we give the elements a more semantic name since this is PSyIR. From the fortran standard I see:

Image So maybe COLON->DEFERRED and ASTERISK->ASSUMED ?

from psyclone.psyir.nodes.datanode import DataNode
if isinstance(value, ScalarType.CharLengthParameter):
self._length = value
elif isinstance(value, int) and not isinstance(value, bool):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the and not isinstance(value, bool) necessary?

Comment on lines +524 to +525
f"The length property of a character ScalarType must be an "
f"int, ScalarType.CharLengthParameter "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"a non-negative int ..."

Comment on lines +454 to +456
type(a_type) :: dtype
type(d_type), pointer :: dtype_ptr
type(a_type), dimension(10) :: type_list
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dtype_ptr and type_list are not used in the assignments below, are they needed? or are there assignments missing?

subroutine test()
integer :: a
a = unsupported_type_symbol()
a = INT(REAL(unsupported_type_symbol()))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why the INT(REAL(?

end subroutine test'''
psyir = fortran_reader.psyir_from_source(code)

trans = ArrayAssignment2LoopsTrans()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is a TODO to 2612 in this file line 631.

Also in src/psyclone/psyir/nodes/intrinsic_call.py
794: # TODO 2612 This may be more complex if we support character len
813: # TODO 2612 This may be more complex if we support character len

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants