gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _build_element_wise_ufunc_wrapper(cres, signature):
    """Build a wrapper for the ufunc loop entry point given by the
    compilation result object, using the element-wise signature.
    """
    ctx = cres.target_context
    library = cres.library
    fname = cres.fndesc.llvm_func_name

    env = cres.environment
    envptr = env.as_pointer(ctx)

    ptr = build_ufunc_wrapper(
        library, ctx, fname, signature, cres.objectmode, envptr, env
    )

    # Get dtypes
    dtypenums = [as_dtype(a).num for a in signature.args]
    dtypenums.append(as_dtype(signature.return_type).num)
    return dtypenums, ptr, env


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def _build_element_wise_ufunc_wrapper(cres, signature):
    """Build a wrapper for the ufunc loop entry point given by the
    compilation result object, using the element-wise signature.
    """
    ctx = cres.target_context
    library = cres.library
    fname = cres.fndesc.llvm_func_name

    env = cres.environment
    envptr = env.as_pointer(ctx)

    with compiler.lock_compiler:
        ptr = build_ufunc_wrapper(
            library, ctx, fname, signature, cres.objectmode, envptr, env
        )

    # Get dtypes
    dtypenums = [as_dtype(a).num for a in signature.args]
    dtypenums.append(as_dtype(signature.return_type).num)
    return dtypenums, ptr, env
# Buggy code
def build(self, cres):
    """
    Returns (dtype numbers, function ptr, EnvironmentObject)
    """
    # Buider wrapper for ufunc entry point
    signature = cres.signature
    ptr, env, wrapper_name = build_gufunc_wrapper(
        self.py_func, cres, self.sin, self.sout, cache=self.cache
    )

    # Get dtypes
    dtypenums = []
    for a in signature.args:
        if isinstance(a, types.Array):
            ty = a.dtype
        else:
            ty = a
        dtypenums.append(as_dtype(ty).num)
    return dtypenums, ptr, env


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def build(self, cres):
    """
    Returns (dtype numbers, function ptr, EnvironmentObject)
    """
    # Buider wrapper for ufunc entry point
    signature = cres.signature
    with compiler.lock_compiler:
        ptr, env, wrapper_name = build_gufunc_wrapper(
            self.py_func, cres, self.sin, self.sout, cache=self.cache
        )

    # Get dtypes
    dtypenums = []
    for a in signature.args:
        if isinstance(a, types.Array):
            ty = a.dtype
        else:
            ty = a
        dtypenums.append(as_dtype(ty).num)
    return dtypenums, ptr, env
# Buggy code
def __init__(self, loop_nests, init_block, loop_body, loc, array_analysis, index_var):
    super(Parfor, self).__init__(op="parfor", loc=loc)

    self.id = type(self).id_counter
    type(self).id_counter = +1
    # self.input_info  = input_info
    # self.output_info = output_info
    self.loop_nests = loop_nests
    self.init_block = init_block
    self.loop_body = loop_body
    self.array_analysis = array_analysis
    self.index_var = index_var


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def __init__(self, loop_nests, init_block, loop_body, loc, array_analysis, index_var):
    super(Parfor, self).__init__(op="parfor", loc=loc)

    self.id = type(self).id_counter
    type(self).id_counter += 1
    # self.input_info  = input_info
    # self.output_info = output_info
    self.loop_nests = loop_nests
    self.init_block = init_block
    self.loop_body = loop_body
    self.array_analysis = array_analysis
    self.index_var = index_var
    self.params = None  # filled right before parallel lowering
# Buggy code
def __repr__(self):
    return repr(self.loop_nests) + repr(self.loop_body) + repr(self.index_var)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def __repr__(self):
    return repr(self.loop_nests) + repr(self.loop_body) + repr(self.index_var)
# Buggy code
def dump(self, file=None):
    file = file or sys.stdout
    print(("begin parfor {}".format(self.id)).center(20, "-"), file=file)
    print("index_var = ", self.index_var)
    for loopnest in self.loop_nests:
        print(loopnest, file=file)
    print("init block:", file=file)
    self.init_block.dump()
    for offset, block in sorted(self.loop_body.items()):
        print("label %s:" % (offset,), file=file)
        block.dump(file)
    print(("end parfor").center(20, "-"), file=file)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def dump(self, file=None):
    file = file or sys.stdout
    print(("begin parfor {}".format(self.id)).center(20, "-"), file=file)
    print("index_var = ", self.index_var)
    for loopnest in self.loop_nests:
        print(loopnest, file=file)
    print("init block:", file=file)
    self.init_block.dump()
    for offset, block in sorted(self.loop_body.items()):
        print("label %s:" % (offset,), file=file)
        block.dump(file)
    print(("end parfor {}".format(self.id)).center(20, "-"), file=file)
