stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
102 stars 24 forks source link

Add support for Calls to StructureType members #2586

Open schreiberx opened 1 month ago

schreiberx commented 1 month ago

It seems that Fortran functions are not supported by PsyIR.

Please see test_a.zip which creates CodeBlocks for fparser.two.Fortran2003.Function_Reference fparser.two.Fortran2003.Function_Reference fparser.two.Fortran2003.Structure_Constructor

This output has been created with branch https://github.com/stfc/PSyclone/compare/2577_support_pointer_assignments

This might be depending on #2577.

sergisiso commented 1 month ago

I tried your code with #2583 PR and I get this: image

Is this what do you see too?

If that's the case, the only parts not supported are the rhs of:

dummy4 => this%foo_function_returning_pointer_oo_style()
varReal = this%foo_function_returning_real_oo_style()
varReal = foo_function_returning_real()
sergisiso commented 1 month ago

@arporter for the 3rd one it's fparser that gets it wrong

function foo_function_returning_real()
   real :: foo_function_returning_real
end function
...
varReal = foo_function_returning_real()

the last line is: CodeBlock[[<class 'fparser.two.Fortran2003.Structure_Constructor'>]] Could fparser use its symbol table to identify the right node?

arporter commented 1 month ago

Potentially, yes. This is probably issue https://github.com/stfc/fparser/issues/255 in fparser.

schreiberx commented 1 month ago

I tried your code with #2583 PR and I get this: image

Is this what do you see too?

If that's the case, the only parts not supported are the rhs of:

dummy4 => this%foo_function_returning_pointer_oo_style()
varReal = this%foo_function_returning_real_oo_style()
varReal = foo_function_returning_real()

Yes, these 3 red CodeBlocks are what I'm getting.

sergisiso commented 2 weeks ago

I will focus this issue to add support for the structure/derive type calls:

dummy4 => this%field%foo_function_returning_pointer_oo_style(arg1, arg2)
varReal = this%array_field(3)%foo_function_returning_real_oo_style(arg1, arg2)

which need to be converted to a PSyIR Call:

Call
   children[0] "routine" : StructureReference "this%array_field(3)%foo_function_returning_real_oo_style"
   children[1] "arguments[0]" Reference "arg1"
   children[2] "arguments[1]" Reference "arg2"

The 3rd statement from my previous comment, which we need to disambiguate between a Type constructor vs a function call with no arguments will be left for another issue.