Clean up extends checks to improve performance
commitb8e001879bb150941e6361441156d69c776848cc
authorAndrew Kennedy <akenn@fb.com>
Mon, 23 Aug 2021 14:43:48 +0000 (23 07:43 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 23 Aug 2021 14:47:14 +0000 (23 07:47 -0700)
treef82ef4cbb58a87c68deada8af5ed9466317f8c8d
parent72c40ae056a7760f819c80c1ca9adf9f7f7ec8bb
Clean up extends checks to improve performance

Summary:
Clean up code in `Typing_extends.ml`. Most importantly, remove the poor checking of consts: for every interface that a class directly implements, we currently construct (the same) map from the list returned from `Cls.consts` on the class, in order to check against the consts defined by that interface. This is O(n^2) or worse.

Refactor the code so that `Typing_extends.ml` deals with *all* interfaces (and parent and traits) declared by a class, instead of iterating over them in `Typing_toplevel.ml`. Avoid calling `Cls.consts` on the class itself, instead just use `Cls.get_const` on demand. Also get rid of the construction and deconstruction of the class instantiated at its generic parameters. There is no need - and there is no need to construct the identity substitution simply in order to apply it to elements of the class! (This results in some slight changes to errors - see tests).

Reviewed By: francesco-zappa-nardelli

Differential Revision: D30453437

fbshipit-source-id: 54bc1cda329b8a5d805fcd57167e18916a124688
hphp/hack/src/typing/typing_extends.ml
hphp/hack/src/typing/typing_extends.mli
hphp/hack/src/typing/typing_toplevel.ml
hphp/hack/test/typecheck/constraint_gen_fail3.php.exp
hphp/hack/test/typecheck/constraints/constraint_override_bad3.php.exp
hphp/hack/test/typecheck/constraints/where_override_bad.php.exp
hphp/hack/test/typecheck/incompatible_interface.php.exp