Skip to content

New transformation: SanitiseUnusedRoutineTransformation.#693

Open
MichaelSt98 wants to merge 1 commit into
mainfrom
nams-sk-sanitise-unused-routines
Open

New transformation: SanitiseUnusedRoutineTransformation.#693
MichaelSt98 wants to merge 1 commit into
mainfrom
nams-sk-sanitise-unused-routines

Conversation

@MichaelSt98
Copy link
Copy Markdown
Collaborator

Introduce a transformation that replaces the executable body of configured routines with a configurable stub while rewriting kept array declarations to fully deferred shape. This allows routines that are no longer called but must still compile to be safely reduced to minimal shells.
The stub_kind parameter controls the replacement body: 'error_stop' (default) inserts a fail-loud ERROR STOP statement so accidental calls are caught at runtime, while 'empty' produces a silent no-op. Routine matching supports both plain names and fully qualified module#routine scheduler item names.
Declarations with intent, pointer, or allocatable attributes are preserved with deferred shape; all other local array declarations are removed. Scalar declarations are kept unchanged.

Description

This pull request introduces the new SanitiseUnusedRoutineTransformation transformation to the codebase, which allows configured routines that are no longer used to be sanitized for compilation. The transformation rewrites array declarations to use deferred shapes, removes unnecessary local arrays, and replaces the routine body with either an error-stop or an empty stub, depending on configuration. Comprehensive tests are added to verify its behavior.

New transformation for sanitizing unused routines:

  • Added the SanitiseUnusedRoutineTransformation class in loki/transformations/sanitise/unused_routines.py, which supports rewriting array declarations to deferred shapes, removing unused local arrays, and replacing the body with a configurable stub (error_stop or empty).
  • Exposed the new transformation in the loki.transformations.sanitise package by importing it in __init__.py.

Testing and validation:

  • Added test_unused_routines.py with comprehensive tests for the new transformation, covering deferred shape rewriting, qualified routine name matching, stub kind selection, non-matching routines, and error handling for invalid stub kinds.

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

Introduce a transformation that replaces the executable body of
configured routines with a configurable stub while rewriting kept array
declarations to fully deferred shape. This allows routines that are no
longer called but must still compile to be safely reduced to minimal
shells.
The stub_kind parameter controls the replacement body: 'error_stop'
(default) inserts a fail-loud ERROR STOP statement so accidental calls
are caught at runtime, while 'empty' produces a silent no-op. Routine
matching supports both plain names and fully qualified module#routine
scheduler item names.
Declarations with intent, pointer, or allocatable attributes are
preserved with deferred shape; all other local array declarations are
removed. Scalar declarations are kept unchanged.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/693/index.html

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 97.47899% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.21%. Comparing base (bfad794) to head (9b8c12b).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
loki/transformations/sanitise/unused_routines.py 94.11% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #693      +/-   ##
==========================================
+ Coverage   94.19%   94.21%   +0.01%     
==========================================
  Files         288      290       +2     
  Lines       47496    47744     +248     
==========================================
+ Hits        44741    44983     +242     
- Misses       2755     2761       +6     
Flag Coverage Δ
lint_rules 96.40% <ø> (ø)
loki 94.19% <97.47%> (+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