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

Import issues #2829

Merged
merged 3 commits into from
Mar 22, 2025
Merged
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
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -606,6 +606,7 @@ RUN(NAME test_import_04 LABELS cpython llvm llvm_jit c)
RUN(NAME test_import_05 LABELS cpython llvm llvm_jit c wasm wasm_x86 wasm_x64)
RUN(NAME test_import_06 LABELS cpython llvm llvm_jit)
RUN(NAME test_import_07 LABELS cpython llvm llvm_jit c)
RUN(NAME test_import_08 LABELS cpython llvm)
RUN(NAME test_math LABELS cpython llvm llvm_jit NOFAST)
RUN(NAME test_membership_01 LABELS cpython llvm)
RUN(NAME test_numpy_01 LABELS cpython llvm llvm_jit c)
3 changes: 3 additions & 0 deletions integration_tests/test_import_08.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show the output of executing this with the lpython built from latest main branch? I would like to see this test getting failed with the current lpython.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current lpython main

% src/bin/lpython test.py -I.
ASR verify pass error: Module __main__ dependencies must contain string because a function present in it is getting called in __main__.
Internal Compiler Error: Unhandled exception
^C

cpython

% python3 test.py
Inside import

lpython after changes

% src/bin/lpython test.py -I.
Inside import

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import string

import test_import_08_module
6 changes: 6 additions & 0 deletions integration_tests/test_import_08_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from lpython import i32

a: i32 = 10
b: i32 = a + 10

print("Inside import")
11 changes: 11 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
@@ -4910,6 +4910,16 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
throw SemanticError("The module '" + mod_sym + "' cannot be loaded",
x.base.base.loc);
}
if( mod_sym == "__init__" ) {
for( auto item: ASRUtils::symbol_symtab(t)->get_scope() ) {
if( ASR::is_a<ASR::ExternalSymbol_t>(*item.second) ) {
current_module_dependencies.push_back(al,
ASR::down_cast<ASR::ExternalSymbol_t>(item.second)->m_module_name);
}
}
} else {
current_module_dependencies.push_back(al, s2c(al, mod_sym));
}
}
}

@@ -5114,6 +5124,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
tmp = nullptr;
tmp_vec.clear();
visit_stmt(*x.m_body[i]);

for (auto t: global_init) {
if (t) {
items.push_back(al, t);
Loading