-
Notifications
You must be signed in to change notification settings - Fork 170
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 26 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,32 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor> | |
verify_unique_dependencies(x.m_dependencies, x.n_dependencies, | ||
x.m_name, x.base.base.loc); | ||
|
||
// Get the x parent symtab. | ||
SymbolTable *sym = x.m_symtab->parent; | ||
|
||
// 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 = sym->get_symbol(found_dep); | ||
|
||
if (dep_sym == nullptr) { | ||
// The symbol `dep_sym` is not in the parent symbol table. For | ||
// now we allow one exception: it can also be in the global scope. | ||
ASR::symbol_t* dep_sym_global = sym->resolve_symbol(found_dep); | ||
|
||
if (dep_sym_global != nullptr && ASRUtils::symbol_parent_symtab(dep_sym_global)->parent == nullptr) { | ||
// This is a global scope symbol, which we allow for now | ||
} else { | ||
// This is not a global scope symbol and not in the parent symbol table, | ||
// Return an error: | ||
require(dep_sym != nullptr, | ||
"Dependency " + found_dep + " was not found in the parent 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++ ) { | ||
|
@@ -868,7 +894,12 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor> | |
} | ||
} | ||
|
||
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name))); | ||
if ((current_symtab->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) || | ||
(ASRUtils::symbol_parent_symtab(x.m_name)->parent == nullptr)) { | ||
// add to dependencies | ||
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)) ) { | ||
|
@@ -1001,7 +1032,13 @@ 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))); | ||
// Check x.m_name is from parent sym tab. | ||
if ((ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() != current_symtab->get_counter()) || | ||
(ASRUtils::symbol_parent_symtab(x.m_name)->parent == nullptr)) { | ||
// add to dependencies | ||
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 |
---|---|---|
|
@@ -506,7 +506,7 @@ | |
[] | ||
.false. | ||
) | ||
[func] | ||
[] | ||
[(Var 6 func) | ||
(Var 6 arg)] | ||
[(= | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ | |
[] | ||
.false. | ||
) | ||
[list] | ||
[] | ||
[] | ||
[(= | ||
(Var 3 s) | ||
|
Uh oh!
There was an error while loading. Please reload this page.