# Buggy code
def __init__(self, func_ir, typemap, calltypes, return_type):
    self.func_ir = func_ir
    self.typemap = typemap
    self.calltypes = calltypes
    self.return_type = return_type
    self.array_analysis = array_analysis.ArrayAnalysis(func_ir, typemap, calltypes)
    ir_utils._max_label = max(func_ir.blocks.keys())


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def __init__(self, func_ir, typemap, calltypes, return_type, typingctx):
    self.func_ir = func_ir
    self.typemap = typemap
    self.calltypes = calltypes
    self.typingctx = typingctx
    self.return_type = return_type
    self.array_analysis = array_analysis.ArrayAnalysis(func_ir, typemap, calltypes)
    ir_utils._max_label = max(func_ir.blocks.keys())
# Buggy code
def _is_supported_npycall(self, expr):
    """check if we support parfor translation for
    this Numpy call.
    """
    # return False # turn off for now
    if not (isinstance(expr, ir.Expr) and expr.op == "call"):
        return False
    if expr.func.name not in self.array_analysis.numpy_calls.keys():
        return False
    call_name = self.array_analysis.numpy_calls[expr.func.name]
    if call_name in ["zeros", "ones", "random.ranf"]:
        return True
    # TODO: add more calls
    if call_name == "dot":
        # only translate matrix/vector and vector/vector multiply to parfor
        # (don't translate matrix/matrix multiply)
        if (
            self._get_ndims(expr.args[0].name) <= 2
            and self._get_ndims(expr.args[1].name) == 1
        ):
            return True
    return False


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def _is_supported_npycall(self, expr):
    """check if we support parfor translation for
    this Numpy call.
    """
    # return False # turn off for now
    if not (isinstance(expr, ir.Expr) and expr.op == "call"):
        return False
    if expr.func.name not in self.array_analysis.numpy_calls.keys():
        return False
    call_name = self.array_analysis.numpy_calls[expr.func.name]
    supported_calls = ["zeros", "ones"] + random_calls
    if call_name in supported_calls:
        return True
    # TODO: add more calls
    if call_name == "dot":
        # only translate matrix/vector and vector/vector multiply to parfor
        # (don't translate matrix/matrix multiply)
        if (
            self._get_ndims(expr.args[0].name) <= 2
            and self._get_ndims(expr.args[1].name) == 1
        ):
            return True
    return False
# Buggy code
def get_parfor_outputs(parfor):
    """get arrays that are written to inside the parfor and need to be passed
    as parameters to gufunc.
    """
    # FIXME: The following assumes the target of all SetItem are outputs, which is wrong!
    last_label = max(parfor.loop_body.keys())
    outputs = []
    for blk in parfor.loop_body.values():
        for stmt in blk.body:
            if isinstance(stmt, ir.SetItem):
                if stmt.index.name == parfor.index_var.name:
                    outputs.append(stmt.target.name)
    parfor_params = get_parfor_params(parfor)
    # make sure these written arrays are in parfor parameters (live coming in)
    outputs = list(set(outputs) & set(parfor_params))
    return sorted(outputs)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def get_parfor_outputs(parfor, parfor_params):
    """get arrays that are written to inside the parfor and need to be passed
    as parameters to gufunc.
    """
    # FIXME: The following assumes the target of all SetItem are outputs,
    # which is wrong!
    last_label = max(parfor.loop_body.keys())
    outputs = []
    for blk in parfor.loop_body.values():
        for stmt in blk.body:
            if isinstance(stmt, ir.SetItem):
                if stmt.index.name == parfor.index_var.name:
                    outputs.append(stmt.target.name)
    # make sure these written arrays are in parfor parameters (live coming in)
    outputs = list(set(outputs) & set(parfor_params))
    return sorted(outputs)
# Buggy code
def wrap_parfor_blocks(parfor):
    """wrap parfor blocks for analysis/optimization like CFG"""
    blocks = parfor.loop_body.copy()  # shallow copy is enough
    first_body_block = min(blocks.keys())
    assert first_body_block > 0  # we are using 0 for init block here
    last_label = max(blocks.keys())
    loc = blocks[last_label].body[-1].loc

    # add dummy jump in init_block for CFG to work
    blocks[0] = parfor.init_block
    blocks[0].body.append(ir.Jump(first_body_block, loc))
    blocks[last_label].body.append(ir.Jump(first_body_block, loc))
    return blocks


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def wrap_parfor_blocks(parfor):
    """wrap parfor blocks for analysis/optimization like CFG"""
    blocks = parfor.loop_body.copy()  # shallow copy is enough
    first_body_block = min(blocks.keys())
    assert first_body_block > 0  # we are using 0 for init block here
    last_label = max(blocks.keys())
    loc = blocks[last_label].loc

    # add dummy jump in init_block for CFG to work
    blocks[0] = parfor.init_block
    blocks[0].body.append(ir.Jump(first_body_block, loc))
    blocks[last_label].body.append(ir.Jump(first_body_block, loc))
    return blocks
