Skip to content

Commit

Permalink
[core] migrate Map and Set containers to Stdlib
Browse files Browse the repository at this point in the history
Summary:
Core 0.15 conflicts with OCaml 5.2. Core 0.16.1 does not, but makes breaking changes to several container types.

This diff moves the majority of Core container usages over to Stdlib ones.

Reviewed By: skcho

Differential Revision:
D66243343

Privacy Context Container: L1208441

fbshipit-source-id: 9bc18124125509fb9c8fba7ca38f5a5147befee4
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Nov 21, 2024
1 parent 230a45b commit 31075e4
Show file tree
Hide file tree
Showing 44 changed files with 262 additions and 208 deletions.
8 changes: 4 additions & 4 deletions infer/src/IR/BiabductionModels.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ let scan_model_proc_names () =
let db = Database.get_database AnalysisDatabase in
Sqlite3.prepare db "SELECT proc_uid FROM model_specs"
|> SqliteUtils.result_fold_single_column_rows db ~log:"scan model procnames"
~init:String.Set.empty ~f:(fun acc proc_uid_sqlite ->
~init:IString.Set.empty ~f:(fun acc proc_uid_sqlite ->
let[@warning "-partial-match"] (Sqlite3.Data.TEXT proc_uid) = proc_uid_sqlite in
String.Set.add acc proc_uid )
IString.Set.add proc_uid acc )


let models_index =
lazy (if Config.biabduction_models_mode then String.Set.empty else scan_model_proc_names ())
lazy (if Config.biabduction_models_mode then IString.Set.empty else scan_model_proc_names ())


let mem proc_name =
let proc_uid = Procname.to_unique_id proc_name in
String.Set.mem (Lazy.force models_index) proc_uid
IString.Set.mem proc_uid (Lazy.force models_index)
20 changes: 9 additions & 11 deletions infer/src/IR/inferconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,20 @@ module FileOrProcMatcher = struct
List.fold
~f:(fun map pattern ->
let previous =
try String.Map.find_exn map pattern.class_name
with Not_found_s _ | Stdlib.Not_found -> []
IString.Map.find_opt pattern.class_name map |> Option.value ~default:[]
in
String.Map.set ~key:pattern.class_name ~data:(pattern :: previous) map )
~init:String.Map.empty m_patterns
IString.Map.add pattern.class_name (pattern :: previous) map )
~init:IString.Map.empty m_patterns
in
let do_java pname_java =
let class_name = Procname.Java.get_class_name pname_java
and method_name = Procname.Java.get_method pname_java in
try
let class_patterns = String.Map.find_exn pattern_map class_name in
List.exists
~f:(fun p ->
match p.method_name with None -> true | Some m -> String.equal m method_name )
class_patterns
with Not_found_s _ | Stdlib.Not_found -> false
IString.Map.find_opt class_name pattern_map
|> Option.exists ~f:(fun class_patterns ->
List.exists
~f:(fun p ->
match p.method_name with None -> true | Some m -> String.equal m method_name )
class_patterns )
in
fun _ proc_name ->
match proc_name with Procname.Java pname_java -> do_java pname_java | _ -> false
Expand Down
6 changes: 3 additions & 3 deletions infer/src/backend/printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ end = struct
in
try
let set = Hashtbl.find err_per_line err_data.loc.Location.line in
Hashtbl.replace err_per_line err_data.loc.Location.line (String.Set.add set err_str)
Hashtbl.replace err_per_line err_data.loc.Location.line (IString.Set.add err_str set)
with Stdlib.Not_found ->
Hashtbl.add err_per_line err_data.loc.Location.line (String.Set.singleton err_str)
Hashtbl.add err_per_line err_data.loc.Location.line (IString.Set.singleton err_str)
in
Errlog.iter add_err err_log ;
err_per_line
Expand Down Expand Up @@ -250,7 +250,7 @@ end = struct
() ) ;
( match Hashtbl.find table_err_per_line line_number with
| errset ->
String.Set.iter errset ~f:(pp_err_message fmt)
IString.Set.iter (pp_err_message fmt) errset
| exception Stdlib.Not_found ->
() ) ;
F.fprintf fmt "</td></tr>@\n"
Expand Down
2 changes: 1 addition & 1 deletion infer/src/base/Config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4720,7 +4720,7 @@ and racerd_always_report_java = !racerd_always_report_java

and racerd_guardedby = !racerd_guardedby

