<commit_before>import AST
import Parser
import Utils
import Sema
import SystemKit

/// The default module loader.
public final class DefaultModuleLoader: ModuleLoader {

  public struct DebugConfig {

    public init() {}

    public var showRawAST: Bool = false
    public var showScopedAST: Bool = false
    public var showTypedAST: Bool = false
    public var showTypeConstraints: Bool = false

  }

  public init(logger: Logger? = nil, config: DebugConfig = DebugConfig()) {
    self.logger = logger
    self.config = config
  }

  /// The loader's logger.
  public let logger: Logger?
  /// The loader's debug config (for logging).
  public let config: DebugConfig

  public func load(_ moduleID: ModuleIdentifier, in context: ASTContext) -> ModuleDecl? {

    // ------- //
    // Parsing //
    // ------- //

    let file = locate(moduleID: moduleID, in: context)
    let parser: Parser
    do {
      parser = try Parser(source: file)
    } catch {
      logger?.error(error)
      return nil
    }

    let parseResult = parser.parse()
    guard parseResult.errors.isEmpty else {
      logger?.errors(parseResult.errors.sorted(by: { a, b in a.range.start < b.range.start }))
      return nil
    }
    var module = parseResult.value

    if config.showRawAST && (moduleID != .builtin) && (moduleID != .stdlib) {
      let buffer = StringBuffer()
      try! ASTDumper(to: buffer).visit(module)
      logger?.debug(buffer.value)
    }

    // ------- //
    // Scoping //<commit_msg>Bug fixes<commit_after>import AST
import Parser
import Utils
import Sema
import SystemKit

/// The default module loader.
public final class DefaultModuleLoader: ModuleLoader {

  public struct DebugConfig {

    public init() {}

    public var showRawAST: Bool = false
    public var showScopedAST: Bool = false
    public var showTypedAST: Bool = false
    public var showTypeConstraints: Bool = false

  }

  public init(logger: Logger? = nil, config: DebugConfig = DebugConfig()) {
    self.logger = logger
    self.config = config
  }

  /// The loader's logger.
  public let logger: Logger?
  /// The loader's debug config (for logging).
  public let config: DebugConfig

  public func load(_ moduleID: ModuleIdentifier, in context: ASTContext) -> ModuleDecl? {

    // ------- //
    // Parsing //
    // ------- //

    let file = locate(moduleID: moduleID, in: context)
    let parser: Parser
    do {
      parser = try Parser(source: file)
    } catch {
      logger?.error(error)
      return nil
    }

    let parseResult = parser.parse()
    guard parseResult.errors.isEmpty else {
      logger?.errors(parseResult.errors.sorted(by: { a, b in a.range.start < b.range.start }))
      return nil
    }
    var module = parseResult.value
    module.id = moduleID

    if config.showRawAST && (moduleID != .builtin) && (moduleID != .stdlib) {
      let buffer = StringBuffer()
      try! ASTDumper(to: buffer).visit(module)
      logger?.debug(buffer.value)
    }

    // ------- //
    // Scoping //
{'fraction_non_alphanumeric': 0.12187812187812187, 'fraction_numerical': 0.0, 'mean_word_length': 2.4768518518518516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3094568', 'n_tokens_mistral': 908, 'n_tokens_neox': 859, 'n_words': 265}