<commit_before>//===------------- InputDependencySourceMap.swift ---------------- --------===//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation
import TSCBasic

@_spi(Testing) public struct InputDependencySourceMap: Equatable {
  
  /// Maps input files (e.g. .swift) to and from the DependencySource object.
  ///
  // This map caches the same information as in the `OutputFileMap`, but it
  // optimizes the reverse lookup, and includes path interning via `DependencySource`.
  // Once created, it does not change.
  
  public typealias BiMap = BidirectionalMap<TypedVirtualPath, DependencySource>
  @_spi(Testing) public let biMap: BiMap

  /// Create the reverse map to map swiftdeps -> input (source) file from the `OutputFileMap`
   ///
   /// - Returns: the map, or nil if error
  init?(_ info: IncrementalCompilationState.IncrementalDependencyAndInputSetup) {
    let outputFileMap = info.outputFileMap
    let diagnosticEngine = info.diagnosticEngine

    assert(outputFileMap.onlySourceFilesHaveSwiftDeps())
    var hadError = false
    self.biMap = info.inputFiles.reduce(into: BiMap()) { biMap, input in
      guard input.type == .swift else {return}
      guard let dependencySource = outputFileMap.getDependencySource(for: input)
       else {
         // The legacy driver fails silently here.
         diagnosticEngine.emit(
           .remarkDisabled("\(input.file.basename) has no swiftDeps file")
         )
         hadError = true
         // Don't stop at the first problem.
         return
       }
       if let sameSourceForInput = biMap.updateValue(dependencySource, forKey: input) {
         diagnosticEngine.emit(
           .remarkDisabled(
             "\(dependencySource) and \(sameSourceForInput) have the same input file in the output file map: \(input)")
         )
         hadError = true
       }
     }
     if hadError {<commit_msg>Fix comment for InputDependencySourceMap.init<commit_after>//===------------- InputDependencySourceMap.swift ---------------- --------===//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation
import TSCBasic

@_spi(Testing) public struct InputDependencySourceMap: Equatable {
  
  /// Maps input files (e.g. .swift) to and from the DependencySource object.
  ///
  // This map caches the same information as in the `OutputFileMap`, but it
  // optimizes the reverse lookup, and includes path interning via `DependencySource`.
  // Once created, it does not change.
  
  public typealias BiMap = BidirectionalMap<TypedVirtualPath, DependencySource>
  @_spi(Testing) public let biMap: BiMap

  /// Based on entries in the `OutputFileMap`, create the bidirectional map to map each source file
  /// path to- and from- the corresponding swiftdeps file path.
  ///
  /// - Returns: the map, or nil if error
  init?(_ info: IncrementalCompilationState.IncrementalDependencyAndInputSetup) {
    let outputFileMap = info.outputFileMap
    let diagnosticEngine = info.diagnosticEngine

    assert(outputFileMap.onlySourceFilesHaveSwiftDeps())
    var hadError = false
    self.biMap = info.inputFiles.reduce(into: BiMap()) { biMap, input in
      guard input.type == .swift else {return}
      guard let dependencySource = outputFileMap.getDependencySource(for: input)
       else {
         // The legacy driver fails silently here.
         diagnosticEngine.emit(
           .remarkDisabled("\(input.file.basename) has no swiftDeps file")
         )
         hadError = true
         // Don't stop at the first problem.
         return
       }
       if let sameSourceForInput = biMap.updateValue(dependencySource, forKey: input) {
         diagnosticEngine.emit(
           .remarkDisabled(
             "\(dependencySource) and \(sameSourceForInput) have the same input file in the output file map: \(input)")
         )
         hadError = true
       }
     }
     if hadError {
{'fraction_non_alphanumeric': 0.1353448275862069, 'fraction_numerical': 0.002586206896551724, 'mean_word_length': 2.440326167531505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 4, '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': '2567389', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1179, 'n_words': 416}