Skip to content

Commit 838bda4

Browse files
committed
Sync changes to upstream
1 parent 7cf975f commit 838bda4

File tree

111 files changed

+3442
-1847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3442
-1847
lines changed

PATENTS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Additional Grant of Patent Rights Version 2
22

33
"Software" means the Flow software distributed by Facebook, Inc.
44

5-
Facebook, Inc. (Facebook) hereby grants to each recipient of the Software
6-
(you) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
5+
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
6+
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
77
(subject to the termination provision below) license under any Necessary
88
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
99
transfer the Software. For avoidance of doubt, no license is granted under
10-
Facebook's rights in any patent claims that are infringed by (i) modifications
10+
Facebooks rights in any patent claims that are infringed by (i) modifications
1111
to the Software made by you or any third party or (ii) the Software in
1212
combination with any software or other technology.
1313

hack/client/clientCheck.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
open ClientEnv
1212
open ClientExceptions
13+
open Utils
1314

1415
let connect args =
1516
let ic, oc = ClientUtils.connect args.root in
@@ -217,6 +218,13 @@ let rec main args retries =
217218
exit 0
218219
| MODE_LINT fnl ->
219220
let ic, oc = connect args in
221+
let fnl = List.fold_left begin fun acc fn ->
222+
match Sys_utils.realpath fn with
223+
| Some path -> path :: acc
224+
| None ->
225+
prerr_endlinef "Could not find file '%s'" fn;
226+
acc
227+
end [] fnl in
220228
ServerMsg.cmd_to_channel oc (ServerMsg.LINT fnl);
221229
let results : ServerLint.result = Marshal.from_channel ic in
222230
ClientLint.go results args.output_json;

hack/format/format_hack.ml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,14 @@ let next_non_ws_token env =
844844
(* Helpers to look ahead. *)
845845
(*****************************************************************************)
846846

847-
let try_word env word f = wrap env begin function
848-
| Tword when !(env.last_str) = word ->
847+
let try_words env wordl f = wrap env begin function
848+
| Tword when List.mem !(env.last_str) wordl ->
849849
f env
850850
| _ -> back env
851851
end
852852

853+
let try_word env word f = try_words env [word] f
854+
853855
let try_token env tok f = wrap env begin function
854856
| tok' when tok = tok' ->
855857
f env
@@ -1203,7 +1205,15 @@ and name env =
12031205

12041206
and name_loop env =
12051207
match token env with
1206-
| Tpercent | Tcolon | Tminus | Tword | Tbslash ->
1208+
(* names can contain colons, but cannot end with them *)
1209+
| Tcolon when attempt env begin fun env ->
1210+
match token env with
1211+
| Tword -> true
1212+
| _ -> false
1213+
end ->
1214+
last_token env;
1215+
name_loop env
1216+
| Tpercent | Tminus | Tword | Tbslash ->
12071217
last_token env;
12081218
name_loop env
12091219
| _ ->
@@ -1283,7 +1293,7 @@ and hint env = wrap env begin function
12831293
return_type env
12841294
| _ ->
12851295
name_loop env;
1286-
as_constraint env;
1296+
typevar_constraint env;
12871297
hint_parameter env
12881298
)
12891299
| Tlp ->
@@ -1294,6 +1304,14 @@ and hint env = wrap env begin function
12941304
back env
12951305
end
12961306

1307+
and typevar_constraint env =
1308+
try_words env ["as"; "super"] begin fun env ->
1309+
space env;
1310+
last_token env;
1311+
space env;
1312+
hint env
1313+
end;
1314+
12971315
and as_constraint env =
12981316
try_word env "as" begin fun env ->
12991317
space env;

