internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: numba/numba

Issue:
setup.py does not support multiple command execution if an info command (e.g. egg_info) is one of them
Attempting to run the following will yield no build output as it contains a single info command:
```
setup.py build build_ext egg_info
```  

This is considered normal practice for running multiple commands at a time with `setup.py`.  This is because the optimization logic around `setup.py:is_building` is using a negative constraint (i.e. no info commands) instead of a positive constraint (e.g. commands are empty or includes one of the build commands).  This should be minor to fix and will make it possible to include info-generating commands with the build step when building from source, which is still useful for exporting entry points, dependency requirements, and other metadata.



Discussion:
@teruokun thank you for submitting this. I have marked it as needing triage and I hope someone will look at it in due course. 
It looks like the problem may be here: https://github.com/numba/numba/blob/00ad12751725391e8423d67ef845ba56110c55df/setup.py#L113-L138

The `'ext_modules'` field of the setup metadata is only appended if the function above returns True.
However that function only if checks if an info command is present in `sys.argv`, it does not check whether ONLY info commands are given.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -121,21 +121,14 @@ def is_building():
         # User forgot to give an argument probably, let setuptools handle that.
         return True
 
-    info_commands = ['--help-commands', '--name', '--version', '-V',
-                     '--fullname', '--author', '--author-email',
-                     '--maintainer', '--maintainer-email', '--contact',
-                     '--contact-email', '--url', '--license', '--description',
-                     '--long-description', '--platforms', '--classifiers',
-                     '--keywords', '--provides', '--requires', '--obsoletes']
-    # Add commands that do more than print info, but also don't need
-    # any build step.
-    info_commands.extend(['egg_info', 'install_egg_info', 'rotate'])
-
-    for command in info_commands:
-        if command in sys.argv[1:]:
-            return False
-
-    return True
+    build_commands = ['build', 'build_py', 'build_ext', 'build_clib'
+                      'build_scripts', 'install', 'install_lib',
+                      'install_headers', 'install_scripts', 'install_data',
+                      'sdist', 'bdist', 'bdist_dumb', 'bdist_rpm',
+                      'bdist_wininst', 'check', 'build_doc', 'bdist_wheel',
+                      'bdist_egg', 'develop', 'easy_install', 'test']
+    return any(bc in sys.argv[1:] for bc in build_commands)
+
 
 
 def get_ext_modules():


Test patch:
Repository: numba/numba

Issue:
Missing conversion from StringLiteral to unicode_type
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included a self contained code sample to reproduce the problem.
  i.e. it's possible to run as 'python bug.py'.

This:
```python
from numba import typeof, types
from numba.core.typing import Context

x = types.literal('string literal')
print(x, type(x))
print("conversion:", x.can_convert_to(Context(), types.unicode_type))
```
does this:
```
Literal[str](string literal) <class 'numba.core.types.misc.StringLiteral'>
conversion: None
```
I think it should be possible to convert a `StringLiteral` to a `unicode_type` but not the converse.

A `can_convert_to()` method needs adding to this class:
https://github.com/numba/numba/blob/3461bcb76a479bffbadbef24b6662107229e2a8a/numba/core/types/misc.py#L40-L41

xref: https://numba.discourse.group/t/how-to-pass-string-argument-to-numba-njit-python-function-from-inside-another-whilst-specifying-signature-type/663 which hits this bug.


Discussion:
Would fixing this also fix #6897?

Resolving patch:
diff --git a/numba/core/types/misc.py b/numba/core/types/misc.py
--- a/numba/core/types/misc.py
+++ b/numba/core/types/misc.py
@@ -38,7 +38,10 @@ class RawPointer(Opaque):
 
 
 class StringLiteral(Literal, Dummy):
-    pass
+
+    def can_convert_to(self, typingctx, other):
+        if isinstance(other, UnicodeType):
+            return Conversion.safe
 
 
 Literal.ctor_map[str] = StringLiteral


Test patch:
diff --git a/numba/tests/test_conversion.py b/numba/tests/test_conversion.py
--- a/numba/tests/test_conversion.py
+++ b/numba/tests/test_conversion.py
@@ -216,6 +216,18 @@ def test_cleanup_optional(self):
         tp = types.Optional(types.Buffer(types.intc, 1, 'C'))
         self.check_argument_cleanup(tp, mem)
 
