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