From 889626c1eb9378783700f194ce1110ffb4cbfbba Mon Sep 17 00:00:00 2001 From: Rolf Heilemann Myhre Date: Fri, 13 Oct 2023 15:16:31 +0200 Subject: [PATCH 1/3] transform body fix --- loki/transform/transform_inline.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/loki/transform/transform_inline.py b/loki/transform/transform_inline.py index 91f41b9bb..f12dc7613 100644 --- a/loki/transform/transform_inline.py +++ b/loki/transform/transform_inline.py @@ -239,7 +239,12 @@ def _map_unbound_dims(var, val): {v: v.clone(name=f'{member.name}_{v.name}') for v in duplicate_locals} ) member.spec = shadow_mapper.visit(member.spec) - member.body = shadow_mapper.visit(member.body) + + var_map = {} + for v in FindVariables(unique=False).visit(member.body): + if v.name in [dl.name for dl in duplicate_locals]: + var_map[v] = v.clone(name=f'{member.name}_{v.name}') + member.body = SubstituteExpressions(var_map).visit(member.body) # Get local variable declarations and hoist them decls = FindNodes(VariableDeclaration).visit(member.spec) From 78464c051f30c9045b842eeacae4bc858e9469d6 Mon Sep 17 00:00:00 2001 From: Rolf Heilemann Myhre Date: Mon, 16 Oct 2023 12:59:05 +0200 Subject: [PATCH 2/3] Fixed wrong test --- tests/test_transform_inline.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_transform_inline.py b/tests/test_transform_inline.py index b5ac37bd0..30dcd683e 100644 --- a/tests/test_transform_inline.py +++ b/tests/test_transform_inline.py @@ -473,12 +473,11 @@ def test_inline_member_routines_variable_shadowing(frontend): fcode = """ subroutine outer() real :: x = 3 ! 'x' is real in outer. - real :: tmp = 0 real :: y y = 1.0 - call inner(tmp, y=y) - x = x + tmp + call inner(y) + x = x + y contains subroutine inner(y) @@ -515,7 +514,7 @@ def test_inline_member_routines_variable_shadowing(frontend): # Check inner 'y' was substituted, not renamed! assign = FindNodes(Assignment).visit(routine.body) assert routine.variable_map['y'] == 'y' - assert assign[2].lhs == 'y' and assign[2].rhs == 'y + sum(x)' + assert assign[2].lhs == 'y' and assign[2].rhs == 'y + sum(inner_x)' @pytest.mark.parametrize('frontend', available_frontends()) From 05956e8496904aa7f7e1c566cd773811f9063c3f Mon Sep 17 00:00:00 2001 From: rolfhm <90390629+rolfhm@users.noreply.github.com> Date: Tue, 17 Oct 2023 13:33:07 +0200 Subject: [PATCH 3/3] Use name.lower to avoid case errors Co-authored-by: Balthasar Reuter <6384870+reuterbal@users.noreply.github.com> --- loki/transform/transform_inline.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loki/transform/transform_inline.py b/loki/transform/transform_inline.py index f12dc7613..3f09e6ed0 100644 --- a/loki/transform/transform_inline.py +++ b/loki/transform/transform_inline.py @@ -241,8 +241,9 @@ def _map_unbound_dims(var, val): member.spec = shadow_mapper.visit(member.spec) var_map = {} + duplicate_locals_names = {dl.name.lower() for dl in duplicate_locals} for v in FindVariables(unique=False).visit(member.body): - if v.name in [dl.name for dl in duplicate_locals]: + if v.name.lower() in duplicate_locals_names: var_map[v] = v.clone(name=f'{member.name}_{v.name}') member.body = SubstituteExpressions(var_map).visit(member.body)