'Test serialization of intrinsic objects'

def test_serialization(self):

    @intrinsic
    def identity(context, x):
        def codegen(context, builder, signature, args):
            return args[0]
        sig = x(x)
        return (sig, codegen)
    @jit(nopython=True)
    def foo(x):
        return identity(x)
    self.assertEqual(foo(1), 1)
    memo = _Intrinsic._memo
    memo_size = len(memo)
    serialized_foo = pickle.dumps(foo)
    memo_size += 1
    self.assertEqual(memo_size, len(memo))
    foo_rebuilt = pickle.loads(serialized_foo)
    self.assertEqual(memo_size, len(memo))
    self.assertEqual(foo(1), foo_rebuilt(1))
    serialized_identity = pickle.dumps(identity)
    self.assertEqual(memo_size, len(memo))
    identity_rebuilt = pickle.loads(serialized_identity)
    self.assertIs(identity, identity_rebuilt)
    self.assertEqual(memo_size, len(memo))
