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

Warning "Op Not Converted: JUMP_IF_FALSE_OR_POP" when running unittest #27

Open
Chubby-Chocobo opened this issue Jun 19, 2018 · 1 comment

Comments

@Chubby-Chocobo
Copy link

Hi, after trying to add some functions to the template, I got this kind of warning when running unit-tests:

[I 180619 08:00:35 pytoken:253] Op Not Converted: JUMP_IF_FALSE_OR_POP

I cut off my additional code, until there's only function declaration left, the warning still appears.
The function is like this:

def foo(ctx, param1, param2, param3):

    if param1 == 0:
        print('case1: param1 == 0')
        return 0

    if param2 == 0:
        print('case2: param1 == 0')
        return 0

    temp_var1 = 0
    stored_value1 = Get(ctx, 'value1')
    stored_value2 = Get(ctx, 'value2')
    stored_value3 = Get(ctx, 'value3')
    stored_value4 = Get(ctx, 'value4')
    stored_value5 = Get(ctx, 'value5')
    stored_value6 = Get(ctx, 'value6')

    if (stored_value1 <= param3) and (param3 <= stored_value2):
        if not Get(ctx, 'condition1'):
            print('case3: condition1')
            return 0

        temp_var1 = stored_value2 + param3
        temp_var2 = stored_value3 + param2

        if temp_var2 > stored_value4:
            stored_value7 = Get(ctx, 'value7')
            if stored_value7 > temp_var1:
                return 0

            return stored_value7

        if temp_var2 > stored_value5:
            temp_var1 = stored_value5 + stored_value6
            if (temp_var1 > param1):
                return stored_value6

        return temp_var1

    if (stored_value3 <= param3) and (param3 <= stored_value4):
        temp_var1 = param1 + param2 + param3
        return temp_var1

    return 0

The weird thing is if I remove some random statement, for example print('case1: param1 == 0') or temp_var1 = param1 + param2 + param3, the warning is gone.
The function is just declared, not used anywhere yet.
To reproduce, you can checkout this commit: Chubby-Chocobo@5e3a3b2, then run the unittest: python -m unittest discover tests

I asked on Discord, and @localhuman advised we should not ignore this warning.
I'm not sure whether it relate to neo-boa compiler or this ico-template, so I'm just report here. Please help to tag right people to check.
Thank you very much.

@conscott
Copy link

conscott commented Jun 19, 2018

I suspect this has something to do with your nested conditionals. To understand why neo-boa might complain it helps to understand how the compiler works.

First it will generate normal python bytecode (something we have no control over) and then try to translate this into NEO VM code. The problem is that neo-boa doesn't always handle every possible bytecode operation that python can generate. In this case, it encounters a JUMP_IF_FALSE_OR_POP instruction, which it doesn't currently know how to handle, so it just skips it (which is probably bad).

Given that you probably don't want to deep dive into neo-boa and try to add support for JUMP_IF_FALSE_OR_POP - I would suggest maybe restructuring your conditionals until the problem goes away. In the general, it seems if you are able to stay away from complex nested conditionals (like 3 levels of if statements), this doesn't happen.

This is somewhat of an annoyance because you do have valid python code, but the neo-boa just doesn't know how to translate it based on the bytecode that's been generated.

You will encounter these issues when you try to do complex python code.

Does that sound more or less correct @localhuman ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants