<commit_before>(**
 * Copyright (c) 2013-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the "flow" directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 *)

module TI = Type_inference_js
module Server = ServerFunctors
module Persistent_connection_prot = ServerProt.Persistent_connection_prot

module FlowProgram : Server.SERVER_PROGRAM = struct
  open Utils_js
  open Sys_utils
  open ServerEnv
  open ServerUtils

  let name = "flow server"

  let sample_init_memory profiling =
    let open SharedMem_js in
    let dep_stats = dep_stats () in
    let hash_stats = hash_stats () in
    let heap_size = heap_size () in
    let memory_metrics = [
      "heap.size", heap_size;
      "dep_table.nonempty_slots", dep_stats.nonempty_slots;
      "dep_table.used_slots", dep_stats.used_slots;
      "dep_table.slots", dep_stats.slots;
      "hash_table.nonempty_slots", hash_stats.nonempty_slots;
      "hash_table.used_slots", hash_stats.used_slots;
      "hash_table.slots", hash_stats.slots;
    ] in
    List.fold_left (fun profiling (metric, value) ->
      Profiling_js.sample_memory
        ~metric:("init_done." ^ metric)
        ~value:(float_of_int value)
         profiling
    ) profiling memory_metrics

  let init ~focus_target genv =
    (* write binary path and version to server log *)
    Hh_logger.info "executable=%s" (Sys_utils.executable_path ());
    Hh_logger.info "version=%s" Flow_version.version;

    let profiling = Profiling_js.empty in

    let workers = genv.ServerEnv.workers in
    let options = genv.ServerEnv.options in

    let profiling, parsed, libs, libs_ok, errors =
      Types_js.init ~profiling ~workers options in

    (* if any libs errored, we'll infer but not merge client code *)
    let should_merge = libs_ok in

    (* compute initial state *)
    let profiling, checked, errors =
      let parsed =
        if Options.is_lazy_mode options then []
        else FilenameSet.elements parsed in
      Types_js.full_check ~profiling ~workers ~focus_target ~options ~should_merge parsed errors in

    let profiling = sample_init_memory profiling in

    SharedMem_js.init_done();

    (* Return an env that initializes invariants required and maintained by
       recheck, namely that `files` contains files that parsed successfully, and
       `errors` contains the current set of errors. *)
    profiling, { ServerEnv.
      files = parsed;
      checked_files = checked;
      libs;<commit_msg>don't run full_check during --lazy<commit_after>(**
 * Copyright (c) 2013-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the "flow" directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 *)

module TI = Type_inference_js
module Server = ServerFunctors
module Persistent_connection_prot = ServerProt.Persistent_connection_prot

module FlowProgram : Server.SERVER_PROGRAM = struct
  open Utils_js
  open Sys_utils
  open ServerEnv
  open ServerUtils

  let name = "flow server"

  let sample_init_memory profiling =
    let open SharedMem_js in
    let dep_stats = dep_stats () in
    let hash_stats = hash_stats () in
    let heap_size = heap_size () in
    let memory_metrics = [
      "heap.size", heap_size;
      "dep_table.nonempty_slots", dep_stats.nonempty_slots;
      "dep_table.used_slots", dep_stats.used_slots;
      "dep_table.slots", dep_stats.slots;
      "hash_table.nonempty_slots", hash_stats.nonempty_slots;
      "hash_table.used_slots", hash_stats.used_slots;
      "hash_table.slots", hash_stats.slots;
    ] in
    List.fold_left (fun profiling (metric, value) ->
      Profiling_js.sample_memory
        ~metric:("init_done." ^ metric)
        ~value:(float_of_int value)
         profiling
    ) profiling memory_metrics

  let init ~focus_target genv =
    (* write binary path and version to server log *)
    Hh_logger.info "executable=%s" (Sys_utils.executable_path ());
    Hh_logger.info "version=%s" Flow_version.version;

    let profiling = Profiling_js.empty in

    let workers = genv.ServerEnv.workers in
    let options = genv.ServerEnv.options in

    let profiling, parsed, libs, libs_ok, errors =
      Types_js.init ~profiling ~workers options in

    (* if any libs errored, we'll infer but not merge client code *)
    let should_merge = libs_ok in

    (* compute initial state *)
    let profiling, checked, errors =
      if Options.is_lazy_mode options then
        profiling, FilenameSet.empty, errors
      else
        let parsed = FilenameSet.elements parsed in
        Types_js.full_check ~profiling ~workers ~focus_target ~options ~should_merge parsed errors
    in

    let profiling = sample_init_memory profiling in

    SharedMem_js.init_done();

    (* Return an env that initializes invariants required and maintained by
       recheck, namely that `files` contains files that parsed successfully, and
       `errors` contains the current set of errors. *)
    profiling, { ServerEnv.
      files = parsed;
      checked_files = checked;
      libs;
{'fraction_non_alphanumeric': 0.07670508218401663, 'fraction_numerical': 0.0015114301908180617, 'mean_word_length': 3.339344262295082, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079647', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1549, 'n_words': 494}