Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error occurs when using --fast with float values #1671

Closed
@gptsarthak

Description

@gptsarthak

The following compiles successfully:

def test_i32() -> i32:
    a : i32 = 5
    a = a + a * 10 
    return a

print(test_i32())
(base) sarthak@pop-os:~/lpython/examples$ lpython --fast add.py
55

But the same program using f64 instead of i32 gives the error:
LCompilersException: Module 'lfortran_intrinsic_optimization' not declared in the current source and the modfile was not found:

def test_i64() -> f64:
    a : f64 = 5.00
    a = a + a * 10.00 
    return a
    # Note: It works if we do
    # b : f64 = a * 10.00 
    # a = a + b 

print(test_i64())
Full Error
(base) sarthak@pop-os:~/lpython/examples$ lpython --fast add.py 
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  Binary file "/home/sarthak/lpython/src/bin/lpython", in _start()
  File "./csu/../csu/libc-start.c", line 392, in __libc_start_main_impl()
  File "./csu/../sysdeps/nptl/libc_start_call_main.h", line 58, in __libc_start_call_main()
  File "/home/sarthak/lpython/src/bin/lpython.cpp", line 1750, in ??
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
  File "/home/sarthak/lpython/src/bin/lpython.cpp", line 750, in ??
    res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
  File "/home/sarthak/lpython/src/lpython/python_evaluator.cpp", line 58, in LCompilers::PythonCompiler::get_llvm3(LCompilers::ASR::TranslationUnit_t&, LCompilers::PassManager&, LCompilers::diag::Diagnostics&, std::__cxx11::basic_string, std::allocator > const&)
    run_fn, infile);
  File "/home/sarthak/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 7027, in LCompilers::asr_to_llvm(LCompilers::ASR::TranslationUnit_t&, LCompilers::diag::Diagnostics&, llvm::LLVMContext&, Allocator&, LCompilers::PassManager&, LCompilers::CompilerOptions&, std::__cxx11::basic_string, std::allocator > const&, std::__cxx11::basic_string, std::allocator > const&)
    pass_manager.apply_passes(al, &asr, pass_options, diagnostics);
  File "/home/sarthak/lpython/src/libasr/pass/pass_manager.h", line 214, in LCompilers::PassManager::apply_passes(Allocator&, LCompilers::ASR::TranslationUnit_t*, LCompilers::PassOptions&, LCompilers::diag::Diagnostics&)
    _apply_passes(al, asr, _with_optimization_passes, pass_options,
  File "/home/sarthak/lpython/src/libasr/pass/pass_manager.h", line 106, in LCompilers::PassManager::_apply_passes(Allocator&, LCompilers::ASR::TranslationUnit_t*, std::vector, std::allocator >, std::allocator, std::allocator > > >&, LCompilers::PassOptions&, LCompilers::diag::Diagnostics&)
    _passes_db[passes[i]](al, *asr, pass_options);
  File "/home/sarthak/lpython/src/libasr/pass/fma.cpp", line 172, in LCompilers::pass_replace_fma(Allocator&, LCompilers::ASR::TranslationUnit_t&, LCompilers::PassOptions const&)
    v.visit_TranslationUnit(unit);
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4673, in LCompilers::ASR::BaseWalkVisitor::visit_TranslationUnit(LCompilers::ASR::TranslationUnit_t const&)
    this->visit_symbol(*a.second);
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4480, in LCompilers::ASR::BaseVisitor::visit_symbol(LCompilers::ASR::symbol_t const&)
    void visit_symbol(const symbol_t &b) { visit_symbol_t(b, self()); }
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4220, in ??
    case symbolType::Module: { v.visit_Module((const Module_t &)x); return; }
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4686, in LCompilers::ASR::BaseWalkVisitor::visit_Module(LCompilers::ASR::Module_t const&)
    this->visit_symbol(*a.second);
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4480, in LCompilers::ASR::BaseVisitor::visit_symbol(LCompilers::ASR::symbol_t const&)
    void visit_symbol(const symbol_t &b) { visit_symbol_t(b, self()); }
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4221, in ??
    case symbolType::Function: { v.visit_Function((const Function_t &)x); return; }
  File "/home/sarthak/lpython/src/libasr/../libasr/pass/pass_utils.h", line 281, in LCompilers::PassUtils::SkipOptimizationFunctionVisitor::visit_Function(LCompilers::ASR::Function_t const&)
    PassUtils::PassVisitor::visit_Function(x);
  File "/home/sarthak/lpython/src/libasr/../libasr/pass/pass_utils.h", line 192, in LCompilers::PassUtils::PassVisitor::visit_Function(LCompilers::ASR::Function_t const&)
    transform_stmts(xx.m_body, xx.n_body);
  File "/home/sarthak/lpython/src/libasr/../libasr/pass/pass_utils.h", line 144, in LCompilers::PassUtils::PassVisitor::transform_stmts(LCompilers::ASR::stmt_t**&, unsigned long&)
    self().visit_stmt(*m_body[i]);
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4495, in LCompilers::ASR::BaseVisitor::visit_stmt(LCompilers::ASR::stmt_t const&)
    void visit_stmt(const stmt_t &b) { visit_stmt_t(b, self()); }
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4242, in ??
    case stmtType::Assignment: { v.visit_Assignment((const Assignment_t &)x); return; }
  File "/home/sarthak/lpython/src/libasr/pass/fma.cpp", line 130, in LCompilers::FMAVisitor::visit_Assignment(LCompilers::ASR::Assignment_t const&)
    visit_expr(*x.m_value);
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4540, in LCompilers::ASR::BaseVisitor::visit_expr(LCompilers::ASR::expr_t const&)
    void visit_expr(const expr_t &b) { visit_expr_t(b, self()); }
  File "/home/sarthak/lpython/src/libasr/../libasr/asr.h", line 4308, in ??
    case exprType::RealBinOp: { v.visit_RealBinOp((const RealBinOp_t &)x); return; }
  File "/home/sarthak/lpython/src/libasr/pass/fma.cpp", line 120, in LCompilers::FMAVisitor::visit_RealBinOp(LCompilers::ASR::RealBinOp_t const&)
    fma_var = PassUtils::get_fma(other_expr, first_arg, second_arg,
  File "/home/sarthak/lpython/src/libasr/pass/pass_utils.cpp", line 632, in LCompilers::PassUtils::get_fma(LCompilers::ASR::expr_t*, LCompilers::ASR::expr_t*, LCompilers::ASR::expr_t*, Allocator&, LCompilers::ASR::TranslationUnit_t&, LCompilers::PassOptions&, LCompilers::SymbolTable*&, LCompilers::Location&, std::function, std::allocator > const&, LCompilers::Location const&)>)
    ASR::symbol_t *v = import_generic_procedure("fma", "lfortran_intrinsic_optimization",
  File "/home/sarthak/lpython/src/libasr/pass/pass_utils.cpp", line 405, in LCompilers::PassUtils::import_generic_procedure(std::__cxx11::basic_string, std::allocator >, std::__cxx11::basic_string, std::allocator >, Allocator&, LCompilers::ASR::TranslationUnit_t&, LCompilers::PassOptions&, LCompilers::SymbolTable*&, LCompilers::Location&)
    ASR::Module_t *m = ASRUtils::load_module(al, current_scope,
  File "/home/sarthak/lpython/src/libasr/asr_utils.cpp", line 172, in LCompilers::ASRUtils::load_module(Allocator&, LCompilers::SymbolTable*, std::__cxx11::basic_string, std::allocator > const&, LCompilers::Location const&, bool, LCompilers::PassOptions&, bool, std::function, std::allocator > const&, LCompilers::Location const&)>)
    err("Module '" + module_name + "' not declared in the current source and the modfile was not found",
  File "/usr/include/c++/11/bits/std_function.h", line 590, in std::function, std::allocator > const&, LCompilers::Location const&)>::operator()(std::__cxx11::basic_string, std::allocator > const&, LCompilers::Location const&) const
    return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
  File "/usr/include/c++/11/bits/std_function.h", line 290, in ??
    return std::__invoke_r<_Res>(*_Base::_M_get_pointer(__functor),
  File "/usr/include/c++/11/bits/invoke.h", line 111, in ??
    std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
  File "/usr/include/c++/11/bits/invoke.h", line 61, in ??
    { return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
LCompilersException: Module 'lfortran_intrinsic_optimization' not declared in the current source and the modfile was not found

Note: This seems to be related to #723 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions