Closed
Description
from lpython import S
from sympy import pi
def func() -> S:
print(pi)
return pi
def test_func():
print(func())
test_func()
(SubroutineCall
2 basic_const_pi
2 basic_const_pi
[((Var 3 _lpython_return_variable))]
()
)
(Return)
(SubroutineCall ;; <== Here
2 basic_free_stack
2 basic_free_stack
[((Var 3 _lpython_return_variable))]
()
)
(SubroutineCall
2 basic_free_stack
2 basic_free_stack
[((Var 3 stack0))]
()
)
Activity
certik commentedon Nov 9, 2023
Consider this example:
I recommend to fix it by calling the
subroutine_from_function
pass, which transforms the above into the following ASR code:And this code in turn should already work today, so nothing needs to be implemented in the Symbolic pass.
certik commentedon Nov 9, 2023
The first issue to fix is:
certik commentedon Nov 9, 2023
There are several independent issues that we need to fix:
basic_free_stack
before return statement #2411 (comment)--dump-all-passes
and--dump-all-passes-fortran
from LFortran #2413subroutine_from_function
pass works as aboveanutosh491 commentedon Nov 11, 2023
Considering the above comment. I would say this
Should transform into something like this
This works with the c backend
But with the llvm backend we face this issue
We define
basic_const_pi
likeBut if you see the error message it is passing a double pointer as the first argument. Is this because
r
has an intent of typeOut
?cc @certik @Thirumalai-Shaktivel
Thirumalai-Shaktivel commentedon Nov 11, 2023
Yup, it's because of intent
Out
.I don't know how to proceed here; I will have to look into it soon and report back.
certik commentedon Nov 11, 2023
@anutosh491 yes, correct. I reopened this issue since the comment #2411 (comment) is not fixed. You are on the right track, we first need to get the
Out[S]
arguments working.anutosh491 commentedon Nov 19, 2023
I think we have all 4 TODOS of #2411 (comment) addressed now. Hence the issue can be closed.
certik commentedon Nov 19, 2023
@anutosh491 great job!