gurudesh/pytracebugs huggingface dataset:
# Buggy code
def func_mt(*args):
    length = len(args[0])
    result = np.empty(length, dtype=np.float64)
    args = (result,) + args
    chunklen = (length + 1) // numthreads
    # Create argument tuples for each chunk
    chunks = [
        [arg[i * chunklen : (i + 1) * chunklen] for arg in args]
        for i in range(numthreads)
    ]

    # You should make sure inner_func is compiled at this point, because
    # the compilation must happen in a single thread at a time. This is
    # the case in this example because we use an explicit signature in jit().
    threads = [threading.Thread(target=inner_func, args=chunk) for chunk in chunks]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    return result


# Traceback (RuntimeError)
Exception in thread Thread-14:
Traceback (most recent call last):
File "/home/antoine/34/lib/python3.4/threading.py", line 921, in _bootstrap_inner
self.run()
File "/home/antoine/34/lib/python3.4/threading.py", line 869, in run
self._target(*self._args, **self._kwargs)
File "/home/antoine/numba/numba/dispatcher.py", line 151, in _compile_for_args
return self.jit(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 141, in jit
return self.compile(sig, **kws)
File "/home/antoine/numba/numba/dispatcher.py", line 312, in compile
with self._compile_lock():
File "/home/antoine/34/lib/python3.4/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/home/antoine/numba/numba/dispatcher.py", line 127, in _compile_lock
raise RuntimeError("Compiler re-entrant")
RuntimeError: Compiler re-entrant

# Fixed code
def func_mt(*args):
    length = len(args[0])
    result = np.empty(length, dtype=np.float64)
    args = (result,) + args
    chunklen = (length + 1) // numthreads
    # Create argument tuples for each input chunk
    chunks = [
        [arg[i * chunklen : (i + 1) * chunklen] for arg in args]
        for i in range(numthreads)
    ]
    # Spawn one thread per chunk
    threads = [threading.Thread(target=inner_func, args=chunk) for chunk in chunks]
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    return result
# Buggy code
def call_function_pointer(self, builder, funcptr, signature, args):
    retty = self.get_value_type(signature.return_type)
    fnty = Type.function(retty, [a.type for a in args])
    fnptrty = Type.pointer(fnty)
    addr = self.get_constant(types.intp, funcptr)
    ptr = builder.inttoptr(addr, fnptrty)
    return builder.call(ptr, args)


# Traceback (ValueError)
ctypes.windll.kernel32.Sleep(100)
0
ctypes.cdll.kernel32.Sleep(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Procedure called with not enough arguments (4 bytes missing) or wron
g calling convention

# Fixed code
def call_function_pointer(self, builder, funcptr, signature, args, cconv=None):
    retty = self.get_value_type(signature.return_type)
    fnty = Type.function(retty, [a.type for a in args])
    fnptrty = Type.pointer(fnty)
    addr = self.get_constant(types.intp, funcptr)
    ptr = builder.inttoptr(addr, fnptrty)
    return builder.call(ptr, args, cconv=cconv)
# Buggy code
def __init__(self, template, funcptr):
    self.funcptr = funcptr
    super(FunctionPointer, self).__init__(template)


# Traceback (ValueError)
ctypes.windll.kernel32.Sleep(100)
0
ctypes.cdll.kernel32.Sleep(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Procedure called with not enough arguments (4 bytes missing) or wron
g calling convention

# Fixed code
def __init__(self, template, funcptr, cconv=None):
    self.funcptr = funcptr
    self.cconv = cconv
    super(FunctionPointer, self).__init__(template)
# Buggy code
def make_function_type(cfnptr):
    cargs = [convert_ctypes(a) for a in cfnptr.argtypes]
    cret = convert_ctypes(cfnptr.restype)

    cases = [templates.signature(cret, *cargs)]
    template = templates.make_concrete_template("CFuncPtr", cfnptr, cases)

    pointer = ctypes.cast(cfnptr, ctypes.c_void_p).value
    return types.FunctionPointer(template, pointer)


# Traceback (ValueError)
ctypes.windll.kernel32.Sleep(100)
0
ctypes.cdll.kernel32.Sleep(100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Procedure called with not enough arguments (4 bytes missing) or wron
g calling convention

# Fixed code
def make_function_type(cfnptr):
    if cfnptr.argtypes is None:
        raise TypeError(
            "ctypes function %r doesn't define its argument types; "
            "consider setting the `argtypes` attribute" % (cfnptr.__name__,)
        )
    cargs = [convert_ctypes(a) for a in cfnptr.argtypes]
    cret = convert_ctypes(cfnptr.restype)
    if sys.platform == "win32" and not cfnptr._flags_ & ctypes._FUNCFLAG_CDECL:
        # 'stdcall' calling convention under Windows
        cconv = "x86_stdcallcc"
    else:
        # Default C calling convention
        cconv = None

    cases = [templates.signature(cret, *cargs)]
    template = templates.make_concrete_template("CFuncPtr", cfnptr, cases)

    pointer = ctypes.cast(cfnptr, ctypes.c_void_p).value
    return types.FunctionPointer(template, pointer, cconv=cconv)
# Buggy code
def _explain_ambiguous(self, *args, **kws):
    assert not kws, "kwargs not handled"
    args = tuple([self.typeof_pyval(a) for a in args])
    resolve_overload(
        self.typingctx, self.py_func, tuple(self.overloads.keys()), args, kws
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "test_disp.py", line 15, in <module>
foo(1, 1)
File "/Users/sklam/dev/numba/numba/dispatcher.py", line 161, in _explain_ambiguous
tuple(self.overloads.keys()), args, kws)
File "/Users/sklam/dev/numba/numba/typing/templates.py", line 84, in resolve_overload
if len(args) == len(case.args):
AttributeError: 'tuple' object has no attribute 'args'

# Fixed code
def _explain_ambiguous(self, *args, **kws):
    assert not kws, "kwargs not handled"
    args = tuple([self.typeof_pyval(a) for a in args])
    sigs = [cr.signature for cr in self._compileinfos.values()]
    resolve_overload(self.typingctx, self.py_func, sigs, args, kws)
# Buggy code
def __init__(self, variable, context, types, assignment=False, **kwds):
    super(PromotionType, self).__init__(variable, **kwds)
    self.context = context
    self.types = types
    self.assignment = assignment
    variable.type = self

    self.add_parents(type for type in types if type.is_unresolved)

    self.count = PromotionType.count
    PromotionType.count += 1


# Traceback (AssertionError)
Traceback (most recent call last):
File "./test_typeinfer_bug.py", line 26, in <module>
test()
File "./test_typeinfer_bug.py", line 23, in test
jenks_matrices(data)
File "numbawrapper.pyx", line 93, in numba.numbawrapper.NumbaSpecializingWrapper.__call__ (numba/numbawrapper.c:2827)
File "/Users/sklam/dev/numba/numba/decorators.py", line 211, in compile_function
compiled_function = dec(f)
File "/Users/sklam/dev/numba/numba/decorators.py", line 299, in _jit2_decorator
**kwargs)
File "/Users/sklam/dev/numba/numba/functions.py", line 222, in compile_function
ctypes=ctypes, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 397, in compile
context, func, restype, argtypes, codegen=True, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 365, in _infer_types
return run_pipeline(context, func, ast, func_signature, **kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 359, in run_pipeline
return pipeline, pipeline.run_pipeline()
File "/Users/sklam/dev/numba/numba/pipeline.py", line 188, in run_pipeline
ast = getattr(self, method_name)(ast)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 255, in type_infer
type_inference.TypeInferer, ast, **self.kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 149, in make_specializer
**kwds)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 170, in __init__
self.init_locals()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 249, in init_locals
self.resolve_variable_types()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 495, in resolve_variable_types
self.remove_resolved_type(start_point)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 393, in remove_resolved_type
assert not type.is_scc
AssertionError

# Fixed code
def __init__(self, variable, context, types, assignment=False, **kwds):
    super(PromotionType, self).__init__(variable, **kwds)
    self.context = context
    self.types = oset.OrderedSet(types)
    self.assignment = assignment
    variable.type = self

    self.add_parents(type for type in types if type.is_unresolved)

    self.count = PromotionType.count
    PromotionType.count += 1
# Buggy code
def find_types(self, seen):
    types = set([self])
    seen.add(self)
    seen.add(self.variable.deferred_type)
    self.dfs(types, seen)
    types.remove(self)
    return types


# Traceback (AssertionError)
Traceback (most recent call last):
File "./test_typeinfer_bug.py", line 26, in <module>
test()
File "./test_typeinfer_bug.py", line 23, in test
jenks_matrices(data)
File "numbawrapper.pyx", line 93, in numba.numbawrapper.NumbaSpecializingWrapper.__call__ (numba/numbawrapper.c:2827)
File "/Users/sklam/dev/numba/numba/decorators.py", line 211, in compile_function
compiled_function = dec(f)
File "/Users/sklam/dev/numba/numba/decorators.py", line 299, in _jit2_decorator
**kwargs)
File "/Users/sklam/dev/numba/numba/functions.py", line 222, in compile_function
ctypes=ctypes, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 397, in compile
context, func, restype, argtypes, codegen=True, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 365, in _infer_types
return run_pipeline(context, func, ast, func_signature, **kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 359, in run_pipeline
return pipeline, pipeline.run_pipeline()
File "/Users/sklam/dev/numba/numba/pipeline.py", line 188, in run_pipeline
ast = getattr(self, method_name)(ast)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 255, in type_infer
type_inference.TypeInferer, ast, **self.kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 149, in make_specializer
**kwds)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 170, in __init__
self.init_locals()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 249, in init_locals
self.resolve_variable_types()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 495, in resolve_variable_types
self.remove_resolved_type(start_point)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 393, in remove_resolved_type
assert not type.is_scc
AssertionError

# Fixed code
def find_types(self, seen):
    types = oset.OrderedSet([self])
    seen.add(self)
    seen.add(self.variable.deferred_type)
    self.dfs(types, seen)
    types.remove(self)
    return types
# Buggy code
def find_simple(self, seen):
    types = set()
    for type in self.types:
        if type.is_promotion:
            types.add(type.types)
        else:
            type.add(type)

    return types


# Traceback (AssertionError)
Traceback (most recent call last):
File "./test_typeinfer_bug.py", line 26, in <module>
test()
File "./test_typeinfer_bug.py", line 23, in test
jenks_matrices(data)
File "numbawrapper.pyx", line 93, in numba.numbawrapper.NumbaSpecializingWrapper.__call__ (numba/numbawrapper.c:2827)
File "/Users/sklam/dev/numba/numba/decorators.py", line 211, in compile_function
compiled_function = dec(f)
File "/Users/sklam/dev/numba/numba/decorators.py", line 299, in _jit2_decorator
**kwargs)
File "/Users/sklam/dev/numba/numba/functions.py", line 222, in compile_function
ctypes=ctypes, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 397, in compile
context, func, restype, argtypes, codegen=True, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 365, in _infer_types
return run_pipeline(context, func, ast, func_signature, **kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 359, in run_pipeline
return pipeline, pipeline.run_pipeline()
File "/Users/sklam/dev/numba/numba/pipeline.py", line 188, in run_pipeline
ast = getattr(self, method_name)(ast)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 255, in type_infer
type_inference.TypeInferer, ast, **self.kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 149, in make_specializer
**kwds)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 170, in __init__
self.init_locals()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 249, in init_locals
self.resolve_variable_types()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 495, in resolve_variable_types
self.remove_resolved_type(start_point)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 393, in remove_resolved_type
assert not type.is_scc
AssertionError

# Fixed code
def find_simple(self, seen):
    types = oset.OrderedSet()
    for type in self.types:
        if type.is_promotion:
            types.add(type.types)
        else:
            type.add(type)

    return types
# Buggy code
def __init__(self, scc, **kwds):
    super(StronglyConnectedCircularType, self).__init__(None, **kwds)
    self.scc = scc

    types = set(scc)
    for type in scc:
        self.add_children(type.children - types)
        self.add_parents(type.parents - types)

    self.types = scc
    self.promotions = set(type for type in scc if type.is_promotion)
    self.reanalyzeable = set(type for type in scc if type.is_reanalyze_circular)


# Traceback (AssertionError)
Traceback (most recent call last):
File "./test_typeinfer_bug.py", line 26, in <module>
test()
File "./test_typeinfer_bug.py", line 23, in test
jenks_matrices(data)
File "numbawrapper.pyx", line 93, in numba.numbawrapper.NumbaSpecializingWrapper.__call__ (numba/numbawrapper.c:2827)
File "/Users/sklam/dev/numba/numba/decorators.py", line 211, in compile_function
compiled_function = dec(f)
File "/Users/sklam/dev/numba/numba/decorators.py", line 299, in _jit2_decorator
**kwargs)
File "/Users/sklam/dev/numba/numba/functions.py", line 222, in compile_function
ctypes=ctypes, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 397, in compile
context, func, restype, argtypes, codegen=True, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 365, in _infer_types
return run_pipeline(context, func, ast, func_signature, **kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 359, in run_pipeline
return pipeline, pipeline.run_pipeline()
File "/Users/sklam/dev/numba/numba/pipeline.py", line 188, in run_pipeline
ast = getattr(self, method_name)(ast)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 255, in type_infer
type_inference.TypeInferer, ast, **self.kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 149, in make_specializer
**kwds)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 170, in __init__
self.init_locals()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 249, in init_locals
self.resolve_variable_types()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 495, in resolve_variable_types
self.remove_resolved_type(start_point)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 393, in remove_resolved_type
assert not type.is_scc
AssertionError

