-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Handle IntegerBinOp_t
when setting array dimension through a module variable
#4034
Handle IntegerBinOp_t
when setting array dimension through a module variable
#4034
Conversation
bff08ca
to
8ab9bd5
Compare
Do you know how to fix CI? |
I see that the CI failure is due to the SIGSEGV which you pointed out. Let's handle it. |
When you look at logs here https://github.com/lfortran/lfortran/actions/runs/9146050049/job/25145719378?pr=4034#step:6:3508, it states funtions_20 segfaults, go ahead run it locally and try to create minimal code that reproduces same error. Then we can see how to fix this. |
I suspect this part of the code to be the culprit: program functions_20
real, dimension(3,3) :: A ! <- variable declared here
real :: B(2)
integer :: k
interface
function diag_rsp_mat(A, k) result(res)
real, intent(in) :: A(:,:) ! <- variable masked here
integer, intent(in) :: k
real :: res(minval(shape(A)) - abs(k))
end function diag_rsp_mat
end interface From the linter comments, I see that we have a re-declaration occurring here. I am new to the language and currently do not understand what |
Does this code give same error when you run it? If yes, seems like you are not checking if end is nullptr or not before processing. A(:,:) means array of 2 dimension with variable size that will be decided at runtime. |
If the comment above do not work then start adding print statement at each line and check where it segfaults. |
Yes it segfaults on my local machine too. The error occurs on the following line |
With the latest commit, we now handle the case were both operands are variables. However, unexpected things are happening now. A lot of |
When running the integration tests, a lot of internal compiler errors pop up. But, running the failing tests one-by-one shows no error and the tests execute properly. (base) saurabh-kumar@Awadh:~/Projects/System/lfortran$ conda activate lf
(lf) saurabh-kumar@Awadh:~/Projects/System/lfortran$ cd ./integration_tests/
(lf) saurabh-kumar@Awadh:~/Projects/System/lfortran/integration_tests$ lfortran include_02.f90
10 10 10
10 3 10
(lf) saurabh-kumar@Awadh:~/Projects/System/lfortran/integration_tests$ lfortran arrays_op_6.f90
(lf) saurabh-kumar@Awadh:~/Projects/System/lfortran/integration_tests$ lfortran cond_02.f90
ap /= bp
cp /= dp
ap == cp
cp /= dp |
With the changes in this PR, we are now able to compile the module |
This case fails for now |
Cannot |
It can be done. This was my initial thought when implementing the changes in this PR, but I chose to follow the implementation for variables as it was easy to implement taking into account the variables we got in the expression. I think this is the correct way to implement this as then we can handle variables and expressions together with a single implementation. I am pushing the new changes. |
I have a few questions:
ASR::Var_t* end_var = ASR::down_cast<ASR::Var_t>(end);
ASR::symbol_t* end_sym = end_var->m_v;
if (ASR::is_a<ASR::ExternalSymbol_t>(*end_sym)) {
...
} We could similarly also handle variables in an
@certik @Pranavchiku could you please guide me on the above? This will help me in completing the new implementation. |
Right, it would require a more thorough analysis, which might not be worth doing. It might be easier then to use the |
The issue occurs when dealing with arbitrary number of integer binary operations. When dealing with an expression like We can handle this case through a recursive approach. |
Yes, I think it has to be handled recursively. |
0b85dd2
to
69879d8
Compare
With the latest commit, we are now able to handle all the cases. module xx
integer :: nx = 4
integer :: ny = 1
end module xx
subroutine a(cs)
use xx
integer, dimension(nx * ny - 1), intent(in) :: cs
print *, cs
end subroutine
program main
integer, dimension(8) :: cs
cs = [1, 2, 3, 4, 5, 6, 7, 8]
call a(cs)
end program (base) saurabh-kumar@Awadh:~/Projects/System/lfortran$ lfortran ./examples/example.f90
1 2 3 |
Currently, the following integration test fails program arrays_op_20
implicit none
real, allocatable :: array(:, :), arrayoutput(:, :)
allocate(array(3, 3))
arrayoutput = f(5, array)
print *, size(arrayoutput)
if( size(arrayoutput) /= 24 ) error stop
contains
function f(m, input) result(output)
integer :: m
real :: input(m)
real :: output(2:m, m:2*m) ! The expression on this line is the cause of the failure
end function
end program (base) saurabh-kumar@Awadh:~/Projects/System/lfortran$ lfortran ./examples/example.f90
ASR verify pass error: ASR verify: The symbol table was not found in the scope of `symtab`.
--> ./examples/example.f90:14:18
|
14 | integer :: m
| ^ failed here
ASR verify pass error: FunctionCall::m_name `__lcompilers_get_m` cannot point outside of its symbol table
--> ./examples/example.f90:14:18
|
14 | integer :: m
| ^ failed here
Note: Please report unclear, confusing or incorrect messages as bugs at
https://github.com/lfortran/lfortran/issues. The cause of failure is the declaration |
Not sure what is wrong. Save all the ASR to files ( |
This implementation is now complete. |
@kmr-srbh beautiful, thank you for pushing this through! It looks ok at first glance to me, but we need to review more carefully. @Shaikh-Ubaid do you think you could please review it carefully? |
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 looks great to me. Thanks for this! We can improve this further as and when we see/find opportunities.
… handling array dimensions
Co-authored-by: Shaikh Ubaid <[email protected]>
4ca2149
to
543e99a
Compare
fixes #4013
is transformed to:
Working