-
Notifications
You must be signed in to change notification settings - Fork 171
Implemented ASR checks for function dependencies #2167
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
Changes from all commits
049fbc6
fc86d98
42d5146
4805b69
71bee66
70f2f9c
a2e802b
8d8bbc7
c1116e3
b531009
2c436ba
6fc8a6d
f1d77ae
f94840f
47d0f5d
456071b
ca26122
dd2d3ab
681514f
433d944
14632b4
0491339
d943c5a
f97063f
b1d00d4
c1c8bd2
f1e1c2f
261c187
6f7c8fa
ccaa3ec
f68f71a
0c7e8b5
74e4251
1801bb5
895f411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,6 +441,20 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor> | |
verify_unique_dependencies(x.m_dependencies, x.n_dependencies, | ||
x.m_name, x.base.base.loc); | ||
|
||
// Get the x symtab. | ||
SymbolTable *x_symtab = x.m_symtab; | ||
|
||
// Dependencies of the function should be from function's parent symbol table. | ||
for( size_t i = 0; i < x.n_dependencies; i++ ) { | ||
std::string found_dep = x.m_dependencies[i]; | ||
|
||
// Get the symbol of the found_dep. | ||
ASR::symbol_t* dep_sym = x_symtab->resolve_symbol(found_dep); | ||
|
||
require(dep_sym != nullptr, | ||
"Dependency " + found_dep + " is inside symbol table " + std::string(x.m_name)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am trying to understand the logic here. Are we ensuring that all dependencies are from the same parent symbol table? It seems this logic is testing that all the symbols (except ExternalSymbol) are NOT from the parent symbol table. Tests pass, so I guess this is the correct logic, but I don't understand it. Once I understand it, let's document this as a comment. |
||
|
||
// Check if there are unnecessary dependencies | ||
// present in the dependency list of the function | ||
for( size_t i = 0; i < x.n_dependencies; i++ ) { | ||
|
@@ -870,7 +884,19 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor> | |
} | ||
} | ||
|
||
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name))); | ||
ASR::symbol_t* asr_owner_sym = nullptr; | ||
if(current_symtab->asr_owner && ASR::is_a<ASR::symbol_t>(*current_symtab->asr_owner) ) { | ||
asr_owner_sym = ASR::down_cast<ASR::symbol_t>(current_symtab->asr_owner); | ||
} | ||
|
||
SymbolTable* temp_scope = current_symtab; | ||
|
||
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() && | ||
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && | ||
!ASR::is_a<ASR::Variable_t>(*x.m_name)) { | ||
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name))); | ||
} | ||
|
||
if( ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) ) { | ||
ASR::ExternalSymbol_t* x_m_name = ASR::down_cast<ASR::ExternalSymbol_t>(x.m_name); | ||
if( x_m_name->m_external && ASR::is_a<ASR::Module_t>(*ASRUtils::get_asr_owner(x_m_name->m_external)) ) { | ||
|
@@ -1003,7 +1029,19 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor> | |
void visit_FunctionCall(const FunctionCall_t &x) { | ||
require(x.m_name, | ||
"FunctionCall::m_name must be present"); | ||
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name))); | ||
ASR::symbol_t* asr_owner_sym = nullptr; | ||
if(current_symtab->asr_owner && ASR::is_a<ASR::symbol_t>(*current_symtab->asr_owner) ) { | ||
asr_owner_sym = ASR::down_cast<ASR::symbol_t>(current_symtab->asr_owner); | ||
} | ||
|
||
SymbolTable* temp_scope = current_symtab; | ||
|
||
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() && | ||
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && | ||
!ASR::is_a<ASR::Variable_t>(*x.m_name)) { | ||
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name))); | ||
} | ||
|
||
if( ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) ) { | ||
ASR::ExternalSymbol_t* x_m_name = ASR::down_cast<ASR::ExternalSymbol_t>(x.m_name); | ||
if( x_m_name->m_external && ASR::is_a<ASR::Module_t>(*ASRUtils::get_asr_owner(x_m_name->m_external)) ) { | ||
|
arteevraina marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
warning: The module 'numpy' located in $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py cannot be loaded | ||
--> tests/../integration_tests/array_01_decl.py:2:1 | ||
| | ||
2 | from numpy import empty, int16, int32, int64, float32, float64, complex64, complex128 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here | ||
|
||
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems there are several errors like above that got committed in this PR. Are these reference errors expected or is it a bug? |
||
warning: The module 'lpython_builtin' located in $DIR/src/bin/../runtime/lpython_builtin.py cannot be loaded | ||
--> $DIR/src/bin/../runtime/lpython_intrinsic_numpy.py:364:12 | ||
| | ||
364 | return x1 % x2 | ||
| ^^^^^^^ imported here | ||
|
||
semantic error: The symbol '_lpython_floordiv' not found in the module 'lpython_builtin' | ||
--> $DIR/src/bin/../runtime/lpython_builtin.py:209:15 | ||
| | ||
209 | if (n_ - (n_ // 2)*2) == 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.
I think this should be
"Dependency " + found_dep + " is not* inside symbol table "
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.
correct, "not inside".
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.
Yes, you both are right.
I assumed the
resolve_symbol
checks in parent scope only and not in thecurrent_scope
. Now that i checked it's documentation, it checks both in current & parent scopes.The check should will be updated like this :
SymbolTable *x_parent_symtab = x.m_symtab->parent;
instead ofSymbolTable* x_symtab = x.m_symtab;
and then "inside" phrase will make sense here.