# Fixed code
def __init__(self, scc, **kwds):
    super(StronglyConnectedCircularType, self).__init__(None, **kwds)
    self.scc = scc

    types = oset.OrderedSet(scc)
    for type in scc:
        self.add_children(type.children - types)
        self.add_parents(type.parents - types)

    self.types = scc
    self.promotions = oset.OrderedSet(type for type in scc if type.is_promotion)
    self.reanalyzeable = oset.OrderedSet(
        type for type in scc if type.is_reanalyze_circular
    )
# Buggy code
def simplify(self):
    if self.reanalyzeable:
        self.retry_infer()
    elif self.promotions:
        self.resolve_promotion_cycles()
    else:
        assert False

    self.is_resolved = True


# Traceback (AssertionError)
Traceback (most recent call last):
File "./test_typeinfer_bug.py", line 26, in <module>
test()
File "./test_typeinfer_bug.py", line 23, in test
jenks_matrices(data)
File "numbawrapper.pyx", line 93, in numba.numbawrapper.NumbaSpecializingWrapper.__call__ (numba/numbawrapper.c:2827)
File "/Users/sklam/dev/numba/numba/decorators.py", line 211, in compile_function
compiled_function = dec(f)
File "/Users/sklam/dev/numba/numba/decorators.py", line 299, in _jit2_decorator
**kwargs)
File "/Users/sklam/dev/numba/numba/functions.py", line 222, in compile_function
ctypes=ctypes, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 397, in compile
context, func, restype, argtypes, codegen=True, **kwds)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 365, in _infer_types
return run_pipeline(context, func, ast, func_signature, **kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 359, in run_pipeline
return pipeline, pipeline.run_pipeline()
File "/Users/sklam/dev/numba/numba/pipeline.py", line 188, in run_pipeline
ast = getattr(self, method_name)(ast)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 255, in type_infer
type_inference.TypeInferer, ast, **self.kwargs)
File "/Users/sklam/dev/numba/numba/pipeline.py", line 149, in make_specializer
**kwds)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 170, in __init__
self.init_locals()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 249, in init_locals
self.resolve_variable_types()
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 495, in resolve_variable_types
self.remove_resolved_type(start_point)
File "/Users/sklam/dev/numba/numba/type_inference/infer.py", line 393, in remove_resolved_type
assert not type.is_scc
AssertionError

# Fixed code
def simplify(self):
    if self.reanalyzeable:
        self.retry_infer()
    elif self.promotions:
        self.resolve_promotion_cycles()
    else:
        # All dependencies are resolved, we are done
        pass

    self.is_resolved = True
# Buggy code
def pprint(self, *args, **kws):
    pprint.pprint(self.__dict__)


# 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 pprint(self, *args, **kws):
    pprint.pprint(self.__dict__, *args, **kws)
# Buggy code
def _analyze_inst(self, inst):
    if isinstance(inst, ir.Assign):
        return self._analyze_assign(inst)
    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 _analyze_inst(self, inst):
    if isinstance(inst, ir.Assign):
        return self._analyze_assign(inst)
    elif type(inst) in array_analysis_extensions:
        # let external calls handle stmt if type matches
        f = array_analysis_extensions[type(inst)]
        return f(inst, self)
    return []
# Buggy code
def stage_parfor_pass(self):
    """
    Convert data-parallel computations into Parfor nodes
    """
    # Ensure we have an IR and type information.
    assert self.func_ir
    parfor_pass = ParforPass(
        self.func_ir,
        self.type_annotation.typemap,
        self.type_annotation.calltypes,
        self.return_type,
    )
    parfor_pass.run()


# 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 stage_parfor_pass(self):
    """
    Convert data-parallel computations into Parfor nodes
    """
    # Ensure we have an IR and type information.
    assert self.func_ir
    parfor_pass = ParforPass(
        self.func_ir,
        self.type_annotation.typemap,
        self.type_annotation.calltypes,
        self.return_type,
        self.typingctx,
    )
    parfor_pass.run()
# Buggy code
def stage_inline_pass(self):
    """
    Inline calls to locally defined closures.
    """
    # Ensure we have an IR and type information.
    assert self.func_ir
    inline_pass = InlineClosureCallPass(self.func_ir, run_frontend)
    inline_pass.run()
    # Remove all Dels, and re-run postproc
    post_proc = postproc.PostProcessor(self.func_ir)
    post_proc.run()

    if config.DEBUG or config.DUMP_IR:
        name = self.func_ir.func_id.func_qualname
        print(("IR DUMP: %s" % name).center(80, "-"))
        self.func_ir.dump()


# 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 stage_inline_pass(self):
    """
    Inline calls to locally defined closures.
    """
    # Ensure we have an IR and type information.
    assert self.func_ir
    inline_pass = InlineClosureCallPass(self.func_ir, self.flags, run_frontend)
    inline_pass.run()
    # Remove all Dels, and re-run postproc
    post_proc = postproc.PostProcessor(self.func_ir)
    post_proc.run()

    if config.DEBUG or config.DUMP_IR:
        name = self.func_ir.func_id.func_qualname
        print(("IR DUMP: %s" % name).center(80, "-"))
        self.func_ir.dump()
# Buggy code
def view(self, start, stop=None):
    base = self.device_pointer.value + start
    if stop is None:
        size = self.size - start
    else:
        size = stop - start
    assert size > 0, "zero or negative memory size"
    pointer = drvapi.cu_device_ptr(base)
    view = MemoryPointer(self.context, pointer, size, owner=self.owner)
    return OwnedPointer(weakref.proxy(self.owner), view)