# Buggy code
def unwrap_parfor_blocks(parfor):
    last_label = max(parfor.loop_body.keys())
    parfor.init_block.body.pop()  # remove dummy jump
    parfor.loop_body[last_label].body.pop()  # remove dummy return
    return


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def unwrap_parfor_blocks(parfor, blocks=None):
    """
    unwrap parfor blocks after analysis/optimization.
    Allows changes to the parfor loop.
    """
    if blocks is not None:
        # make sure init block isn't removed
        assert 0 in blocks
        # update loop body blocks
        blocks.pop(0)
        parfor.loop_body = blocks

    # make sure dummy jump to loop body isn't altered
    first_body_label = min(parfor.loop_body.keys())
    assert isinstance(parfor.init_block.body[-1], ir.Jump)
    assert parfor.init_block.body[-1].target == first_body_label

    # remove dummy jump to loop body
    parfor.init_block.body.pop()

    # make sure dummy jump back to loop body isn't altered
    last_label = max(parfor.loop_body.keys())
    assert isinstance(parfor.loop_body[last_label].body[-1], ir.Jump)
    assert parfor.loop_body[last_label].body[-1].target == first_body_label
    # remove dummy jump back to loop
    parfor.loop_body[last_label].body.pop()
    return
# Buggy code
def get_parfor_call_table(parfor, call_table={}, reverse_call_table={}):
    blocks = wrap_parfor_blocks(parfor)
    call_table, reverse_call_table = get_call_table(
        blocks, call_table, reverse_call_table
    )
    unwrap_parfor_blocks(parfor)
    return call_table, reverse_call_table


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def get_parfor_call_table(parfor, call_table=None, reverse_call_table=None):
    if call_table is None:
        call_table = {}
    if reverse_call_table is None:
        reverse_call_table = {}
    blocks = wrap_parfor_blocks(parfor)
    call_table, reverse_call_table = get_call_table(
        blocks, call_table, reverse_call_table
    )
    unwrap_parfor_blocks(parfor)
    return call_table, reverse_call_table
# Buggy code
def get_parfor_tuple_table(parfor, tuple_table={}):
    blocks = wrap_parfor_blocks(parfor)
    tuple_table = ir_utils.get_tuple_table(blocks, tuple_table)
    unwrap_parfor_blocks(parfor)
    return tuple_table


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def get_parfor_tuple_table(parfor, tuple_table=None):
    if tuple_table is None:
        tuple_table = {}
    blocks = wrap_parfor_blocks(parfor)
    tuple_table = ir_utils.get_tuple_table(blocks, tuple_table)
    unwrap_parfor_blocks(parfor)
    return tuple_table
# Buggy code
def match(self, interp, block, typemap, calltypes):
    self.prints = prints = {}
    self.block = block
    # Find all assignments with a right-hand print() call
    for inst in block.find_insts(ir.Assign):
        if isinstance(inst.value, ir.Expr) and inst.value.op == "call":
            expr = inst.value
            if expr.kws:
                # Only positional args are supported
                continue
            try:
                callee = interp.infer_constant(expr.func)
            except errors.ConstantInferenceError:
                continue
            if callee is print:
                prints[inst] = expr
    return len(prints) > 0


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def match(self, func_ir, block, typemap, calltypes):
    self.prints = prints = {}
    self.block = block
    # Find all assignments with a right-hand print() call
    for inst in block.find_insts(ir.Assign):
        if isinstance(inst.value, ir.Expr) and inst.value.op == "call":
            expr = inst.value
            if expr.kws:
                # Only positional args are supported
                continue
            try:
                callee = func_ir.infer_constant(expr.func)
            except errors.ConstantInferenceError:
                continue
            if callee is print:
                prints[inst] = expr
    return len(prints) > 0
# Buggy code
def match(self, interp, block, typemap, calltypes):
    self.consts = consts = {}
    self.block = block
    for inst in block.find_insts(ir.Print):
        if inst.consts:
            # Already rewritten
            continue
        for idx, var in enumerate(inst.args):
            try:
                const = interp.infer_constant(var)
            except errors.ConstantInferenceError:
                continue
            consts.setdefault(inst, {})[idx] = const

    return len(consts) > 0


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def match(self, func_ir, block, typemap, calltypes):
    self.consts = consts = {}
    self.block = block
    for inst in block.find_insts(ir.Print):
        if inst.consts:
            # Already rewritten
            continue
        for idx, var in enumerate(inst.args):
            try:
                const = func_ir.infer_constant(var)
            except errors.ConstantInferenceError:
                continue
            consts.setdefault(inst, {})[idx] = const

    return len(consts) > 0
