Skip to content

Commit

Permalink
updates for pull request comments from andy
Browse files Browse the repository at this point in the history
  • Loading branch information
SCHREIBER Martin committed Nov 15, 2024
1 parent fa5b311 commit e5cf0db
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 32 deletions.
49 changes: 27 additions & 22 deletions src/psyclone/psyir/nodes/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


class CallMatchingArgumentsNotFound(BaseException):
"""Excepction to signal that matching arguments have not been found
"""Exception to signal that matching arguments have not been found
for this routine
"""

Expand Down Expand Up @@ -342,7 +342,7 @@ def routine(self):
return None

@property
def arguments(self) -> DataNode:
def arguments(self) -> List[DataNode]:
'''
:returns: the children of this node that represent its arguments.
:rtype: list[py:class:`psyclone.psyir.nodes.DataNode`]
Expand Down Expand Up @@ -434,6 +434,7 @@ def copy(self):
:returns: a copy of this node and its children.
:rtype: :py:class:`psyclone.psyir.node.Node`
'''

# ensure _argument_names is consistent with actual arguments
# before copying.
self._reconcile()
Expand Down Expand Up @@ -605,27 +606,25 @@ def get_argument_routine_match(self, routine: Routine):
"""Return a list of integers giving for each argument of the call
the index of the argument in argument_list (typically of a routine)
:param argument_list: List of arguments
:type argument_list: Arguments
:return: None if no match was found, otherwise list of integers
referring to matching arguments.
referring to matching arguments.
:rtype: None|List[int]
"""

# Create a copy of the list
# Create a copy of the list of actual arguments to the routine.
# Once an argument has been successfully matched, set it to 'None'
routine_argument_list: List[DataNode] = \
routine.symbol_table.argument_list[:]

if len(self.arguments) > len(routine.symbol_table.argument_list):
raise CallMatchingArgumentsNotFound(
f"More arguments in callee (call '{self.routine.name}')"
f" than caller (routine '{routine.name}')"
f"More arguments in call ('{self.debug_string()}')"
f" than callee (routine '{routine.name}')"
)

assert len(self.arguments) == len(self.argument_names)

# Iterate over all arguments
# Iterate over all arguments to the call
ret_arg_idx_list = []
for call_arg_idx, call_arg in enumerate(self.arguments):
call_arg_idx: int
Expand All @@ -641,7 +640,8 @@ def get_argument_routine_match(self, routine: Routine):
#
# TODO #759: If optional is used, it's an unsupported Fortran
# type and we need to use the following workaround
# Once this issue is resolved, simply remove this if branch
# Once this issue is resolved, simply remove this if branch.
# Optional arguments are processed further down.
if not isinstance(
routine_arg.datatype,
UnsupportedFortranType):
Expand All @@ -660,8 +660,8 @@ def get_argument_routine_match(self, routine: Routine):
# Next, we handle all named arguments
#
arg_name = self.argument_names[call_arg_idx]
named_arg_found = False
routine_arg_idx = None

for routine_arg_idx, routine_arg in enumerate(
routine_argument_list):
routine_arg: DataSymbol
Expand All @@ -673,7 +673,9 @@ def get_argument_routine_match(self, routine: Routine):
if arg_name == routine_arg.name:
# TODO #759: If optional is used, it's an unsupported
# Fortran type and we need to use the following workaround
# Once this issue is resolved, simply remove this if branch
# Once this issue is resolved, simply remove this if
# branch.
# Optional arguments are processed further down.
if not isinstance(
routine_arg.datatype,
UnsupportedFortranType):
Expand All @@ -685,10 +687,9 @@ def get_argument_routine_match(self, routine: Routine):
)

ret_arg_idx_list.append(routine_arg_idx)
named_arg_found = True
break

if not named_arg_found:
else:
# It doesn't match => Raise exception
raise CallMatchingArgumentsNotFound(
f"Named argument '{arg_name}' not found"
Expand Down Expand Up @@ -721,19 +722,22 @@ def get_callee(
self,
ret_arg_match_list: List[int] = None,
check_matching_arguments: bool = True):
'''
"""
Searches for the implementation(s) of the target routine for this Call
including argument checks.
:param ret_arg_match_list: List in which the matching argument
indices will be returned
:type ret_arg_match_list: List[int]
:param check_matching_arguments: Also check argument types to match.
:type ret_arg_match_list: bool
:returns: the Routine(s) that this call targets.
:rtype: list[:py:class:`psyclone.psyir.nodes.Routine`]
:returns: The routine that this call targets.
:rtype: psyclone.psyir.nodes.Routine
:raises NotImplementedError: if the routine is not local and not found
in any containers in scope at the call site.
'''
"""

routine_list = self.get_callees()

Expand All @@ -749,8 +753,7 @@ def get_callee(
error = err
continue

error = None

# Provide list of indices of matching arguments if requested
if ret_arg_match_list is not None:
ret_arg_match_list[:] = arg_match_list

Expand All @@ -764,8 +767,10 @@ def get_callee(
return routine_list[0]

Check warning on line 767 in src/psyclone/psyir/nodes/call.py

View check run for this annotation

Codecov / codecov/patch

src/psyclone/psyir/nodes/call.py#L767

Added line #L767 was not covered by tests

if error is not None:
raise error
raise CallMatchingArgumentsNotFound(
f"No matching routine found for '{self.debug_string()}'"
) from error
else:
raise NotImplementedError(

Check warning on line 774 in src/psyclone/psyir/nodes/call.py

View check run for this annotation

Codecov / codecov/patch

src/psyclone/psyir/nodes/call.py#L774

Added line #L774 was not covered by tests
f"No matching routine for call " f"'{self.routine.name}' found"
f"No matching routine found for " f"'{self.routine.name}'"
)
6 changes: 3 additions & 3 deletions src/psyclone/tests/psyir/nodes/call_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def test_call_get_callee_3_trigger_error(fortran_reader):
call_foo.get_callee(ret_arg_match_list=arg_idx_list)

except CallMatchingArgumentsNotFound as err:
assert "More arguments in callee" in str(err)
assert "No matching routine found for" in str(err)
print("Success! Exception triggered (as expected)")
return

Expand Down Expand Up @@ -1109,7 +1109,7 @@ def test_call_get_callee_7_matching_arguments_not_found(fortran_reader):
call_foo.get_callee()

except CallMatchingArgumentsNotFound as err:
assert "Named argument 'd' not found" in str(err)
assert "No matching routine found for 'call foo(e, f, d=g)" in str(err)
print("Success! Exception triggered (as expected)")
return

Expand Down Expand Up @@ -1152,7 +1152,7 @@ def test_call_get_callee_8_arguments_not_handled(fortran_reader):
call_foo.get_callee()

except CallMatchingArgumentsNotFound as err:
assert "Argument 'c' in subroutine 'foo' not handled" in str(err)
assert "No matching routine found for 'call foo(e, f)" in str(err)
print("Success! Exception triggered (as expected)")
return

Expand Down
31 changes: 24 additions & 7 deletions bin_git/run_flake8.sh → utils/run_flake8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd "$SCRIPTPATH/.."

# An example hook script to verify what is about to be pushed. Called by "git
# push" after it has checked the remote status, but before anything has been
# pushed. If this script exits with a non-zero status nothing will be pushed.

#
# Hint for vscode:
# ===========================
#
# Install black-formatter
#
# In settings:
# - Activate 'Code Actions On Save'
# - Set 'Format on Save Mode' to 'modifications'
#

#
# GIT related information:
# ===========================
#
# This script can be also used as a git hook in .git/hooks/pre-push
# It then ensures that the whole of PSyclone is linted successfully
# before the push is executed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
Expand All @@ -14,13 +32,12 @@ cd "$SCRIPTPATH/.."
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
# Information about the commits which are being pushed is supplied as lines
# to the standard input in the form:
#
# <local ref> <local oid> <remote ref> <remote oid>
#
# This script ensures that the whole of PSyclone is linted successfully
# before the push is executed.


remote="$1"
url="$2"
Expand Down
32 changes: 32 additions & 0 deletions utils/run_pytest_cov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

#
# Hint: For vscode
#
# Install the extension `coverage-gutters` and execute the command "Coverage Gutters: Display Coverage"
#

SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd "$SCRIPTPATH/.."

PSYCLONE_MODULE="psyclone"
if [[ ! -z $1 ]]; then
PSYCLONE_MODULE=$1
fi

SRC_DIR="src/psyclone/tests"
if [[ ! -z $2 ]]; then
SRC_DIR=$2
fi

COV_REPORT="xml:cov.xml"

# Additional options
# Also write to Terminal
#OPTS=" --cov-report term"

#echo "Running 'pytest --cov $PSYCLONE_MODULE --cov-report term-missing -n $(nproc) $SRC_DIR'"
#pytest --cov $PSYCLONE_MODULE -v --cov-report term-missing -n $(nproc) $SRC_DIR
echo "Running 'pytest --cov $PSYCLONE_MODULE --cov-report $COV_REPORT -n $(nproc) $SRC_DIR'"
pytest --cov $PSYCLONE_MODULE -v --cov-report $COV_REPORT $OPTS -n $(nproc) $SRC_DIR

0 comments on commit e5cf0db

Please sign in to comment.