<commit_before>module Data.GhcLinks
  ( GhcLinks(..)
  , readGhcLinks
  ) where

import ClassyPrelude.Yesod
import Control.Monad.State.Strict (modify, execStateT)
import qualified Data.HashMap.Strict as HashMap
import Filesystem (readTextFile, isFile)

import Types


newtype GhcLinks = GhcLinks
  { ghcLinksMap :: HashMap (SupportedArch, GhcMajorVersion) Text }
  -- ^ a map from (arch, ver) to yaml

supportedArches :: [SupportedArch]
supportedArches = [minBound .. maxBound]

supportedGhcMajorVersions :: [GhcMajorVersion]
supportedGhcMajorVersions = ["7.8", "7.10"]


readGhcLinks :: FilePath -> IO GhcLinks
readGhcLinks dir = do
  let opts =
        [ (arch, ver)
        | arch <- supportedArches
        , ver <- supportedGhcMajorVersions
        ]
  hashMap <- flip execStateT HashMap.empty
           $ forM_ opts $ \(arch, ver) -> do
    let fileName = "ghc-" <> ver <> "-links.yaml"
    let path = dir
          </> fpFromText (toPathPiece arch)
          </> fpFromText fileName
    whenM (liftIO $ isFile path) $ do
      text <- liftIO $ readTextFile path
      modify (HashMap.insert (arch, ver) text)
  return $ GhcLinks hashMap
<commit_msg>Ghc major version whitelist is now drawn from stackage-content<commit_after>module Data.GhcLinks
  ( GhcLinks(..)
  , readGhcLinks
  ) where

import ClassyPrelude.Yesod
import Control.Monad.State.Strict (modify, execStateT)
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Yaml as Yaml
import Filesystem (readTextFile, isFile)

import Types


newtype GhcLinks = GhcLinks
  { ghcLinksMap :: HashMap (SupportedArch, GhcMajorVersion) Text }
  -- ^ a map from (arch, ver) to yaml

supportedArches :: [SupportedArch]
supportedArches = [minBound .. maxBound]

readGhcLinks :: FilePath -> IO GhcLinks
readGhcLinks dir = do
  let ghcMajorVersionsPath = dir </> "supported-ghc-major-versions.yaml"
  Yaml.decodeFile (fpToString ghcMajorVersionsPath) >>= \case
    Nothing -> return $ GhcLinks HashMap.empty
    Just (ghcMajorVersions :: [GhcMajorVersion]) -> do
      let opts =
            [ (arch, ver)
            | arch <- supportedArches
            , ver <- ghcMajorVersions
            ]
      hashMap <- flip execStateT HashMap.empty
               $ forM_ opts $ \(arch, ver) -> do
        let fileName = "ghc-" <> ver <> "-links.yaml"
        let path = dir
              </> fpFromText (toPathPiece arch)
              </> fpFromText fileName
        whenM (liftIO $ isFile path) $ do
          text <- liftIO $ readTextFile path
          modify (HashMap.insert (arch, ver) text)
      return $ GhcLinks hashMap

{'fraction_non_alphanumeric': 0.10142691862707288, 'fraction_numerical': 0.0019282684149633628, 'mean_word_length': 2.8716417910447762, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '4775630', 'n_tokens_mistral': 838, 'n_tokens_neox': 813, 'n_words': 226}