<commit_before>open Std


(* Build settings *)

let setup_config config = (
  let open Mconfig in
  let open Clflags in
  let ocaml = config.ocaml in
  Config.load_path := Mconfig.build_path config;
  Location.input_name  := config.query.filename;
  fast                 := ocaml.unsafe ;
  classic              := ocaml.classic ;
  principal            := ocaml.principal ;
  real_paths           := ocaml.real_paths ;
  recursive_types      := ocaml.recursive_types ;
  strict_sequence      := ocaml.strict_sequence ;
  applicative_functors := ocaml.applicative_functors ;
  unsafe_string        := ocaml.unsafe_string ;
  nopervasives         := ocaml.nopervasives ;
  strict_formats       := ocaml.strict_formats ;
  open_modules         := ocaml.open_modules ;
)

(* Instance of environment cache & btype unification log  *)

type typer_state = Local_store.scope

let new_state ~unit_name =
  let scope = Local_store.(merge (fresh Btype.state) (fresh Env.state)) in
  Local_store.with_scope scope
    (fun () -> Env.set_unit_name unit_name);
  scope

let current_state = ref None

let with_state state f =
  let state' = !current_state in
  current_state := Some state;
  match Local_store.with_scope state f with
  | r -> current_state := state'; r
  | exception exn ->
    current_state := state';
    reraise exn

let is_current_state state = match !current_state with
  | Some state' -> state == state'
  | None -> false

(** Switchable implementation of Oprint *)

let default_out_value          = !Oprint.out_value
let default_out_type           = !Oprint.out_type
let default_out_class_type     = !Oprint.out_class_type
let default_out_module_type    = !Oprint.out_module_type
let default_out_sig_item       = !Oprint.out_sig_item
let default_out_signature      = !Oprint.out_signature
let default_out_type_extension = !Oprint.out_type_extension
let default_out_phrase         = !Oprint.out_phrase<commit_msg>fix memory leak<commit_after>open Std


(* Build settings *)

let setup_config config = (
  let open Mconfig in
  let open Clflags in
  let ocaml = config.ocaml in
  Config.load_path := Mconfig.build_path config;
  Location.input_name  := config.query.filename;
  fast                 := ocaml.unsafe ;
  classic              := ocaml.classic ;
  principal            := ocaml.principal ;
  real_paths           := ocaml.real_paths ;
  recursive_types      := ocaml.recursive_types ;
  strict_sequence      := ocaml.strict_sequence ;
  applicative_functors := ocaml.applicative_functors ;
  unsafe_string        := ocaml.unsafe_string ;
  nopervasives         := ocaml.nopervasives ;
  strict_formats       := ocaml.strict_formats ;
  open_modules         := ocaml.open_modules ;
)

(* Instance of environment cache & btype unification log  *)

type typer_state = Local_store.scope

let new_state ~unit_name =
  let scope = Local_store.(merge (fresh Btype.state) (fresh Env.state)) in
  Local_store.with_scope scope
    (fun () -> Env.set_unit_name unit_name);
  scope

let current_state = ref None

let with_state state f =
  let state' = !current_state in
  current_state := Some state;
  match Local_store.with_scope state f with
  | r ->
    current_state := state';
    Cmt_format.clear ();
    r
  | exception exn ->
    current_state := state';
    Cmt_format.clear ();
    reraise exn

let is_current_state state = match !current_state with
  | Some state' -> state == state'
  | None -> false

(** Switchable implementation of Oprint *)

let default_out_value          = !Oprint.out_value
let default_out_type           = !Oprint.out_type
let default_out_class_type     = !Oprint.out_class_type
let default_out_module_type    = !Oprint.out_module_type
let default_out_sig_item       = !Oprint.out_sig_item
let default_out_signature      = !Oprint.out_signature
let default_out_type_extension = !Oprint.out_type_extension
let default_out_phrase         = !Oprint.out_phrase
{'fraction_non_alphanumeric': 0.08354689902614044, 'fraction_numerical': 0.0, 'mean_word_length': 3.1832797427652735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3997217', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1256, 'n_words': 289}