ecmwf-ifs / loki

Freely programmable source-to-source translation for Fortran

Home Page:https://sites.ecmwf.int/docs/loki/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when derived_types.py passes arguments with None as intent to arguement setter in idem transformation on acraneb2.

rolfhm opened this issue · comments

commented

Loki crashes when trying to set arguements in derived_types.py that appear to haev None as intent.
In the argument setter on line 386

assert arg.type.intent is not None

called by derived_types.py on line 322
routine.arguments = [a for arg in routine.arguments for a in arguments_map.get(arg, [arg])]

File "/home/rolfhm/install/loki/loki_env/bin/loki-transform.py", line 11, in
sys.exit(cli())
File "/home/rolfhm/install/loki/loki_env/lib/python3.10/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/home/rolfhm/install/loki/loki_env/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/rolfhm/install/loki/loki_env/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/rolfhm/install/loki/loki_env/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/rolfhm/install/loki/loki_env/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/rolfhm/progs/loki/scripts/loki_transform.py", line 195, in convert
scheduler.process(transformation=DerivedTypeArgumentsTransformation())
File "/home/rolfhm/progs/loki/loki/bulk/scheduler.py", line 642, in process
transformation.apply(
File "/home/rolfhm/progs/loki/loki/transform/transformation.py", line 108, in apply
self.apply_file(source, **kwargs)
File "/home/rolfhm/progs/loki/loki/transform/transformation.py", line 145, in apply_file
self.apply_subroutine(routine, **kwargs)
File "/home/rolfhm/progs/loki/loki/transform/transformation.py", line 172, in apply_subroutine
self.transform_subroutine(subroutine, **kwargs)
File "/home/rolfhm/progs/loki/transformations/transformations/derived_types.py", line 95, in transform_subroutine
trafo_data = self.expand_derived_args_kernel(routine)
File "/home/rolfhm/progs/loki/transformations/transformations/derived_types.py", line 322, in expand_derived_args_kernel
routine.arguments = [a for arg in routine.arguments for a in arguments_map.get(arg, [arg])]
File "", line 5, in setattr
File "/home/rolfhm/progs/loki/loki/subroutine.py", line 386, in arguments
assert arg.type.intent is not None

I'm not sure what the double loops on line 322 in derived_types.py is supposed to do. The crash seems to happen after reading in the source files for the idem transformation on acraneb2 https://github.com/rolfhm/acraneb2 .

Thanks! Does the code you are reading in use dummy arguments without intent specified?

commented

No, all dummies have intent as far as I can tell.

Note that this is Fortran code with contained subroutines. However, I did merge my branch (https://github.com/rolfhm/loki/tree/sbrm-experimental-body-insertion) with main and got the same error.

commented

I tried with Michael's inline branch, but it hits the same error.

I did a bit of digging and the crash happens when processing acraneb2.
https://github.com/rolfhm/acraneb2/blob/master/acraneb2/src/acraneb2.F90

This print just before line 322 in derived_types.py

        for arg in routine.arguments:
            print('arg:', arg, arg)
            for a in arguments_map.get(arg, [arg]):
                print('a:', a, a.type.intent)
            print()

produced, among other things,

arg: YDML_PHY_MF YDML_PHY_MF
a: YDML_PHY_MF_YRPHY inout
a: YDML_PHY_MF_YRPHY_LRAYLU None
a: YDML_PHY_MF_YRPHY_LRAYPL None
a: YDML_PHY_MF_YRPHY_LRNUEXP None
a: YDML_PHY_MF_YRPHY_LRNUMX None
a: YDML_PHY_MF_YRPHY_LRPROX None
a: YDML_PHY_MF_YRPHY_LRTPP None
a: YDML_PHY_MF_YRPHY_LRTRUEBBC None
a: YDML_PHY_MF_YRPHY_LRTRUEDIR None
a: YDML_PHY_MF_YRPHY_NPHYREP None
a: YDML_PHY_MF_YRPHY_NRAUTOEV None
a: YDML_PHY_MF_YRPHY_NSORAYFR None
a: YDML_PHY_MF_YRPHY_NTHRAYFR None
a: YDML_PHY_MF_YRPHY2_TSPHY None
a: YDML_PHY_MF_YRPHY3 inout
a: YDML_PHY_MF_YRPHY3_BSFSA None
a: YDML_PHY_MF_YRPHY3_BSFTA None
a: YDML_PHY_MF_YRPHY3_EARRT None
a: YDML_PHY_MF_YRPHY3_EOASA None
a: YDML_PHY_MF_YRPHY3_EOATA None
a: YDML_PHY_MF_YRPHY3_EODSA None
a: YDML_PHY_MF_YRPHY3_EODTA None
a: YDML_PHY_MF_YRPHY3_FSM_AA None
a: YDML_PHY_MF_YRPHY3_FSM_BB None
a: YDML_PHY_MF_YRPHY3_RII0 None
a: YDML_PHY_MF_YRPHY3_RMIXD None
a: YDML_PHY_MF_YRPHY3_RMIXP0 None
a: YDML_PHY_MF_YRPHY3_RTL None
a: YDML_PHY_MF_YRPHY3_USAA None
a: YDML_PHY_MF_YRPHY3_USBA None

Loki is able to add the correct intent to YRPHY and YRPHY3, but not to YRPHY2 and all the components of the contained subroutines. In the subroutine, YRPHY and YRPHY3 are accessed directly, but all the other listed things are only accessed through associate statements.

It fails in both the idem and the scc transformation.

Can you create a minimal failing example please? We'll try to fix this asap.

commented

Okay, I made a branch of the minimal example repo that fails.
https://github.com/rolfhm/minimal_test/tree/associate-bug

It looks like it's the nested derived types, not associate that causes the crash.

The print above only printed the object itself, not its components when the derived types were not nested. Is that correct behaviour?

Ok, many thanks @rolfhm for providing the MFE; this really helped narrow it down quickly. So, it turns out that the symptom and the actual bug were quite far removed. We were effectively dropping the intent(in) attribute when updating DEFERRED type info, which then causes the argument updater to complain. PR #138 should fix this now, but please verify and confirm this.