Remove some string checks from the default path for typing function calls
commitafe98128f68b81083c70db41e1ecfbc6c2476563
authorVassil Mladenov <vmladenov@fb.com>
Wed, 30 Dec 2020 22:32:53 +0000 (30 14:32 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 30 Dec 2020 22:34:50 +0000 (30 14:34 -0800)
tree90136785651de6379aadccece197dbf31212c392
parentb97dc8ae8b1deb7ae0740df9a0afca7de9ed55f1
Remove some string checks from the default path for typing function calls

Summary:
I noticed these string checks were happening every single function call, so I put the relevant strings in a `Hash_set` and do the slower checking if that passes. For shapes `Shapes::`, the restructure won't be much faster since each branch always checked the class name first, but it does fewer checks in the case when a Shapes:: function is encountered.

Besides the performance improvement, a nice benefit of this change is that the outer `match` for dispatch_call folds up to
```
  match fun_expr with
  (* Special top-level function *)
  | Id ((p, x) as id) when SN.StdlibFunctions.needs_special_dispatch x -> ...
  (* Special Shapes:: function *)
  | Class_const (((_, CI (_, shapes)) as class_id), ((_, x) as method_id))
    when String.equal shapes SN.Shapes.cShapes -> ...
  (* Special function `parent::__construct` *)
  | Class_const ((pos, CIparent), ((_, construct) as id))
    when String.equal construct SN.Members.__construct -> ...
  (* Calling parent / class method *)
  | Class_const (class_id, m) -> dispatch_class_const env class_id m
  (* Call instance method *)
  | Obj_get (e1, (pos_id, Id m), nullflavor, false)
    when not (TypecheckerOptions.method_call_inference (Env.get_tcopt env)) -> ...
  (* Call instance method using new method call inference *)
  | Obj_get (receiver, (pos_id, Id meth), nullflavor, false) -> ...
  (* Function invocation *)
  | Fun_id x -> ...
  | Id id -> dispatch_id env id
  | _ -> ...
```
which is quite a bit easier to follow.

Reviewed By: losvald

Differential Revision: D25729833

fbshipit-source-id: fb28e12095835dde5616d5f072fdfdfbae7a4b5a
hphp/hack/src/naming/naming_special_names.ml
hphp/hack/src/typing/typing.ml