First stage of constraints refactoring: bounds environment
commit784ea81c6123a3ce573ce97f7ee3d8cf41b488ec
authorAndrew Kennedy <akenn@fb.com>
Thu, 28 Apr 2016 13:17:43 +0000 (28 06:17 -0700)
committerHhvm Bot <hhvm-bot-bot@fb.com>
Thu, 28 Apr 2016 13:30:34 +0000 (28 06:30 -0700)
tree0320ea2950a2ba88960e0590c93881996e2af480
parent30ea9d577a8f4148f878452af68ffea2288bfab6
First stage of constraints refactoring: bounds environment

Summary:
Constraints on type parameters (as and super) are currently carried around
with the formal type parameter inside the type itself. In future we may wish
to "evolve" the constraints on a type parameter in different contexts, for
example adding constraints on class type parameters at the method level, or
deducing new constraints on type parameters inside an instanceof block.
The current scheme also precludes F-bounded constraints such
as T:IComparable<T>.

The usual technique in presentations of constrained generics is to carry
a "constraint" environment, indexed by the formal type parameters.

This change introduces such an environment, mapping formal type parameters
to a pair of lists of lower and upper bounds on the type parameter. (In future
we may want to support both lower and upper bounds on a parameter, and more
than one of each.) The type syntax in Typing_defs has been changed to remove
the "super" type from AKgeneric. The subtyping function is much simpler. The
next stage is to remove the "as" type from Tabstract, at least in the case where
it is used for formal type parameters. But there is quite a lot of special casing
in typing.ml that needs to be refactored.

Reviewed By: dlreeves

Differential Revision: D3212437

fb-gh-sync-id: 377374958b2543945b03cda152196672735dbc98
fbshipit-source-id: 377374958b2543945b03cda152196672735dbc98
21 files changed:
hphp/hack/src/decl/decl_instantiate.ml
hphp/hack/src/typing/type_mapper.ml
hphp/hack/src/typing/type_visitor.ml
hphp/hack/src/typing/typing.ml
hphp/hack/src/typing/typing_defs.ml
hphp/hack/src/typing/typing_enum.ml
hphp/hack/src/typing/typing_env.ml
hphp/hack/src/typing/typing_env.mli
hphp/hack/src/typing/typing_generic.ml
hphp/hack/src/typing/typing_instantiate.mli
hphp/hack/src/typing/typing_phase.ml
hphp/hack/src/typing/typing_print.ml
hphp/hack/src/typing/typing_subtype.ml
hphp/hack/src/typing/typing_suggest.ml
hphp/hack/src/typing/typing_taccess.ml
hphp/hack/src/typing/typing_unify.ml
hphp/hack/test/typecheck/gen4a.php [new file with mode: 0644]
hphp/hack/test/typecheck/gen4a.php.exp [new file with mode: 0644]
hphp/hack/test/typecheck/hh_show_typevar.php.exp
hphp/hack/test/typecheck/super_constraint_5.php.exp
hphp/hack/test/typecheck/super_constraint_6.php