<commit_before>{-# LANGUAGE KindSignatures, 
MultiParamTypeClasses, NoImplicitPrelude, RankNTypes
 #-}
{-# OPTIONS -Wall #-}

-- | tipycal optimization menu

module Language.Paraiso.Optimization (
  optimize,
  Level(..),
  Ready
  ) where

import           Language.Paraiso.Annotation
import           Language.Paraiso.OM
import           Language.Paraiso.Optimization.BoundaryAnalysis
import           Language.Paraiso.Optimization.DeadCodeElimination
import           Language.Paraiso.Optimization.DecideAllocation
import           Language.Paraiso.Optimization.DependencyAnalysis
import           Language.Paraiso.Optimization.Graph
import           Language.Paraiso.Optimization.Identity
import           Language.Paraiso.Prelude



optimize :: (Ready v g)            
            => Level 
            -> OM v g Annotation 
            -> OM v g Annotation
            
optimize level = case level of
  O0 -> gmap identity . writeGrouping . gmap boundaryAnalysis . gmap decideAllocation . gmap deadCodeElimination
  _  -> optimize O0

data Level 
  = O0 -- perform mandatory code analysis
  | O1
  | O2
  | O3<commit_msg>double optimization circumbented.<commit_after>{-# LANGUAGE DeriveDataTypeable, KindSignatures, 
MultiParamTypeClasses, NoImplicitPrelude, RankNTypes
 #-}
{-# OPTIONS -Wall #-}

-- | tipycal optimization menu

module Language.Paraiso.Optimization (
  optimize,
  Level(..),
  Ready
  ) where

import           Data.Typeable
import qualified Language.Paraiso.Annotation as Anot
import           Language.Paraiso.OM (OM(..))
import           Language.Paraiso.OM.Graph (globalAnnotation)
import           Language.Paraiso.Optimization.BoundaryAnalysis
import           Language.Paraiso.Optimization.DeadCodeElimination
import           Language.Paraiso.Optimization.DecideAllocation
import           Language.Paraiso.Optimization.DependencyAnalysis
import           Language.Paraiso.Optimization.Graph
import           Language.Paraiso.Optimization.Identity
import           Language.Paraiso.Prelude



optimize :: (Ready v g)            
            => Level 
            -> OM v g Anot.Annotation 
            -> OM v g Anot.Annotation
            
optimize level om = 
  if (Just level > maybeOldLevel) 
  then recordLevel $ optimizer om 
  else om
  where
    maybeOldLevel = Anot.toMaybe $ globalAnnotation $ setup om
    
    recordLevel om = 
      om
      { setup = (setup om)
        { globalAnnotation = Anot.set (level) $ globalAnnotation (setup om)
        }
      }

    optimizer = case level of
      O0 -> gmap identity . 
            writeGrouping . 
            gmap boundaryAnalysis . 
            gmap decideAllocation . 
            gmap deadCodeElimination 
      _  -> optimize O0

data Level 
  = O0 -- perform mandatory code analysis
  | O1
  | O2
  | O3
    deriving (Eq, Ord, Show, Typeable)
{'fraction_non_alphanumeric': 0.07281041153710868, 'fraction_numerical': 0.004220893422441084, 'mean_word_length': 2.284064665127021, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '5502999', 'n_tokens_mistral': 843, 'n_tokens_neox': 801, 'n_words': 196}