# 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 view(self, start, stop=None):
    if stop is None:
        size = self.size - start
    else:
        size = stop - start

    # Handle NULL/empty memory buffer
    if self.device_pointer.value is None:
        if size != 0:
            raise RuntimeError("non-empty slice into empty slice")
        view = self  # new view is just a reference to self
    # Handle normal case
    else:
        base = self.device_pointer.value + start
        if size < 0:
            raise RuntimeError("size cannot be negative")
        pointer = drvapi.cu_device_ptr(base)
        view = MemoryPointer(self.context, pointer, size, owner=self.owner)
    return OwnedPointer(weakref.proxy(self.owner), view)
# Buggy code
def _compute_extent(self):
    firstidx = [0] * self.ndim
    lastidx = [s - 1 for s in self.shape]
    start = compute_index(firstidx, self.dims)
    stop = compute_index(lastidx, self.dims) + self.itemsize
    return Extent(start, stop)


# 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 _compute_extent(self):
    firstidx = [0] * self.ndim
    lastidx = [s - 1 for s in self.shape]
    start = compute_index(firstidx, self.dims)
    stop = compute_index(lastidx, self.dims) + self.itemsize
    stop = max(stop, start)  # ensure postive extent
    return Extent(start, stop)
# Buggy code
def __init__(self, func_ir, run_frontend):
    self.func_ir = func_ir
    self.run_frontend = run_frontend


