diff --git a/src/psyclone/domain/common/transformations/kernel_module_inline_trans.py b/src/psyclone/domain/common/transformations/kernel_module_inline_trans.py index 22265d22db..0886a8bc0e 100644 --- a/src/psyclone/domain/common/transformations/kernel_module_inline_trans.py +++ b/src/psyclone/domain/common/transformations/kernel_module_inline_trans.py @@ -48,7 +48,7 @@ from psyclone.psyGen import Transformation, CodedKern from psyclone.psyir.transformations import TransformationError from psyclone.psyir.symbols import ( - ContainerSymbol, DataSymbol, DataTypeSymbol, DefaultModuleInterface, + ContainerSymbol, DataSymbol, DataTypeSymbol, IntrinsicSymbol, RoutineSymbol, Symbol) from psyclone.psyir.nodes import ( Container, Reference, Routine, ScopingNode, @@ -153,8 +153,6 @@ def validate(self, node, options=None): f"'{kname}' due to: {error}" ) from error - if not isinstance(kernels, list): - import pdb; pdb.set_trace() # TODO ARPDBG - need to examine every kernel implementation, not just # the first one. kernel_schedule = kernels[0] @@ -259,13 +257,14 @@ def _prepare_code_to_inline(routines_to_inline): for name in cblock.get_symbol_names(): all_symbols.add(cblock.scope.symbol_table.lookup(name)) - # Then decide which symbols need to be brought inside the subroutine + # Decide which symbols need to be brought inside the subroutine symbols_to_bring_in = set() for symbol in all_symbols: if symbol.is_unresolved or symbol.is_import: # This symbol is already in the symbol table, but adding it - # to the 'symbols_to_bring_in' will make the next step bring - # into the subroutine all modules that it could come from. + # to the 'symbols_to_bring_in' will make the next step + # bring into the subroutine all modules that it could come + # from. symbols_to_bring_in.add(symbol) if isinstance(symbol, DataSymbol): # DataTypes can reference other symbols @@ -295,10 +294,11 @@ def _prepare_code_to_inline(routines_to_inline): if module_symbol.name not in code_to_inline.symbol_table: code_to_inline.symbol_table.add(module_symbol) else: - # If it already exists, we know it's a container (from the - # validation) so we just need to point to it + # If it already exists, we know it's a container (from + # the validation) so we just need to point to it symbol.interface.container_symbol = \ - code_to_inline.symbol_table.lookup(module_symbol.name) + code_to_inline.symbol_table.lookup( + module_symbol.name) @staticmethod def _get_psyir_to_inline(node): @@ -397,26 +397,26 @@ def apply(self, node, options=None): node.ancestor(Container).addchild(code_to_inline.detach()) else: if existing_symbol.is_import: - # The RoutineSymbol is in the table but that is because it is - # imported. We must therefore update its interface and - # potentially remove the ContainerSymbol (from which it is - # imported) altogether. + # The RoutineSymbol is in the table but that is + # because it is imported. We must therefore update + # its interface and potentially remove the + # ContainerSymbol (from which it is imported) + # altogether. csym = existing_symbol.interface.container_symbol - # The import of the routine symbol may be in an outer scope. + # The import of the routine symbol may be in an + # outer scope. ctable = csym.find_symbol_table(node) remove_csym = (ctable.symbols_imported_from(csym) == [existing_symbol]) - #existing_symbol.interface = DefaultModuleInterface() - #existing_symbol.visibility = Symbol.Visibility.PRIVATE if code_to_inline.name == existing_symbol.name: # Have to remove Symbol as adding the Routine into # the Container will insert it again. ctable._symbols.pop(existing_symbol.name) if remove_csym: ctable.remove(csym) + # Inline the code. This will automatically add the + # associated RoutineSymbol into the Container. code_to_inline = code_to_inline.detach() - # Set the routine's symbol to the existing_symbol - #code_to_inline.symbol = existing_symbol container.addchild(code_to_inline) sym = ctable.lookup(code_to_inline.name) sym.visibility = Symbol.Visibility.PRIVATE @@ -426,31 +426,31 @@ def apply(self, node, options=None): # exactly the same. for routine in container.walk(Routine, stop_type=Routine): if routine.name == caller_name: - # This TransformationError happens here and not in the - # validation because it needs the symbols_to_bring_in - # applied to effectively compare both versions. - # This will be fixed when module-inlining versioning is - # implemented. - # (It is OK to fail here because we have not yet made - # any modifications to the tree - code_to_inline is a - # detached copy.) + # This TransformationError happens here and not in + # the validation because it needs the + # symbols_to_bring_in applied to effectively + # compare both versions. This will be fixed when + # module-inlining versioning is implemented. (It + # is OK to fail here because we have not yet made + # any modifications to the tree - code_to_inline + # is a detached copy.) if routine != code_to_inline: raise TransformationError( - f"Cannot inline subroutine '{caller_name}' " - f"because another, different, subroutine with " - f"the same name already exists and versioning " - f"of module-inlined subroutines is not " - f"implemented yet.") - # Finally, ensure that the RoutineSymbol for the inlined routine is - # in the correct symbol table. + f"Cannot inline subroutine '{caller_name}'" + f" because another, different, subroutine " + f"with the same name already exists and " + f"versioning of module-inlined subroutines" + f" is not implemented yet.") + # Finally, ensure that the RoutineSymbol for the inlined + # routine is in the correct symbol table. routine_symbol = existing_symbol table = routine_symbol.find_symbol_table(node) if table.node is not container: # Set the visibility of the symbol to always be private. sym = container.symbol_table.lookup(routine_symbol.name) sym.visibility = Symbol.Visibility.PRIVATE - # Force removal of the routine_symbol if its also present in - # the Routine's symbol table. + # Force removal of the routine_symbol if it's also present + # in the Routine's symbol table. table.lookup(routine_symbol.name) norm_name = table._normalize(routine_symbol.name) table._symbols.pop(norm_name) diff --git a/src/psyclone/domain/lfric/lfric_kern.py b/src/psyclone/domain/lfric/lfric_kern.py index 5e12b54be0..ce67fdb499 100644 --- a/src/psyclone/domain/lfric/lfric_kern.py +++ b/src/psyclone/domain/lfric/lfric_kern.py @@ -679,29 +679,23 @@ class creates the PSyIR schedule on first invocation which is # problem in LFRic that this fixes. routine.debug_string() -# if len(routines) == 1: -# sched = routines[0] -# # TODO #928: We don't validate the arguments yet because the -# # validation has many false negatives. -# # self.validate_kernel_code_args(sched.symbol_table) +# # The kernel name corresponds to an interface block. Find which +# # of the routines matches the precision of the arguments. +# for routine in routines: +# try: +# # The validity check for the kernel arguments should raise +# # an exception if the precisions don't match but currently +# # does not! +# self.validate_kernel_code_args(routine.symbol_table) +# sched = routine +# break +# except GenerationError: +# pass # else: -# # The kernel name corresponds to an interface block. Find which -# # of the routines matches the precision of the arguments. -# for routine in routines: -# try: -# # The validity check for the kernel arguments will raise -# # an exception if the precisions don't match. -# self.validate_kernel_code_args(routine.symbol_table) -# sched = routine -# break -# except GenerationError: -# pass -# else: -# raise GenerationError( -# f"Failed to find a kernel implementation with an interface" -# f" that matches the invoke of '{self.name}'. (Tried " -# f"routines {[item.name for item in routines]}.)") -# +# raise GenerationError( +# f"Failed to find a kernel implementation with an interface" +# f" that matches the invoke of '{self.name}'. (Tried " +# f"routines {[item.name for item in routines]}.)") if len(routines) > 1: table = routines[0].scope.symbol_table @@ -711,10 +705,11 @@ class creates the PSyIR schedule on first invocation which is new_schedules = [] for sched in routines: - # TODO #935 - replace the PSyIR argument data symbols with LFRic data - # symbols. For the moment we just return the unmodified PSyIR schedule - # but this should use RaisePSyIR2LFRicKernTrans once KernelInterface - # is fully functional (#928). + # TODO #935 - replace the PSyIR argument data symbols with + # LFRic data symbols. For the moment we just return the + # unmodified PSyIR schedule but this should use + # RaisePSyIR2LFRicKernTrans once KernelInterface is fully + # functional (#928). ksched = KernelSchedule(sched.symbol, symbol_table=sched.symbol_table.detach()) for child in sched.pop_all_children(): diff --git a/src/psyclone/domain/lfric/lfric_types.py b/src/psyclone/domain/lfric/lfric_types.py index afa066b1dc..fe71a834a3 100644 --- a/src/psyclone/domain/lfric/lfric_types.py +++ b/src/psyclone/domain/lfric/lfric_types.py @@ -185,8 +185,6 @@ def _create_generic_scalars(): "precision"]) api_config = Config.get().api_conf("lfric") - lfric_kinds = list(api_config.precision_map.keys()) - generic_scalar_datatypes = [ GenericScalar("LFRicIntegerScalar", ScalarType.Intrinsic.INTEGER, LFRicTypes("I_DEF")), diff --git a/src/psyclone/tests/domain/common/transformations/kernel_module_inline_trans_test.py b/src/psyclone/tests/domain/common/transformations/kernel_module_inline_trans_test.py index 2919986e8f..682242257f 100644 --- a/src/psyclone/tests/domain/common/transformations/kernel_module_inline_trans_test.py +++ b/src/psyclone/tests/domain/common/transformations/kernel_module_inline_trans_test.py @@ -44,13 +44,12 @@ from fparser.common.readfortran import FortranStringReader from psyclone.configuration import Config from psyclone.domain.common.transformations import KernelModuleInlineTrans -from psyclone.errors import InternalError from psyclone.psyGen import CodedKern, Kern from psyclone.psyir.nodes import ( Container, Routine, CodeBlock, Call, IntrinsicCall) from psyclone.psyir.symbols import ( ContainerSymbol, DataSymbol, ImportInterface, RoutineSymbol, REAL_TYPE, - Symbol, SymbolError, SymbolTable) + Symbol, SymbolError) from psyclone.psyir.transformations import TransformationError from psyclone.tests.gocean_build import GOceanBuild from psyclone.tests.lfric_build import LFRicBuild