Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: When we localize a function type with where constraints, we might localize type const access like T1::T. Whenever we localize type consts like T1::T, create a tvar v2 representing T1::T, and add it in the node for v1, representing T1: ``` v1 -> { upper_bound: [ StringBox; ... ] lower_bounds: ... appears_covariantly: ... appears_contravariantly: ... type_consts: varid SidMap.t = [ "T" -> v2 ] } ``` Note: if we localize T1::T::T, then we would need v1 for T1, v2 for v1::T and v3 for v2::T. For all present and future upper bounds U of #1, localize U::T as a type variable #3 with the same constraints as T in U, then make #2 equivalent to #3. For all present and future lower bounds L of #1, simply make #2 equivalent to L::T. For upper bounds, we're just checking that the constraints on U::T are satisfied. For lower bounds L however, we make #1::T equal to the type constant in L, possibly making it an expression dependent type if T is abstract in L. Reviewed By: andrewjkennedy Differential Revision: D13958402 fbshipit-source-id: 23b8d157fd78ae27d777904bbea53a166f6a939b
- Loading branch information
1 parent
a93f0eb
commit 57efb74
Showing
29 changed files
with
694 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Env = Typing_env | ||
module Phase = Typing_phase | ||
module TySet = Typing_set | ||
module Utils = Typing_utils | ||
|
||
(** Make tconstty (usually a type variable representing the type constant of | ||
another type variable v) equal to ty::tconstid (where ty is usually a bound | ||
of v) *) | ||
let make_type_const_equal env tconstty ty tconstid ~as_tyvar_with_cnstr = | ||
let ety_env = Phase.env_with_self env in | ||
let (env, (_ety_env, tytconst)) = | ||
Utils.expand_typeconst ety_env env ~as_tyvar_with_cnstr (fst ty) ty | ||
[tconstid] in | ||
let env = Utils.sub_type env tytconst tconstty in | ||
let env = Utils.sub_type env tconstty tytconst in | ||
env | ||
|
||
(** Add a type constant with id `tyconstid` and type `ty` to a type variable, | ||
and propagate constraints to all type constants `tyconstid` of upper bounds and | ||
lower bounds. *) | ||
let add_tyvar_type_const env var tconstid ty = | ||
let env = Env.set_tyvar_type_const env var tconstid ty in | ||
let upper_bounds = Env.get_tyvar_upper_bounds env var in | ||
let env = TySet.fold | ||
(fun bound env -> make_type_const_equal env ty bound tconstid | ||
~as_tyvar_with_cnstr:true) | ||
upper_bounds env in | ||
let lower_bounds = Env.get_tyvar_lower_bounds env var in | ||
TySet.fold | ||
(fun bound env -> make_type_const_equal env ty bound tconstid | ||
~as_tyvar_with_cnstr:false) | ||
lower_bounds env | ||
|
||
|
||
(** For all type constants T of var, make its type equal to ty::T *) | ||
let make_all_type_consts_equal env var ty ~as_tyvar_with_cnstr = | ||
SMap.fold | ||
(fun _ (tconstid, tconstty) env -> | ||
make_type_const_equal env tconstty ty tconstid ~as_tyvar_with_cnstr) | ||
(Env.get_tyvar_type_consts env var) | ||
env | ||
|
||
|
||
(** `p` is the position where var::tconstid was encountered. *) | ||
let get_tyvar_type_const env var (pos, _ as tconstid) = | ||
match Env.get_tyvar_type_const env var tconstid with | ||
| Some (_pos, ty) -> env, ty | ||
| None -> | ||
let env, tvar = Env.fresh_invariant_type_var env pos in | ||
let env = add_tyvar_type_const env var tconstid tvar in | ||
env, tvar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
open Typing_defs | ||
|
||
module Env = Typing_env | ||
|
||
(** For all type constant T of type variable, make its type equal to `ty`::T *) | ||
val make_all_type_consts_equal: | ||
Env.env -> | ||
Ident.t -> | ||
locl ty -> | ||
as_tyvar_with_cnstr:bool -> | ||
Env.env | ||
|
||
(** Get the type of a type constant of a type variable by looking it up in the | ||
environment. | ||
If that type constant is not present, make a fresh invariant | ||
type variable and add it as the type of the type constant in the environment. | ||
*) | ||
val get_tyvar_type_const: | ||
Env.env -> | ||
Ident.t -> | ||
Nast.sid -> | ||
Env.env * locl ty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--new-inference | ||
--all-errors |
Oops, something went wrong.