refactor Naming_global.type_canon_pos
commit30e43393d5bdd8c930ada0166c40b6e73be02129
authorLucian Wischik <ljw@fb.com>
Tue, 30 Mar 2021 22:16:56 +0000 (30 15:16 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 30 Mar 2021 22:19:25 +0000 (30 15:19 -0700)
treed5eb2df6e9a2f9ae6ba9c26e2070c854f4f783a5
parentf9c89ea4a52a55c68ca94cd32fc812b5f384e086
refactor Naming_global.type_canon_pos

Summary:
Look at this code:
```
let type_canon_pos ctx name =
   let name2 = Option.value (type_canon_name ctx name1) ~default:name1 in
   let pos_opt = type_pos ctx name2 in
   pos_opt
```
1. It looks up the naming-table to see if there's a canonical casing for name1
2. If there was a canonical casing name2, it looks up in the naming table to find name2's position
3. If the name was absent from the naming table, then it makes a futile lookup of the naming table to find name1's position

I don't know why the code was written this way. If nothing was found in the naming table in step1, there's no point in looking it  up in step 3. The code should have been written
```
type_canon_name ctx name |> Option.bind ~f:(type_pos ctx)
```
That's all this diff does. Just minor cleanup. (Also, I moved the function out of being a top-level function, into an inline function in the only place it's used).

Reviewed By: CatherineGasnier

Differential Revision: D27420750

fbshipit-source-id: a1e608c6d8149021d27b947cc534d640e45c446e
hphp/hack/src/naming/naming_global.ml