We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Tuples containing bools do not work with `numba.typed.List` or `numba.typed.Dict`
On the latest release (v0.35.1) on Python 3.7, the following:


```
import numba
numba.typed.List.empty_list(numba.typeof(("hello", True)))
```

fails with:

<details>
<summary>Stack Trace</summary>

```
TypingError                               Traceback (most recent call last)
<ipython-input-45-d29ae2daf2f2> in <module>
----> 1 l = numba.typed.List.empty_list(numba.typeof((0.0, "hello", True)))

/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py in empty_list(cls, item_type)
    149         of the list .
    150         """
--> 151         return cls(lsttype=ListType(item_type))
    152 
    153     def __init__(self, **kwargs):

/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py in __init__(self, **kwargs)
    164         """
    165         if kwargs:
--> 166             self._list_type, self._opaque = self._parse_arg(**kwargs)
    167         else:
    168             self._list_type = None

/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py in _parse_arg(self, lsttype, meminfo)
    175             opaque = meminfo
    176         else:
--> 177             opaque = _make_list(lsttype.item_type)
    178         return lsttype, opaque
    179 

/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)
    374                 e.patch_message(msg)
    375 
--> 376             error_rewrite(e, 'typing')
    377         except errors.UnsupportedError as e:
    378             # Something unsupported is present in the user code, add help info

/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/dispatcher.py in error_rewrite(e, issue_type)
    341                 raise e
    342             else:
--> 343                 reraise(type(e), e, None)
    344 
    345         argtypes = []

/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/six.py in reraise(tp, value, tb)
    656             value = tp()
    657         if value.__traceback__ is not tb:
--> 658             raise value.with_traceback(tb)
    659         raise value
    660 


TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function new_list at 0x7f29d63d4510>) with argument(s) of type(s): (typeref[(unicode_type, bool)])
 * parameterized
In definition 0:
    LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
expecting {{i8*, i64, i32, i32, i64, i8*, i8*}, i1} but got {{i8*, i64, i32, i32, i64, i8*, i8*}, i8}

File "../../opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py", line 347:
    def imp(item):
        <source elided>
        lp = _list_new(itemty)
        _list_set_method_table(lp, itemty)
        ^

[1] During: lowering "$0.7 = call $0.4(lp, $0.6, func=$0.4, args=[Var(lp, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (346)), Var($0.6, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347))], kws=(), vararg=None)" at /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347)
    raised from /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/six.py:659
In definition 1:
    LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
expecting {{i8*, i64, i32, i32, i64, i8*, i8*}, i1} but got {{i8*, i64, i32, i32, i64, i8*, i8*}, i8}

File "../../opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py", line 347:
    def imp(item):
        <source elided>
        lp = _list_new(itemty)
        _list_set_method_table(lp, itemty)
        ^

[1] During: lowering "$0.7 = call $0.4(lp, $0.6, func=$0.4, args=[Var(lp, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (346)), Var($0.6, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347))], kws=(), vararg=None)" at /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347)
    raised from /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/six.py:659
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function new_list at 0x7f29d63d4510>)
[2] During: typing of call at /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py (29)

```

</details>


It looks like using a tuple of `(int32, bool)` works fine, however.


## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I am 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 below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

<!--

Please include details of the bug here, including, if applicable, what you
expected to happen!