and racerd_ignore_classes = RevList.to_list !racerd_ignore_classes |> String.Set.of_list
and racerd_ignore_classes = RevList.to_list !racerd_ignore_classes |> IString.Set.of_list

and reactive_mode = !reactive

Expand Down
2 changes: 1 addition & 1 deletion infer/src/base/Config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ val racerd_always_report_java : bool

val racerd_guardedby : bool

val racerd_ignore_classes : String.Set.t
val racerd_ignore_classes : IString.Set.t

val reactive_mode : bool

Expand Down
13 changes: 6 additions & 7 deletions infer/src/base/DBWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,20 @@ module Implementation = struct
in
let update_statement =
let stmts =
List.fold PayloadId.database_fields ~init:String.Map.empty ~f:(fun acc payload_id ->
String.Map.add_exn ~key:payload_id
~data:
(Database.register_statement AnalysisDatabase
{|
List.fold PayloadId.database_fields ~init:IString.Map.empty ~f:(fun acc payload_id ->
IString.Map.add payload_id
(Database.register_statement AnalysisDatabase
{|
UPDATE specs SET
report_summary = :report_summary,
summary_metadata = :summary_metadata,
%s = :value
WHERE proc_uid = :proc_uid
|}
payload_id )
payload_id )
acc )
in
fun payload_id -> String.Map.find_exn stmts (PayloadId.Variants.to_name payload_id)
fun payload_id -> IString.Map.find (PayloadId.Variants.to_name payload_id) stmts
in
fun analysis_req ~proc_uid ~proc_name ~merge_pulse_payload ~merge_report_summary
~merge_summary_metadata ->
Expand Down
10 changes: 5 additions & 5 deletions infer/src/base/Scuba.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*)

open! IStd
module SMap = Map.Make (String)
module SMap = IString.Map

type table = InferEvents

Expand All @@ -27,23 +27,23 @@ let new_sample ~time =


let add_int ~name ~value sample =
let int_section = SMap.set sample.int_section ~key:name ~data:value in
let int_section = SMap.add name value sample.int_section in
{sample with int_section}


let add_normal ~name ~value sample =
let normal_section = SMap.set sample.normal_section ~key:name ~data:value in
let normal_section = SMap.add name value sample.normal_section in
{sample with normal_section}


let add_tagset ~name ~value sample =
let tagset_section = SMap.set sample.tagset_section ~key:name ~data:value in
let tagset_section = SMap.add name value sample.tagset_section in
{sample with tagset_section}


let sample_to_json sample =
let map_to_assoc value_to_json key_value_map =
let pairs = SMap.to_alist key_value_map in
let pairs = SMap.bindings key_value_map in
let assocs = List.map pairs ~f:(fun (name, data) -> (name, value_to_json data)) in
`Assoc assocs
in
Expand Down
12 changes: 6 additions & 6 deletions infer/src/base/SourceFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ let is_under_project_root = function
false


let exists_cache = String.Table.create ~size:256 ()
let exists_cache = IString.Hash.create 256

let path_exists abs_path =
try String.Table.find_exn exists_cache abs_path
with Not_found_s _ | Stdlib.Not_found ->
let result = ISys.file_exists abs_path in
String.Table.set exists_cache ~key:abs_path ~data:result ;
result
IString.Hash.find_opt exists_cache abs_path
|> Option.value_or_thunk ~default:(fun () ->
let result = ISys.file_exists abs_path in
IString.Hash.replace exists_cache abs_path result ;
result )


let of_header ?(warn_on_error = true) header_file =
Expand Down
4 changes: 2 additions & 2 deletions infer/src/base/ToplLexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
let quoted = Str.regexp "\\\\\\(.\\)"
let unquote x = Str.global_replace quoted "\\1" x

(* We open Caml, because ocamllex generates code that uses Array.make,
(* We open Stdlib, because ocamllex generates code that uses Array.make,
which is not available in Core. Ideally, this should go away. *)
open! Caml
open! Stdlib
}

let id_tail = ['a'-'z' 'A'-'Z' '0'-'9']*
Expand Down
6 changes: 3 additions & 3 deletions infer/src/biabduction/BiabductionSummary.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ module Visitedset = struct
end)

let pp fmt visitedset =
let collect_lines (_, ns) acc = List.fold ns ~f:Int.Set.add ~init:acc in
let lines = fold collect_lines visitedset Int.Set.empty in
Pp.seq F.pp_print_int fmt (Int.Set.elements lines)
let collect_lines (_, ns) acc = List.fold ns ~f:(fun acc i -> IInt.Set.add i acc) ~init:acc in
let lines = fold collect_lines visitedset IInt.Set.empty in
Pp.seq F.pp_print_int fmt (IInt.Set.elements lines)
end

(** A spec consists of:
Expand Down
9 changes: 4 additions & 5 deletions infer/src/bufferoverrun/bufferOverrunAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ module TransferFunctions = struct


let join_java_static_final =
let known_java_static_fields = String.Set.of_list [".EMPTY"] in
let known_java_static_fields = IString.Set.of_list [".EMPTY"] in
let is_known_java_static_field fn =
let fieldname = Fieldname.to_string fn in
String.Set.exists known_java_static_fields ~f:(fun suffix ->
String.is_suffix fieldname ~suffix )
IString.Set.exists (fun suffix -> String.is_suffix fieldname ~suffix) known_java_static_fields
in
let copy_reachable_locs_from loc ~from_mem ~to_mem =
let copy loc acc =
Expand Down Expand Up @@ -279,11 +278,11 @@ module TransferFunctions = struct


let modeled_load_of_empty_collection_opt =
let known_empty_collections = String.Set.of_list ["EMPTY_LIST"; "EMPTY_SET"; "EMPTY_MAP"] in
let known_empty_collections = IString.Set.of_list ["EMPTY_LIST"; "EMPTY_SET"; "EMPTY_MAP"] in
fun exp model_env ret mem ->
match exp with
| Exp.Lfield (_, fieldname, typ)
when String.Set.mem known_empty_collections (Fieldname.get_field_name fieldname)
when IString.Set.mem (Fieldname.get_field_name fieldname) known_empty_collections
&& String.equal "java.util.Collections" (Typ.to_string typ) ->
Models.Collection.create_collection model_env ~ret mem ~length:Itv.zero |> Option.some
| _ ->
Expand Down
20 changes: 16 additions & 4 deletions infer/src/checkers/LithoDomain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,29 @@ end

module LocalAccessPathSet = PrettyPrintable.MakePPSet (LocalAccessPath)

let suffixes = String.Set.of_list ["Attr"; "Dip"; "Px"; "Res"; "Sp"]
let suffixes = IString.Set.of_list ["Attr"; "Dip"; "Px"; "Res"; "Sp"]

module MethodCallPrefix = struct
type t =
{prefix: string; procname: Procname.t [@compare.ignore]; location: Location.t [@compare.ignore]}
[@@deriving compare]

exception Found of string

let make_with_prefixes procname location =
let method_name = Procname.get_method procname in
let prefix_opt =
String.Set.find_map suffixes ~f:(fun suffix -> String.chop_suffix method_name ~suffix)
try
IString.Set.iter
(fun suffix ->
match String.chop_suffix method_name ~suffix with
| Some res ->
raise (Found res)
| None ->
() )
suffixes ;
None
with Found res -> Some res
in
let default = [{prefix= method_name; procname; location}] in
Option.value_map prefix_opt ~default ~f:(fun prefix ->
Expand Down Expand Up @@ -185,9 +197,9 @@ module MethodCalls = struct

let to_string_set method_calls =
let accum_as_string method_call acc =
String.Set.add acc (MethodCallPrefix.procname_to_string method_call)
IString.Set.add (MethodCallPrefix.procname_to_string method_call) acc
in
S.fold accum_as_string method_calls String.Set.empty
S.fold accum_as_string method_calls IString.Set.empty


let get_call_chain method_calls =
Expand Down
4 changes: 2 additions & 2 deletions infer/src/checkers/LithoDomain.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module LocalAccessPath : sig
val make_from_access_expression : HilExp.AccessExpression.t -> Procname.t -> t
end

val suffixes : String.Set.t
val suffixes : IString.Set.t

(** Called procedure & location *)
module MethodCallPrefix : sig
Expand Down Expand Up @@ -76,6 +76,6 @@ val pp_summary : Format.formatter -> summary -> unit
val get_summary : is_void_func:bool -> t -> summary

val check_required_props :
check_on_string_set:(Typ.name -> Location.t -> MethodCallPrefix.t list -> String.Set.t -> unit)
check_on_string_set:(Typ.name -> Location.t -> MethodCallPrefix.t list -> IString.Set.t -> unit)
-> summary
-> summary
8 changes: 5 additions & 3 deletions infer/src/checkers/RequiredProps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ let report_missing_required_prop proc_desc err_log prop parent_typename ~create_

let has_prop prop_set prop =
let check prop =
String.Set.mem prop_set prop
IString.Set.mem prop prop_set
|| (* @Prop(resType = ...) myProp can also be set via myProp(), myPropAttr(), myPropDip(), myPropPx(), myPropRes() or myPropSp().
Our annotation parameter parsing is too primitive to identify resType, so just assume
that all @Prop's can be set any of these 6 ways. *)
String.Set.exists prop_set ~f:(fun el ->
IString.Set.exists
(fun el ->
String.chop_prefix el ~prefix:prop
|> Option.exists ~f:(fun suffix -> String.Set.mem LithoDomain.suffixes suffix) )
|> Option.exists ~f:(fun suffix -> IString.Set.mem suffix LithoDomain.suffixes) )
prop_set
in
match prop with
| Prop prop ->
Expand Down
6 changes: 3 additions & 3 deletions infer/src/clang/ClangCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s) ?(
arg file, we need to remove its argument now *)
aux in_argfiles (false, res_rev, true) tl
| at_argfile :: tl
when String.is_prefix at_argfile ~prefix:"@" && not (String.Set.mem in_argfiles at_argfile)
when String.is_prefix at_argfile ~prefix:"@" && not (IString.Set.mem at_argfile in_argfiles)
-> (
let in_argfiles' = String.Set.add in_argfiles at_argfile in
let in_argfiles' = IString.Set.add at_argfile in_argfiles in
let argfile = String.slice at_argfile 1 (String.length at_argfile) in
match In_channel.read_lines argfile with
| lines ->
Expand Down Expand Up @@ -129,7 +129,7 @@ let filter_and_replace_unsupported_args ?(replace_options_arg = fun _ s -> s) ?(
let arg' = replace_options_arg res_rev arg in
aux in_argfiles (false, arg' :: res_rev, changed || not (phys_equal arg arg')) tl
in
match aux String.Set.empty (false, [], false) args with
match aux IString.Set.empty (false, [], false) args with
| _, res_rev, _ ->
(* return non-reversed list *)
List.append pre_args (List.rev_append res_rev post_args)
Expand Down
22 changes: 11 additions & 11 deletions infer/src/clang/ClangPointers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

open! IStd
module L = Logging
module Map = Map.Make (Int)
module Map = IInt.Map

let ivar_to_property_table = Int.Table.create ~size:256 ()
let ivar_to_property_table = IInt.Hash.create 256

let pointer_decl_table = Int.Table.create ~size:256 ()
let pointer_decl_table = IInt.Hash.create 256

let pointer_stmt_table = Int.Table.create ~size:256 ()
let pointer_stmt_table = IInt.Hash.create 256

let pointer_type_table = Int.Table.create ~size:256 ()
let pointer_type_table = IInt.Hash.create 256

let empty_v = Clang_ast_visit.empty_visitor

Expand Down Expand Up @@ -55,15 +55,15 @@ let get_val_from_node node =
let add_node_to_cache node cache =
let key = get_ptr_from_node node in
let data = get_val_from_node node in
Int.Table.set cache ~key ~data
IInt.Hash.replace cache key data


let process_decl _ decl =
add_node_to_cache (`DeclNode decl) pointer_decl_table ;
match decl with
| Clang_ast_t.ObjCPropertyDecl (_, _, {opdi_ivar_decl= Some decl_ref}) ->
let ivar_pointer = decl_ref.Clang_ast_t.dr_decl_pointer in
Int.Table.set ivar_to_property_table ~key:ivar_pointer ~data:decl
IInt.Hash.replace ivar_to_property_table ivar_pointer decl
| _ ->
()

Expand Down Expand Up @@ -113,10 +113,10 @@ let complete_source_location _ source_loc =


let reset_cache () =
Int.Table.clear pointer_decl_table ;
Int.Table.clear pointer_stmt_table ;
Int.Table.clear pointer_type_table ;
Int.Table.clear ivar_to_property_table ;
IInt.Hash.clear pointer_decl_table ;
IInt.Hash.clear pointer_stmt_table ;
IInt.Hash.clear pointer_type_table ;
IInt.Hash.clear ivar_to_property_table ;
reset_sloc previous_sloc


Expand Down
Loading

0 comments on commit 31075e4

Please sign in to comment.