Ejemplo n.º 1
0
    def compile_subroutine(self, builder, impl, sig, locals={}, flags=None,
                           caching=True):
        """
        Compile the function *impl* for the given *sig* (in nopython mode).
        Return a placeholder object that's callable from another Numba
        function.

        If *caching* evaluates True, the function keeps the compiled function
        for reuse in *.cached_internal_func*.
        """
        cache_key = (impl.__code__, sig, type(self.error_model))
        if not caching:
            cached = None
        else:
            if impl.__closure__:
                # XXX This obviously won't work if a cell's value is
                # unhashable.
                cache_key += tuple(c.cell_contents for c in impl.__closure__)
            cached = self.cached_internal_func.get(cache_key)
        if cached is None:
            cres = self._compile_subroutine_no_cache(builder, impl, sig,
                                                     locals=locals,
                                                     flags=flags)
            lib = cres.library
            ty = types.NumbaFunction(cres.fndesc, sig)
            self.cached_internal_func[cache_key] = ty, lib

        ty, lib = self.cached_internal_func[cache_key]
        # Allow inlining the function inside callers.
        self.active_code_library.add_linking_library(lib)
        return ty
Ejemplo n.º 2
0
 def compile_subroutine(self, builder, impl, sig, locals={}):
     """
     Compile the function *impl* for the given *sig* (in nopython mode).
     Return a placeholder object that's callable from another Numba
     function.
     """
     cache_key = (impl.__code__, sig, type(self.error_model))
     if impl.__closure__:
         # XXX This obviously won't work if a cell's value is
         # unhashable.
         cache_key += tuple(c.cell_contents for c in impl.__closure__)
     ty = self.cached_internal_func.get(cache_key)
     if ty is None:
         cres = self.compile_subroutine_no_cache(builder, impl, sig,
                                                 locals=locals)
         ty = types.NumbaFunction(cres.fndesc, sig)
         self.cached_internal_func[cache_key] = ty
     return ty