-->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `numba/typedobjectutils.py`
Content:
```
1 """ Common compiler level utilities for typed dict and list. """
2 
3 import operator
4 import warnings
5 
6 from llvmlite import ir
7 from llvmlite.llvmpy.core import Builder
8 
9 from numba import cgutils
10 from numba import types
11 from numba import typing
12 from numba.targets.registry import cpu_target
13 from numba.typeconv import Conversion
14 from numba.extending import intrinsic
15 from numba.errors import TypingError, NumbaTypeSafetyWarning
16 
17 
18 def _as_bytes(builder, ptr):
19     """Helper to do (void*)ptr
20     """
21     return builder.bitcast(ptr, cgutils.voidptr_t)
22 
23 
24 @intrinsic
25 def _cast(typingctx, val, typ):
26     """Cast *val* to *typ*
27     """
28     def codegen(context, builder, signature, args):
29         [val, typ] = args
30         context.nrt.incref(builder, signature.return_type, val)
31         return val
32     # Using implicit casting in argument types
33     casted = typ.instance_type
34     _sentry_safe_cast(val, casted)
35     sig = casted(casted, typ)
36     return sig, codegen
37 
38 
39 def _sentry_safe_cast(fromty, toty):
40     """Check and raise TypingError if *fromty* cannot be safely cast to *toty*
41     """
42     tyctxt = cpu_target.typing_context
43     fromty, toty = map(types.unliteral, (fromty, toty))
44     by = tyctxt.can_convert(fromty, toty)
45 
46     def warn():
47         m = 'unsafe cast from {} to {}. Precision may be lost.'
48         warnings.warn(m.format(fromty, toty),
49                       category=NumbaTypeSafetyWarning)
50 
51     isint = lambda x: isinstance(x, types.Integer)
52     isflt = lambda x: isinstance(x, types.Float)
53     iscmplx = lambda x: isinstance(x, types.Complex)
54     # Only check against numeric types.
55     if by is None or by > Conversion.safe:
56         if isint(fromty) and isint(toty):
57             # Accept if both types are ints
58             warn()
59         elif isint(fromty) and isflt(toty):
60             # Accept if ints to floats
61             warn()
62         elif isflt(fromty) and isflt(toty):
63             # Accept if floats to floats
64             warn()
65         elif iscmplx(fromty) and iscmplx(toty):
66             # Accept if complex to complex
67             warn()
68         elif not isinstance(toty, types.Number):
69             # Non-numbers
70             warn()
71         else:
72             # Make it a hard error for numeric type that changes domain.
73             m = 'cannot safely cast {} to {}. Please cast explicitly.'
74             raise TypingError(m.format(fromty, toty))
75 
76 
77 def _sentry_safe_cast_default(default, valty):
78     """Similar to _sentry_safe_cast but handle default value.
79     """
80     # Handle default values
81     # TODO: simplify default values; too many possible way to spell None
82     if default is None:
83         return
84     if isinstance(default, (types.Omitted, types.NoneType)):
85         return
86     return _sentry_safe_cast(default, valty)
87 
88 
89 @intrinsic
90 def _nonoptional(typingctx, val):
91     """Typing trick to cast Optional[T] to T
92     """
93     if not isinstance(val, types.Optional):
94         raise TypeError('expected an optional')
95 
96     def codegen(context, builder, sig, args):
97         context.nrt.incref(builder, sig.return_type, args[0])
98         return args[0]
99 
100     casted = val.type
101     sig = casted(casted)
102     return sig, codegen
103 
104 
105 def _container_get_data(context, builder, container_ty, c):
106     """Helper to get the C list pointer in a numba containers.
107     """
108     ctor = cgutils.create_struct_proxy(container_ty)
109     conatainer_struct = ctor(context, builder, value=c)
110     return conatainer_struct.data
111 
112 
113 def _container_get_meminfo(context, builder, container_ty, c):
114     """Helper to get the meminfo for a container
115     """
116     ctor = cgutils.create_struct_proxy(container_ty)
117     conatainer_struct = ctor(context, builder, value=c)
118     return conatainer_struct.meminfo
119 
120 
121 def _get_incref_decref(context, module, datamodel, container_type):
122     assert datamodel.contains_nrt_meminfo()
123 
124     fe_type = datamodel.fe_type
125     data_ptr_ty = datamodel.get_data_type().as_pointer()
126     refct_fnty = ir.FunctionType(ir.VoidType(), [data_ptr_ty])
127     incref_fn = module.get_or_insert_function(
128         refct_fnty,
129         name='.numba_{}_incref${}'.format(container_type, fe_type),
130     )
131     builder = ir.IRBuilder(incref_fn.append_basic_block())
132     context.nrt.incref(builder, fe_type, builder.load(incref_fn.args[0]))
133     builder.ret_void()
134 
135     decref_fn = module.get_or_insert_function(
136         refct_fnty,
137         name='.numba_{}_decref${}'.format(container_type, fe_type),
138     )
139     builder = ir.IRBuilder(decref_fn.append_basic_block())
140     context.nrt.decref(builder, fe_type, builder.load(decref_fn.args[0]))
141     builder.ret_void()
142 
143     return incref_fn, decref_fn
144 
145 
146 def _get_equal(context, module, datamodel, container_type):
147     assert datamodel.contains_nrt_meminfo()
148 
149     fe_type = datamodel.fe_type
150     data_ptr_ty = datamodel.get_data_type().as_pointer()
151 
152     wrapfnty = context.call_conv.get_function_type(types.int32, [fe_type, fe_type])
153     argtypes = [fe_type, fe_type]
154 
155     def build_wrapper(fn):
156         builder = Builder(fn.append_basic_block())
157         args = context.call_conv.decode_arguments(builder, argtypes, fn)
158 
159         sig = typing.signature(types.boolean, fe_type, fe_type)
160         op = operator.eq
161         fnop = context.typing_context.resolve_value_type(op)
162         fnop.get_call_type(context.typing_context, sig.args, {})
163         eqfn = context.get_function(fnop, sig)
164         res = eqfn(builder, args)
165         intres = context.cast(builder, res, types.boolean, types.int32)
166         context.call_conv.return_value(builder, intres)
167 
168     wrapfn = module.get_or_insert_function(
169         wrapfnty,
170         name='.numba_{}_item_equal.wrap${}'.format(container_type, fe_type)
171     )
172     build_wrapper(wrapfn)
173 
174     equal_fnty = ir.FunctionType(ir.IntType(32), [data_ptr_ty, data_ptr_ty])
175     equal_fn = module.get_or_insert_function(
176         equal_fnty,
177         name='.numba_{}_item_equal${}'.format(container_type, fe_type),
178     )
179     builder = Builder(equal_fn.append_basic_block())
180     lhs = datamodel.load_from_data_pointer(builder, equal_fn.args[0])
181     rhs = datamodel.load_from_data_pointer(builder, equal_fn.args[1])
182 
183     status, retval = context.call_conv.call_function(
184         builder, wrapfn, types.boolean, argtypes, [lhs, rhs],
185     )
186     with builder.if_then(status.is_ok, likely=True):
187         with builder.if_then(status.is_none):
188             builder.ret(context.get_constant(types.int32, 0))
189         retval = context.cast(builder, retval, types.boolean, types.int32)
190         builder.ret(retval)
191     # Error out
192     builder.ret(context.get_constant(types.int32, -1))
193 
194     return equal_fn
195
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/numba/typedobjectutils.py b/numba/typedobjectutils.py
--- a/numba/typedobjectutils.py
+++ b/numba/typedobjectutils.py
@@ -128,8 +128,12 @@
         refct_fnty,
         name='.numba_{}_incref${}'.format(container_type, fe_type),
     )
+
     builder = ir.IRBuilder(incref_fn.append_basic_block())
-    context.nrt.incref(builder, fe_type, builder.load(incref_fn.args[0]))
+    context.nrt.incref(
+        builder, fe_type,
+        datamodel.load_from_data_pointer(builder, incref_fn.args[0]),
+    )
     builder.ret_void()
 
     decref_fn = module.get_or_insert_function(
@@ -137,7 +141,10 @@
         name='.numba_{}_decref${}'.format(container_type, fe_type),
     )
     builder = ir.IRBuilder(decref_fn.append_basic_block())
-    context.nrt.decref(builder, fe_type, builder.load(decref_fn.args[0]))
+    context.nrt.decref(
+        builder, fe_type,
+        datamodel.load_from_data_pointer(builder, decref_fn.args[0]),
+    )
     builder.ret_void()
 
     return incref_fn, decref_fn

{"golden_diff": "diff --git a/numba/typedobjectutils.py b/numba/typedobjectutils.py\n--- a/numba/typedobjectutils.py\n+++ b/numba/typedobjectutils.py\n@@ -128,8 +128,12 @@\n         refct_fnty,\n         name='.numba_{}_incref${}'.format(container_type, fe_type),\n     )\n+\n     builder = ir.IRBuilder(incref_fn.append_basic_block())\n-    context.nrt.incref(builder, fe_type, builder.load(incref_fn.args[0]))\n+    context.nrt.incref(\n+        builder, fe_type,\n+        datamodel.load_from_data_pointer(builder, incref_fn.args[0]),\n+    )\n     builder.ret_void()\n \n     decref_fn = module.get_or_insert_function(\n@@ -137,7 +141,10 @@\n         name='.numba_{}_decref${}'.format(container_type, fe_type),\n     )\n     builder = ir.IRBuilder(decref_fn.append_basic_block())\n-    context.nrt.decref(builder, fe_type, builder.load(decref_fn.args[0]))\n+    context.nrt.decref(\n+        builder, fe_type,\n+        datamodel.load_from_data_pointer(builder, decref_fn.args[0]),\n+    )\n     builder.ret_void()\n \n     return incref_fn, decref_fn\n", "issue": "Tuples containing bools do not work with `numba.typed.List` or `numba.typed.Dict`\nOn the latest release (v0.35.1) on Python 3.7, the following:\r\n\r\n\r\n```\r\nimport numba\r\nnumba.typed.List.empty_list(numba.typeof((\"hello\", True)))\r\n```\r\n\r\nfails with:\r\n\r\n<details>\r\n<summary>Stack Trace</summary>\r\n\r\n```\r\nTypingError                               Traceback (most recent call last)\r\n<ipython-input-45-d29ae2daf2f2> in <module>\r\n----> 1 l = numba.typed.List.empty_list(numba.typeof((0.0, \"hello\", True)))\r\n\r\n/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py in empty_list(cls, item_type)\r\n    149         of the list .\r\n    150         \"\"\"\r\n--> 151         return cls(lsttype=ListType(item_type))\r\n    152 \r\n    153     def __init__(self, **kwargs):\r\n\r\n/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py in __init__(self, **kwargs)\r\n    164         \"\"\"\r\n    165         if kwargs:\r\n--> 166             self._list_type, self._opaque = self._parse_arg(**kwargs)\r\n    167         else:\r\n    168             self._list_type = None\r\n\r\n/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py in _parse_arg(self, lsttype, meminfo)\r\n    175             opaque = meminfo\r\n    176         else:\r\n--> 177             opaque = _make_list(lsttype.item_type)\r\n    178         return lsttype, opaque\r\n    179 \r\n\r\n/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)\r\n    374                 e.patch_message(msg)\r\n    375 \r\n--> 376             error_rewrite(e, 'typing')\r\n    377         except errors.UnsupportedError as e:\r\n    378             # Something unsupported is present in the user code, add help info\r\n\r\n/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/dispatcher.py in error_rewrite(e, issue_type)\r\n    341                 raise e\r\n    342             else:\r\n--> 343                 reraise(type(e), e, None)\r\n    344 \r\n    345         argtypes = []\r\n\r\n/opt/anaconda/envs/test/lib/python3.7/site-packages/numba/six.py in reraise(tp, value, tb)\r\n    656             value = tp()\r\n    657         if value.__traceback__ is not tb:\r\n--> 658             raise value.with_traceback(tb)\r\n    659         raise value\r\n    660 \r\n\r\n\r\nTypingError: Failed in nopython mode pipeline (step: nopython frontend)\r\nInvalid use of Function(<function new_list at 0x7f29d63d4510>) with argument(s) of type(s): (typeref[(unicode_type, bool)])\r\n * parameterized\r\nIn definition 0:\r\n    LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)\r\nexpecting {{i8*, i64, i32, i32, i64, i8*, i8*}, i1} but got {{i8*, i64, i32, i32, i64, i8*, i8*}, i8}\r\n\r\nFile \"../../opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py\", line 347:\r\n    def imp(item):\r\n        <source elided>\r\n        lp = _list_new(itemty)\r\n        _list_set_method_table(lp, itemty)\r\n        ^\r\n\r\n[1] During: lowering \"$0.7 = call $0.4(lp, $0.6, func=$0.4, args=[Var(lp, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (346)), Var($0.6, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347))], kws=(), vararg=None)\" at /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347)\r\n    raised from /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/six.py:659\r\nIn definition 1:\r\n    LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)\r\nexpecting {{i8*, i64, i32, i32, i64, i8*, i8*}, i1} but got {{i8*, i64, i32, i32, i64, i8*, i8*}, i8}\r\n\r\nFile \"../../opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py\", line 347:\r\n    def imp(item):\r\n        <source elided>\r\n        lp = _list_new(itemty)\r\n        _list_set_method_table(lp, itemty)\r\n        ^\r\n\r\n[1] During: lowering \"$0.7 = call $0.4(lp, $0.6, func=$0.4, args=[Var(lp, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (346)), Var($0.6, /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347))], kws=(), vararg=None)\" at /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/listobject.py (347)\r\n    raised from /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/six.py:659\r\nThis error is usually caused by passing an argument of a type that is unsupported by the named function.\r\n[1] During: resolving callee type: Function(<function new_list at 0x7f29d63d4510>)\r\n[2] During: typing of call at /opt/anaconda/envs/test/lib/python3.7/site-packages/numba/typed/typedlist.py (29)\r\n\r\n```\r\n\r\n</details>\r\n\r\n\r\nIt looks like using a tuple of `(int32, bool)` works fine, however.\r\n\r\n\r\n## Reporting a bug\r\n\r\n<!--\r\n\r\nBefore submitting a bug report please ensure that you can check off these boxes:\r\n\r\n-->\r\n\r\n- [x] I am using the latest released version of Numba (most recent is visible in\r\n the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).\r\n- [x] I have included below a minimal working reproducer (if you are unsure how\r\n to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).\r\n\r\n<!--\r\n\r\nPlease include details of the bug here, including, if applicable, what you\r\nexpected to happen!\r\n\r\n-->\r\n\n", "before_files": [{"content": "\"\"\" Common compiler level utilities for typed dict and list. \"\"\"\n\nimport operator\nimport warnings\n\nfrom llvmlite import ir\nfrom llvmlite.llvmpy.core import Builder\n\nfrom numba import cgutils\nfrom numba import types\nfrom numba import typing\nfrom numba.targets.registry import cpu_target\nfrom numba.typeconv import Conversion\nfrom numba.extending import intrinsic\nfrom numba.errors import TypingError, NumbaTypeSafetyWarning\n\n\ndef _as_bytes(builder, ptr):\n    \"\"\"Helper to do (void*)ptr\n    \"\"\"\n    return builder.bitcast(ptr, cgutils.voidptr_t)\n\n\n@intrinsic\ndef _cast(typingctx, val, typ):\n    \"\"\"Cast *val* to *typ*\n    \"\"\"\n    def codegen(context, builder, signature, args):\n        [val, typ] = args\n        context.nrt.incref(builder, signature.return_type, val)\n        return val\n    # Using implicit casting in argument types\n    casted = typ.instance_type\n    _sentry_safe_cast(val, casted)\n    sig = casted(casted, typ)\n    return sig, codegen\n\n\ndef _sentry_safe_cast(fromty, toty):\n    \"\"\"Check and raise TypingError if *fromty* cannot be safely cast to *toty*\n    \"\"\"\n    tyctxt = cpu_target.typing_context\n    fromty, toty = map(types.unliteral, (fromty, toty))\n    by = tyctxt.can_convert(fromty, toty)\n\n    def warn():\n        m = 'unsafe cast from {} to {}. Precision may be lost.'\n        warnings.warn(m.format(fromty, toty),\n                      category=NumbaTypeSafetyWarning)\n\n    isint = lambda x: isinstance(x, types.Integer)\n    isflt = lambda x: isinstance(x, types.Float)\n    iscmplx = lambda x: isinstance(x, types.Complex)\n    # Only check against numeric types.\n    if by is None or by > Conversion.safe:\n        if isint(fromty) and isint(toty):\n            # Accept if both types are ints\n            warn()\n        elif isint(fromty) and isflt(toty):\n            # Accept if ints to floats\n            warn()\n        elif isflt(fromty) and isflt(toty):\n            # Accept if floats to floats\n            warn()\n        elif iscmplx(fromty) and iscmplx(toty):\n            # Accept if complex to complex\n            warn()\n        elif not isinstance(toty, types.Number):\n            # Non-numbers\n            warn()\n        else:\n            # Make it a hard error for numeric type that changes domain.\n            m = 'cannot safely cast {} to {}. Please cast explicitly.'\n            raise TypingError(m.format(fromty, toty))\n\n\ndef _sentry_safe_cast_default(default, valty):\n    \"\"\"Similar to _sentry_safe_cast but handle default value.\n    \"\"\"\n    # Handle default values\n    # TODO: simplify default values; too many possible way to spell None\n    if default is None:\n        return\n    if isinstance(default, (types.Omitted, types.NoneType)):\n        return\n    return _sentry_safe_cast(default, valty)\n\n\n@intrinsic\ndef _nonoptional(typingctx, val):\n    \"\"\"Typing trick to cast Optional[T] to T\n    \"\"\"\n    if not isinstance(val, types.Optional):\n        raise TypeError('expected an optional')\n\n    def codegen(context, builder, sig, args):\n        context.nrt.incref(builder, sig.return_type, args[0])\n        return args[0]\n\n    casted = val.type\n    sig = casted(casted)\n    return sig, codegen\n\n\ndef _container_get_data(context, builder, container_ty, c):\n    \"\"\"Helper to get the C list pointer in a numba containers.\n    \"\"\"\n    ctor = cgutils.create_struct_proxy(container_ty)\n    conatainer_struct = ctor(context, builder, value=c)\n    return conatainer_struct.data\n\n\ndef _container_get_meminfo(context, builder, container_ty, c):\n    \"\"\"Helper to get the meminfo for a container\n    \"\"\"\n    ctor = cgutils.create_struct_proxy(container_ty)\n    conatainer_struct = ctor(context, builder, value=c)\n    return conatainer_struct.meminfo\n\n\ndef _get_incref_decref(context, module, datamodel, container_type):\n    assert datamodel.contains_nrt_meminfo()\n\n    fe_type = datamodel.fe_type\n    data_ptr_ty = datamodel.get_data_type().as_pointer()\n    refct_fnty = ir.FunctionType(ir.VoidType(), [data_ptr_ty])\n    incref_fn = module.get_or_insert_function(\n        refct_fnty,\n        name='.numba_{}_incref${}'.format(container_type, fe_type),\n    )\n    builder = ir.IRBuilder(incref_fn.append_basic_block())\n    context.nrt.incref(builder, fe_type, builder.load(incref_fn.args[0]))\n    builder.ret_void()\n\n    decref_fn = module.get_or_insert_function(\n        refct_fnty,\n        name='.numba_{}_decref${}'.format(container_type, fe_type),\n    )\n    builder = ir.IRBuilder(decref_fn.append_basic_block())\n    context.nrt.decref(builder, fe_type, builder.load(decref_fn.args[0]))\n    builder.ret_void()\n\n    return incref_fn, decref_fn\n\n\ndef _get_equal(context, module, datamodel, container_type):\n    assert datamodel.contains_nrt_meminfo()\n\n    fe_type = datamodel.fe_type\n    data_ptr_ty = datamodel.get_data_type().as_pointer()\n\n    wrapfnty = context.call_conv.get_function_type(types.int32, [fe_type, fe_type])\n    argtypes = [fe_type, fe_type]\n\n    def build_wrapper(fn):\n        builder = Builder(fn.append_basic_block())\n        args = context.call_conv.decode_arguments(builder, argtypes, fn)\n\n        sig = typing.signature(types.boolean, fe_type, fe_type)\n        op = operator.eq\n        fnop = context.typing_context.resolve_value_type(op)\n        fnop.get_call_type(context.typing_context, sig.args, {})\n        eqfn = context.get_function(fnop, sig)\n        res = eqfn(builder, args)\n        intres = context.cast(builder, res, types.boolean, types.int32)\n        context.call_conv.return_value(builder, intres)\n\n    wrapfn = module.get_or_insert_function(\n        wrapfnty,\n        name='.numba_{}_item_equal.wrap${}'.format(container_type, fe_type)\n    )\n    build_wrapper(wrapfn)\n\n    equal_fnty = ir.FunctionType(ir.IntType(32), [data_ptr_ty, data_ptr_ty])\n    equal_fn = module.get_or_insert_function(\n        equal_fnty,\n        name='.numba_{}_item_equal${}'.format(container_type, fe_type),\n    )\n    builder = Builder(equal_fn.append_basic_block())\n    lhs = datamodel.load_from_data_pointer(builder, equal_fn.args[0])\n    rhs = datamodel.load_from_data_pointer(builder, equal_fn.args[1])\n\n    status, retval = context.call_conv.call_function(\n        builder, wrapfn, types.boolean, argtypes, [lhs, rhs],\n    )\n    with builder.if_then(status.is_ok, likely=True):\n        with builder.if_then(status.is_none):\n            builder.ret(context.get_constant(types.int32, 0))\n        retval = context.cast(builder, retval, types.boolean, types.int32)\n        builder.ret(retval)\n    # Error out\n    builder.ret(context.get_constant(types.int32, -1))\n\n    return equal_fn\n", "path": "numba/typedobjectutils.py"}], "after_files": [{"content": "\"\"\" Common compiler level utilities for typed dict and list. \"\"\"\n\nimport operator\nimport warnings\n\nfrom llvmlite import ir\nfrom llvmlite.llvmpy.core import Builder\n\nfrom numba import cgutils\nfrom numba import types\nfrom numba import typing\nfrom numba.targets.registry import cpu_target\nfrom numba.typeconv import Conversion\nfrom numba.extending import intrinsic\nfrom numba.errors import TypingError, NumbaTypeSafetyWarning\n\n\ndef _as_bytes(builder, ptr):\n    \"\"\"Helper to do (void*)ptr\n    \"\"\"\n    return builder.bitcast(ptr, cgutils.voidptr_t)\n\n\n@intrinsic\ndef _cast(typingctx, val, typ):\n    \"\"\"Cast *val* to *typ*\n    \"\"\"\n    def codegen(context, builder, signature, args):\n        [val, typ] = args\n        context.nrt.incref(builder, signature.return_type, val)\n        return val\n    # Using implicit casting in argument types\n    casted = typ.instance_type\n    _sentry_safe_cast(val, casted)\n    sig = casted(casted, typ)\n    return sig, codegen\n\n\ndef _sentry_safe_cast(fromty, toty):\n    \"\"\"Check and raise TypingError if *fromty* cannot be safely cast to *toty*\n    \"\"\"\n    tyctxt = cpu_target.typing_context\n    fromty, toty = map(types.unliteral, (fromty, toty))\n    by = tyctxt.can_convert(fromty, toty)\n\n    def warn():\n        m = 'unsafe cast from {} to {}. Precision may be lost.'\n        warnings.warn(m.format(fromty, toty),\n                      category=NumbaTypeSafetyWarning)\n\n    isint = lambda x: isinstance(x, types.Integer)\n    isflt = lambda x: isinstance(x, types.Float)\n    iscmplx = lambda x: isinstance(x, types.Complex)\n    # Only check against numeric types.\n    if by is None or by > Conversion.safe:\n        if isint(fromty) and isint(toty):\n            # Accept if both types are ints\n            warn()\n        elif isint(fromty) and isflt(toty):\n            # Accept if ints to floats\n            warn()\n        elif isflt(fromty) and isflt(toty):\n            # Accept if floats to floats\n            warn()\n        elif iscmplx(fromty) and iscmplx(toty):\n            # Accept if complex to complex\n            warn()\n        elif not isinstance(toty, types.Number):\n            # Non-numbers\n            warn()\n        else:\n            # Make it a hard error for numeric type that changes domain.\n            m = 'cannot safely cast {} to {}. Please cast explicitly.'\n            raise TypingError(m.format(fromty, toty))\n\n\ndef _sentry_safe_cast_default(default, valty):\n    \"\"\"Similar to _sentry_safe_cast but handle default value.\n    \"\"\"\n    # Handle default values\n    # TODO: simplify default values; too many possible way to spell None\n    if default is None:\n        return\n    if isinstance(default, (types.Omitted, types.NoneType)):\n        return\n    return _sentry_safe_cast(default, valty)\n\n\n@intrinsic\ndef _nonoptional(typingctx, val):\n    \"\"\"Typing trick to cast Optional[T] to T\n    \"\"\"\n    if not isinstance(val, types.Optional):\n        raise TypeError('expected an optional')\n\n    def codegen(context, builder, sig, args):\n        context.nrt.incref(builder, sig.return_type, args[0])\n        return args[0]\n\n    casted = val.type\n    sig = casted(casted)\n    return sig, codegen\n\n\ndef _container_get_data(context, builder, container_ty, c):\n    \"\"\"Helper to get the C list pointer in a numba containers.\n    \"\"\"\n    ctor = cgutils.create_struct_proxy(container_ty)\n    conatainer_struct = ctor(context, builder, value=c)\n    return conatainer_struct.data\n\n\ndef _container_get_meminfo(context, builder, container_ty, c):\n    \"\"\"Helper to get the meminfo for a container\n    \"\"\"\n    ctor = cgutils.create_struct_proxy(container_ty)\n    conatainer_struct = ctor(context, builder, value=c)\n    return conatainer_struct.meminfo\n\n\ndef _get_incref_decref(context, module, datamodel, container_type):\n    assert datamodel.contains_nrt_meminfo()\n\n    fe_type = datamodel.fe_type\n    data_ptr_ty = datamodel.get_data_type().as_pointer()\n    refct_fnty = ir.FunctionType(ir.VoidType(), [data_ptr_ty])\n    incref_fn = module.get_or_insert_function(\n        refct_fnty,\n        name='.numba_{}_incref${}'.format(container_type, fe_type),\n    )\n\n    builder = ir.IRBuilder(incref_fn.append_basic_block())\n    context.nrt.incref(\n        builder, fe_type,\n        datamodel.load_from_data_pointer(builder, incref_fn.args[0]),\n    )\n    builder.ret_void()\n\n    decref_fn = module.get_or_insert_function(\n        refct_fnty,\n        name='.numba_{}_decref${}'.format(container_type, fe_type),\n    )\n    builder = ir.IRBuilder(decref_fn.append_basic_block())\n    context.nrt.decref(\n        builder, fe_type,\n        datamodel.load_from_data_pointer(builder, decref_fn.args[0]),\n    )\n    builder.ret_void()\n\n    return incref_fn, decref_fn\n\n\ndef _get_equal(context, module, datamodel, container_type):\n    assert datamodel.contains_nrt_meminfo()\n\n    fe_type = datamodel.fe_type\n    data_ptr_ty = datamodel.get_data_type().as_pointer()\n\n    wrapfnty = context.call_conv.get_function_type(types.int32, [fe_type, fe_type])\n    argtypes = [fe_type, fe_type]\n\n    def build_wrapper(fn):\n        builder = Builder(fn.append_basic_block())\n        args = context.call_conv.decode_arguments(builder, argtypes, fn)\n\n        sig = typing.signature(types.boolean, fe_type, fe_type)\n        op = operator.eq\n        fnop = context.typing_context.resolve_value_type(op)\n        fnop.get_call_type(context.typing_context, sig.args, {})\n        eqfn = context.get_function(fnop, sig)\n        res = eqfn(builder, args)\n        intres = context.cast(builder, res, types.boolean, types.int32)\n        context.call_conv.return_value(builder, intres)\n\n    wrapfn = module.get_or_insert_function(\n        wrapfnty,\n        name='.numba_{}_item_equal.wrap${}'.format(container_type, fe_type)\n    )\n    build_wrapper(wrapfn)\n\n    equal_fnty = ir.FunctionType(ir.IntType(32), [data_ptr_ty, data_ptr_ty])\n    equal_fn = module.get_or_insert_function(\n        equal_fnty,\n        name='.numba_{}_item_equal${}'.format(container_type, fe_type),\n    )\n    builder = Builder(equal_fn.append_basic_block())\n    lhs = datamodel.load_from_data_pointer(builder, equal_fn.args[0])\n    rhs = datamodel.load_from_data_pointer(builder, equal_fn.args[1])\n\n    status, retval = context.call_conv.call_function(\n        builder, wrapfn, types.boolean, argtypes, [lhs, rhs],\n    )\n    with builder.if_then(status.is_ok, likely=True):\n        with builder.if_then(status.is_none):\n            builder.ret(context.get_constant(types.int32, 0))\n        retval = context.cast(builder, retval, types.boolean, types.int32)\n        builder.ret(retval)\n    # Error out\n    builder.ret(context.get_constant(types.int32, -1))\n\n    return equal_fn\n", "path": "numba/typedobjectutils.py"}]}