Uh oh!
There was an error while loading. Please reload this page.
Replace BlockCall symbol with the one in current scope - #1688
Conversation
The issue was in the deffunc() ->i32:
return30deftest() ->i32:
temp: i32=func()
returntempx : i32x=test()
print(x)(TranslationUnit
(SymbolTable1
{
_global_symbols:
(Module
(SymbolTable6
{
_lpython_main_program:
(Function
(SymbolTable5
{
_lpython_return_variable_func_test:
(Variable5
_lpython_return_variable_func_test
[]
Local
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
),
_lpython_return_variable_test:
(Variable5
_lpython_return_variable_test
[]
Local
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
),
temp_test:
(Variable5
temp_test
[]
Local
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
),
~empty_block:
(Block
(SymbolTable8
{
})
~empty_block
[]
)
})
_lpython_main_program
(FunctionType
[]
()
Source
Implementation
()
.false.
.false.
.false.
.false.
.false.
[]
[]
.false.
)
[]
[]
[(=
(Var5 _lpython_return_variable_func_test)
(IntegerConstant30 (Integer4 []))
()
)
(GoTo1
__1
)
(BlockCall13 ~empty_block ! < ------------- Here is the issue
)
(=
(Var5 temp_test)
(Var5 _lpython_return_variable_func_test)
()
)
(=
(Var5 _lpython_return_variable_test)
(Var5 temp_test)
()
)
(GoTo2
__2
)
(BlockCall25 ~empty_block
)
(=
(Var6 x)
(Var5 _lpython_return_variable_test)
()
)
(Print
()
[(Var6 x)]
()
()
)]
()
Public
.false.
.false.
),
func:
(Function
(SymbolTable2
{
_lpython_return_variable:
(Variable2
_lpython_return_variable
[]
ReturnVar
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
)
})
func
(FunctionType
[]
(Integer4 [])
Source
Implementation
()
.false.
.false.
.false.
.false.
.false.
[]
[]
.false.
)
[]
[]
[(=
(Var2 _lpython_return_variable)
(IntegerConstant30 (Integer4 []))
()
)
(Return)]
(Var2 _lpython_return_variable)
Public
.false.
.false.
),
test:
(Function
(SymbolTable3
{
_lpython_return_variable:
(Variable3
_lpython_return_variable
[]
ReturnVar
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
),
_lpython_return_variable_func:
(Variable3
_lpython_return_variable_func
[]
Local
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
),
temp:
(Variable3
temp
[]
Local
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
),
~empty_block:
(Block
(SymbolTable7
{
})
~empty_block
[]
)
})
test
(FunctionType
[]
(Integer4 [])
Source
Implementation
()
.false.
.false.
.false.
.false.
.false.
[]
[]
.false.
)
[]
[]
[(=
(Var3 _lpython_return_variable_func)
(IntegerConstant30 (Integer4 []))
()
)
(GoTo1
__1
)
(BlockCall13 ~empty_block
)
(=
(Var3 temp)
(Var3 _lpython_return_variable_func)
()
)
(=
(Var3 _lpython_return_variable)
(Var3 temp)
()
)
(Return)]
(Var3 _lpython_return_variable)
Public
.false.
.false.
),
x:
(Variable6
x
[]
Local
()
()
Default
(Integer4 [])
Source
Public
Required
.false.
)
})
_global_symbols
[]
.false.
.false.
),
main_program:
(Program
(SymbolTable4
{
_lpython_main_program:
(ExternalSymbol4
_lpython_main_program
6 _lpython_main_program
_global_symbols
[]
_lpython_main_program
Public
)
})
main_program
[_global_symbols]
[(SubroutineCall4 _lpython_main_program
()
[]
()
)]
)
})
[]
)Here the statements from the |
gptsarthak
commented
Apr 9, 2023
Thank you. Please check if this also fixes #1677 |
certik
commented
Apr 9, 2023
We need to be careful here, I think you want to duplicate it, don't you? |
I thought the If we duplicate it, should we create an ExternalSymbol for the Block? ...
_lpython_main_program:
(Function
(SymbolTable5
{
...
(BlockCall13 ~empty_block ! < ---- This is created in another function symtab
)
...
(BlockCall25 ~empty_block
)
... |
certik
commented
Apr 9, 2023
I don't know. I agree that goto is specific to a function. But removing it seems to make the code incorrect. So we need to figure out how to solve this. |
czgdp1807
commented
Apr 10, 2023
Correct. We need to duplicate it and then edit |
53ad721 to
1f60cf0CompareThirumalai-Shaktivel
commented
Apr 10, 2023
I'm not sure if this new change was a correct fix. What does the |
| std::string block_name = ASRUtils::symbol_name(bc->m_m); | ||
| LCOMPILERS_ASSERT(current_scope->get_symbol(block_name)) | ||
| bc->m_m = current_scope->get_symbol(block_name); | ||
| } |
There was a problem hiding this comment.
Instead of doing the edit here, you need to follow the same pattern as in visit_Var (add visit_BlockCall and then edit its symbol, if the code is exactly the same then add a macro to generate code for each method).
lpython/src/libasr/pass/inline_function_calls.cpp
Lines 98 to 123 in 1f60cf0
certik
commented
Apr 12, 2023
I think the bug is in the inline pass. It must create a unique name for the |
certik
commented
Apr 12, 2023
Rather, it looks like the issue is that the Block symbol points to the old location and BlockCall is calling it from the old location, so one gets the following error message: caused by: So it looks like the nested function pass needs to copy over the Block symbol (duplicate). |
#1688 (comment) is the correct approach. If one is not doing it fully then ASR verify pass errors will always be there. Also I think editing is not happening correctly for BlockCall. https://github.com/lcompilers/lpython/pull/1688/files#r1161810225 isn’t addressed yet. |
1f60cf0 to
165df87Compare165df87 to
63fbb9dCompareThirumalai-Shaktivel
commented
Apr 13, 2023
This seems to fix the issue. |
czgdp1807
commented
Apr 14, 2023
If you are not sure then apply changes to LFortran and see if they work there. If they do then we are good. More testing should ensure that we are not facing any bugs. |
czgdp1807
commented
Apr 14, 2023
Also, I think we should have a |
Yes, we need |
Thirumalai-Shaktivel
commented
Apr 17, 2023
LFortran PR: lfortran/lfortran#1566 |
Fixes: #1668