# 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, flags, run_frontend):
    self.func_ir = func_ir
    self.flags = flags
    self.run_frontend = run_frontend
# Buggy code
def _replace_returns(blocks, target, return_label):
    """
    Return return statement by assigning directly to target, and a jump.
    """
    for label, block in blocks.items():
        for i in range(len(block.body)):
            stmt = block.body[i]
            if isinstance(stmt, ir.Return):
                assert i + 1 == len(block.body)
                block.body[i] = ir.Assign(stmt.value, target, stmt.loc)
                block.body.append(ir.Jump(return_label, stmt.loc))


# 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 _replace_returns(blocks, target, return_label):
    """
    Return return statement by assigning directly to target, and a jump.
    """
    for label, block in blocks.items():
        casts = []
        for i in range(len(block.body)):
            stmt = block.body[i]
            if isinstance(stmt, ir.Return):
                assert i + 1 == len(block.body)
                block.body[i] = ir.Assign(stmt.value, target, stmt.loc)
                block.body.append(ir.Jump(return_label, stmt.loc))
                # remove cast of the returned value
                for cast in casts:
                    if cast.target.name == stmt.value.name:
                        cast.value = cast.value.value
            elif (
                isinstance(stmt, ir.Assign)
                and isinstance(stmt.value, ir.Expr)
                and stmt.value.op == "cast"
            ):
                casts.append(stmt)
# Buggy code
def get_definition(self, value):
    """
    Get the definition site for the given variable name or instance.
    A Expr instance is returned.
    """
    while True:
        if isinstance(value, Var):
            name = value.name
        elif isinstance(value, str):
            name = value
        else:
            return value
        defs = self._definitions[name]
        if len(defs) == 0:
            raise KeyError("no definition for %r" % (name,))
        if len(defs) > 1:
            raise KeyError("more than one definition for %r" % (name,))
        value = defs[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 get_definition(self, value, lhs_only=False):
    """
    Get the definition site for the given variable name or instance.
    A Expr instance is returned by default, but if lhs_only is set
    to True, the left-hand-side variable is returned instead.
    """
    lhs = value
    while True:
        if isinstance(value, Var):
            lhs = value
            name = value.name
        elif isinstance(value, str):
            lhs = value
            name = value
        else:
            return lhs if lhs_only else value
        defs = self._definitions[name]
        if len(defs) == 0:
            raise KeyError("no definition for %r" % (name,))
        if len(defs) > 1:
            raise KeyError("more than one definition for %r" % (name,))
        value = defs[0]
# Buggy code
def add_offset_to_labels(blocks, offset):
    """add an offset to all block labels and jump/branch targets"""
    new_blocks = {}
    for l, b in blocks.items():
        term = b.body[-1]
        if isinstance(term, ir.Jump):
            term.target += offset
        if isinstance(term, ir.Branch):
            term.truebr += offset
            term.falsebr += offset
        new_blocks[l + offset] = b
    return new_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 add_offset_to_labels(blocks, offset):
    """add an offset to all block labels and jump/branch targets"""
    new_blocks = {}
    for l, b in blocks.items():
        # some parfor last blocks might be empty
        term = None
        if b.body:
            term = b.body[-1]
            for inst in b.body:
                for T, f in add_offset_to_labels_extensions.items():
                    if isinstance(inst, T):
                        f_max = f(inst, offset)
        if isinstance(term, ir.Jump):
            term.target += offset
        if isinstance(term, ir.Branch):
            term.truebr += offset
            term.falsebr += offset
        new_blocks[l + offset] = b
    return new_blocks
# Buggy code
def has_no_side_effect(rhs, lives, call_table):
    # TODO: find side-effect free calls like Numpy calls
    if isinstance(rhs, ir.Expr) and rhs.op == "call":
        func_name = rhs.func.name
        if func_name not in call_table:
            return False
        call_list = call_table[func_name]
        if call_list == ["empty", numpy] or call_list == [slice]:
            return True
        return False
    if isinstance(rhs, ir.Expr) and rhs.op == "inplace_binop":
        return rhs.lhs.name not in lives
    if isinstance(rhs, ir.Yield):
        return False
    return True


# 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 has_no_side_effect(rhs, lives, call_table):
    # TODO: find side-effect free calls like Numpy calls
    if isinstance(rhs, ir.Expr) and rhs.op == "call":
        func_name = rhs.func.name
        if func_name not in call_table or call_table[func_name] == []:
            return False
        call_list = call_table[func_name]
        if call_list == ["empty", numpy] or call_list == [slice]:
            return True
        from numba.targets.registry import CPUDispatcher
        from numba.targets.linalg import dot_3_mv_check_args

        if isinstance(call_list[0], CPUDispatcher):
            py_func = call_list[0].py_func
            if py_func == dot_3_mv_check_args:
                return True
        return False
    if isinstance(rhs, ir.Expr) and rhs.op == "inplace_binop":
        return rhs.lhs.name not in lives
    if isinstance(rhs, ir.Yield):
        return False
    return True
# Buggy code
def get_tuple_table(blocks, tuple_table={}):
    """returns a dictionary of tuple variables and their values."""
    for block in blocks.values():
        for inst in block.body:
            if isinstance(inst, ir.Assign):
                lhs = inst.target.name
                rhs = inst.value
                if isinstance(rhs, ir.Expr) and rhs.op == "build_tuple":
                    tuple_table[lhs] = rhs.items
                if isinstance(rhs, ir.Const) and isinstance(rhs.value, tuple):
                    tuple_table[lhs] = rhs.value
            for T, f in tuple_table_extensions.items():
                if isinstance(inst, T):
                    f(inst, tuple_table)
    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_tuple_table(blocks, tuple_table=None):
    """returns a dictionary of tuple variables and their values."""
    if tuple_table is None:
        tuple_table = {}

    for block in blocks.values():
        for inst in block.body:
            if isinstance(inst, ir.Assign):
                lhs = inst.target.name
                rhs = inst.value
                if isinstance(rhs, ir.Expr) and rhs.op == "build_tuple":
                    tuple_table[lhs] = rhs.items
                if isinstance(rhs, ir.Const) and isinstance(rhs.value, tuple):
                    tuple_table[lhs] = rhs.value
            for T, f in tuple_table_extensions.items():
                if isinstance(inst, T):
                    f(inst, tuple_table)
    return tuple_table