Skip to content

Commit

Permalink
Merge remote-tracking branch 'facebook/master' into feat-6103
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed Jun 27, 2018
2 parents a704436 + b729d93 commit 8791bbe
Show file tree
Hide file tree
Showing 110 changed files with 3,522 additions and 1,546 deletions.
16 changes: 12 additions & 4 deletions hack/procs/multiWorkerLwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ include MultiWorker.CallFunctor (struct
run_worker worker
in

let%lwt () = LwtUtils.iter_all (List.map run_worker workers) in
let%lwt () =
let worker_threads = List.map run_worker workers in
try%lwt
LwtUtils.iter_all worker_threads
with Lwt.Canceled as exn ->
Hh_logger.info ~exn "Cancelling MultiWorkerLwt.multi_threaded_call";
(* For most exceptions, we want to propagate the exception as soon as one worker throws.
* However, for Canceled we want to wait for all the workers to process the Canceled.
* Lwt.join will wait for every thread to finish or fail *)
(Lwt.join worker_threads) [%lwt.finally SharedMem.resume_workers (); Lwt.return_unit]
in

Lwt.return (!acc)
end)
Expand All @@ -80,9 +90,7 @@ let call workers ~job ~merge ~neutral ~next =
raise MultiWorkersBusy
else begin
is_busy := true;
let%lwt result = call workers ~job ~merge ~neutral ~next in
is_busy := false;
Lwt.return result
(call workers ~job ~merge ~neutral ~next) [%lwt.finally is_busy := false; Lwt.return_unit]
end

(* A separate abstract type from MultiWorker.worker forces users to always use MultiWorkerLwt *)
Expand Down
15 changes: 14 additions & 1 deletion hack/procs/workerControllerLwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ let call w (type a) (type b) (f : a -> b) (x : a) : b Lwt.t =
let _ = Marshal_tools.to_fd_with_preamble ~flags:[Marshal.Closures] outfd request in
Lwt.return_unit
with exn ->
Hh_logger.error ~exn "Failed to read response from work #%d" (worker_id w);
(* Failed to send the job to the worker. Is it because the worker is dead or is it
* something else? *)
let%lwt pid, status = Lwt_unix.waitpid [Unix.WNOHANG] slave_pid in
Expand All @@ -69,7 +70,19 @@ let call w (type a) (type b) (f : a -> b) (x : a) : b Lwt.t =
(* Read in a lwt-unfriendly, blocking manner from the worker *)
(* Due to https://github.com/ocsigen/lwt/issues/564, annotation cannot go on let%let node *)
Lwt.return (Marshal_tools.from_fd_with_preamble infd: (b * Measure.record_data))
with exn ->
with
| Lwt.Canceled as exn ->
(* Worker is handling a job but we're cancelling *)
Hh_logger.info ~exn "Stopping running worker #%d" (worker_id w);
(* Each worker might call this but that's ok *)
SharedMem.stop_workers ();
(* Wait for the worker to finish cancelling *)
let%lwt () = Lwt_unix.wait_read infd_lwt in
(* Read the junk from the pipe *)
let _ = Marshal_tools.from_fd_with_preamble infd in
Hh_logger.info ~exn "Finished cancelling running worker #%d" (worker_id w);
raise exn
| exn ->
let%lwt pid, status = Lwt_unix.waitpid [Unix.WNOHANG] slave_pid in
begin match pid, status with
| 0, _ | _, Unix.WEXITED 0 ->
Expand Down
13 changes: 13 additions & 0 deletions hack/utils/collections/lSMap.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*)

include MyMap.Make (LowerStringKey)

let pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit =
fun pp_data -> make_pp Format.pp_print_string pp_data
15 changes: 15 additions & 0 deletions hack/utils/collections/lowerStringKey.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(**
* Copyright (c) 2018, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*)

type t = string

let compare (x: t) (y: t) =
(String.compare
(String.lowercase_ascii x)
(String.lowercase_ascii y))
6 changes: 6 additions & 0 deletions lib/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ declare class React$Component<Props, State = void> {
prevContext: any,
): mixed;
componentWillUnmount(): mixed;
componentDidCatch(
error: Error,
info: {
componentStack: string,
}
): mixed;

// long tail of other stuff not modeled very well

Expand Down
407 changes: 255 additions & 152 deletions newtests/FacebookismIdx/test.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions newtests/lsp/diagnostics/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export default suite(
addFile('witherrors2.js')
.waitUntilIDEMessage(
9000,
'textDocument/publishDiagnostics{is not an instance type}',
'textDocument/publishDiagnostics{Cannot extend}',
)
.verifyAllIDEMessagesInStep(
[
'textDocument/publishDiagnostics{"`H` [1] is not an instance type.","message":"[1] `H`"}',
'textDocument/publishDiagnostics{"Cannot extend `H` [1] with `I` because `H` [1] is not inheritable.","message":"[1] `H`"}',
],
[
'textDocument/publishDiagnostics',
Expand Down
23 changes: 19 additions & 4 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ let assert_version flowconfig =
type flowconfig_params = {
ignores: string list;
untyped: string list;
declarations: string list;
includes: string list;
libs: string list;
(* We store raw_lint_severities as a string list instead of as a LintSettings.t so we
Expand All @@ -394,13 +395,14 @@ let list_of_string_arg = function
| None -> []
| Some arg_str -> Str.split (Str.regexp ",") arg_str

let collect_flowconfig_flags main ignores_str untyped_str includes_str lib_str lints_str =
let collect_flowconfig_flags main ignores_str untyped_str declarations_str includes_str lib_str lints_str =
let ignores = list_of_string_arg ignores_str in
let untyped = list_of_string_arg untyped_str in
let declarations = list_of_string_arg declarations_str in
let includes = list_of_string_arg includes_str in
let libs = list_of_string_arg lib_str in
let raw_lint_severities = list_of_string_arg lints_str in
main { ignores; includes; libs; raw_lint_severities; untyped; }
main { ignores; includes; libs; raw_lint_severities; untyped; declarations; }

let file_options =
let default_lib_dir ~no_flowlib tmp_dir =
Expand Down Expand Up @@ -466,7 +468,7 @@ let file_options =
| [] -> config_libs
| _ -> config_libs @ (List.map (Files.make_path_absolute root) extras)
in
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped flowconfig ->
fun ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~declarations flowconfig ->
let default_lib_dir =
let no_flowlib = no_flowlib || FlowConfig.no_flowlib flowconfig in
Some (default_lib_dir ~no_flowlib temp_dir)
Expand All @@ -479,6 +481,10 @@ let file_options =
root
(FlowConfig.untyped flowconfig)
untyped in
let declarations = ignores_of_arg
root
(FlowConfig.declarations flowconfig)
declarations in
let lib_paths = lib_paths ~root flowconfig libs in
let includes =
includes
Expand All @@ -488,6 +494,7 @@ let file_options =
default_lib_dir;
ignores;
untyped;
declarations;
includes;
lib_paths;
module_file_exts = FlowConfig.module_file_exts flowconfig;
Expand All @@ -507,6 +514,12 @@ let untyped_flag prev = CommandSpec.ArgSpec.(
~doc:"Specify one or more patterns, comma separated, for files to treat as untyped"
)

let declaration_flag prev = CommandSpec.ArgSpec.(
prev
|> flag "--declaration" (optional string)
~doc:"Specify one or more patterns, comma separated, for files to treat as declarations"
)

let include_flag prev = CommandSpec.ArgSpec.(
prev
|> flag "--include" (optional string)
Expand Down Expand Up @@ -536,6 +549,7 @@ let flowconfig_flags prev = CommandSpec.ArgSpec.(
|> collect collect_flowconfig_flags
|> ignore_flag
|> untyped_flag
|> declaration_flag
|> include_flag
|> lib_flag
|> lints_flag
Expand Down Expand Up @@ -793,8 +807,9 @@ let make_options ~flowconfig ~lazy_mode ~root (options_flags: Options_flags.t) =
libs;
raw_lint_severities=_;
untyped;
declarations;
} = options_flags.flowconfig_flags in
file_options ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped flowconfig
file_options ~root ~no_flowlib ~temp_dir ~includes ~ignores ~libs ~untyped ~declarations flowconfig
in
let lint_severities = parse_lints_flag
(FlowConfig.lint_severities flowconfig) options_flags.flowconfig_flags.raw_lint_severities
Expand Down
18 changes: 17 additions & 1 deletion src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ type config = {
ignores: string list;
(* files that should be treated as untyped *)
untyped: string list;
(* files that should be treated as declarations *)
declarations: string list;
(* non-root include paths *)
includes: string list;
(* library paths. no wildcards *)
Expand All @@ -341,6 +343,9 @@ end = struct
let untyped o untyped =
List.iter (fun ex -> (fprintf o "%s\n" ex)) untyped

let declarations o declarations =
List.iter (fun ex -> (fprintf o "%s\n" ex)) declarations

let includes o includes =
List.iter (fun inc -> (fprintf o "%s\n" inc)) includes

Expand Down Expand Up @@ -402,6 +407,7 @@ end = struct
ignores o config.ignores;
fprintf o "\n";
section_if_nonempty o "untyped" untyped config.untyped;
section_if_nonempty o "declarations" declarations config.declarations;
section_header o "include";
includes o config.includes;
fprintf o "\n";
Expand All @@ -421,6 +427,7 @@ end
let empty_config = {
ignores = [];
untyped = [];
declarations = [];
includes = [];
libs = [];
lint_severities = LintSettings.empty_severities;
Expand Down Expand Up @@ -474,6 +481,10 @@ let parse_untyped config lines =
let untyped = trim_lines lines in
{ config with untyped; }

let parse_declarations config lines =
let declarations = trim_lines lines in
{ config with declarations; }

let parse_options config lines =
let open Opts in
let (>>=) = Core_result.(>>=) in
Expand Down Expand Up @@ -959,6 +970,7 @@ let parse_section config ((section_ln, section), lines) =
| "ignore", _ -> parse_ignores config lines
| "libs", _ -> parse_libs config lines
| "lints", _ -> parse_lints config lines
| "declarations", _ -> parse_declarations config lines
| "strict", _ -> parse_strict config lines
| "options", _ -> parse_options config lines
| "untyped", _ -> parse_untyped config lines
Expand Down Expand Up @@ -1003,15 +1015,17 @@ let read filename =
} in
parse config lines, hash

let init ~ignores ~untyped ~includes ~libs ~options ~lints =
let init ~ignores ~untyped ~declarations ~includes ~libs ~options ~lints =
let ignores_lines = List.map (fun s -> (1, s)) ignores in
let untyped_lines = List.map (fun s -> (1, s)) untyped in
let declarations_lines = List.map (fun s -> (1, s)) declarations in
let includes_lines = List.map (fun s -> (1, s)) includes in
let options_lines = List.map (fun s -> (1, s)) options in
let lib_lines = List.map (fun s -> (1, s)) libs in
let lint_lines = List.map (fun s -> (1, s)) lints in
let config = parse_ignores empty_config ignores_lines in
let config = parse_untyped config untyped_lines in
let config = parse_declarations config declarations_lines in
let config = parse_includes config includes_lines in
let config = parse_options config options_lines in
let config = parse_libs config lib_lines in
Expand Down Expand Up @@ -1048,6 +1062,8 @@ let get_hash ?allow_cache filename =
let ignores config = config.ignores
(* files that should be treated as untyped *)
let untyped config = config.untyped
(* files that should be treated as declarations *)
let declarations config = config.declarations
(* non-root include paths *)
let includes config = config.includes
(* library paths. no wildcards *)
Expand Down
3 changes: 3 additions & 0 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ val empty_config: config
val init:
ignores: string list ->
untyped: string list ->
declarations: string list ->
includes: string list ->
libs: string list ->
options: string list ->
Expand All @@ -27,6 +28,8 @@ val write: config -> out_channel -> unit
val ignores: config -> string list
(* files that should be treated as untyped *)
val untyped: config -> string list
(* files that should be treated as declarations *)
val declarations: config -> string list
(* non-root include paths *)
val includes: config -> string list
(* library paths. no wildcards *)
Expand Down
5 changes: 3 additions & 2 deletions src/commands/genFlowFilesCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let spec = {
|> ignore_flag
|> include_flag
|> untyped_flag
|> declaration_flag
|> from_flag
|> anon "src" (required string)
|> flag "--out-dir" string
Expand Down Expand Up @@ -85,7 +86,7 @@ let write_file strip_root root content perm src_file_path dest_file_path =
Unix.close fd

let main option_values root error_flags strip_root ignore_flag
include_flag untyped_flag from src out_dir () = (
include_flag untyped_flag declaration_flag from src out_dir () = (
FlowEventLogger.set_from from;
let src = expand_path src in
let root = guess_root (
Expand All @@ -111,7 +112,7 @@ let main option_values root error_flags strip_root ignore_flag
FlowExitStatus.exit ~msg FlowExitStatus.Commandline_usage_error
);

let options = LsCommand.make_options ~root ~ignore_flag ~include_flag ~untyped_flag in
let options = LsCommand.make_options ~root ~ignore_flag ~include_flag ~untyped_flag ~declaration_flag in
let _, libs = Files.init options in
let next_files =
LsCommand.get_ls_files ~root ~all:false ~options ~libs ~imaginary:false (Some src)
Expand Down
3 changes: 2 additions & 1 deletion src/commands/initCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ let main from flowconfig_flags options root () =
in
let ignores = flowconfig_flags.CommandUtils.ignores in
let untyped = flowconfig_flags.CommandUtils.untyped in
let declarations = flowconfig_flags.CommandUtils.declarations in
let includes = flowconfig_flags.CommandUtils.includes in
let libs = flowconfig_flags.CommandUtils.libs in
let lints = flowconfig_flags.CommandUtils.raw_lint_severities in
Expand All @@ -61,7 +62,7 @@ let main from flowconfig_flags options root () =
FlowExitStatus.(exit ~msg Invalid_flowconfig)
end;

let config = FlowConfig.init ~ignores ~untyped ~includes ~libs ~options ~lints in
let config = FlowConfig.init ~ignores ~untyped ~declarations ~includes ~libs ~options ~lints in

let out = Sys_utils.open_out_no_fail file in
FlowConfig.write config out;
Expand Down
10 changes: 6 additions & 4 deletions src/commands/lsCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let spec = {
|> ignore_flag
|> include_flag
|> untyped_flag
|> declaration_flag
|> root_flag
|> json_flags
|> from_flag
Expand Down Expand Up @@ -106,15 +107,16 @@ let rec iter_get_next ~f get_next =
List.iter f result;
iter_get_next ~f get_next

let make_options ~root ~ignore_flag ~include_flag ~untyped_flag =
let make_options ~root ~ignore_flag ~include_flag ~untyped_flag ~declaration_flag =
let flowconfig = FlowConfig.get (Server_files_js.config_file root) in
let temp_dir = FlowConfig.temp_dir flowconfig in
let includes = CommandUtils.list_of_string_arg include_flag in
let ignores = CommandUtils.list_of_string_arg ignore_flag in
let untyped = CommandUtils.list_of_string_arg untyped_flag in
let declarations = CommandUtils.list_of_string_arg declaration_flag in
let libs = [] in
CommandUtils.file_options flowconfig
~root ~no_flowlib:true ~temp_dir ~ignores ~includes ~libs ~untyped
~root ~no_flowlib:true ~temp_dir ~ignores ~includes ~libs ~untyped ~declarations

(* The problem with Files.wanted is that it says yes to everything except ignored files and libs.
* So implicitly ignored files (like files in another directory) pass the Files.wanted check *)
Expand Down Expand Up @@ -174,7 +176,7 @@ let get_next_append_const get_next const =
ret

let main
strip_root ignore_flag include_flag untyped_flag root_flag json pretty from all imaginary reason
strip_root ignore_flag include_flag untyped_flag declaration_flag root_flag json pretty from all imaginary reason
input_file root_or_files () =

let files_or_dirs = get_filenames_from_input ~allow_imaginary:true input_file root_or_files in
Expand All @@ -194,7 +196,7 @@ let main
| _ -> None)
) in

let options = make_options ~root ~ignore_flag ~include_flag ~untyped_flag in
let options = make_options ~root ~ignore_flag ~include_flag ~untyped_flag ~declaration_flag in
(* Turn on --no-flowlib by default, so that flow ls never reports flowlib files *)
let options = { options with Files.default_lib_dir = None; } in
let _, libs = Files.init options in
Expand Down
Loading

0 comments on commit 8791bbe

Please sign in to comment.