Skip to content

Commit

Permalink
Merge pull request #2391 from stfc/2390_generator_message_bug
Browse files Browse the repository at this point in the history
generator.py exception message bug fix (closes #2390)
  • Loading branch information
arporter authored Nov 13, 2023
2 parents 74bcfbf + b72f36e commit f6c635b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
25) PR #2100 for #2091. Renames DynKern to LFRicKern and moves its
implementation to domain/lfric.

26) PR #2391 for #2390. Fix bug in generator.py error message.

release 2.4.0 29th of September 2023

1) PR #1758 for #1741. Splits the PSyData read functionality into a
Expand Down
Binary file modified psyclone.pdf
Binary file not shown.
9 changes: 4 additions & 5 deletions src/psyclone/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ def generate(filename, api="", kernel_paths=None, script_name=None,
container_symbols += [
symbol.name for symbol in st_ref.containersymbols]
message = (
f"Kernel functor '{kern.symbol.name}' in routine "
f"'{kern.scope.name}' from algorithm file "
f"'{filename}' must be named in a use "
f"statement (found {container_symbols})")
f"Kernel functor '{kern.name}' in routine "
f"'{kern.ancestor(Routine).name}' from algorithm file "
f"'{filename}' must be named in a use statement "
f"(found {container_symbols})")
if api == "dynamo0.3":
message += (
f" or be a recognised built-in (one of "
Expand Down Expand Up @@ -369,7 +369,6 @@ def generate(filename, api="", kernel_paths=None, script_name=None,
kernel_psyir,
options={"metadata_name": kern.symbol.name})

# kernels[id(invoke)][id(kern)] = kernel_psyir
kernels[id(invoke)][id(kern)] = kernel_psyir

# Transform 'invoke' calls into calls to PSy-layer subroutines
Expand Down
36 changes: 19 additions & 17 deletions src/psyclone/tests/generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,14 +1279,17 @@ def test_no_invokes_lfric_new(monkeypatch):
"empty PSy code" in str(info.value))


def test_generate_unknown_container_lfric(tmpdir, monkeypatch):
@pytest.mark.parametrize("invoke", ["call invoke", "if (.true.) call invoke"])
def test_generate_unknown_container_lfric(invoke, tmpdir, monkeypatch):
'''Test that a GenerationError exception in the generate function is
raised for the LFRic DSL if one of the functors is not explicitly
declared. This can happen in LFRic algorithm code as it is never
compiled. The exception is only raised with the new PSyIR approach
to modify the algorithm layer which is currently in development so
is protected by a switch. This switch is turned on in this test by
monkeypatching.
monkeypatching. Test when the functor is at different levels of
PSyIR hierarchy to ensure that the name of the parent routine is
always found.
At the moment this exception is only raised if the functor is
declared in a different subroutine or function, as the original
Expand All @@ -1296,21 +1299,20 @@ def test_generate_unknown_container_lfric(tmpdir, monkeypatch):
'''
monkeypatch.setattr(generator, "LFRIC_TESTING", True)
code = (
"module some_kernel_mod\n"
"use module_mod, only : module_type\n"
"contains\n"
"subroutine dummy_kernel()\n"
" use testkern_mod, only: testkern_type\n"
"end subroutine dummy_kernel\n"
"subroutine some_kernel()\n"
" use constants_mod, only: r_def\n"
" use field_mod, only : field_type\n"
" type(field_type) :: field1, field2, field3, field4\n"
" real(kind=r_def) :: scalar\n"
" call invoke(testkern_type(scalar, field1, field2, field3, "
"field4))\n"
"end subroutine some_kernel\n"
"end module some_kernel_mod\n")
f"module some_kernel_mod\n"
f"use module_mod, only : module_type\n"
f"contains\n"
f"subroutine dummy_kernel()\n"
f" use testkern_mod, only: testkern_type\n"
f"end subroutine dummy_kernel\n"
f"subroutine some_kernel()\n"
f" use constants_mod, only: r_def\n"
f" use field_mod, only : field_type\n"
f" type(field_type) :: field1, field2, field3, field4\n"
f" real(kind=r_def) :: scalar\n"
f" {invoke}(testkern_type(scalar, field1, field2, field3, field4))\n"
f"end subroutine some_kernel\n"
f"end module some_kernel_mod\n")
alg_filename = str(tmpdir.join("alg.f90"))
with open(alg_filename, "w", encoding='utf-8') as my_file:
my_file.write(code)
Expand Down

0 comments on commit f6c635b

Please sign in to comment.