lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.47k stars 157 forks source link

Verify pass fails in the symbolic pass #2532

Closed certik closed 5 months ago

certik commented 5 months ago
from lpython import S
from sympy import Symbol, pi

def test_main():
    x: S = Symbol('x')
    if x == pi:
        print('hi')

test_main()

This gives:

$ lpython a.py --enable-symengine
ASR verify pass error: ASR verify: Function test_main doesn't depend on basic_eq but is found in its dependency list.
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
  File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 1872
    err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
  File "/Users/ondrej/repos/lpython/src/bin/lpython.cpp", line 824
    res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
  File "/Users/ondrej/repos/lpython/src/lpython/python_evaluator.cpp", line 71
    run_fn, infile);
  File "/Users/ondrej/repos/lpython/src/libasr/codegen/asr_to_llvm.cpp", line 9276
    pass_manager.apply_passes(al, &asr, co.po, diagnostics);
  File "/Users/ondrej/repos/lpython/src/libasr/pass/pass_manager.h", line 299
    apply_passes(al, asr, _passes, pass_options, diagnostics);
  File "/Users/ondrej/repos/lpython/src/libasr/pass/pass_manager.h", line 164
    throw LCompilersException("Verify failed in the pass: "
LCompilersException: Verify failed in the pass: symbolic
certik commented 5 months ago

The problem is that the if condition:

                                    (If
                                        (SymbolicCompare
                                            (Var 3 x)
                                            Eq
                                            (IntrinsicScalarFunction
                                                SymbolicPi
                                                []
                                                0
                                                (SymbolicExpression)
                                                ()
                                            )
                                            (Logical 4)
                                            ()
                                        )
                                        [(Print
                                            [(StringConstant
                                                "hi"
                                                (Character 1 2 ())
                                            )]
                                            ()
                                            ()
                                        )]
                                        []
                                    )]

becomes missing after the symbolic pass, so the basic_eq is still in the dependency list, but is not being used, and thus the verify fails.

anutosh491 commented 5 months ago

Fixed by #2535