+    def test_stringliteral_to_unicode(self):
+        # See issue #6907, explicit signature on bar() takes a unicode_type but
+        # the call to bar() in foo() is with a StringLiteral
+
+        @jit(types.void(types.unicode_type), nopython=True)
+        def bar(string):
+            pass
+
+        @jit(types.void(), nopython=True)
+        def foo2():
+            bar("literal string")
+
 
 if __name__ == '__main__':
     unittest.main()
Repository: numba/numba

Issue:
 Memory leak when returning bytes from input argument
# Bug description
I found a memory leak when I return bytes object from njitted function that I put inside as argument. It can be illustrated by example below (function `leak`).

Amount of leaked memory does not depend on the size of the bytes object (i.e. when I set `arg` to `b"a"*100000` I get the same behaviour).

The leak is also present when I return slice of the bytes object (`leak2`), but not when I only return one character (`noLeak2`). Also, the leak is not present when I don't use numba (`noLeak3`). The workaround that works for me is to return numpy array of bytes (`noLeak`)

I used numba 0.53.1, which I believe is the current version as of writing this report. The bug works on both windows and linux systems which I tested. Python version is 3.8.7.

# Minimal example
```python
#!/usr/bin/env python3
import numpy as np
from numba import njit,version_info
import psutil,os
print(version_info,end="\n\n")
pythonProcess = psutil.Process(os.getpid())
def printMem():    
    print("mem: %.2fM"%(float(pythonProcess.memory_info().rss)/1e6))


@njit
def leak(b):
    return b
@njit
def leak2(b):
    return b[0:1]
@njit
def noLeak(b):
    return np.frombuffer(b,dtype=np.uint8)
@njit
def noLeak2(b):
    return b[0]

def noLeak3(b):
    return b

arg=b"a"
for fcn in (leak,leak2,noLeak,noLeak2,noLeak3):
    print(fcn.__name__)
    for _ in range(3):
        for _ in range(100000):
            fcn(arg)
        printMem()
```


## Example output

```
version_info(major=0, minor=53, patch=1, short=(0, 53), full=(0, 53, 1), string='0.53.1', tuple=('0', '53', '1'), git_revision=None)

leak
mem: 98.61M
mem: 103.41M
mem: 108.27M
leak2
mem: 114.58M
mem: 119.44M
mem: 124.23M
noLeak
mem: 125.41M
mem: 125.41M
mem: 125.41M
noLeak2
mem: 125.59M
mem: 125.59M
mem: 125.59M
noLeak3
mem: 125.59M
mem: 125.59M
mem: 125.59M
```



Discussion:

Resolving patch:
diff --git a/numba/core/boxing.py b/numba/core/boxing.py
--- a/numba/core/boxing.py
+++ b/numba/core/boxing.py
@@ -262,7 +262,9 @@ def unbox_unicodecharseq(typ, obj, c):
 @box(types.Bytes)
 def box_bytes(typ, val, c):
     obj = c.context.make_helper(c.builder, typ, val)
-    return c.pyapi.bytes_from_string_and_size(obj.data, obj.nitems)
+    ret = c.pyapi.bytes_from_string_and_size(obj.data, obj.nitems)
+    c.context.nrt.decref(c.builder, typ, val)
+    return ret
 
 
 @box(types.CharSeq)


Test patch:
Repository: numba/numba

Issue:
ir not imported
https://github.com/numba/numba/blob/d4d09f378c471b702c5ec0f9a9f0f32a4637f6c7/numba/core/base.py#L1132 Can not find the ir module in the above file.


Discussion:
Thanks for the report. Think this got accidentally altered in https://github.com/numba/numba/commit/05e9a67c13ca4761b6e58080a43d5622825ccbdc

Resolving patch:
diff --git a/numba/core/base.py b/numba/core/base.py
--- a/numba/core/base.py
+++ b/numba/core/base.py
@@ -1128,8 +1128,12 @@ def post_lowering(self, mod, library):
 
     def create_module(self, name):
         """Create a LLVM module
+        
+        The default implementation in BaseContext always raises a
+        ``NotImplementedError`` exception. Subclasses should implement 
+        this method.
         """
