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

(Closes #2845 #1792) fix for inline symbol bug #2848

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
04e347d
#2845 alter validate to check routine symbol table
arporter Jan 13, 2025
234101b
#2845 fix linting
arporter Jan 13, 2025
b78c558
#2845 always inline symbols into Routine symbol table.
arporter Jan 14, 2025
f6b67f2
#2845 ensure consistent symbol table used
arporter Jan 15, 2025
dbce296
#2845 get coverge for new branch in SymbolTable
arporter Jan 15, 2025
edf4556
Merge branch 'master' into 2845_inline_symbol_bug
arporter Jan 27, 2025
5821016
#2845 add reference_accesses() method to Extent class
arporter Jan 27, 2025
54a4445
#2845 improve inlining transformations
arporter Jan 27, 2025
4087300
#2845 WIP fixing issues [skip ci]
arporter Jan 27, 2025
4191a22
#2845 WIP fixing failures [skip ci]
arporter Jan 29, 2025
8b2e8ed
#2845 WIP fix linting [skip ci]
arporter Jan 29, 2025
a12e27a
Merge branch 'master' into 2845_inline_symbol_bug
arporter Jan 30, 2025
35638ca
#2845 extend get_invoke() utility to set include path for infrastruct…
arporter Jan 30, 2025
16991ca
#2845 update SymbolTable.wildcard_imports so that it returns Symbols,…
arporter Jan 30, 2025
fe8dbbb
#2845 updates to improve symbol resolution in KernelModuleInlineTrans
arporter Jan 30, 2025
36d2dfa
#2845 update GOOpenCLTrans to ignore kernel imports of compile-time c…
arporter Jan 30, 2025
63dbeaf
#2845 fix linting
arporter Jan 30, 2025
616ab1e
#2854 WIP fixing GOcean examples
arporter Jan 30, 2025
a7d22af
#2854 extend globalstoargs transformation to allow for precision symbols
arporter Jan 30, 2025
2afdc19
#2854 fix linting
arporter Jan 30, 2025
b0f2c64
#2845 fix lfric eg2
arporter Jan 30, 2025
d8dd055
#2845 ensure Config.include_paths set where necessary
arporter Jan 31, 2025
4e1dc3e
#2845 fix linting
arporter Jan 31, 2025
e4fe10c
#2845 get full cov of datatypes.py
arporter Jan 31, 2025
1ee160f
#2845 WIP fixing issues with GenericInterfaceSymbols [skip ci]
arporter Jan 31, 2025
7478204
#2845 WIP test fixing [skip ci]
arporter Feb 3, 2025
1adb642
#2854 WIP fixing resolve_imports and remove
arporter Feb 4, 2025
0c3ed07
#2845 add new _replace_symbol method
arporter Feb 4, 2025
8d52d47
#2845 overdue linting fixes
arporter Feb 4, 2025
af6c0ea
Merge branch 'master' into 2845_inline_symbol_bug
arporter Feb 6, 2025
a4577d9
#2845 simplify changes to SymbolTable
arporter Feb 10, 2025
a1387e6
#2845 fix tests using monkeypatch rather than hacking test kernel
arporter Feb 11, 2025
b929f12
#2845 fix linting
arporter Feb 11, 2025
4e272d3
Merge branch 'master' into 2845_inline_symbol_bug
arporter Feb 11, 2025
019b6f8
Merge branch 'master' into 2845_inline_symbol_bug
arporter Feb 11, 2025
f3779d6
#2845 improving funcionality.
arporter Feb 11, 2025
5368cd7
#2845 WIP towards coverage [skip ci]
arporter Feb 11, 2025
b8b334b
#2845 construct test demonstrating deep-copy bug
arporter Feb 12, 2025
9ab5e6a
#2845 fix linting [skip ci]
arporter Feb 12, 2025
ee9bb8e
#2845 add new_parent argument to Node.copy()
arporter Feb 12, 2025
2083fbe
#2845 fixes to gocean tests to allow for random ordering of USE stmts…
arporter Feb 13, 2025
d56d2c8
#2845 wip fixing issues [skip ci]
arporter Feb 13, 2025
aace9a3
#2845 move to ordering use stmts alphabetically
arporter Feb 13, 2025
6346eef
#2845 revert changes to GOcean test kernels
arporter Feb 13, 2025
f53c50e
#2845 revert changes to LFRic test kernels
arporter Feb 13, 2025
06c6c03
#2845 update to check deps of imported symbol
arporter Feb 13, 2025
82fe43d
#2845 tidying un-needed modifications
arporter Feb 13, 2025
8666430
#2845 revert gocean1p0 transformations test
arporter Feb 13, 2025
b27de1e
#2845 fix alpha-ording of gocean module uses
arporter Feb 14, 2025
6483093
#2845 get full cov of KernelModuleInlineTrans
arporter Feb 14, 2025
97d5fdb
#2845 get cov of GenericInterfaceSymbol
arporter Feb 14, 2025
98eb562
#2845 WIP improving SymbolTable cov [skip ci]
arporter Feb 14, 2025
bf97dd5
#2845 WIP improving coverage [skip ci]
arporter Feb 18, 2025
95e1040
#2845 rationalise symbol-removal/update code
arporter Feb 19, 2025
deed911
#2845 simplify code and improve coverage
arporter Feb 19, 2025
79d907c
Merge branch 'master' into 2845_inline_symbol_bug
arporter Feb 19, 2025
8f08a70
#2845 initial test for _replace_symbol_refs
arporter Feb 19, 2025
7831acf
#2845 WIP on SymbolTable coverage [skip ci]
arporter Feb 19, 2025
97f7a5f
#2845 more SymbolTable coverage [skip ci]
arporter Feb 20, 2025
86da8b3
#2845 add reference_accesses() to DataType and refactor [skip ci]
arporter Feb 20, 2025
6abf21d
#2845 fix tests and tidy
arporter Feb 20, 2025
4f2123f
#2845 get full cov of DataSymbol
arporter Feb 20, 2025
75301e5
#2845 improve cov of TypedSymbol
arporter Feb 20, 2025
2bac52e
#2845 fix tests and improve cov
arporter Feb 20, 2025
34004a1
#2845 fix cov of DataTypeSymbol
arporter Feb 20, 2025
149d033
#2845 fix issues in NEMO4 [skip ci]
arporter Feb 20, 2025
7a59ed9
#2845 make resolve_imports respect limited imports
arporter Feb 21, 2025
0099f66
Merge branch 'master' into 2845_inline_symbol_bug
arporter Feb 21, 2025
3d88219
#2845 update fortran backend so that a wildcard import preserves any …
arporter Feb 21, 2025
20d9f1e
#2845 fix bug in SymbolTable.resolve_imports() for renamed imports
arporter Feb 21, 2025
ce432f3
#2845 fix KernelModuleInlineTrans to work with wildcard imports [skip…
arporter Feb 21, 2025
faf8c16
#2845 update symbols in shapes of ArrayTypes and ComponentTypes
arporter Feb 24, 2025
768eb84
Merge branch 'master' into 2845_inline_symbol_bug
arporter Feb 25, 2025
90334cd
#2845 reject routines that ALLOCATE
arporter Feb 25, 2025
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
Prev Previous commit
Next Next commit
#2845 WIP fixing issues [skip ci]
arporter committed Jan 27, 2025

Verified

This commit was signed with the committer’s verified signature.
Pierre-Lannoy Pierre Lannoy
commit 40873004108c0b6aed34da6b3b959be42ad45b76
Original file line number Diff line number Diff line change
@@ -205,18 +205,20 @@ def check_data_accesses(call, kernel_schedule, kname, kern_or_call):
if symbol.is_unresolved:
routine_wildcards = table.wildcard_imports()
try:
# This symbol must be imported from the one Container with
# a wildcard import.
# If there's more than one Container with a wildcard import
# this will raise a ValueError.
(cname,) = routine_wildcards
csym = table.lookup(cname, symbol_type=ContainerSymbol)
symbol.interface = ImportInterface(csym)
except (ValueError, KeyError):
callsite_wildcards = call.scope.symbol_table.wildcard_imports()
callsite_wildcards = (
call.scope.symbol_table.wildcard_imports())
if not routine_wildcards.issubset(callsite_wildcards):
raise TransformationError(
f"{kern_or_call} '{kname}' contains accesses to "
f"'{symbol.name}' which is unresolved. It is being "
f"brought into scope from one of {routine_wildcards}")
f"'{symbol.name}' which is unresolved. It is being"
f" brought into scope from one of "
f"{routine_wildcards}")
if not symbol.is_import and symbol.name not in table:
sym_at_call_site = call.scope.symbol_table.lookup(
sig.var_name, otherwise=None)
2 changes: 1 addition & 1 deletion src/psyclone/psyir/symbols/symbol_table.py
Original file line number Diff line number Diff line change
@@ -929,7 +929,7 @@ def lookup(
name: str,
visibility: Optional[Union[Symbol.Visibility,
List[Symbol.Visibility]]] = None,
scope_limit = None,
scope_limit=None,
symbol_type: Optional[type] = None,
otherwise: Any = DEFAULT_SENTINEL) -> Any:
'''Look up a symbol in the symbol table. The lookup can be limited
56 changes: 32 additions & 24 deletions src/psyclone/psyir/transformations/inline_trans.py
Original file line number Diff line number Diff line change
@@ -41,13 +41,13 @@
from psyclone.psyGen import Transformation
from psyclone.psyir.nodes import (
ArrayReference, ArrayOfStructuresReference, BinaryOperation, Call,
CodeBlock, IntrinsicCall, Literal, Node, Range, Routine, Reference,
Return, ScopingNode, Statement, StructureMember, StructureReference)
CodeBlock, Container, IntrinsicCall, Literal, Node, Range, Routine,
Reference, Return, ScopingNode, Statement, StructureMember,
StructureReference)
from psyclone.psyir.nodes.array_mixin import ArrayMixin
from psyclone.psyir.symbols import (
ArgumentInterface, ArrayType, DataSymbol, UnresolvedType, INTEGER_TYPE,
StaticInterface, SymbolError, UnknownInterface,
UnsupportedType, IntrinsicSymbol)
ArgumentInterface, ArrayType, UnresolvedType, INTEGER_TYPE,
StaticInterface, SymbolError, UnknownInterface, UnsupportedType)
from psyclone.psyir.transformations.reference2arrayrange_trans import (
Reference2ArrayRangeTrans)
from psyclone.psyir.transformations.transformation_error import (
@@ -153,7 +153,9 @@ def apply(self, node, options=None):

# Ensure we don't modify the original Routine by working with a
# copy of it.
routine = orig_routine.copy()
container = orig_routine.ancestor(Container).copy()
routine = container.find_routine_psyir(orig_routine.name,
allow_private=True)
routine_table = routine.symbol_table

# Construct lists of the nodes that will be inserted and all of the
@@ -685,48 +687,54 @@ def validate(self, node, options=None):
if isinstance(sym.interface, ArgumentInterface):
if isinstance(sym.datatype, UnsupportedType):
raise TransformationError(
f"Routine '{routine.name}' cannot be inlined because "
f"it contains a Symbol '{sym.name}' which is an "
f"Argument of UnsupportedType: "
f"Routine '{routine.name}' cannot be inlined "
f"because it contains a Symbol '{sym.name}' which "
f"is an Argument of UnsupportedType: "
f"'{sym.datatype.declaration}'")
# We don't inline symbols that have an UnknownInterface, as we
# don't know how they are brought into this scope.
if isinstance(sym.interface, UnknownInterface):
raise TransformationError(
f"Routine '{routine.name}' cannot be inlined because it "
f"contains a Symbol '{sym.name}' with an UnknownInterface:"
f" '{sym.datatype.declaration}'. You may be able to work "
f"around this limitation by adding the name of the module "
f"containing this Symbol to RESOLVE_IMPORTS in the "
f"transformation script.")
# Check that there are no static variables in the routine (because
# we don't know whether the routine is called from other places).
f"Routine '{routine.name}' cannot be inlined because "
f"it contains a Symbol '{sym.name}' with an "
f"UnknownInterface: '{sym.datatype.declaration}'. You "
f"may be able to work around this limitation by "
f"adding the name of the module containing this Symbol"
f" to RESOLVE_IMPORTS in the transformation script.")
# Check that there are no static variables in the routine
# (because we don't know whether the routine is called from
# other places).
if (isinstance(sym.interface, StaticInterface) and
not sym.is_constant):
raise TransformationError(
f"Routine '{routine.name}' cannot be inlined because it "
f"has a static (Fortran SAVE) interface for Symbol "
f"Routine '{routine.name}' cannot be inlined because "
f"it has a static (Fortran SAVE) interface for Symbol "
f"'{sym.name}'.")

# We can't handle a clash between (apparently) different symbols that
# share a name but are imported from different containers.
routine_arg_list = routine.symbol_table.argument_list[:]
for scope in routine.walk(ScopingNode):
routine_table = scope.symbol_table
for scope in parent_routine.walk(ScopingNode):
table = scope.symbol_table
try:
table.check_for_clashes(
routine_table,
symbols_to_skip=routine_table.argument_list[:])
symbols_to_skip=routine_arg_list)
except SymbolError as err:
raise TransformationError(
f"One or more symbols from routine '{routine.name}' cannot be "
f"added to the table at the call site. Error was: {err}") from err
f"One or more symbols from routine '{routine.name}' "
f"cannot be added to the table at the call site. "
f"Error was: {err}") from err

# Check for unresolved symbols or for any accessed from the Container
# containing the target routine.
from psyclone.domain.common.transformations import KernelModuleInlineTrans
KernelModuleInlineTrans.check_data_accesses(node, routine, routine.name,
# TODO refactor this functionality
from psyclone.domain.common.transformations import (
KernelModuleInlineTrans)
KernelModuleInlineTrans.check_data_accesses(node, routine,
routine.name,
"routine")
# TODO #1792 - kind parameters will not be found by simply doing
# `walk(Reference)`. Although SymbolTable has the
10 changes: 5 additions & 5 deletions src/psyclone/tests/psyir/transformations/inline_trans_test.py
Original file line number Diff line number Diff line change
@@ -1836,17 +1836,17 @@ def test_validate_unresolved_precision_sym(fortran_reader, code_body,
call = psyir.walk(Call)[0]
if use_stmt:
# There is a module import within the called routine and therefore
# we
# don't know which module any unresolved symbols come from.
# we don't know which module any unresolved symbols come from.
with pytest.raises(TransformationError) as err:
inline_trans.validate(call)
if "i_def" in code_body:
assert "A symbol named 'i_def' is present but unresolved in one or both tables" in str(err.value)
assert ("A symbol named 'i_def' is present but unresolved in one "
"or both tables" in str(err.value))
else:
assert ("routine 'sub' contains accesses to" in str(err.value))
else:
# There is only one module import and it is common to the target routine
# and the call site.
# There is only one module import and it is common to the target
# routine and the call site.
inline_trans.validate(call)