<commit_before>"""
This module contains the Pipeline class which provides a pluggable way to
define the transformations and the order in which they run on the AST.
"""

import inspect
import ast as ast_module
import logging
import functools
import pprint
from timeit import default_timer as _timer

import llvm.core as lc

import numba.closure
from numba import error
from numba import functions, naming, transforms, visitors, control_flow
from numba import ast_type_inference as type_inference
from numba import ast_constant_folding as constant_folding
from numba import ast_translate
from numba import utils
from numba.utils import dump
from numba.asdl import schema
from numba.minivect import minitypes

logger = logging.getLogger(__name__)

class Pipeline(object):
    """
    Runs a pipeline of transforms.
    """

    order = [
        'cfg',
        #'dump_cfg',
        #'const_folding',
        'type_infer',
        'type_set',
        'dump_cfg',
        'closure_type_inference',
        'transform_for',
        'specialize',
        'late_specializer',
        'fix_ast_locations',
        'cleanup_symtab',
        'codegen',
    ]

    mixins = {}
    _current_pipeline_stage = None

    def __init__(self, context, func, ast, func_signature,
                 nopython=False, locals=None, order=None, codegen=False,
                 symtab=None, allow_rebind_args=True, **kwargs):
        self.context = context
        self.func = func
        self.ast = ast
        self.func_signature = func_signature

        # Whether argument variables may be rebound to different types.
        # e.g. def f(a): a = "hello" ;; f(0.0)
        self.allow_rebind_args = allow_rebind_args

        ast.pipeline = self

        self.func_name = kwargs.get('name')
        if not self.func_name:
            if func:
                module_name = inspect.getmodule(func).__name__
                name = '.'.join([module_name, func.__name__])
            else:
                name = ast.name

            self.func_name = naming.specialized_mangle(
                                    name, self.func_signature.args)

        self.symtab = symtab
        if symtab is None:
            self.symtab = {}

        # Let the pipeline create a module for the function it is compiling
        # and the user will link that in.
        assert 'llvm_module' not in kwargs
        self.llvm_module = lc.Module.new('tmp.module.%x' % id(func))

        self.nopython = nopython
        self.locals = locals or {}
        self.kwargs = kwargs<commit_msg>Fix obtain module name for transforms for generated functions<commit_after>"""
This module contains the Pipeline class which provides a pluggable way to
define the transformations and the order in which they run on the AST.
"""

import inspect
import ast as ast_module
import logging
import functools
import pprint
from timeit import default_timer as _timer

import llvm.core as lc

import numba.closure
from numba import error
from numba import functions, naming, transforms, visitors, control_flow
from numba import ast_type_inference as type_inference
from numba import ast_constant_folding as constant_folding
from numba import ast_translate
from numba import utils
from numba.utils import dump
from numba.asdl import schema
from numba.minivect import minitypes

logger = logging.getLogger(__name__)

class Pipeline(object):
    """
    Runs a pipeline of transforms.
    """

    order = [
        'cfg',
        #'dump_cfg',
        #'const_folding',
        'type_infer',
        'type_set',
        'dump_cfg',
        'closure_type_inference',
        'transform_for',
        'specialize',
        'late_specializer',
        'fix_ast_locations',
        'cleanup_symtab',
        'codegen',
    ]

    mixins = {}
    _current_pipeline_stage = None

    def __init__(self, context, func, ast, func_signature,
                 nopython=False, locals=None, order=None, codegen=False,
                 symtab=None, allow_rebind_args=True, **kwargs):
        self.context = context
        self.func = func
        self.ast = ast
        self.func_signature = func_signature

        # Whether argument variables may be rebound to different types.
        # e.g. def f(a): a = "hello" ;; f(0.0)
        self.allow_rebind_args = allow_rebind_args

        ast.pipeline = self

        self.func_name = kwargs.get('name')
        if not self.func_name:
            if func:
                module_name = func.__module__ or '<unknown>'
                name = '.'.join([module_name, func.__name__])
            else:
                name = ast.name

            self.func_name = naming.specialized_mangle(
                                    name, self.func_signature.args)

        self.symtab = symtab
        if symtab is None:
            self.symtab = {}

        # Let the pipeline create a module for the function it is compiling
        # and the user will link that in.
        assert 'llvm_module' not in kwargs
        self.llvm_module = lc.Module.new('tmp.module.%x' % id(func))

        self.nopython = nopython
        self.locals = locals or {}
        self.kwargs = kwargs
{'fraction_non_alphanumeric': 0.07885514018691589, 'fraction_numerical': 0.000778816199376947, 'mean_word_length': 2.3313878080415047, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7103879', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1450, 'n_words': 449}