-        return ir.Module(name)
+        raise NotImplementedError
 
     @property
     def active_code_library(self):


Test patch:
Repository: numba/numba

Issue:
Initialize NUMBA_DEFAULT_NUM_THREADS with a batch scheduler aware value

---

<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Feature request

As it is `numba` initializes `NUMBA_DEFAULT_NUM_THREADS` with the number of cores of the machine with `multiprocessing.cpu_count()`.
When running a job through a batch scheduler (e.g., SLURM), not all cores might be useable (when the job request does not use an entire compute node).
In this case, using a scheduler aware number of cores sounds a better default, so one does not need to configure the number of threads to use when having requested only part of a machine.

[`multiprocessing.cpu_count`'s doc](https://docs.python.org/3/library/multiprocessing.html#multiprocessing.cpu_count) suggests to use `len(os.sched_getaffinity(0))` ([os.sched_getaffinity](https://docs.python.org/3/library/os.html#os.sched_getaffinity)) when available.


<!--

Please include details of the feature you would like to see, why you would
like to see it/the use case.

-->



Discussion:

Resolving patch:
diff --git a/numba/core/config.py b/numba/core/config.py
--- a/numba/core/config.py
+++ b/numba/core/config.py
@@ -367,7 +367,12 @@ def avx_default():
         DISABLE_HSA = _readenv("NUMBA_DISABLE_HSA", int, 0)
 
         # The default number of threads to use.
-        NUMBA_DEFAULT_NUM_THREADS = max(1, multiprocessing.cpu_count())
+        NUMBA_DEFAULT_NUM_THREADS = max(
+            1,
+            len(os.sched_getaffinity(0))
+            if hasattr(os, "sched_getaffinity")
+            else multiprocessing.cpu_count(),
+        )
 
         # Numba thread pool size (defaults to number of CPUs on the system).
         _NUMBA_NUM_THREADS = _readenv("NUMBA_NUM_THREADS", int,


Test patch:
Repository: numba/numba

Issue:
Ignore type annotations instead of crashing
---

<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Feature request

<!--

Please include details of the feature you would like to see, why you would
like to see it/the use case.

-->
As it is type annotations in internal functions error out compilation:
```python
import numba as nb
@nb.njit
def f(x):
    def g(x:int):
        return x
    return g(x)
f(1)
``` 
```
...
~/miniconda3/lib/python3.9/site-packages/numba/core/interpreter.py in op_MAKE_FUNCTION(self, inst, name, code, closure, annotations, kwdefaults, defaults, res)
   1685         if annotations is not None:
   1686             msg = "op_MAKE_FUNCTION with annotations is not implemented"
-> 1687             raise NotImplementedError(msg)
   1688         if kwdefaults is not None:
   1689             msg = "op_MAKE_FUNCTION with kwdefaults is not implemented"

NotImplementedError: Failed in nopython mode pipeline (step: analyzing bytecode)
op_MAKE_FUNCTION with annotations is not implemented
```
However annotations enable static analysis tools.
The situation would be improved if numba were to ignore them instead of raising an exception.
In my limited experimentation,commenting out the check seems to work.


Discussion:
Thanks for the report. I've taken a look at the interpreter code and also think that just ignoring them ought to work. I also considered whether raising a warning would be appropriate but think that to be consistent with the use of type annotations at the jit-decorated-function level, ignoring is the way to go.
Good first issue task is to create a patch that removes the above check and leaves a comment in its place that refers to the issue and offers an explanation for ignoring the annotations.

Resolving patch:
diff --git a/numba/core/interpreter.py b/numba/core/interpreter.py
--- a/numba/core/interpreter.py
+++ b/numba/core/interpreter.py
@@ -1715,9 +1715,8 @@ def op_YIELD_VALUE(self, inst, value, res):
 
     def op_MAKE_FUNCTION(self, inst, name, code, closure, annotations,
                          kwdefaults, defaults, res):
-        if annotations is not None:
-            msg = "op_MAKE_FUNCTION with annotations is not implemented"
-            raise NotImplementedError(msg)
+        # annotations are ignored by numba but useful for static analysis
+        # re. https://github.com/numba/numba/issues/7269
         if kwdefaults is not None:
             msg = "op_MAKE_FUNCTION with kwdefaults is not implemented"
             raise NotImplementedError(msg)


Test patch:
Repository: numba/numba

Issue:
Typeguard fail in mangled flags tests.
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the ~latest released~ mainline version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [ ] I have included a self contained code sample to reproduce the problem.
  i.e. it's possible to run as 'python bug.py'.

From https://github.com/numba/numba/pull/7460, the typeguard build slice is failing:
https://dev.azure.com/numba/numba/_build/results?buildId=10049&view=logs&j=5aa00cf4-14fd-5601-2112-54b04f2176e9&t=826075b5-1299-5e63-92a0-5aa178032eb6
with:
```
======================================================================
ERROR: test_mangled_flags_with_fastmath_parfors_inline (numba.tests.test_compiler_flags.TestFlagMangling)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vsts/work/1/s/numba/tests/test_compiler_flags.py", line 78, in test_mangled_flags_with_fastmath_parfors_inline
    demangled = flags.demangle(flags.get_mangle_string()).decode()
  File "/home/vsts/miniconda3/envs/azure_ci/lib/python3.8/site-packages/typeguard/__init__.py", line 1019, in wrapper
    raise TypeError(*exc.args) from None
TypeError: type of the return value must be str; got bytes instead

```
cc @sklam 


Discussion:

Resolving patch:
diff --git a/numba/core/targetconfig.py b/numba/core/targetconfig.py
--- a/numba/core/targetconfig.py
+++ b/numba/core/targetconfig.py
@@ -304,4 +304,4 @@ def demangle(self, mangled: str) -> str:
             buf.append(dc.decompress(raw))
             raw = dc.unconsumed_tail
         buf.append(dc.flush())
-        return b''.join(buf)
+        return b''.join(buf).decode()


Test patch:
diff --git a/numba/tests/test_compiler_flags.py b/numba/tests/test_compiler_flags.py
--- a/numba/tests/test_compiler_flags.py
+++ b/numba/tests/test_compiler_flags.py
@@ -42,7 +42,7 @@ def test_demangle(self):
 
         def check(flags):
             mangled = flags.get_mangle_string()
-            out = flags.demangle(mangled).decode()
+            out = flags.demangle(mangled)
             # Demangle result MUST match summary()
             self.assertEqual(out, flags.summary())
 
@@ -75,7 +75,7 @@ def test_mangled_flags_with_fastmath_parfors_inline(self):
         flags.fastmath = True
         flags.inline = "always"
         self.assertLess(len(flags.get_mangle_string()), len(flags.summary()))
-        demangled = flags.demangle(flags.get_mangle_string()).decode()
+        demangled = flags.demangle(flags.get_mangle_string())
         # There should be no pointer value in the demangled string.
         self.assertNotIn("0x", demangled)
Repository: numba/numba

Issue:
LiteralStrKeyDict incorrectly handles missing const-key at compile time.
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest released version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included a self contained code sample to reproduce the problem.
  i.e. it's possible to run as 'python bug.py'.

<!--

Please include details of the bug here, including, if applicable, what you
expected to happen!

-->
This:
```python
from numba import njit
@njit
def foo():
    a = {'not_a': 2j, 'c': 'd', 'e': np.zeros(4)}
    return a['a']

foo()
```
does this (or wraps it as an `InternalError` in the `old_style` error capturing):
```
numba/core/typing/builtins.py", line 648, in generic
    lookup = tup.fields.index(idx)
ValueError: tuple.index(x): x not in tuple
```


Discussion:

Resolving patch:
diff --git a/numba/core/typing/builtins.py b/numba/core/typing/builtins.py
--- a/numba/core/typing/builtins.py
+++ b/numba/core/typing/builtins.py
@@ -645,7 +645,10 @@ def generic(self, args, kws):
         if not isinstance(tup, types.LiteralStrKeyDict):
             return
         if isinstance(idx, str):
-            lookup = tup.fields.index(idx)
+            if idx in tup.fields:
+                lookup = tup.fields.index(idx)
+            else:
+                raise errors.NumbaKeyError(f"Key '{idx}' is not in dict.")
             ret = tup.types[lookup]
         if ret is not None:
             sig = signature(ret, *args)


Test patch:
diff --git a/numba/tests/test_dictobject.py b/numba/tests/test_dictobject.py
--- a/numba/tests/test_dictobject.py
+++ b/numba/tests/test_dictobject.py
@@ -2251,6 +2251,18 @@ def foo():
 
         foo()
 
+    def test_const_key_not_in_dict(self):
+
+        @njit
+        def foo():
+            a = {'not_a': 2j, 'c': 'd', 'e': np.zeros(4)}
+            return a['a']
+
+        with self.assertRaises(TypingError) as raises:
+            foo()
+
+        self.assertIn("Key 'a' is not in dict.", str(raises.exception))
+
     def test_uncommon_identifiers(self):
         # Tests uncommon identifiers like numerical values and operators in
         # the key fields. See #6518 and #7416.
Repository: numba/numba

Issue:
NUMBA_DUMP_IR generate duplicates
for eg test.py:

```
import numba as nb

@nb.njit()
def test(i) :
    return i+1

print(test(2))
```

I am using:
NUMBA_DUMP_IR=1 python test.py > test.ll

In test.ll I find function test is generated 2 times:

```
---------------------------------IR DUMP: test----------------------------------
label 0:
    i = arg(0, name=i)                       ['i']
    $const4.1 = const(int, 1)                ['$const4.1']
    $6binary_add.2 = i + $const4.1           ['$6binary_add.2', '$const4.1', 'i']
    $8return_value.3 = cast(value=$6binary_add.2) ['$6binary_add.2', '$8return_value.3']
    return $8return_value.3                  ['$8return_value.3']

---------------------------------IR DUMP: test----------------------------------
label 0:
    i = arg(0, name=i)                       ['i']
    $const4.1 = const(int, 1)                ['$const4.1']
    $6binary_add.2 = i + $const4.1           ['$6binary_add.2', '$const4.1', 'i']
    $8return_value.3 = cast(value=$6binary_add.2) ['$6binary_add.2', '$8return_value.3']
    return $8return_value.3                  ['$8return_value.3']

3
```

Is this normal ?
On bigger code functions are even generated 4 times producing very big dump file...


Discussion:
Hi @sfornengo, thanks for the report.

This is normal. The first `IR DUMP` you see is from right after Numba runs the IR Processing function pass. The second one is after `InlineClosureLikes`. There are other places in this file which dumps the IR if one sets the `NUMBA_DEBUG=1`. See:

https://github.com/numba/numba/blob/181f57c22e8b9708f5864196ef4f254895181374/numba/core/untyped_passes.py#L123-L130

https://github.com/numba/numba/blob/181f57c22e8b9708f5864196ef4f254895181374/numba/core/untyped_passes.py#L214-L217

But there's should be a text indicating where this IR is coming from (i.e. `--IR DUMP [InlineClosureLikes]: test--`)

>  On bigger code functions are even generated 4 times producing very big dump file...

As I see it, the flags `DEBUG` and `DUMP_IR` should have the behavior described below. This would reduce the size dump you're seeing.
* `NUMBA_DEBUG=1` dumps the IR after every function pass.
* `NUMBA_DUMP_IR=1` should dump the unoptimized IR (after `IRProcessing`) and the optimized one (before code generation).

I'll mark this for discussion at the next triage meeting.
Triage meeting note:

- get rid of `NUMBA_DUMP_IR` use in `InlineClosureLikes` so it only print once


Resolving patch:
diff --git a/numba/core/untyped_passes.py b/numba/core/untyped_passes.py
--- a/numba/core/untyped_passes.py
+++ b/numba/core/untyped_passes.py
@@ -211,10 +211,6 @@ def run_pass(self, state):
 
         fixup_var_define_in_scope(state.func_ir.blocks)
 
-        if config.DEBUG or config.DUMP_IR:
-            name = state.func_ir.func_id.func_qualname
-            print(("IR DUMP: %s" % name).center(80, "-"))
-            state.func_ir.dump()
         return True
 
 


Test patch: