<commit_before>#!/usr/bin/env python3

from pass_utils import *
from expression_walker import walk

import collections
import re
import sys
import subprocess
import os.path as path


def single_assignment(exp, inputs, assigns, consts=None):
  PASSTHROUGH = {"Integer", "Float", "Input", "Const", "ConstantInterval",
                 "PointInterval"}
  UNCACHED    = PASSTHROUGH.union({"Tuple", "Variable"})
  TWO_ITEMS   = BINOPS.union({"Tuple"})
  ONE_ITEM    = UNOPS.union({"Return"})


  def cache(exp, hashed=dict()):
    if exp[0] in UNCACHED:
      return exp
    try:
      key = hashed[exp]
    except KeyError:
      key = "_expr_"+str(len(hashed))
      hashed[exp] = key
      assigns[key] = exp
    return ("Variable", key)
<commit_msg>Added logging of eliminated redundant subexpressions at -v 5<commit_after>#!/usr/bin/env python3

from pass_utils import *
from expression_walker import walk
import ian_utils as iu

import collections
import re
import sys
import subprocess
import os.path as path


def single_assignment(exp, inputs, assigns, consts=None):
  PASSTHROUGH = {"Integer", "Float", "Input", "Const", "ConstantInterval",
                 "PointInterval"}
  UNCACHED    = PASSTHROUGH.union({"Tuple", "Variable"})
  TWO_ITEMS   = BINOPS.union({"Tuple"})
  ONE_ITEM    = UNOPS.union({"Return"})


  def cache(exp, hashed=dict()):
    if exp[0] in UNCACHED:
      return exp
    try:
      key = hashed[exp]
      iu.log(5, lambda :iu.cyan("Eliminated redundant subexpression") + ": {}".format(exp))
    except KeyError:
      key = "_expr_"+str(len(hashed))
      hashed[exp] = key
      assigns[key] = exp
    return ("Variable", key)

{'fraction_non_alphanumeric': 0.13027744270205066, 'fraction_numerical': 0.0036188178528347406, 'mean_word_length': 3.5702479338842976, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7587396', 'n_tokens_mistral': 579, 'n_tokens_neox': 542, 'n_words': 144}