Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator.py exception message bug fix (closes #2390) #2391

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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