lcompilers / lpython

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

Fixed visit_if for SymbolicCompare cases #2535

Closed anutosh491 closed 5 months ago

anutosh491 commented 5 months ago

The way I addresssed #2532 is by creating a new If node instead of editing the m_test parameter of the old node itself and this works. I think the original code should itself be sufficient but we haven't been able to find the error hence using this.

I've added a test for the same.

anutosh491 commented 5 months ago

Hmm, I think the first two branches do work. We can obviously get them changed but think about this.

Whenever we encounter an if block, something like if x == pi:

1) We first transform/modify the if body through transform_stmts 2) So once that is done, we don't need to add any new if stmt to pass_result 3) Rather just make a change to the m_test field of the if statments . 4) So if x == pi, changes to if basic_eq(x, pi): and the if body has been modified as per the pass too.

Well we have test_gruntz.py on master

def mmrv(e: S, x: S) -> list[S]:
    if not e.has(x):
        list0: list[S] = []
        return list0
    elif e == x:
        list1: list[S] = [x]
        return list1
    elif e.func == log:
        arg0: S = e.args[0]
        list2: list[S] = mmrv(arg0, x)
        return list2
    else:
        raise

which are based on the first two conditions we have. So I think we are doing fine, but just to get rid of any unwanted errors we can address this.

certik commented 5 months ago

Ok. If it works then let it be. I am just surprised that the last case didn't work and I don't see how it is different to the previous two cases.