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

Fix scoping issue #2161

Merged
merged 10 commits into from
Jul 16, 2023
Prev Previous commit
Next Next commit
Remove unused passes global_stmts_program, global_symbols
Remove unused function move_symbols_from_global_scope()

The global_symbols pass that uses it was removed. This function is
unused now.
  • Loading branch information
Shaikh-Ubaid committed Jul 16, 2023
commit aea2a6f87bb735d03eb027163e862fa4a1ce6df0
2 changes: 0 additions & 2 deletions src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ set(SRC
pass/do_loops.cpp
pass/for_all.cpp
pass/global_stmts.cpp
pass/global_stmts_program.cpp
pass/global_symbols.cpp
pass/select_case.cpp
pass/init_expr.cpp
pass/implied_do_loops.cpp
Expand Down
98 changes: 0 additions & 98 deletions src/libasr/asr_scopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,102 +96,4 @@ std::string SymbolTable::get_unique_name(const std::string &name, bool use_uniqu
return unique_name;
}

void SymbolTable::move_symbols_from_global_scope(Allocator &al,
SymbolTable *module_scope, Vec<char *> &syms,
SetChar &mod_dependencies) {
// TODO: This isn't scalable. We have write a visitor in asdl_cpp.py
syms.reserve(al, 4);
mod_dependencies.reserve(al, 4);
for (auto &a : scope) {
switch (a.second->type) {
case (ASR::symbolType::Module): {
// Pass
break;
} case (ASR::symbolType::Function) : {
ASR::Function_t *fn = ASR::down_cast<ASR::Function_t>(a.second);
for (size_t i = 0; i < fn->n_dependencies; i++ ) {
ASR::symbol_t *s = fn->m_symtab->get_symbol(
fn->m_dependencies[i]);
if (s == nullptr) {
std::string block_name = "block";
ASR::symbol_t *block_s = fn->m_symtab->get_symbol(block_name);
int32_t j = 1;
while(block_s != nullptr) {
while(block_s != nullptr) {
ASR::Block_t *b = ASR::down_cast<ASR::Block_t>(block_s);
s = b->m_symtab->get_symbol(fn->m_dependencies[i]);
if (s == nullptr) {
block_s = b->m_symtab->get_symbol("block");
} else {
break;
}
}
if (s == nullptr) {
block_s = fn->m_symtab->get_symbol(block_name +
std::to_string(j));
j++;
} else {
break;
}
}
}
if (s == nullptr) {
s = fn->m_symtab->parent->get_symbol(fn->m_dependencies[i]);
}
if (s != nullptr && ASR::is_a<ASR::ExternalSymbol_t>(*s)) {
char *es_name = ASR::down_cast<
ASR::ExternalSymbol_t>(s)->m_module_name;
mod_dependencies.push_back(al, es_name);
}
}
fn->m_symtab->parent = module_scope;
module_scope->add_symbol(a.first, (ASR::symbol_t *) fn);
syms.push_back(al, s2c(al, a.first));
break;
} case (ASR::symbolType::GenericProcedure) : {
ASR::GenericProcedure_t *es = ASR::down_cast<ASR::GenericProcedure_t>(a.second);
es->m_parent_symtab = module_scope;
module_scope->add_symbol(a.first, (ASR::symbol_t *) es);
syms.push_back(al, s2c(al, a.first));
break;
} case (ASR::symbolType::ExternalSymbol) : {
ASR::ExternalSymbol_t *es = ASR::down_cast<ASR::ExternalSymbol_t>(a.second);
mod_dependencies.push_back(al, es->m_module_name);
es->m_parent_symtab = module_scope;
LCOMPILERS_ASSERT(ASRUtils::symbol_get_past_external(a.second));
module_scope->add_symbol(a.first, (ASR::symbol_t *) es);
syms.push_back(al, s2c(al, a.first));
break;
} case (ASR::symbolType::StructType) : {
ASR::StructType_t *st = ASR::down_cast<ASR::StructType_t>(a.second);
st->m_symtab->parent = module_scope;
module_scope->add_symbol(a.first, (ASR::symbol_t *) st);
syms.push_back(al, s2c(al, a.first));
break;
} case (ASR::symbolType::EnumType) : {
ASR::EnumType_t *et = ASR::down_cast<ASR::EnumType_t>(a.second);
et->m_symtab->parent = module_scope;
module_scope->add_symbol(a.first, (ASR::symbol_t *) et);
syms.push_back(al, s2c(al, a.first));
break;
} case (ASR::symbolType::UnionType) : {
ASR::UnionType_t *ut = ASR::down_cast<ASR::UnionType_t>(a.second);
ut->m_symtab->parent = module_scope;
module_scope->add_symbol(a.first, (ASR::symbol_t *) ut);
syms.push_back(al, s2c(al, a.first));
break;
} case (ASR::symbolType::Variable) : {
ASR::Variable_t *v = ASR::down_cast<ASR::Variable_t>(a.second);
v->m_parent_symtab = module_scope;
module_scope->add_symbol(a.first, (ASR::symbol_t *) v);
syms.push_back(al, s2c(al, a.first));
break;
} default : {
throw LCompilersException("Moving the symbol:`" + a.first +
"` from global scope is not implemented yet");
}
}
}
}

} // namespace LCompilers
4 changes: 0 additions & 4 deletions src/libasr/asr_scopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ struct SymbolTable {
size_t n_scope_names, char **m_scope_names);

std::string get_unique_name(const std::string &name, bool use_unique_id=true);

void move_symbols_from_global_scope(Allocator &al,
SymbolTable *module_scope, Vec<char *> &syms,
SetChar &mod_dependencies);
};

} // namespace LCompilers
Expand Down
2 changes: 0 additions & 2 deletions src/libasr/gen_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"replace_fma",
"replace_for_all",
"wrap_global_stmts",
"wrap_global_stmts_program",
"wrap_global_symbols",
"replace_implied_do_loops",
"replace_init_expr",
"inline_function_calls",
Expand Down
72 changes: 0 additions & 72 deletions src/libasr/pass/global_stmts_program.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions src/libasr/pass/global_symbols.cpp

This file was deleted.

14 changes: 0 additions & 14 deletions src/libasr/pass/wrap_global_stmts_program.h

This file was deleted.

14 changes: 0 additions & 14 deletions src/libasr/pass/wrap_global_symbols.h

This file was deleted.

1 change: 0 additions & 1 deletion src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <libasr/config.h>
#include <libasr/string_utils.h>
#include <libasr/utils.h>
#include <libasr/pass/wrap_global_stmts_program.h>
#include <libasr/pass/instantiate_template.h>
#include <libasr/pass/wrap_global_stmts.h>
#include <libasr/pass/intrinsic_function_registry.h>
Expand Down