ecmwf-ifs / loki

Freely programmable source-to-source translation for Fortran
https://sites.ecmwf.int/docs/loki/
Apache License 2.0
22 stars 11 forks source link

Proposal: resolution of concrete procedures #339

Open quepas opened 1 week ago

quepas commented 1 week ago

This is only a proposal. A draft implementation has been prepared here: #340 .

One of the useful information missing in loki is the information about the real function being called when a generic interface is used:

...
interface swap
        module procedure swap_int, swap_real
end interface swap
...

Then, called somewhere else:

real :: r1, r2
...
! Loki knows it is a "generic" procedure, but that's all 
call swap(r1, r2)

Currently, in the CallStmt, loki points to a dtype with a procedure of DEFERED type. This PR adds capability of figuring out the concrete function really called (in some easy cases). The resolution mechanism tries to match parameters of each concrete function with arguments passed to the generic function call. Of course, the whole resolution is conservative (as everything in compilers! :D) and additional information is added only when everything matches.

The matching is based on the ExpressionDimensionsMapper and a new ExpressionTypeMapper which takes a piece of the AST and tries to deduce it's final type. This mapper is not very capable, it works well on typed variables, literals and some easy expressions (with sum op).

We weren't sure if we should populate the procedure with the concrete routine in the ProcedureType, so we have added an additional field concrete_procedure which points to the concrete procedure when a generic is used, and the normal procedure otherwise.

I am looking forward to your comments and the discussion of this feature.

Things to do: