From e1c8065eedad4c30d1a06fc223f990d01f1760ae Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 16 Dec 2024 15:21:03 +0000 Subject: [PATCH 1/2] Inline: When inlining stmt funcs we also skip explicit intrinsics This caused issue when the following lines attempt to touch the non-existent procedure definition. --- loki/transformations/inline/mapper.py | 3 ++- loki/transformations/inline/tests/test_functions.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/loki/transformations/inline/mapper.py b/loki/transformations/inline/mapper.py index 232e38ee6..7803f11fa 100644 --- a/loki/transformations/inline/mapper.py +++ b/loki/transformations/inline/mapper.py @@ -58,7 +58,8 @@ def map_procedure_symbol(self, expr, *args, **kwargs): return expr.clone(parent=parent) def map_inline_call(self, expr, *args, **kwargs): - if expr.procedure_type is None or expr.procedure_type is BasicType.DEFERRED: + if expr.procedure_type is None or expr.procedure_type is BasicType.DEFERRED \ + or expr.procedure_type.is_intrinsic: # Unkonw inline call, potentially an intrinsic # We still need to recurse and ensure re-scoping return super().map_inline_call(expr, *args, **kwargs) diff --git a/loki/transformations/inline/tests/test_functions.py b/loki/transformations/inline/tests/test_functions.py index 9711f9130..502ad5795 100644 --- a/loki/transformations/inline/tests/test_functions.py +++ b/loki/transformations/inline/tests/test_functions.py @@ -253,7 +253,7 @@ def test_inline_statement_functions(frontend, stmt_decls): real :: FOEDELTA FOEDELTA ( PTARE ) = PTARE + 1.0 real :: FOEEW - FOEEW ( PTARE ) = PTARE + FOEDELTA(PTARE) + FOEEW ( PTARE ) = PTARE + FOEDELTA(PTARE) + EXP(PTARE) """.strip() fcode = f""" @@ -280,10 +280,10 @@ def test_inline_statement_functions(frontend, stmt_decls): assert not FindNodes(ir.StatementFunction).visit(routine.spec) if stmt_decls: - assert not FindInlineCalls().visit(routine.body) + assert len(FindInlineCalls().visit(routine.body)) == 1 assignments = FindNodes(ir.Assignment).visit(routine.body) assert assignments[0].lhs == 'ret' - assert assignments[0].rhs == "arr + arr + 1.0" + assert assignments[0].rhs == "arr + arr + 1.0 + exp(arr)" assert assignments[1].lhs == 'ret2' assert assignments[1].rhs == "3.0 + 1.0" else: From 53394c74f4a228bc0336583748f8ab70d5efb79c Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Wed, 18 Dec 2024 14:50:13 +0100 Subject: [PATCH 2/2] Inline: Better way to skip intrinsic function calls in stmt func inliner Co-authored-by: Balthasar Reuter <6384870+reuterbal@users.noreply.github.com> --- loki/transformations/inline/mapper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/loki/transformations/inline/mapper.py b/loki/transformations/inline/mapper.py index 7803f11fa..1ea0e0f8c 100644 --- a/loki/transformations/inline/mapper.py +++ b/loki/transformations/inline/mapper.py @@ -58,8 +58,7 @@ def map_procedure_symbol(self, expr, *args, **kwargs): return expr.clone(parent=parent) def map_inline_call(self, expr, *args, **kwargs): - if expr.procedure_type is None or expr.procedure_type is BasicType.DEFERRED \ - or expr.procedure_type.is_intrinsic: + if expr.procedure_type in (None, BasicType.DEFERRED) or expr.procedure_type.is_intrinsic: # Unkonw inline call, potentially an intrinsic # We still need to recurse and ensure re-scoping return super().map_inline_call(expr, *args, **kwargs)