hack/hh_single_type_check.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ let builtins = "<?hh // decl\n"^
4343
"interface KeyedContainer<Tk, Tv> extends Container<Tv>, KeyedTraversable<Tk,Tv> {}\n"^
4444
"interface KeyedIterator<Tk, Tv> extends KeyedTraversable<Tk, Tv>, Iterator<Tv> {}\n"^
4545
"interface KeyedIterable<Tk, Tv> extends KeyedTraversable<Tk, Tv>, Iterable<Tv> {}\n"^
46-
"interface Awaitable<T> {"^
46+
"interface Awaitable<+T> {"^
4747
" public function getWaitHandle(): WaitHandle<T>;"^
4848
"}\n"^
49-
"interface WaitHandle<T> extends Awaitable<T> {}\n"^
49+
"interface WaitHandle<+T> extends Awaitable<T> {}\n"^
5050
"interface ConstVector<+Tv> extends KeyedIterable<int, Tv>, KeyedContainer<int, Tv>{"^
5151
" public function map<Tu>((function(Tv): Tu) $callback): ConstVector<Tu>;"^
5252
"}\n"^
@@ -82,7 +82,7 @@ let builtins = "<?hh // decl\n"^
8282
"final class Set<Tv> implements ConstSet<Tv> {}\n"^
8383
"final class ImmSet<Tv> implements ConstSet<Tv> {}\n"^
8484
"class Exception { public function __construct(string $x) {} }\n"^
85-
"class Generator<Tk, Tv, Ts> implements KeyedIterator<Tk, Tv> {\n"^
85+
"class Generator<+Tk, +Tv, -Ts> implements KeyedIterator<Tk, Tv> {\n"^
8686
" public function next(): void;\n"^
8787
" public function current(): Tv;\n"^
8888
" public function key(): Tk;\n"^
@@ -97,7 +97,7 @@ let builtins = "<?hh // decl\n"^
9797
"interface Countable { public function count(): int; }\n"^
9898
"interface AsyncIterator<Tv> {}\n"^
9999
"interface AsyncKeyedIterator<Tk, Tv> extends AsyncIterator<Tv> {}\n"^
100-
"class AsyncGenerator<Tk, Tv, Ts> implements AsyncKeyedIterator<Tk, Tv> {\n"^
100+
"class AsyncGenerator<+Tk, +Tv, -Ts> implements AsyncKeyedIterator<Tk, Tv> {\n"^
101101
" public function next(): Awaitable<?(Tk, Tv)> {}\n"^
102102
" public function send(?Ts $v): Awaitable<?(Tk, Tv)> {}\n"^
103103
" public function raise(Exception $e): Awaitable<?(Tk, Tv)> {}"^
@@ -272,7 +272,8 @@ let handle_mode mode filename nenv files_info errors lint_errors ai_results =
272272
Relative_path.Map.iter begin fun fn fileinfo ->
273273
if fn = builtins_filename then () else begin
274274
let result = ServerColorFile.get_level_list
275-
(fun () -> ignore (ServerIdeUtils.check_defs fileinfo); fn) in
275+
(fun () -> ignore (ServerIdeUtils.check_defs
276+
TypecheckerOptions.default fileinfo); fn) in
276277
print_colored fn result;
277278
end
278279
end files_info
@@ -305,7 +306,7 @@ let handle_mode mode filename nenv files_info errors lint_errors ai_results =
305306
| Suggest
306307
| Errors ->
307308
let errors = Relative_path.Map.fold begin fun _ fileinfo errors ->
308-
errors @ ServerIdeUtils.check_defs fileinfo
309+
errors @ ServerIdeUtils.check_defs TypecheckerOptions.default fileinfo
309310
end files_info errors in
310311
if mode = Suggest
311312
then Relative_path.Map.iter suggest_and_print files_info;
@@ -348,11 +349,11 @@ let main_hack { filename; mode; } =
348349
consider_names_just_for_autoload = false }
349350
end parsed_files in
350351

351-
(* Note that nenv.Naming.itcopt remains TypecheckerOptions.empty *)
352+
(* Note that nenv.Naming.itcopt remains TypecheckerOptions.default *)
352353
let nenv = Relative_path.Map.fold begin fun fn fileinfo nenv ->
353354
let {FileInfo.funs; classes; typedefs; consts; _} = fileinfo in
354355
Naming.make_env nenv ~funs ~classes ~typedefs ~consts
355-
end files_info Naming.empty in
356+
end files_info (Naming.empty TypecheckerOptions.default) in
356357

357358
let all_classes =
358359
Relative_path.Map.fold begin fun fn {FileInfo.classes; _} acc ->

hack/js/hh_ide.ml

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let error el =
4747

4848
let type_fun x fn =
4949
try
50-
let tenv = Typing_env.empty fn in
50+
let tenv = Typing_env.empty TypecheckerOptions.permissive fn in
5151
let fun_ = Naming_heap.FunHeap.find_unsafe x in
5252
Typing.fun_def tenv x fun_;
5353
with Not_found ->
@@ -56,7 +56,7 @@ let type_fun x fn =
5656
let type_class x fn =
5757
try
5858
let class_ = Naming_heap.ClassHeap.find_unsafe x in
59-
let tenv = Typing_env.empty fn in
59+
let tenv = Typing_env.empty TypecheckerOptions.permissive fn in
6060
Typing.class_def tenv x class_
6161
with Not_found ->
6262
()
@@ -111,7 +111,8 @@ let declare_file fn content =
111111
then begin
112112
let funs, classes, typedefs, consts = make_funs_classes ast in
113113
Hashtbl.replace globals fn (is_php, funs, classes);
114-
let nenv = Naming.make_env Naming.empty ~funs ~classes ~typedefs ~consts in
114+
let nenv = Naming.empty TypecheckerOptions.permissive in
115+
let nenv = Naming.make_env nenv ~funs ~classes ~typedefs ~consts in
115116
let all_classes = List.fold_right begin fun (_, cname) acc ->
116117
SMap.add cname (Relative_path.Set.singleton fn) acc
117118
end classes SMap.empty in
@@ -120,7 +121,7 @@ let declare_file fn content =
120121
SSet.iter begin fun cname ->
121122
match Naming_heap.ClassHeap.get cname with
122123
| None -> ()
123-
| Some c -> Typing_decl.class_decl TypecheckerOptions.empty c
124+
| Some c -> Typing_decl.class_decl (Naming.typechecker_options nenv) c
124125
end sub_classes
125126
end
126127
else Hashtbl.replace globals fn (false, [], [])
@@ -168,9 +169,8 @@ let hh_check fn =
168169
begin fun () ->
169170
let ast = Parser_heap.ParserHeap.find_unsafe fn in
170171
let funs, classes, typedefs, consts = make_funs_classes ast in
171-
let nenv =
172-
Naming.make_env Naming.empty ~funs ~classes ~typedefs ~consts
173-
in
172+
let nenv = Naming.empty TypecheckerOptions.permissive in
173+
let nenv = Naming.make_env nenv ~funs ~classes ~typedefs ~consts in
174174
let all_classes = List.fold_right begin fun (_, cname) acc ->
175175
SMap.add cname (Relative_path.Set.singleton fn) acc
176176
end classes SMap.empty in
@@ -183,6 +183,12 @@ let hh_check fn =
183183
error [l]
184184
end
185185

186+
let permissive_empty_envs fn =
187+
let tcopt = TypecheckerOptions.permissive in
188+
let nenv = Naming.empty tcopt in
189+
let tenv = Typing_env.empty tcopt fn in
190+
(nenv, tenv)
191+
186192
let hh_auto_complete fn =
187193
let fn = Relative_path.create Relative_path.Root fn in
188194
AutocompleteService.attach_hooks();
@@ -192,15 +198,14 @@ let hh_auto_complete fn =
192198
List.iter begin fun def ->
193199
match def with
194200
| Ast.Fun f ->
195-
let nenv = Naming.empty in
196-
let tenv = Typing_env.empty fn in
201+
let nenv, tenv = permissive_empty_envs fn in
197202
let f = Naming.fun_ nenv f in
198203
Typing.fun_def tenv (snd f.Nast.f_name) f
199204
| Ast.Class c ->
200-
let nenv = Naming.empty in
201-
let tenv = Typing_env.empty fn in
205+
let nenv, tenv = permissive_empty_envs fn in
206+
let tcopt = Naming.typechecker_options nenv in
202207
let c = Naming.class_ nenv c in
203-
Typing_decl.class_decl TypecheckerOptions.empty c;
208+
Typing_decl.class_decl tcopt c;
204209
let res = Typing.class_def tenv (snd c.Nast.c_name) c in
205210
res
206211
| _ -> ()
@@ -239,13 +244,11 @@ let hh_get_method_at_position fn line char =
239244
List.iter begin fun def ->
240245
match def with
241246
| Ast.Fun f ->
242-
let nenv = Naming.empty in
243-
let tenv = Typing_env.empty fn in
247+
let nenv, tenv = permissive_empty_envs fn in
244248
let f = Naming.fun_ nenv f in
245249
Typing.fun_def tenv (snd f.Nast.f_name) f
246250
| Ast.Class c ->
247-
let nenv = Naming.empty in
248-
let tenv = Typing_env.empty fn in
251+
let nenv, tenv = permissive_empty_envs fn in
249252
let c = Naming.class_ nenv c in
250253
let res = Typing.class_def tenv (snd c.Nast.c_name) c in
251254
res
@@ -321,16 +324,17 @@ let hh_find_lvar_refs file line char =
321324
try
322325
let get_result = FindLocalsService.attach_hooks line char in
323326
let ast = Parser_heap.ParserHeap.find_unsafe file in
327+
let tcopt = TypecheckerOptions.permissive in
324328
Errors.ignore_ begin fun () ->
325329
(* We only need to name to find references to locals *)
326330
List.iter begin fun def ->
327331
match def with
328332
| Ast.Fun f ->
329-
let nenv = Naming.empty in
333+
let nenv = Naming.empty tcopt in
330334
let _ = Naming.fun_ nenv f in
331335
()
332336
| Ast.Class c ->
333-
let nenv = Naming.empty in
337+
let nenv = Naming.empty tcopt in
334338
let _ = Naming.class_ nenv c in
335339
()
336340
| _ -> ()
@@ -434,12 +438,14 @@ let hh_arg_info fn line char =
434438
let _, funs, classes = Hashtbl.find globals fn in
435439
Errors.ignore_ begin fun () ->
436440
List.iter begin fun (_, f_name) ->
437-
let tenv = Typing_env.empty fn in
441+
let tcopt = TypecheckerOptions.permissive in
442+
let tenv = Typing_env.empty tcopt fn in
438443
let f = Naming_heap.FunHeap.find_unsafe f_name in
439444
Typing.fun_def tenv f_name f
440445
end funs;
441446
List.iter begin fun (_, c_name) ->
442-
let tenv = Typing_env.empty fn in
447+
let tcopt = TypecheckerOptions.permissive in
448+
let tenv = Typing_env.empty tcopt fn in
443449
let c = Naming_heap.ClassHeap.find_unsafe c_name in
444450
Typing.class_def tenv c_name c
445451
end classes;

0 commit comments

Comments
 (0)