Skip to content
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

refactor: check for dependency only in parent scope #2394

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading