ecmwf-ifs / loki

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

BlockIndex transformations fail on non-enriched non-targets calls #336

Closed reuterbal closed 2 months ago

reuterbal commented 3 months ago

Even though the block index transformations only process calls to routines included in the targets list, it builds lists using inter-procedural annotations where this filtering is missing, and therefore fails processing. This can be reproduced by amending the tests like this:

diff --git a/loki/transformations/tests/test_block_index_inject.py b/loki/transformations/tests/test_block_index_inject.py
index 26ded84a..ff932df0 100644
--- a/loki/transformations/tests/test_block_index_inject.py
+++ b/loki/transformations/tests/test_block_index_inject.py
@@ -37,7 +37,7 @@ def fixture_config():
             'expand': True,
             'strict': True,
             'enable_imports': True,
-            'disable': ['*%init', '*%final']
+            'disable': ['*%init', '*%final', 'abor1'],
         },
     }

@@ -157,7 +157,8 @@ subroutine kernel(nlon, nlev, {'start, end, ibl' if request.param else 'bnds'},
    {'use dims_type_mod, only: dims_type' if not request.param else ''}
    implicit none

-   #include "another_kernel.intfb.h"
+#include "another_kernel.intfb.h"
+#include "abor1.intfb.h"

    integer, intent(in) :: nlon, nlev
    type(field_variables), intent(inout) :: ydvars
@@ -168,6 +169,8 @@ subroutine kernel(nlon, nlev, {'start, end, ibl' if request.param else 'bnds'},
    integer :: jl, jfld
    {'associate(start=>bnds%start, end=>bnds%end, ibl=>bnds%kbl)' if not request.param else ''}

+   if(nlon < 0) call abor1('kernel')
+
    ydvars%var%p_field(:,:) = 0. !... this should only get the block-index
    ydvars%var%p_field(:,:,ibl) = 0. !... this should be untouched

failing with the following backtrace:

loki/transformations/tests/test_block_index_inject.py:233:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
loki/batch/scheduler.py:398: in process
    self.process_transformation(transformation=transformation)
loki/batch/scheduler.py:494: in process_transformation
    transformation.apply(
loki/batch/transformation.py:185: in apply
    self.apply_subroutine(source, **kwargs)
loki/batch/transformation.py:291: in apply_subroutine
    self.transform_subroutine(subroutine, **kwargs)
loki/transformations/block_index_transformations.py:342: in transform_subroutine
    self.process_kernel(routine, targets, exclude_arrays)
loki/transformations/block_index_transformations.py:416: in process_kernel
    routine.body = self.process_body(routine.body, block_index, targets, exclude_arrays)
loki/transformations/block_index_transformations.py:375: in process_body
    call_args = [a for call in FindNodes(ir.CallStatement).visit(body) for a in call.arg_map.values()]
loki/transformations/block_index_transformations.py:375: in <listcomp>
    call_args = [a for call in FindNodes(ir.CallStatement).visit(body) for a in call.arg_map.values()]
loki/ir/nodes.py:942: in arg_map
    return dict(self.arg_iter())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = Call:: abor1

    def arg_iter(self):
        """
        Iterator that maps argument definitions in the target :any:`Subroutine`
        to arguments and keyword arguments in the call.

        Returns
        -------
        iterator
            An iterator that traverses the mapping ``(arg name, call arg)`` for
            all positional and then keyword arguments.
        """
        routine = self.routine
>       assert routine is not BasicType.DEFERRED
E       AssertionError

loki/ir/nodes.py:930: AssertionError