Repository: numba/numba

Issue:
Type cannot be determined when using 'if a not in b' in list construction 
- [x] I have tried using the latest released version of Numba
- [x] I have included below a minimal working reproducer

In trying to make a replacement for numpy's setxor1d I came across the following error (minimal example below):
```
@nb.njit()
def test():
    included = np.array([1, 2, 6, 8])
    not_included = [i for i in range(10) if i not in list(included)]
    return not_included
```
Which results in:

`Type of variable '$18compare_op.7.7054' cannot be determined, operation: unary(fn=<built-in function not_>, value=$18compare_op.7.7054), location: <ipython-input-138-e85438f982c0> (4)`

Which does not occur when the 'not' statement (in if i not in list(included)]) is not there
I could get around this by instead doing:
```
@nb.njit()
def test():
    included = np.array([1, 2, 6, 8])
    not_included = [i for i in range(10) if (i in list(included)) is False]
    return not_included
```
Which is not very pretty.
Type cannot be determined when using 'if a not in b' in list construction 
- [x] I have tried using the latest released version of Numba
- [x] I have included below a minimal working reproducer

In trying to make a replacement for numpy's setxor1d I came across the following error (minimal example below):
```
@nb.njit()
def test():
    included = np.array([1, 2, 6, 8])
    not_included = [i for i in range(10) if i not in list(included)]
    return not_included
```
Which results in:

`Type of variable '$18compare_op.7.7054' cannot be determined, operation: unary(fn=<built-in function not_>, value=$18compare_op.7.7054), location: <ipython-input-138-e85438f982c0> (4)`

Which does not occur when the 'not' statement (in if i not in list(included)]) is not there
I could get around this by instead doing:
```
@nb.njit()
def test():
    included = np.array([1, 2, 6, 8])
    not_included = [i for i in range(10) if (i in list(included)) is False]
    return not_included
```
Which is not very pretty.


Discussion:
@LucIJspeert thanks for reporting this! I can reproduce it. It seems like the `not` doesn't work properly in the list comprehension context.
@LucIJspeert thanks for reporting this! I can reproduce it. It seems like the `not` doesn't work properly in the list comprehension context.

Resolving patch:
diff --git a/numba/core/ir_utils.py b/numba/core/ir_utils.py
--- a/numba/core/ir_utils.py
+++ b/numba/core/ir_utils.py
@@ -1669,12 +1669,30 @@ def __init__(self, f_ir):
             self.state.typemap = None
             self.state.return_type = None
             self.state.calltypes = None
-    rewrites.rewrite_registry.apply('before-inference', DummyPipeline(ir).state)
+    state = DummyPipeline(ir).state
+    rewrites.rewrite_registry.apply('before-inference', state)
     # call inline pass to handle cases like stencils and comprehensions
     swapped = {} # TODO: get this from diagnostics store
     inline_pass = numba.core.inline_closurecall.InlineClosureCallPass(
         ir, numba.core.cpu.ParallelOptions(False), swapped)
     inline_pass.run()
+
+    # TODO: DO NOT ADD MORE THINGS HERE!
+    # If adding more things here is being contemplated, it really is time to
+    # retire this function and work on getting the InlineWorker class from
+    # numba.core.inline_closurecall into sufficient shape as a replacement.
+    # The issue with `get_ir_of_code` is that it doesn't run a full compilation
+    # pipeline and as a result various additional things keep needing to be
+    # added to create valid IR.
+
+    # rebuild IR in SSA form
+    from numba.core.untyped_passes import ReconstructSSA
+    from numba.core.typed_passes import PreLowerStripPhis
+    reconstruct_ssa = ReconstructSSA()
+    phistrip = PreLowerStripPhis()
+    reconstruct_ssa.run_pass(state)
+    phistrip.run_pass(state)
+
     post_proc = postproc.PostProcessor(ir)
     post_proc.run(True)
     return ir


Test patch:
diff --git a/numba/tests/test_comprehension.py b/numba/tests/test_comprehension.py
--- a/numba/tests/test_comprehension.py
+++ b/numba/tests/test_comprehension.py
@@ -186,12 +186,21 @@ def list24(x):
             z = [float(y) if y > 3 else y for y in x]
             return z
 
+        def list25(x):
+            # See issue #6260. Old style inline_closure_call uses get_ir_of_code
+            # for the closure->IR transform, without SSA there's multiply
+            # defined labels, the unary negation is self referent and DCE runs
+            # eliminating the duplicated labels.
+            included = np.array([1, 2, 6, 8])
+            not_included = [i for i in range(10) if i not in list(included)]
+            return not_included
+
         # functions to test that are expected to pass
         f = [list1, list2, list3, list4,
              list6, list7, list8, list9, list10, list11,
              list12, list13, list14, list15,
              list16, list17, list18, list19, list20,
-             list21, list22, list23, list24]
+             list21, list22, list23, list24, list25]
 
         var = [1, 2, 3, 4, 5]
         for ref in f: