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
Semantic checks for Select-rank construct(#R1148) #895
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good start.
Done |
The specification doesn't speak on what happens when selector is an expression. |
R1150 requires that the expression be a scalar integer constant (which will be packaged as an |
I am unable to figure out how to handle to TODO case. |
test/semantics/select-rank.f90
Outdated
!ERROR: Selector is not an assumed-rank array variable | ||
SELECT RANK(y) | ||
RANK (0) | ||
print *, "PRINT RANK 0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a better test here if y
were to be used in some context that required it to be a scalar variable. Similarly, in the other RANK
cases, use the associate-name in some context that will elicit an error if the required rank were incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added some tests are they as expected ones ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Instead of just having a PRINT
statement, try using the SELECT RANK
construct entity in the test in some way that would work only when the construct entity has the expected rank, using something with a compile-time test of the rank.
SELECT RANK(x)
RANK(0)
j = INT(0, KIND=MERGE(KIND(0), -1, RANK(x) == 0)) ! will fail when RANK(x) is not zero here
END SELECT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the patch submitted(currently passed a non zero value to pass the drone.io build) , test Fails with below error, when the rank
is 0
, which is supposed to fail instead when rank
is not zero
.
_../f18/test/semantics/select-rank.f90:39:11: error: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type
j = INT(0, KIND=MERGE(KIND(0), -1, RANK(x) == 0)) ! will fail when RANK(x) is not zero ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _
Is this an issue with the RANK
construct or select rank
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to indicate a problem with the semantics or name resolution of xin the
RANK. If the rank of
xin that context were zero, as it should be, the
KIND=argument would have had a valid value. You can test that hypothesis by changing
==to
/=` in that expression and seeing whether it (incorrectly) does not emit an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conformed for above discussed test with suggested changes,
j = INT(0, KIND=MERGE(KIND(0), -1, RANK(x) /= 0))
!Is evaluating to true,
which means RANK
is not resolving properly the value of x
.
private: | ||
MaybeExpr expr_; | ||
std::optional<int> associationRank_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this new field relevant to the shape analysis code in lib/Evaluate/shape.cpp
? I think that it must be, so that code should be extended to use the specific case ranks so that operations that depend on the shape of an array will be compiled correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain more on what do you mean by
new field relevant to the shape analysis code
The tests other than select rank which depend on shape of array seem to be successful for ninja test check-all
What I can understand from comments is that,
MaybeExpr expr_
private member function in class AssocEntityDetails
is being used in lib/Evaluate/shape.cpp
inside function GetShape()
and my patch doesn't seem to handle the expr_
inside SetRankFromParserNode
but is handled in SetTypeFromAssociation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure that your tests for SELECT RANK
include operations in the rank cases that will force the compiler to analyze the shape of the array at the specific rank. Use FORALL
statements, the SHAPE
intrinsic, array assignments, &c. There is probably code in the shape analysis framework that will need to be updated to handle this new representation of construct entities correctly, using the rank of the construct entity and the descriptor of the assumed-rank dummy argument for inquiries.
0. Added more testing related to shape of array.
@klausler I have tried to formulate some tests from my understanding of Fortran language. |
If the tests seem to be written as expected, I see all passing except the following condition.
Checking |
Within a |
@klausler thanks for explaining, but there seems to be regression for other tests and the select-rank cases, not sure why are they regressing(They tend to Abort the compiler). |
A better implementation of querying the Shape from `DescriptorInquiry` using `GetExtent`.
lib/Evaluate/shape.cpp
Outdated
[&](const semantics::AssocEntityDetails &assoc) { | ||
return (*this)(assoc.expr()); | ||
Shape shape; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about association entities that are not RANK
cases, like ASSOCIATE(x=>array)
? This code used to work for them, and now it won't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have added a guard using if (!assoc.associationRank())
, the regression pass now.
Is there any related function you know apart from above usage, or suggest some other design pattern you think, like adding something in class AssocEntityDetails
like IsAssumedRank()
function similar to ObjectEentityDetails
? I think the only way we can identify select rank is the -fdebug-dump-symbols
will have a new rank:
field.
lib/Semantics/check-select-stmt.cpp
Outdated
@@ -0,0 +1,126 @@ | |||
//===-- lib/semantics/check-select-stmt.cpp -------------------------------===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good name for this file. Fortran has three different SELECT
statements and this file only checks one of the three.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about check-select-rank.[cpp|h]
?
test/Semantics/select-rank02.f90
Outdated
INTEGER :: j | ||
select rank (arr) | ||
rank(2) | ||
j = INT(0, KIND=MERGE(KIND(0), -1, RANK(arr) == SIZE(SHAPE(arr)))) !arr is dummy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't test RANK(arr)
and SIZE(SHAPE(arr))
against each other when you know what their values should be (2). They could both be wrong.
test/Semantics/select-rank02.f90
Outdated
|
||
select rank (arr) | ||
rank(2) | ||
j = INT(0, KIND=MERGE(KIND(0), -1, RANK(arr) == SIZE(SHAPE(brr)))) !brr is local to subroutine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what's being tested here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I was trying to test with a local copy and the dummy arguments.
Remove this test?
test/Semantics/select-rank02.f90
Outdated
integer,dimension(-1:10, 20:30) :: brr | ||
select rank (arr) | ||
rank(2) | ||
j = LOC(brr(0,25)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is just working with a local array and doesn't depend on the effective shape of the assumed-rank array at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changing it to arr.
@klausler I have incorporated most of the changes. |
Ping.. |
Merged in llvm-project/master. |
Semantic checks for R1148