Skip to content

Commit

Permalink
Factor ServerConfig to be a little nicer
Browse files Browse the repository at this point in the history
Summary: Extracting a key and casting it to a certain type is a pretty
common operation

Reviewed By: @jwatzman

Differential Revision: D2098537
  • Loading branch information
int3 authored and hhvm-bot committed May 27, 2015
1 parent 0da08ad commit 3ecb3e9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
47 changes: 20 additions & 27 deletions hphp/hack/src/server/serverConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@ type t = {
tc_options : TypecheckerOptions.t;
}

let make_gc_control config =
let minor_heap_size = match SMap.get "gc_minor_heap_size" config with
| Some s -> int_of_string s
| None -> GlobalConfig.gc_control.Gc.minor_heap_size in
let space_overhead = match SMap.get "gc_space_overhead" config with
| Some s -> int_of_string s
| None -> GlobalConfig.gc_control.Gc.space_overhead in
{ GlobalConfig.gc_control with Gc.minor_heap_size; Gc.space_overhead; }
let int_ key ~default config =
Option.value_map (SMap.get key config) ~default ~f:int_of_string

let bool_ key ~default config =
Option.value_map (SMap.get key config) ~default ~f:bool_of_string

let config_assume_php config =
match SMap.get "assume_php" config with
| Some s -> bool_of_string s
| None -> true
let make_gc_control config =
let {Gc.minor_heap_size; space_overhead; _} = GlobalConfig.gc_control in
let minor_heap_size =
int_ "gc_minor_heap_size" ~default:minor_heap_size config in
let space_overhead =
int_ "gc_space_overhead" ~default:space_overhead config in
{ GlobalConfig.gc_control with Gc.minor_heap_size; space_overhead; }

let config_unsafe_xhp config =
match SMap.get "unsafe_xhp" config with
| Some s -> bool_of_string s
| None -> false

let config_list_regexp = (Str.regexp "[, \t]+")

Expand All @@ -49,23 +45,20 @@ let config_user_attributes config =

let load config_filename =
let config = Config_file.parse (Relative_path.to_absolute config_filename) in
let load_script =
Option.map ~f:Path.make (SMap.get "load_script" config) in
let load_script = Option.map ~f:Path.make (SMap.get "load_script" config) in
(* Since we use the unix alarm() for our timeouts, a timeout value of 0 means
* to wait indefinitely *)
let load_script_timeout =
Option.value_map (SMap.get "load_script_timeout" config)
~default:0 ~f:int_of_string in
let tcopts = {
TypecheckerOptions.tco_assume_php = config_assume_php config;
tco_unsafe_xhp = config_unsafe_xhp config;
let load_script_timeout = int_ "load_script_timeout" ~default:0 config in
let tcopts = { TypecheckerOptions.
tco_assume_php = bool_ "assume_php" ~default:true config;
tco_unsafe_xhp = bool_ "unsafe_xhp" ~default:false config;
tco_user_attrs = config_user_attributes config;
} in
{
load_script = load_script;
load_script = load_script;
load_script_timeout = load_script_timeout;
gc_control = make_gc_control config;
tc_options = tcopts;
gc_control = make_gc_control config;
tc_options = tcopts;
}

(* useful in testing code *)
Expand Down
9 changes: 1 addition & 8 deletions hphp/hack/src/server/serverConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
*
*)

type t = {
load_script : Path.t option;
load_script_timeout : int;
(* Configures only the workers. Workers can have more relaxed GC configs as
* they are short-lived processes *)
gc_control : Gc.control;
tc_options : TypecheckerOptions.t;
}
type t

val load : Relative_path.t -> t

Expand Down

0 comments on commit 3ecb3e9

Please sign in to comment.