Skip to content

Commit 842d96c

Browse files
Fix ASR verify pass error while using Interactive
1 parent 0de9355 commit 842d96c

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/libasr/asr_scopes.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <libasr/asr_scopes.h>
55
#include <libasr/asr_utils.h>
6+
#include <libasr/pass/pass_utils.h>
67

78
std::string lcompilers_unique_ID;
89

@@ -39,14 +40,13 @@ void SymbolTable::mark_all_variables_external(Allocator &al) {
3940
case (ASR::symbolType::Function) : {
4041
ASR::Function_t *v = ASR::down_cast<ASR::Function_t>(a.second);
4142
ASR::FunctionType_t* v_func_type = ASR::down_cast<ASR::FunctionType_t>(v->m_function_signature);
42-
if ((v_func_type->m_abi != ASR::abiType::Intrinsic) &&
43-
(v_func_type->m_abi != ASR::abiType::Interactive)) {
44-
v->m_dependencies = nullptr;
45-
v->n_dependencies = 0;
43+
if (v_func_type->m_abi != ASR::abiType::Interactive) {
44+
v_func_type->m_abi = ASR::abiType::Interactive;
4645
v->m_body = nullptr;
4746
v->n_body = 0;
47+
PassUtils::UpdateDependenciesVisitor ud(al);
48+
ud.visit_Function(*v);
4849
}
49-
v_func_type->m_abi = ASR::abiType::Interactive;
5050
break;
5151
}
5252
case (ASR::symbolType::Module) : {

src/libasr/asr_verify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor>
420420
}
421421

422422
void visit_Function(const Function_t &x) {
423+
ASR::FunctionType_t* x_func_type = ASR::down_cast<ASR::FunctionType_t>(x.m_function_signature);
424+
if (x_func_type->m_abi == abiType::Interactive) {
425+
require(x.n_body == 0,
426+
"The Function::n_body should be 0 if abi set to Interactive");
427+
}
423428
std::vector<std::string> function_dependencies_copy = function_dependencies;
424429
function_dependencies.clear();
425430
function_dependencies.reserve(x.n_dependencies);

src/lpython/tests/test_llvm.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,20 @@ TEST_CASE("PythonCompiler 1") {
621621
CHECK(r.ok);
622622
CHECK(r.result.type == PythonCompiler::EvalResult::none); // TODO: change to integer4 and check the value once printing top level expressions is implemented
623623
}
624+
625+
TEST_CASE("PythonCompiler 2") {
626+
CompilerOptions cu;
627+
cu.po.disable_main = true;
628+
cu.emit_debug_line_column = false;
629+
cu.generate_object_code = false;
630+
cu.interactive = true;
631+
cu.po.runtime_library_dir = LCompilers::LPython::get_runtime_library_dir();
632+
PythonCompiler e(cu);
633+
LCompilers::Result<PythonCompiler::EvalResult>
634+
r = e.evaluate2("i: i32 = 3 % 1");
635+
CHECK(r.ok);
636+
CHECK(r.result.type == PythonCompiler::EvalResult::none);
637+
r = e.evaluate2("i");
638+
CHECK(r.ok);
639+
CHECK(r.result.type == PythonCompiler::EvalResult::none); // TODO: change to integer4 and check the value once printing top level expressions is implemented
640+
}

0 commit comments

Comments
 (0)