add command to report all TAST `Holes` for a given fils
commitca27a521303d83dd718e94ac07b5bdc9fb751a00
authorMichael Thomas <mjt@fb.com>
Wed, 19 May 2021 11:00:54 +0000 (19 04:00 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 19 May 2021 11:02:26 +0000 (19 04:02 -0700)
tree7f4162a34d5f16c64d55b27bf7dd48a6f50ecf78
parent7c81b9d633083666c8d4115a467fca93bfaefaeb
add command to report all TAST `Holes` for a given fils

Summary:
As part of a codemod for the proposed `unsafe_cast` migration, we would like to access subtyping / coercion error information using `HackAst`. The initial approach to this was to provide a command (`--type-error-at-pos`) which operated in a similar manner to `--type-at-pos` which provided an API to call from `HackAst` for a given expression. The workflow was then:

i) Find all expressions with a covering fixmes
ii) Call `--type-error-at-pos` for each subexpression
iii) Modify expression if `Hole` was found

This diff adds a command `--tast-holes` which will be used to provide _all_ `Hole`s on the TAST and their positions at once, i.e.

i) Call `--tast-holes`
ii) Find largest expression exactly contained in each Hole
iii) Modify expression

This approach leads to fewer calls to `hh` and has the benefit of handling corner cases arising in `HackClient` due to using positional information to find `Hole`s. In particular, this approach will allow us to correctly handle `Hole`s on an expression and a constituent subexpression which have the same start position e.g.

```
function foo(bool $x): string {
  /* HH_FIXME[4110] */
  return $x + 1 ? '1' : 1;
}
```
```
Hole
  ( ( ([5:10-26], (int | string))
    , Eif
        ( ( ([5:10-16], int)
          , Binop
              ( Plus
              , ( ([5:10-12], bool)
                , Hole
                    ( (([5:10-12], bool), (Lvar ([5:10-12], $x)))
                    , bool
                    , num
                    , Typing
                    )
                )
              , (([5:15-16], int), (Int "1"))
              )
          )
        , (Some (([5:19-22], string), String "1"))
        , ( ([5:25-26], int), Int "1")
        )
    )
  , (int | string)
  , string
  , Typing
  )
```

Reviewed By: madgen

Differential Revision: D28091408

fbshipit-source-id: 868b115b9d0b3471e439a5e1d4e4dddb04cf1406
27 files changed:
hphp/hack/src/client/clientArgs.ml
hphp/hack/src/client/clientCheck.ml
hphp/hack/src/client/clientEnv.ml
hphp/hack/src/client/clientTastHoles.ml [new file with mode: 0644]
hphp/hack/src/client/clientTastHoles.mli [new file with mode: 0644]
hphp/hack/src/ide_rpc/nuclide_rpc_message_printer.ml
hphp/hack/src/server/dune
hphp/hack/src/server/serverCollectTastHoles.ml [new file with mode: 0644]
hphp/hack/src/server/serverCollectTastHoles.mli [new file with mode: 0644]
hphp/hack/src/server/serverCommand.ml
hphp/hack/src/server/serverCommandTypes.ml
hphp/hack/src/server/serverCommandTypesUtils.ml
hphp/hack/src/server/serverRpc.ml
hphp/hack/src/server/tastHolesService.ml [new file with mode: 0644]
hphp/hack/src/server/tastHolesService.mli [new file with mode: 0644]
hphp/hack/src/utils/pos_embedded.ml
hphp/hack/src/utils/pos_embedded.mli
hphp/hack/test/integration/data/holes/call_multiple.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/data/holes/call_single.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/data/holes/call_unpack.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/data/holes/coincident_holes.php [new file with mode: 0644]
hphp/hack/test/integration/data/holes/coincident_holes.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/data/holes/member_call_multiple.php [new file with mode: 0644]
hphp/hack/test/integration/data/holes/member_call_multiple.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/data/holes/return_and_fn_arg.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/data/holes/return_expr_only.php.holes.exp [new file with mode: 0644]
hphp/hack/test/integration/test_tast_holes.py [new file with mode: 0644]