def autojit_method_compiler(env, extclass, method, signature): """ Called to compile a new specialized method. The result should be added to the perfect hash-based vtable. """ # compiled_method = numba.jit(argtypes=argtypes)(method.py_func) func_env = pipeline.compile2(env, method.py_func, restype=signature.return_type, argtypes=signature.args) # Create Method for the specialization new_method = signatures.Method( method.py_func, method.name, func_env.func_signature, is_class=method.is_class, is_static=method.is_static) new_method.update_from_env(func_env) # Update vtable type vtable_wrapper = extclass.__numba_vtab vtable_type = extclass.exttype.vtab_type vtable_type.specialized_methods[new_method.name, signature.args] = new_method # Replace vtable (which will update the vtable all (live) objects use) new_vtable = virtual.build_hashing_vtab(vtable_type) vtable_wrapper.replace_vtable(new_vtable) return func_env.numba_wrapper_func
def compile_function(env, func, argtypes, restype=None, **kwds): """ Compile a python function given the argument types. Compile only if not compiled already, and only if it is registered to the function cache. Returns a triplet of (signature, llvm_func, python_callable) `python_callable` is the wrapper function (NumbaFunction). """ function_cache = env.specializations # For NumbaFunction, we get the original python function. func = getattr(func, "py_func", func) # get the compile flags flags = None # stub # Search in cache result = function_cache.get_function(func, argtypes, flags) if result is not None: sig, lfunc, pycall = result return sig, lfunc, pycall # Compile the function from numba import pipeline compile_only = getattr(func, "_numba_compile_only", False) kwds["compile_only"] = kwds.get("compile_only", compile_only) assert kwds.get("llvm_module") is None, kwds.get("llvm_module") func_env = pipeline.compile2(env, func, restype, argtypes, **kwds) function_cache.register_specialization(func_env) return (func_env.func_signature, func_env.lfunc, func_env.numba_wrapper_func)
def _compile_methods(class_dict, env, ext_type, lmethods, method_pointers, flags): parent_method_pointers = getattr( ext_type.py_class, '__numba_method_pointers', None) for i, (method_name, func_signature) in enumerate(ext_type.methods): if method_name not in class_dict: # Inherited method assert parent_method_pointers is not None name, p = parent_method_pointers[i] assert name == method_name method_pointers.append((method_name, p)) continue method = class_dict[method_name] # Don't use compile_after_type_inference, re-infer, since we may # have inferred some return types # TODO: delayed types and circular calls/variable assignments logger.debug(method.py_func) func_env = pipeline.compile2( env, method.py_func, func_signature.return_type, func_signature.args, name=method.py_func.__name__, **flags) lmethods.append(func_env.lfunc) method_pointers.append((method_name, func_env.translator.lfunc_pointer)) class_dict[method_name] = method.result(func_env.numba_wrapper_func)
def autojit_method_compiler(env, extclass, method, signature): """ Called to compile a new specialized method. The result should be added to the perfect hash-based vtable. """ # compiled_method = numba.jit(argtypes=argtypes)(method.py_func) func_env = pipeline.compile2(env, method.py_func, restype=signature.return_type, argtypes=signature.args) # Create Method for the specialization new_method = signatures.Method(method.py_func, method.name, func_env.func_signature, is_class=method.is_class, is_static=method.is_static) new_method.update_from_env(func_env) # Update vtable type vtable_wrapper = extclass.__numba_vtab vtable_type = extclass.exttype.vtab_type vtable_type.specialized_methods[new_method.name, signature.args] = new_method # Replace vtable (which will update the vtable all (live) objects use) new_vtable = virtual.build_hashing_vtab(vtable_type) vtable_wrapper.replace_vtable(new_vtable) return func_env.numba_wrapper_func
def type_infer_method(self, method): func_env = pipeline.compile2(self.env, method.py_func, method.signature.return_type, method.signature.args, # don't use qualified name name=method.name, pipeline_name='type_infer', **self.flags) self.func_envs[method] = func_env # Verify signature after type inference with registered # (user-declared) signature method.signature = methods.ExtMethodType( method.signature.return_type, method.signature.args, method.name, is_class_method=method.is_class, is_static_method=method.is_static) self.ext_type.add_method(method)
def compile_function(env, func, argtypes, restype=None, func_ast=None, **kwds): """ Compile a python function given the argument types. Compile only if not compiled already, and only if it is registered to the function cache. Returns a triplet of (signature, llvm_func, python_callable) `python_callable` is the wrapper function (NumbaFunction). """ function_cache = env.specializations # For NumbaFunction, we get the original python function. func = getattr(func, 'py_func', func) # get the compile flags flags = None # stub # Search in cache result = function_cache.get_function(func, argtypes, flags) if result is not None: sig, lfunc, pycall = result return sig, lfunc, pycall # Compile the function from numba import pipeline compile_only = getattr(func, '_numba_compile_only', False) kwds['compile_only'] = kwds.get('compile_only', compile_only) assert kwds.get('llvm_module') is None, kwds.get('llvm_module') func_env = pipeline.compile2(env, func, restype, argtypes, func_ast=func_ast, **kwds) function_cache.register_specialization(func_env) return (func_env.func_signature, func_env.lfunc, func_env.numba_wrapper_func)
def type_infer_method(self, method): func_env = pipeline.compile2( self.env, method.py_func, method.signature.return_type, method.signature.args, # don't use qualified name name=method.name, pipeline_name='type_infer', **self.flags) self.func_envs[method] = func_env # Verify signature after type inference with registered # (user-declared) signature method.signature = methods.ExtMethodType(method.signature.return_type, method.signature.args, method.name, is_class=method.is_class, is_static=method.is_static) self.ext_type.add_method(method)