Beispiel #1
0
def createModuleTree(module, source_ref, source_code, is_main):
    if Options.isShowMemory():
        memory_watch = MemoryUsage.MemoryWatch()

    try:
        module_body = buildParseTree(provider=module,
                                     source_code=source_code,
                                     source_ref=source_ref,
                                     is_module=True,
                                     is_main=is_main)
    except RuntimeError as e:
        if "maximum recursion depth" in e.args[0]:
            raise CodeTooComplexCode(module.getFullName(),
                                     module.getCompileTimeFilename())

        raise

    if module_body.isStatementsFrame():
        module_body = makeStatementsSequenceFromStatement(
            statement=module_body, )

    module.setBody(module_body)

    completeVariableClosures(module)

    if Options.isShowMemory():
        memory_watch.finish()

        info("Memory usage changed loading module '%s': %s" %
             (module.getFullName(), memory_watch.asStr()))
Beispiel #2
0
def createModuleTree(module, source_ref, ast_tree, is_main):
    if Options.isShowMemory():
        memory_watch = MemoryUsage.MemoryWatch()

    module_body = buildParseTree(
        provider=module,
        ast_tree=ast_tree,
        source_ref=source_ref,
        is_module=True,
        is_main=is_main,
    )

    if module_body.isStatementsFrame():
        module_body = makeStatementsSequenceFromStatement(
            statement=module_body)

    module.setChild("body", module_body)

    completeVariableClosures(module)

    if Options.isShowMemory():
        memory_watch.finish()

        memory_logger.info("Memory usage changed loading module '%s': %s" %
                           (module.getFullName(), memory_watch.asStr()))
Beispiel #3
0
def optimizeCompiledPythonModule(module):
    if _progress:
        progress_logger.info(
            "Doing module local optimizations for '{module_name}'.".format(
                module_name=module.getFullName()))

    touched = False

    if _progress and Options.isShowMemory():
        memory_watch = MemoryUsage.MemoryWatch()

    while True:
        tag_set.clear()

        try:
            # print("Compute module")
            module.computeModule()
        except BaseException:
            general.info("Interrupted while working on '%s'." % module)
            raise

        Graphs.onModuleOptimizationStep(module)

        # Search for local change tags.
        for tag in tag_set:
            if tag == "new_code":
                continue

            break
        else:
            if _progress:
                progress_logger.info("Finished with the module.")
            break

        if _progress:
            if "new_code" in tag_set:
                tag_set.remove("new_code")

            progress_logger.info(
                "Not finished with the module due to following change kinds: %s"
                % ",".join(sorted(tag_set)))

        # Otherwise we did stuff, so note that for return value.
        touched = True

    if _progress and Options.isShowMemory():
        memory_watch.finish()

        memory_logger.info(
            "Memory usage changed during optimization of '%s': %s" %
            (module.getFullName(), memory_watch.asStr()))

    Plugins.considerImplicitImports(module=module, signal_change=signalChange)

    return touched
Beispiel #4
0
def optimizeCompiledPythonModule(module):
    if _progress:
        info(
            "Doing module local optimizations for '{module_name}'.".format(
                module_name = module.getFullName()
            )
        )

    touched = False

    if _progress and Options.isShowMemory():
        memory_watch = MemoryUsage.MemoryWatch()

    while True:
        tag_set.clear()

        try:
            module.computeModule()
        except BaseException:
            info("Interrupted while working on '%s'." % module)
            raise

        Graphs.onModuleOptimizationStep(module)

        # Search for local change tags.
        for tag in tag_set:
            if tag == "new_code":
                continue

            break
        else:
            break

        # Otherwise we did stuff, so note that for return value.
        touched = True

    if _progress and Options.isShowMemory():
        memory_watch.finish()

        info(
            "Memory usage changed during optimization of '%s': %s" % (
                module.getFullName(),
                memory_watch.asStr()
            )
        )

    Plugins.considerImplicitImports(
        module        = module,
        signal_change = signalChange
    )

    return touched
Beispiel #5
0
def optimizePythonModule(module):
    if _progress:
        printLine(
            "Doing module local optimizations for '{module_name}'.".format(
                module_name=module.getFullName()))

    # The tag set is global, so it can react to changes without context.
    # pylint: disable=W0603
    global tag_set
    tag_set = TagSet()

    touched = False

    if _progress:
        memory_watch = MemoryUsage.MemoryWatch()

    while True:
        tag_set.clear()

        try:
            module.computeModule()
        except BaseException:
            info("Interrupted while working on '%s'." % module)
            raise

        if not tag_set:
            break

        if graph is not None:
            computation_counters[module] = computation_counters.get(module,
                                                                    0) + 1
            module_graph = module.asGraph(computation_counters[module])

            graph.subgraph(module_graph)

        touched = True

    if _progress:
        memory_watch.finish()

        printLine("Memory usage changed during optimization of '%s': %s" %
                  (module.getFullName(), memory_watch.asStr()))

    Plugins.considerImplicitImports(module, signal_change=signalChange)

    return touched