Skip to content

Commit

Permalink
#1960 improvements for review
Browse files Browse the repository at this point in the history
  • Loading branch information
arporter committed Feb 2, 2024
1 parent 470ffdb commit 19b5661
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/psyclone/psyir/nodes/array_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create(symbol, indices):
f"indices argument in create method of ArrayReference class "
f"should be a list but found '{type(indices).__name__}'.")
if not symbol.is_array:
# Deferred and Unsupported types may still be arrays
# Unresolved and Unsupported types may still be arrays
if not isinstance(symbol.datatype, (UnresolvedType,
UnsupportedType)):
raise GenerationError(
Expand Down
4 changes: 2 additions & 2 deletions src/psyclone/tests/psyir/frontend/fparser2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,8 +1553,8 @@ def test_process_save_attribute_declarations(parser):
assert isinstance(fake_parent.symbol_table.lookup("var4").interface,
StaticInterface)

# Test when is part of an UnknownDataType (target attribute in this case)
# it becomes an UnknownInterface
# Test that when it is part of an UnsupportedType (target attribute in
# this case) it becomes an UnknownInterface.
reader = FortranStringReader("integer, target :: var5")
fparser2spec = Specification_Part(reader).content[0]
processor.process_declarations(fake_parent, [fparser2spec], [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
from psyclone.errors import InternalError
from psyclone.psyir.frontend.fparser2 import Fparser2Reader
from psyclone.psyir.nodes import (
Schedule, Call, CodeBlock, Loop, ArrayReference, Assignment, IfBlock,
IntrinsicCall, Literal, Reference, UnaryOperation, BinaryOperation,
Routine, Container, Range, ArrayMember)
ArrayMember, ArrayReference, Assignment, BinaryOperation, Call, CodeBlock,
Container, IfBlock, IntrinsicCall, Literal, Loop, Range, Routine, Schedule,
UnaryOperation)
from psyclone.psyir.symbols import (
DataSymbol, ArrayType, ScalarType, REAL_TYPE, INTEGER_TYPE,
UnresolvedInterface)
Expand Down Expand Up @@ -399,7 +399,7 @@ def test_where_mask_starting_value(fortran_reader, fortran_writer):
# TODO #949 - we can't currently take advantage of any knowledge of the
# declared lower bounds of arrays because the fparser2 frontend doesn't yet
# capture this information (we get an UnknownFortranType).
# capture this information (we get an UnsupportedFortranType).
'''
code = '''\
program my_sub
Expand Down
55 changes: 50 additions & 5 deletions src/psyclone/tests/psyir/nodes/array_mixin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ def test_get_effective_shape(fortran_reader):
" integer :: indices(8,3)\n"
" real a(10), b(10,10)\n"
" a(1:10) = 0.0\n"
" a(1:10:3) = 0.0\n"
" a(:) = 0.0\n"
" a(2:) = 0.0\n"
" a(:5) = 0.0\n"
" a(::4) = 0.0\n"
" a(lbound(b,1):ubound(b,2)) = 0.0\n"
" b(indices(2:3,1), 2:5) = 2.0\n"
" b(indices(2:3,1:2), 2:5) = 2.0\n"
" a(f()) = 2.0\n"
Expand All @@ -507,11 +513,47 @@ def test_get_effective_shape(fortran_reader):
psyir = fortran_reader.psyir_from_source(code)
routine = psyir.walk(Routine)[0]
# Direct array slice.
shape = routine.children[0].lhs._get_effective_shape()
child_idx = 0
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
assert isinstance(shape[0], BinaryOperation)
# Array slice with non-unit step.
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
assert shape[0].debug_string() == "(10 - 1) / 3 + 1"
# Full array slice without bounds.
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
assert "SIZE(a, dim=1)" in shape[0].debug_string()
# Array slice with only lower-bound specified.
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
assert shape[0].debug_string() == "UBOUND(a, dim=1) - 2 + 1"
# Array slice with only upper-bound specified.
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
assert shape[0].debug_string() == "5 - LBOUND(a, dim=1) + 1"
# Array slice with only step specified.
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
# Since step is not unity, this is not a 'full-range' access so we still
# end up with UBOUND and LBOUND, even though SIZE would be nicer.
assert (shape[0].debug_string() ==
"(UBOUND(a, dim=1) - LBOUND(a, dim=1)) / 4 + 1")
# Array slice defined using LBOUND and UBOUND intrinsics but for a
# different array altogether.
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 1
assert shape[0].debug_string() == "UBOUND(b, 2) - LBOUND(b, 1) + 1"
# Indirect array slice.
shape = routine.children[1].lhs._get_effective_shape()
child_idx += 1
shape = routine.children[child_idx].lhs._get_effective_shape()
assert len(shape) == 2
assert isinstance(shape[0], BinaryOperation)
# An ArrayType does not store the number of elements, just lower and upper
Expand All @@ -520,18 +562,21 @@ def test_get_effective_shape(fortran_reader):
assert shape[0].debug_string() == "3 - 2 + 1"
assert shape[1].debug_string() == "5 - 2 + 1"
# An indirect array slice can only be 1D.
child_idx += 1
with pytest.raises(InternalError) as err:
_ = routine.children[2].lhs._get_effective_shape()
_ = routine.children[child_idx].lhs._get_effective_shape()
assert ("array defining a slice of a dimension of another array must be "
"1D but 'indices' used to index into 'b' has 2 dimensions" in
str(err.value))
# Indirect array access using function call.
child_idx += 1
with pytest.raises(NotImplementedError) as err:
_ = routine.children[3].lhs._get_effective_shape()
_ = routine.children[child_idx].lhs._get_effective_shape()
assert "include a function call or expression" in str(err.value)
# Array access with expression in indices.
child_idx += 1
with pytest.raises(NotImplementedError) as err:
_ = routine.children[4].lhs._get_effective_shape()
_ = routine.children[child_idx].lhs._get_effective_shape()
assert "include a function call or expression" in str(err.value)


Expand Down

0 comments on commit 19b5661

Please sign in to comment.