Skip to content

Commit b382eed

Browse files
authored
Merge pull request #2394 from arteevraina/asr-verify-update
refactor: check for dependency only in parent scope
2 parents dcaf253 + c487d20 commit b382eed

File tree

3 files changed

+61
-22
lines changed

3 files changed

+61
-22
lines changed

src/libasr/asr_utils.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
} \
2121
SymbolTable* temp_scope = current_scope; \
2222
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter() && \
23-
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && \
24-
!ASR::is_a<ASR::Variable_t>(*final_sym)) { \
25-
current_function_dependencies.push_back(al, ASRUtils::symbol_name(final_sym)); \
23+
!ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && !ASR::is_a<ASR::Variable_t>(*final_sym)) { \
24+
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) { \
25+
temp_scope = temp_scope->parent; \
26+
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter()) { \
27+
current_function_dependencies.push_back(al, ASRUtils::symbol_name(final_sym)); \
28+
} \
29+
} else { \
30+
current_function_dependencies.push_back(al, ASRUtils::symbol_name(final_sym)); \
31+
} \
2632
} \
2733

2834
#define ADD_ASR_DEPENDENCIES_WITH_NAME(current_scope, final_sym, current_function_dependencies, dep_name) ASR::symbol_t* asr_owner_sym = nullptr; \
@@ -31,9 +37,15 @@
3137
} \
3238
SymbolTable* temp_scope = current_scope; \
3339
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter() && \
34-
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && \
35-
!ASR::is_a<ASR::Variable_t>(*final_sym)) { \
36-
current_function_dependencies.push_back(al, dep_name); \
40+
!ASR::is_a<ASR::ExternalSymbol_t>(*final_sym) && !ASR::is_a<ASR::Variable_t>(*final_sym)) { \
41+
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) { \
42+
temp_scope = temp_scope->parent; \
43+
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(final_sym)->get_counter()) { \
44+
current_function_dependencies.push_back(al, dep_name); \
45+
} \
46+
} else { \
47+
current_function_dependencies.push_back(al, dep_name); \
48+
} \
3749
} \
3850

3951
namespace LCompilers {

src/libasr/asr_verify.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,15 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
441441
verify_unique_dependencies(x.m_dependencies, x.n_dependencies,
442442
x.m_name, x.base.base.loc);
443443

444-
// Get the x symtab.
445-
SymbolTable *x_symtab = x.m_symtab;
444+
// Get the x parent symtab.
445+
SymbolTable *x_parent_symtab = x.m_symtab->parent;
446446

447447
// Dependencies of the function should be from function's parent symbol table.
448448
for( size_t i = 0; i < x.n_dependencies; i++ ) {
449449
std::string found_dep = x.m_dependencies[i];
450450

451451
// Get the symbol of the found_dep.
452-
ASR::symbol_t* dep_sym = x_symtab->resolve_symbol(found_dep);
452+
ASR::symbol_t* dep_sym = x_parent_symtab->resolve_symbol(found_dep);
453453

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

892892
SymbolTable* temp_scope = current_symtab;
893893

894-
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() &&
895-
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) &&
896-
!ASR::is_a<ASR::Variable_t>(*x.m_name)) {
897-
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
894+
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() &&
895+
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
896+
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
897+
temp_scope = temp_scope->parent;
898+
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
899+
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
900+
}
901+
} else {
902+
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
903+
}
898904
}
899905

900906
if( ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) ) {
@@ -1037,9 +1043,15 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
10371043
SymbolTable* temp_scope = current_symtab;
10381044

10391045
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() &&
1040-
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) &&
1041-
!ASR::is_a<ASR::Variable_t>(*x.m_name)) {
1042-
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
1046+
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
1047+
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
1048+
temp_scope = temp_scope->parent;
1049+
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
1050+
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
1051+
}
1052+
} else {
1053+
function_dependencies.push_back(std::string(ASRUtils::symbol_name(x.m_name)));
1054+
}
10431055
}
10441056

10451057
if( ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) ) {

src/libasr/pass/pass_utils.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,15 @@ namespace LCompilers {
341341
SymbolTable* temp_scope = current_scope;
342342

343343
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() &&
344-
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) &&
345-
!ASR::is_a<ASR::Variable_t>(*x.m_name)) {
346-
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
344+
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
345+
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
346+
temp_scope = temp_scope->parent;
347+
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
348+
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
349+
}
350+
} else {
351+
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
352+
}
347353
}
348354
}
349355

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

369375
if (asr_owner_sym && temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter() &&
370-
!ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) && !ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) &&
371-
!ASR::is_a<ASR::Variable_t>(*x.m_name)) {
372-
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
376+
!ASR::is_a<ASR::ExternalSymbol_t>(*x.m_name) && !ASR::is_a<ASR::Variable_t>(*x.m_name)) {
377+
if (ASR::is_a<ASR::AssociateBlock_t>(*asr_owner_sym) || ASR::is_a<ASR::Block_t>(*asr_owner_sym)) {
378+
temp_scope = temp_scope->parent;
379+
if (temp_scope->get_counter() != ASRUtils::symbol_parent_symtab(x.m_name)->get_counter()) {
380+
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
381+
}
382+
} else {
383+
function_dependencies.push_back(al, ASRUtils::symbol_name(x.m_name));
384+
}
373385
}
374386
}
375387

@@ -384,10 +396,13 @@ namespace LCompilers {
384396
}
385397

386398
void visit_BlockCall(const ASR::BlockCall_t& x) {
399+
SymbolTable *parent_symtab = current_scope;
387400
ASR::Block_t* block = ASR::down_cast<ASR::Block_t>(x.m_m);
401+
current_scope = block->m_symtab;
388402
for (size_t i=0; i<block->n_body; i++) {
389403
visit_stmt(*(block->m_body[i]));
390404
}
405+
current_scope = parent_symtab;
391406
}
392407

393408
void visit_AssociateBlock(const ASR::AssociateBlock_t& x) {

0 commit comments

Comments
 (0)