<commit_before>{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, ScopedTypeVariables #-}
module Oracles.ModuleFiles (moduleFiles, haskellModuleFiles, moduleFilesOracle) where

import Base
import Oracles.PackageData
import Package
import Stage
import Settings.TargetDirectory

newtype ModuleFilesKey = ModuleFilesKey ([String], [FilePath])
    deriving (Show, Typeable, Eq, Hashable, Binary, NFData)

moduleFiles :: Stage -> Package -> Action [FilePath]
moduleFiles stage pkg = do
    let path = targetPath stage pkg
    srcDirs <- fmap sort . pkgDataList $ SrcDirs path
    modules <- fmap sort . pkgDataList $ Modules path
    let dirs = [ pkgPath pkg -/- dir | dir <- srcDirs ]
    found :: [(String, FilePath)] <- askOracle $ ModuleFilesKey (modules, dirs)
    return $ map snd found

haskellModuleFiles :: Stage -> Package -> Action ([FilePath], [String])
haskellModuleFiles stage pkg = do
    let path    = targetPath stage pkg
        autogen = path -/- "build/autogen"
    srcDirs <- fmap sort . pkgDataList $ SrcDirs path
    modules <- fmap sort . pkgDataList $ Modules path
    let dirs = [ pkgPath pkg -/- dir | dir <- srcDirs ]
    foundSrcDirs <- askOracle $ ModuleFilesKey (modules, dirs     )
    foundAutogen <- askOracle $ ModuleFilesKey (modules, [autogen])

    let found          = foundSrcDirs ++ foundAutogen
        missingMods    = modules `minusOrd` (sort $ map fst found)
        otherMods      = map (replaceEq '/' '.' . dropExtension) otherFiles
        (haskellFiles, otherFiles) = partition ("//*hs" ?==) (map snd found)
    return (haskellFiles, missingMods ++ otherMods)
<commit_msg>Fix paths to generated Haskell files.<commit_after>{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, ScopedTypeVariables #-}
module Oracles.ModuleFiles (moduleFiles, haskellModuleFiles, moduleFilesOracle) where

import Base
import Oracles.PackageData
import Package
import Stage
import Settings.TargetDirectory

newtype ModuleFilesKey = ModuleFilesKey ([String], [FilePath])
    deriving (Show, Typeable, Eq, Hashable, Binary, NFData)

moduleFiles :: Stage -> Package -> Action [FilePath]
moduleFiles stage pkg = do
    let path = targetPath stage pkg
    srcDirs <- fmap sort . pkgDataList $ SrcDirs path
    modules <- fmap sort . pkgDataList $ Modules path
    let dirs = [ pkgPath pkg -/- dir | dir <- srcDirs ]
    found :: [(String, FilePath)] <- askOracle $ ModuleFilesKey (modules, dirs)
    return $ map snd found

haskellModuleFiles :: Stage -> Package -> Action ([FilePath], [String])
haskellModuleFiles stage pkg = do
    let path        = targetPath stage pkg
        autogen     = path -/- "build/autogen"
        dropPkgPath = drop $ length (pkgPath pkg) + 1
    srcDirs <- fmap sort . pkgDataList $ SrcDirs path
    modules <- fmap sort . pkgDataList $ Modules path
    let dirs = [ pkgPath pkg -/- dir | dir <- srcDirs ]
    foundSrcDirs <- askOracle $ ModuleFilesKey (modules, dirs     )
    foundAutogen <- askOracle $ ModuleFilesKey (modules, [autogen])

    let found          = foundSrcDirs ++ foundAutogen
        missingMods    = modules `minusOrd` (sort $ map fst found)
        otherFileToMod = replaceEq '/' '.' . dropExtension . dropPkgPath
        (haskellFiles, otherFiles) = partition ("//*hs" ?==) (map snd found)

    return (haskellFiles, missingMods ++ map otherFileToMod otherFiles)

{'fraction_non_alphanumeric': 0.10101311084624554, 'fraction_numerical': 0.0002979737783075089, 'mean_word_length': 3.388235294117647, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '3278362', 'n_tokens_mistral': 1047, 'n_tokens_neox': 975, 'n_words': 314}