Skip to content

Commit

Permalink
Merge pull request lcompilers#2394 from arteevraina/asr-verify-update
Browse files Browse the repository at this point in the history
refactor: check for dependency only in parent scope
  • Loading branch information
certik committed Nov 5, 2023
2 parents dcaf253 + c487d20 commit b382eed
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
24 changes: 18 additions & 6 deletions src/libasr/asr_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
} \
SymbolTable* temp_scope = current_scope; \
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter() && \
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && \
!ASR::is_a<ASR::Variable_t>(*final_sym)) { \
current_function_dependencies.push_back(al, ASRUtils::symbol_name(final_sym)); \
!ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && !ASR::is_a<ASR::Variable_t>(*final_sym)) { \
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) { \
temp_scope = temp_scope->parent; \
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter()) { \
current_function_dependencies.push_back(al, ASRUtils::symbol_name(final_sym)); \
} \
} else { \
current_function_dependencies.push_back(al, ASRUtils::symbol_name(final_sym)); \
} \
} \

#define ADD_ASR_DEPENDENCIES_WITH_NAME(current_scope, final_sym, current_function_dependencies, dep_name) ASR::symbol_t* asr_owner_sym = nullptr; \
Expand All @@ -31,9 +37,15 @@
} \
SymbolTable* temp_scope = current_scope; \
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter() && \
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && \
!ASR::is_a<ASR::Variable_t>(*final_sym)) { \
current_function_dependencies.push_back(al, dep_name); \
!ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && !ASR::is_a<ASR::Variable_t>(*final_sym)) { \
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) { \
temp_scope = temp_scope->parent; \
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter()) { \
current_function_dependencies.push_back(al, dep_name); \
} \
} else { \
current_function_dependencies.push_back(al, dep_name); \
} \
} \

namespace LCompilers {
Expand Down
32 changes: 22 additions & 10 deletions src/libasr/asr_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ 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;
// Get the x parent symtab.
SymbolTable *x_parent_symtab = 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 = x_symtab->resolve_symbol(found_dep);
ASR::symbol_t* dep_sym = x_parent_symtab->resolve_symbol(found_dep);

require(dep_sym != nullptr,
"Dependency " + found_dep + " is inside symbol table " + std::string(x.m_name));
Expand Down Expand Up @@ -891,10 +891,16 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>

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_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() &&
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
temp_scope = temp_scope->parent;
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
}
} else {
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
}
}

if( ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) ) {
Expand Down Expand Up @@ -1037,9 +1043,15 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
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)));
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
temp_scope = temp_scope->parent;
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
}
} else {
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
}
}

if( ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) ) {
Expand Down
27 changes: 21 additions & 6 deletions src/libasr/pass/pass_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,15 @@ namespace LCompilers {
SymbolTable* temp_scope = current_scope;

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(al, ASRUtils::symbol_name(x.m_name));
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
temp_scope = temp_scope->parent;
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
}
} else {
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
}
}
}

Expand All @@ -367,9 +373,15 @@ namespace LCompilers {
SymbolTable* temp_scope = current_scope;

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(al, ASRUtils::symbol_name(x.m_name));
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
temp_scope = temp_scope->parent;
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
}
} else {
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
}
}
}

Expand All @@ -384,10 +396,13 @@ namespace LCompilers {
}

void visit_BlockCall(const ASR::BlockCall_t& x) {
SymbolTable *parent_symtab = current_scope;
ASR::Block_t* block = ASR::down_cast<ASR::Block_t>(x.m_m);
current_scope = block->m_symtab;
for (size_t i=0; i<block->n_body; i++) {
visit_stmt(*(block->m_body[i]));
}
current_scope = parent_symtab;
}

void visit_AssociateBlock(const ASR::AssociateBlock_t& x) {
Expand Down

0 comments on commit b382eed

Please sign in to comment.