# Buggy code
def match(self, block, typemap, calltypes):
    """Overload this method to check an IR block for matching terms in the
    rewrite.
    """
    return False


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def match(self, func_ir, block, typemap, calltypes):
    """Overload this method to check an IR block for matching terms in the
    rewrite.
    """
    return False
# Buggy code
def register(self, kind):
    """
    Decorator adding a subclass of Rewrite to the registry for
    the given *kind*.
    """
    if not kind in self._kinds:
        raise KeyError("invalid kind %r" % (kind,))

    def do_register(rewrite_cls):
        if not issubclass(rewrite_cls, Rewrite):
            raise TypeError("{0} is not a subclass of Rewrite".format(rewrite_cls))
        self.rewrites[kind].append(rewrite_cls)
        return rewrite_cls

    return do_register


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def register(self, kind):
    """
    Decorator adding a subclass of Rewrite to the registry for
    the given *kind*.
    """
    if kind not in self._kinds:
        raise KeyError("invalid kind %r" % (kind,))

    def do_register(rewrite_cls):
        if not issubclass(rewrite_cls, Rewrite):
            raise TypeError("{0} is not a subclass of Rewrite".format(rewrite_cls))
        self.rewrites[kind].append(rewrite_cls)
        return rewrite_cls

    return do_register
# Buggy code
def match(self, interp, block, typemap, calltypes):
    self.static_lhs = {}
    self.static_rhs = {}
    self.block = block
    # Find binop expressions with a constant lhs or rhs
    for expr in block.find_exprs(op="binop"):
        try:
            if expr.fn in self.rhs_operators and expr.static_rhs is ir.UNDEFINED:
                self.static_rhs[expr] = interp.infer_constant(expr.rhs)
        except errors.ConstantInferenceError:
            continue

    return len(self.static_lhs) > 0 or len(self.static_rhs) > 0


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def match(self, func_ir, block, typemap, calltypes):
    self.static_lhs = {}
    self.static_rhs = {}
    self.block = block
    # Find binop expressions with a constant lhs or rhs
    for expr in block.find_exprs(op="binop"):
        try:
            if expr.fn in self.rhs_operators and expr.static_rhs is ir.UNDEFINED:
                self.static_rhs[expr] = func_ir.infer_constant(expr.rhs)
        except errors.ConstantInferenceError:
            continue

    return len(self.static_lhs) > 0 or len(self.static_rhs) > 0
# Buggy code
def match(self, interp, block, typemap, calltypes):
    self.getitems = getitems = {}
    self.block = block
    # Detect all getitem expressions and find which ones can be
    # rewritten
    for expr in block.find_exprs(op="getitem"):
        if expr.op == "getitem":
            try:
                const = interp.infer_constant(expr.index)
            except errors.ConstantInferenceError:
                continue
            getitems[expr] = const

    return len(getitems) > 0


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def match(self, func_ir, block, typemap, calltypes):
    self.getitems = getitems = {}
    self.block = block
    # Detect all getitem expressions and find which ones can be
    # rewritten
    for expr in block.find_exprs(op="getitem"):
        if expr.op == "getitem":
            try:
                const = func_ir.infer_constant(expr.index)
            except errors.ConstantInferenceError:
                continue
            getitems[expr] = const

    return len(getitems) > 0
# Buggy code
def match(self, interp, block, typemap, calltypes):
    self.setitems = setitems = {}
    self.block = block
    # Detect all setitem statements and find which ones can be
    # rewritten
    for inst in block.find_insts(ir.SetItem):
        try:
            const = interp.infer_constant(inst.index)
        except errors.ConstantInferenceError:
            continue
        setitems[inst] = const

    return len(setitems) > 0


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def match(self, func_ir, block, typemap, calltypes):
    self.setitems = setitems = {}
    self.block = block
    # Detect all setitem statements and find which ones can be
    # rewritten
    for inst in block.find_insts(ir.SetItem):
        try:
            const = func_ir.infer_constant(inst.index)
        except errors.ConstantInferenceError:
            continue
        setitems[inst] = const

    return len(setitems) > 0
# Buggy code
def _break_constant(self, interp, const):
    """
    Break down constant exception.
    """
    if isinstance(const, BaseException):
        return const.__class__, const.args
    elif self._is_exception_type(const):
        return const, None
    else:
        raise NotImplementedError("unsupported exception constant %r" % (const,))


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def _break_constant(self, const):
    """
    Break down constant exception.
    """
    if isinstance(const, BaseException):
        return const.__class__, const.args
    elif self._is_exception_type(const):
        return const, None
    else:
        raise NotImplementedError("unsupported exception constant %r" % (const,))