Skip to content

Commit

Permalink
#2845 move to ordering use stmts alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
arporter committed Feb 13, 2025
1 parent d56d2c8 commit aace9a3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 28 deletions.
12 changes: 8 additions & 4 deletions src/psyclone/psyir/backend/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,11 @@ def container_node(self, node):

self._depth += 1

# Generate module imports
# Generate module imports in alpha order.
imports = ""
for symbol in node.symbol_table.containersymbols:
csymbols = node.symbol_table.containersymbols
csymbols.sort(key=lambda e: e.name)
for symbol in csymbols:
imports += self.gen_use(symbol, node.symbol_table)

# Declare the Container's data
Expand Down Expand Up @@ -1218,9 +1220,11 @@ def routine_node(self, node):
node.symbol_table.detach()
whole_routine_scope.attach(node)

# Generate module imports
# Generate module imports in alpha order.
imports = ""
for symbol in whole_routine_scope.containersymbols:
csymbols = whole_routine_scope.containersymbols
csymbols.sort(key=lambda e: e.name)
for symbol in csymbols:
imports += self.gen_use(symbol, whole_routine_scope)

# Generate declaration statements
Expand Down
2 changes: 2 additions & 0 deletions src/psyclone/psyir/symbols/datasymbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,7 @@ def replace_symbols_using(self, table):
if isinstance(dim, ArrayType.Extent):
continue
for bnd in [dim.lower, dim.upper]:
if not isinstance(bnd, nodes.Node):
continue
for ref in bnd.walk(nodes.Reference):
ref.symbol.replace_symbols_using(table)
20 changes: 1 addition & 19 deletions src/psyclone/psyir/symbols/symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,25 +716,7 @@ def _add_container_symbols_from_table(self, other_table):
:type other_table: :py:class:`psyclone.psyir.symbols.SymbolTable`
'''
# Check for symbol dependencies that are imported.
from psyclone.core.variables_access_info import VariablesAccessInfo
vai = VariablesAccessInfo()
other_table.reference_accesses(vai)
cntr_symbols = set()
if False: # ARPDBG for sig in vai.all_signatures:
# This is just looking at container symbols referenced by symbols
# in this table - the container symbols may not actually be in
# this table so we don't actually want to handle them here.
sym = other_table.lookup(sig.var_name)
if sym.is_import:
src_cntr = sym.interface.container_symbol
cntr = self.lookup(src_cntr.name, otherwise=None)
if not cntr:
cntr = src_cntr
cntr_symbols.add(src_cntr)

cntr_symbols.update(other_table.containersymbols)
for csym in cntr_symbols:
for csym in other_table.containersymbols:
if csym.name in self:
# We have a clash with another symbol in this table.
self_csym = self.lookup(csym.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,8 @@ def test_psy_init_multiple_devices_per_node(kernel_outputdir, monkeypatch):

expected = '''
subroutine psy_init()
use parallel_mod, only: get_rank
use fortcl, only: add_kernels, ocl_env_init
use parallel_mod, only: get_rank
character(len=30) kernel_names(1)
integer, save :: ocl_device_num = 1
logical, save :: initialised = .false.
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/tests/gocean1p0_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ def test_scalar_float_arg_from_module():
" IMPLICIT NONE\n"
" CONTAINS\n"
" SUBROUTINE invoke_0_bc_ssh(ssh_fld)\n"
" USE my_mod, ONLY: a_scalar\n"
" USE kernel_scalar_float, ONLY: bc_ssh_code\n"
" USE my_mod, ONLY: a_scalar\n"
" TYPE(r2d_field), intent(inout) :: ssh_fld\n"
" INTEGER j\n"
" INTEGER i\n"
Expand Down
2 changes: 1 addition & 1 deletion src/psyclone/tests/psyad/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
end module tl_foo_kernel_mod'''

EXPECTED_HARNESS_CODE = '''program adj_test
use my_mod, only : kern
use adj_my_mod, only : adj_kern
use my_mod, only : kern
integer, parameter :: array_extent = 20
real, parameter :: overall_tolerance = 1500.0
real :: inner1
Expand Down
1 change: 1 addition & 0 deletions src/psyclone/tests/psyad/tl2ad_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ def test_generate_harness_constant_kind(fortran_reader, fortran_writer):
test_psyir = generate_adjoint_test(tl_psyir, ad_psyir, ["field"])
harness = fortran_writer(test_psyir)
assert (" use adj_my_mod, only : adj_kern\n"
" use my_mod, only : kern\n"
" integer, parameter :: r_def = 8\n" in harness)
assert (" real(kind=r_def), dimension(npts) :: field\n"
" real(kind=r_def), dimension(npts) :: field_input" in harness)
Expand Down
4 changes: 2 additions & 2 deletions src/psyclone/tests/psyir/transformations/inline_trans_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,8 @@ def test_apply_callsite_rename(fortran_reader, fortran_writer):
inline_trans.apply(call)
output = fortran_writer(psyir)
assert (" subroutine run_it()\n"
" use kinds_mod, only : i_def, r_def\n"
" use a_mod, only : a_clash\n"
" use kinds_mod, only : i_def, r_def\n"
" integer :: i\n"
" integer :: a_clash_1\n\n"
" a_clash_1 = 2\n"
Expand Down Expand Up @@ -1262,8 +1262,8 @@ def test_apply_callsite_rename_container(fortran_reader, fortran_writer):
inline_trans.apply(call)
output = fortran_writer(psyir)
assert (" subroutine run_it()\n"
" use kinds_mod, only : i_def, r_def\n"
" use a_mod, only : a_clash\n"
" use kinds_mod, only : i_def, r_def\n"
" integer :: i\n"
" integer :: a_mod_1\n\n"
" a_mod_1 = 2\n"
Expand Down

0 comments on commit aace9a3

Please sign in to comment.