Unbox ~?ty expected types deeply to fix pessimised nullable closure inference
commit5683de374a98eff3ffc31d1c6c878beaead21d8c
authorVassil Mladenov <[email protected]>
Tue, 30 Nov 2021 22:49:33 +0000 (30 14:49 -0800)
committerFacebook GitHub Bot <[email protected]>
Tue, 30 Nov 2021 22:51:16 +0000 (30 14:51 -0800)
tree13fee58b95f7db52dd43dd3f9102de2f9acf5abd
parent4b1ef31b0669c58b991058b13f8860bb5923f93e
Unbox ~?ty expected types deeply to fix pessimised nullable closure inference

Summary:
The function that unboxes like and null from expected types stopped after a single unwrap, which means that `~?ty` became `?ty` instead of `ty`. This broke closure inference which expects to get the unboxed `Tfun` directly and it exacerbated a bug (detailed in the comment). This change continues until all instances we care about are eliminated. Added a case to catch dynamic on the right similar to D32377869 (https://github.com/facebook/hhvm/commit/ec875229cd0cd6fd57e9c60419b24eef7b9296a7).

Noted inline that we do not treat `?t` as `(null | t)` yet, so the function does not pull null out of unions. If we do move to that representation, we need to change the expand function and take care that `~null` does not become `nothing`.

The actual function that exhibited this problem was the pessimised `Vec\filter_nulls`

Reviewed By: francesco-zappa-nardelli

Differential Revision: D32714811

fbshipit-source-id: 7fcca546692ce80d826549af5c01bee7f95bd652
hphp/hack/src/typing/typing.ml
hphp/hack/test/sound_dynamic/typing/hof.good.php [new file with mode: 0644]
hphp/hack/test/sound_dynamic/typing/hof.good.php.exp [new file with mode: 0644]