Skip to content

Improve ASSOCIATE handling#664

Open
marsdeno wants to merge 1 commit into
ecmwf-ifs:mainfrom
marsdeno:daom-associate
Open

Improve ASSOCIATE handling#664
marsdeno wants to merge 1 commit into
ecmwf-ifs:mainfrom
marsdeno:daom-associate

Conversation

@marsdeno
Copy link
Copy Markdown
Contributor

@marsdeno marsdeno commented Apr 1, 2026

The IFS fortran code base makes heavy, structural use of ASSOCIATE statements.
In many subroutines, nested ASSOCIATE statements can be found, and some cases of deep nests exist.
This PR improves handling of ASSOCIATE removal, in particular by correctly resolving associated variables in calls to intrinsic functions, such as PRINT and WRITE.
Given the prevalence of ASSOCIATE usage, this PR also provides an easy-to-use option for resolving associates in a single file. This option can be invoked as follows : loki-transform.py convert --source nested_example.F90 --ass-wipe

An example of this is provided below.

cat nested_example.F90

subroutine nested_example()
      implicit none
      type test_type
              real :: realval
      end type
      type nasty_nested_type
              type(test_type) :: this_test_type
      end type
      type(test_type) :: my_test_type
      type(nasty_nested_type) :: my_nasty_type
      real :: local_real
      associate( assoc_real => my_test_type%realval, associated_test_type => my_nasty_type%this_test_type )
      associate( nested_real => associated_test_type%realval )
      local_real = 3.14
      assoc_real = 3.14159
      nested_real = 3.141592654
      local_real = nested_real
      print *,'local and associated reals : ',local_real, assoc_real, nested_real
      write(*,*) 'testing a write as well', nested_real
      end associate
      end associate
end subroutine nested_example

The result of launching loki-transform.py convert --source nested_example.F90 --ass-wipe
is a correctly modified nested_example.F90, along with the following output:

[Loki] Removing ASSOCIATE blocks from source files
  [DONE] nested_toto.F90
[Loki] ASS-WIPE request completed

 * handle associations in intrinsic calls
 * add a direct command-line demonstration of in-place ASSOCIATE removal
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 94.97207% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.39%. Comparing base (b711b95) to head (cc3e50b).
⚠️ Report is 103 commits behind head on main.

Files with missing lines Patch % Lines
loki/transformations/sanitise/associates.py 88.46% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #664      +/-   ##
==========================================
- Coverage   96.39%   96.39%   -0.01%     
==========================================
  Files         266      266              
  Lines       46418    46595     +177     
==========================================
+ Hits        44745    44915     +170     
- Misses       1673     1680       +7     
Flag Coverage Δ
lint_rules 96.40% <ø> (ø)
loki 96.39% <94.97%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant