Skip to content

Commit c826b67

Browse files
committed
Sync changes to upstream
1 parent 78890c3 commit c826b67

Some content is hidden

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

79 files changed

+1308
-274
lines changed

auxiliary/lib/auxiliary.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
declare var XXX: string;
2+
declare module Foo {
3+
declare var x: string;
4+
}
5+
declare module Bar {
6+
declare var y: string;
7+
}

auxiliary_tests/module_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* @flow */
2+
var Foo = require('Foo');
3+
var Bar = require('Bar');
4+
5+
var x:number = Foo.x;
6+
var y:number = Bar.y;

auxiliary_tests/node_modules/Bar.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auxiliary_tests/node_modules/Foo_.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auxiliary_tests/type_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/* @flow */
12
var _:number = XXX;

examples/flux-chat/js/dispatcher/ChatAppDispatcher.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ type ViewAction = ViewCreateMessageAction | ViewClickThreadAction;
5050

5151
type PayloadType = {
5252
source: any;
53-
action: any/*ServerAction | ViewAction*/;
53+
action: ViewCreateMessageAction
54+
| ViewClickThreadAction
55+
| ServerReceiveRawMessagesAction
56+
| ServerReceiveRawCreatedMessageAction;
5457
};
5558

5659
var PayloadSources = ChatConstants.PayloadSources;

examples/flux-chat/js/stores/MessageStore.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ MessageStore.dispatchToken = ChatAppDispatcher.register(function(payload: any) {
145145
break;
146146

147147
case ActionTypes.CREATE_MESSAGE:
148-
var message = MessageStore.getCreatedMessageData(action.text);
148+
// WORKAROUND: getCreatedMessageData could create a message object
149+
// with threadID being null. This seems like a potentially serious
150+
// issue. However, fixing this issue would require a major refactoring
151+
// on threadID assignment to be consistent. Since in the example setup
152+
// null never appears in this spot, we simply silence flow's errors
153+
// about it.
154+
var message: any = MessageStore.getCreatedMessageData(action.text);
149155
_messages[message.id] = message;
150156
MessageStore.emitChange();
151157
break;

hack/heap/hh_shared.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,27 @@
2525
* read-only mode with all the workers.
2626
* The master stores, the workers read.
2727
* Only concurrent reads allowed. No concurrent write/read and write/write.
28+
* There are a few different OCaml modules that act as interfaces to this
29+
* global storage. They all use the same area of memory, so only one can be
30+
* active at any one time. The caller is responsible for zeroing out the
31+
* memory when it is done.
2832
*
2933
* II) The dependency table. It's a hashtable that contains all the
3034
* dependencies between Hack objects. It is filled concurrently by
3135
* the workers. The dependency table is made of 2 hashtables, one that
3236
* can is used to quickly answer if a dependency exists. The other one
3337
* to retrieve the list of dependencies associated with an object.
38+
* Only the hashes of the objects are stored, so this uses relatively
39+
* little memory. No dynamic allocation is required.
3440
*
35-
* III) The Hashtable.
41+
* III) The Hashtable that maps string keys to string values. (The strings
42+
* are really serialized / marshalled representations of OCaml structures.)
3643
* Key observation of the table is that data with the same key are
3744
* considered equivalent, and so you can arbitrarily get any copy of it;
3845
* furthermore if data is missing it can be recomputed, so incorrectly
3946
* saying data is missing when it is being written is only a potential perf
4047
* loss. Note that "equivalent" doesn't necessarily mean "identical", e.g.,
41-
* two alpha-converted types are "equivalent" though not litterally byte-
48+
* two alpha-converted types are "equivalent" though not literally byte-
4249
* identical. (That said, I'm pretty sure the Hack typechecker actually does
4350
* always write identical data, but the hashtable doesn't need quite that
4451
* strong of an invariant.)
@@ -60,6 +67,11 @@
6067
* -) Concurrent removes: NOT SUPPORTED
6168
* Only the master can remove, and can only do so if there are no other
6269
* concurrent operations (reads or writes).
70+
*
71+
* Since the values are variably sized and can get quite large, they are
72+
* stored separately from the hashes in a garbage-collected heap.
73+
*
74+
* Both II and III resolve hash collisions via linear probing.
6375
*/
6476
/*****************************************************************************/
6577

@@ -175,6 +187,12 @@ static char* heap_init;
175187
/* This should only be used by the master */
176188
static size_t heap_init_size = 0;
177189

190+
/* For debugging */
191+
value hh_heap_size() {
192+
CAMLparam0();
193+
CAMLreturn(Val_long(*heap - heap_init));
194+
}
195+
178196
/*****************************************************************************/
179197
/* Given a pointer to the shared memory address space, initializes all
180198
* the globals that live in shared memory.

hack/heap/sharedMem.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ external save: string -> unit = "hh_save"
4040
(*****************************************************************************)
4141
external load: string -> unit = "hh_load"
4242

43+
(*****************************************************************************)
44+
(* The size of the dynamically allocated shared memory section *)
45+
(*****************************************************************************)
46+
external heap_size: unit -> int = "hh_heap_size"
47+
4348
(*****************************************************************************)
4449
(* Module returning the MD5 of the key. It's because the code in C land
4550
* expects this format. I prefer to make it an abstract type to make sure

hack/heap/sharedMem.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ val save: string -> unit
5050
(*****************************************************************************)
5151
val load: string -> unit
5252

53+
(*****************************************************************************)
54+
(* The size of the dynamically allocated shared memory section *)
55+
(*****************************************************************************)
56+
val heap_size : unit -> int
57+
5358
(*****************************************************************************)
5459
(* Cache invalidation. *)
5560
(*****************************************************************************)

hack/parsing/lexer_hack.mll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ let xhpname = ('%')? letter (alphanumeric | ':' [^':''>'] | '-')*
272272
let otag = '<' ['a'-'z''A'-'Z'] (alphanumeric | ':' | '-')*
273273
let ctag = '<' '/' (alphanumeric | ':' | '-')+ '>'
274274
let lvar = '$' varname
275-
let reflvar = '&' '$' varname
276275
let ws = [' ' '\t' '\r' '\x0c']
277-
let wsnl = [' ' '\t' '\r' '\x0c''\n']
278276
let hex = digit | ['a'-'f''A'-'F']
279277
let hex_number = '0' 'x' hex+
280278
let bin_number = '0' 'b' ['0'-'1']+
@@ -698,3 +696,11 @@ and format_xhptoken = parse
698696
| "<!--" { Topen_xhp_comment }
699697
| "-->" { Tclose_xhp_comment }
700698
| _ { Terror }
699+
700+
(* Normally you can just use "token" and get back Tlvar, but specifically for
701+
* member variable accesses, the part to the right of the "->" isn't a word
702+
* (cannot contain '-' for example) but doesn't start with '$' so isn't an lvar
703+
* either. *)
704+
and varname = parse
705+
| varname { Tword }
706+
| _ { Terror }

hack/parsing/parser_hack.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ and expr_binop env bop ast_bop e1 =
25172517
and expr_arrow env e1 tok =
25182518
reduce env e1 tok begin fun e1 env ->
25192519
let e2 =
2520-
match L.token env.file env.lb with
2520+
match L.varname env.lb with
25212521
| Tword ->
25222522
let name = Lexing.lexeme env.lb in
25232523
let pos = Pos.make env.file env.lb in

hack/procs/multiWorker.ml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@
1111
type 'a nextlist =
1212
unit -> 'a list
1313

14-
let rec make_bucket n acc l =
15-
match l with
16-
| _ when n <= 0 -> acc, l
17-
| [] -> acc, l
18-
| x :: rl ->
19-
make_bucket (n-1) (x :: acc) rl
20-
21-
let make_bucket l =
22-
let x = ref l in
23-
fun _ ->
24-
let res, next = make_bucket 1000 [] l in
25-
x := next;
26-
res
27-
2814
let single_threaded_call job merge neutral next =
2915
let x = ref (next()) in
3016
let acc = ref neutral in

hack/procs/multiWorker.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
type 'a nextlist =
1515
unit -> 'a list
1616

17-
val make_bucket: 'a list -> ('b -> 'a list)
18-
1917
val call :
2018
Worker.t list option ->
2119
job:('b -> 'a list -> 'b) ->

hack/server/serverInit.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ open ServerEnv
1212

1313
(* Initialization of the server *)
1414
let init_hack genv env get_next =
15+
let t = Unix.gettimeofday() in
16+
1517
let files_info, errorl1, failed1 =
1618
Parsing_service.go genv.workers ~get_next in
1719

20+
let t2 = Unix.gettimeofday() in
21+
Printf.printf "Parsing: %f\n%!" (t2 -. t);
22+
Printf.printf "Heap size: %d\n%!" (SharedMem.heap_size ());
23+
let t = t2 in
24+
1825
let is_check_mode =
1926
ServerArgs.check_mode genv.options &&
2027
ServerArgs.convert genv.options = None &&
@@ -31,11 +38,24 @@ let init_hack genv env get_next =
3138
Relative_path.Map.fold
3239
Naming.ndecl_file files_info ([], Relative_path.Set.empty, nenv) in
3340

41+
let t2 = Unix.gettimeofday() in
42+
Printf.printf "Naming: %f\n%!" (t2 -. t);
43+
let t = t2 in
44+
3445
let fast = FileInfo.simplify_fast files_info in
3546
let fast = Relative_path.Set.fold Relative_path.Map.remove failed2 fast in
3647
let errorl3, failed3 = Typing_decl_service.go genv.workers nenv fast in
48+
49+
let t2 = Unix.gettimeofday() in
50+
Printf.printf "Type-decl: %f\n%!" (t2 -. t);
51+
Printf.printf "Heap size: %d\n%!" (SharedMem.heap_size ());
52+
let t = t2 in
53+
3754
let errorl4, failed4 = Typing_check_service.go genv.workers fast in
3855

56+
let t2 = Unix.gettimeofday() in
57+
Printf.printf "Type-check: %f\n%!" (t2 -. t);
58+
3959
let failed =
4060
List.fold_right Relative_path.Set.union
4161
[failed1; failed2; failed3; failed4]

hack/server/serverTypeCheck.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ let type_check genv env =
217217
let t = Unix.gettimeofday() in
218218
let fast_parsed, errorl, failed_parsing = parsing genv env in
219219
let t2 = Unix.gettimeofday() in
220-
Printf.printf "Parsing: %f\n" (t2 -. t); flush stdout;
220+
Printf.printf "Parsing: %f\n%!" (t2 -. t);
221221
let t = t2 in
222222

223223
(* UPDATE FILE INFO *)
@@ -237,14 +237,14 @@ let type_check genv env =
237237
let fast = add_old_decls env.files_info fast in
238238

239239
let t2 = Unix.gettimeofday() in
240-
Printf.printf "Naming: %f\n" (t2 -. t); flush stdout;
240+
Printf.printf "Naming: %f\n%!" (t2 -. t);
241241
let t = t2 in
242242

243243
let _, _, to_redecl_phase2, to_recheck1 =
244244
Typing_redecl_service.redo_type_decl
245245
~update_pos:true genv.workers nenv fast in
246246
let t2 = Unix.gettimeofday() in
247-
Printf.printf "Determining changes: %f\n" (t2 -. t); flush stdout;
247+
Printf.printf "Determining changes: %f\n%!" (t2 -. t);
248248
let t = t2 in
249249

250250
let to_redecl_phase2 = Typing_deps.get_files to_redecl_phase2 in
@@ -258,7 +258,7 @@ let type_check genv env =
258258
~update_pos:false genv.workers nenv fast_redecl_phase2 in
259259

260260
let t2 = Unix.gettimeofday() in
261-
Printf.printf "Type-decl: %f\n" (t2 -. t); flush stdout;
261+
Printf.printf "Type-decl: %f\n%!" (t2 -. t);
262262
let t = t2 in
263263

264264
let errorl = List.rev_append errorl' errorl in
@@ -279,7 +279,7 @@ let type_check genv env =
279279
let errorl = List.rev (List.rev_append errorl' errorl) in
280280

281281
let t2 = Unix.gettimeofday() in
282-
Printf.printf "Type-check: %f\n" (t2 -. t); flush stdout;
282+
Printf.printf "Type-check: %f\n%!" (t2 -. t);
283283

284284
(* Done, that's the new environment *)
285285
{ files_info = files_info;

hack/typing/typing_decl.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module SN = Naming_special_names
3232
* a worker needs to know if the type of a class is ready or if it needs to
3333
* be recomputed. When ClassStatus.mem *class-name* returns true, we know
3434
* the class has already been recomputed by a different worker.
35-
* TypedefStatus is a similar mechanism for typedefs.
35+
* TypedefHeap is a similar mechanism for typedefs.
3636
*)
3737
(*****************************************************************************)
3838

hack/typing/typing_decl_service.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
(* Module declaring the types in parallel *)
1414
(*****************************************************************************)
1515
open Utils
16-
module PHeap = Parser_heap.ParserHeap
1716

1817
(* filename => functions defined, classes defined *)
1918
type fast = (SSet.t * SSet.t * SSet.t * SSet.t) SMap.t

hack/typing/typing_exts.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ let fresh_tvars (env:Env.env) (ts:tparam list) (ps:fun_params) (uniq:int) : Env.
7676
let ts' = List.map (fun (x, y, z) -> x, map_snd rename_str y, z) ts in
7777
env, ps', ts'
7878

79-
8079
let lookup_magic_type (env:Env.env) (class_:ty) (fname:string) (uniq:int) :
8180
Env.env * (fun_params * tparam list * ty option) option =
8281
match class_ with
@@ -132,7 +131,6 @@ let parse_printf_string (env:Env.env) (s:string) (pos:Pos.t) (class_:ty) : Env.e
132131
in
133132
read_text env 0
134133

135-
136134
type ('a, 'b) either = Left of 'a | Right of 'b
137135

138136
let mapM (f:'s->'x->'s*'y) : 'st -> 'x list -> 's * 'y list =

hack/typing/typing_redecl_service.ml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ let compute_deps_neutral = ISet.empty, ISet.empty
2828
(* This is the place where we are going to put everything necessary for
2929
* the redeclaration. We could "pass" the values directly to the workers,
3030
* but it gives too much work to the master and slows things downn.
31-
* So what we do instead is:
32-
* Set the value of "data_storage", which means that one of the data nodes
33-
* has this value.
34-
* Let each worker pool the data from "data_storage".
31+
* So what we do instead is pass the data through shared memory via
32+
* OnTheFlyStore.
3533
* I tried replicating the data to speed things up but it had no effect.
3634
*)
3735
(*****************************************************************************)
@@ -46,7 +44,7 @@ end)
4644
(* Re-declaring the types in a file *)
4745
(*****************************************************************************)
4846

49-
let on_the_fly_decl_file nenv all_classes fast (errors, failed) fn =
47+
let on_the_fly_decl_file nenv all_classes (errors, failed) fn =
5048
let decl_errors, () = Errors.do_
5149
begin fun () ->
5250
(* We start "recording" dependencies.
@@ -170,16 +168,16 @@ let update_positions classes to_update =
170168
*)
171169
(*****************************************************************************)
172170

173-
let redeclare_files nenv all_classes fast filel =
171+
let redeclare_files nenv all_classes filel =
174172
List.fold_left
175-
(on_the_fly_decl_file nenv all_classes fast)
173+
(on_the_fly_decl_file nenv all_classes)
176174
([], Relative_path.Set.empty)
177175
filel
178176

179-
let otf_decl_files nenv all_classes fast filel =
177+
let otf_decl_files nenv all_classes filel =
180178
SharedMem.invalidate_caches();
181179
(* Redeclaring the files *)
182-
let errors, failed = redeclare_files nenv all_classes fast filel in
180+
let errors, failed = redeclare_files nenv all_classes filel in
183181
errors, failed
184182

185183
let compute_deps ~update_pos nenv fast filel =
@@ -215,7 +213,7 @@ let compute_deps ~update_pos nenv fast filel =
215213
let load_and_otf_decl_files acc filel =
216214
try
217215
let nenv, all_classes, fast = OnTheFlyStore.load() in
218-
otf_decl_files nenv all_classes fast filel
216+
otf_decl_files nenv all_classes filel
219217
with e ->
220218
Printf.printf "Error: %s\n" (Printexc.to_string e);
221219
flush stdout;
@@ -296,23 +294,19 @@ let get_defs fast =
296294
end fast FileInfo.empty_names
297295

298296
(*****************************************************************************)
299-
(* The main entry points *)
297+
(* The main entry point *)
300298
(*****************************************************************************)
301299

302-
let init workers fast =
303-
let fnl = Relative_path.Map.fold (fun x _ y -> x :: y) fast [] in
304-
let all_classes = Typing_decl_service.get_classes fast in
305-
all_classes, fnl
306-
307300
let redo_type_decl ~update_pos workers nenv fast =
308-
let all_classes, fnl = init workers fast in
301+
let fnl = Relative_path.Map.keys fast in
302+
let all_classes = Typing_decl_service.get_classes fast in
309303
let defs = get_defs fast in
310304
invalidate_heap defs;
311305
(* If there aren't enough files, let's do this ourselves ... it's faster! *)
312306
let result =
313307
if List.length fnl < 10
314308
then
315-
let errors, failed = otf_decl_files nenv all_classes fast fnl in
309+
let errors, failed = otf_decl_files nenv all_classes fnl in
316310
let to_redecl, to_recheck = compute_deps ~update_pos nenv fast fnl in
317311
errors, failed, to_redecl, to_recheck
318312
else parallel_otf_decl ~update_pos workers nenv all_classes fast fnl

0 commit comments

Comments
 (0)