Skip to content

Unifying RETURN_VALUE bytecode #90

Open
@sklam

Description

@sklam

The RETURN_VALUE bytecode is not unified by when SCFG join returns. This leads to SCFG that semantically terminates in the middle of switches.

For example:

import dis
from numba_rvsdg.core.datastructures.scfg import SCFG
from numba_rvsdg.core.datastructures.byte_flow import ByteFlow

def example(x):
    if x:
        return 1
    else:
        return 2


dis.dis(example)

bf = ByteFlow.from_bytecode(example).restructure()
bf.scfg.view()

The bytecode is:

  5           0 RESUME                   0

  6           2 LOAD_FAST                0 (x)
              4 POP_JUMP_FORWARD_IF_FALSE     2 (to 10)

  7           6 LOAD_CONST               1 (1)
              8 RETURN_VALUE

  9     >>   10 LOAD_CONST               2 (2)
             12 RETURN_VALUE

The SCFG
Screenshot 2023-07-31 at 6 28 27 PM

Notice that both "branch" regions contain a RETURN_VALUE.

I have two workarounds at sklam/numba@c9d3634:

Update - Aug 4

I have a new workaround that solely addresses the problem in RVSDG->NumbaIR (bcinterp.py) at numba/numba@a117aae. It relies on interpreting RETURN_VALUE as non terminating.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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