Skip to content

Commit

Permalink
Implement new module type alias visibility in the typechecker
Browse files Browse the repository at this point in the history
Summary: This diff adds a new OpaqueModule visibility for typedefs. It does not make use of the visibility in the diff. In the next diff, we will lower and declare code that uses module newtypes properly.

Reviewed By: hgoldstein

Differential Revision: D37467892

fbshipit-source-id: 16fd323b4b87c97ab20adcfbe1b5ce0f8745cb51
  • Loading branch information
jamesjwu authored and facebook-github-bot committed Jul 14, 2022
1 parent 0381be5 commit cf3f1a9
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions hphp/hack/src/annotated_ast/aast_defs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ and vc_kind =
and typedef_visibility =
| Transparent
| Opaque
| OpaqueModule

and enum_ = {
e_base: hint;
Expand Down
3 changes: 2 additions & 1 deletion hphp/hack/src/oxidized/aast_visitor/node_impl_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
//
// @generated SignedSource<<4663f33dc340eac94f007d08add7615d>>
// @generated SignedSource<<47475db39c74d793be28e5a2c9df1ac1>>
//
// To regenerate this file, run:
// hphp/hack/src/oxidized_regen.sh
Expand Down Expand Up @@ -2044,6 +2044,7 @@ impl<P: Params> Node<P> for TypedefVisibility {
match self {
TypedefVisibility::Transparent => Ok(()),
TypedefVisibility::Opaque => Ok(()),
TypedefVisibility::OpaqueModule => Ok(()),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion hphp/hack/src/oxidized/aast_visitor/node_mut_impl_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
//
// @generated SignedSource<<a7141cc7d56063b33f35c9ac25f7426b>>
// @generated SignedSource<<30e561f4665ce11cc087fb2b94571bf9>>
//
// To regenerate this file, run:
// hphp/hack/src/oxidized_regen.sh
Expand Down Expand Up @@ -2044,6 +2044,7 @@ impl<P: Params> NodeMut<P> for TypedefVisibility {
match self {
TypedefVisibility::Transparent => Ok(()),
TypedefVisibility::Opaque => Ok(()),
TypedefVisibility::OpaqueModule => Ok(()),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion hphp/hack/src/oxidized/gen/aast_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
//
// @generated SignedSource<<a0b3cf17629d79dab8c4685bd0ca3e38>>
// @generated SignedSource<<5dc75b2deb593ef70fb33420b9fe9e6e>>
//
// To regenerate this file, run:
// hphp/hack/src/oxidized_regen.sh
Expand Down Expand Up @@ -510,6 +510,7 @@ arena_deserializer::impl_deserialize_in_arena!(VcKind);
pub enum TypedefVisibility {
Transparent,
Opaque,
OpaqueModule,
}
impl TrivialDrop for TypedefVisibility {}
arena_deserializer::impl_deserialize_in_arena!(TypedefVisibility);
Expand Down
11 changes: 10 additions & 1 deletion hphp/hack/src/oxidized/impl_gen/aast_defs_impl_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
//
// @generated SignedSource<<59a153c855ab440abb144288231d63e7>>
// @generated SignedSource<<f0bfabe86bc06356652901512ea1bb84>>
//
// To regenerate this file, run:
// hphp/hack/src/oxidized_regen.sh
Expand Down Expand Up @@ -946,6 +946,9 @@ impl TypedefVisibility {
pub fn mk_opaque() -> Self {
TypedefVisibility::Opaque
}
pub fn mk_opaque_module() -> Self {
TypedefVisibility::OpaqueModule
}
pub fn is_transparent(&self) -> bool {
match self {
TypedefVisibility::Transparent => true,
Expand All @@ -958,6 +961,12 @@ impl TypedefVisibility {
_ => false,
}
}
pub fn is_opaque_module(&self) -> bool {
match self {
TypedefVisibility::OpaqueModule => true,
_ => false,
}
}
}
impl ReifyKind {
pub fn mk_erased() -> Self {
Expand Down
3 changes: 2 additions & 1 deletion hphp/hack/src/oxidized_by_ref/decl_visitor/node_impl_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
//
// @generated SignedSource<<afb6506b9039a742739205f4e8fe92cd>>
// @generated SignedSource<<e386c44ddbc84f8675748159c2dd3dae>>
//
// To regenerate this file, run:
// hphp/hack/src/oxidized_regen.sh
Expand Down Expand Up @@ -1163,6 +1163,7 @@ impl<'a> Node<'a> for TypedefVisibility {
match self {
TypedefVisibility::Transparent => {}
TypedefVisibility::Opaque => {}
TypedefVisibility::OpaqueModule => {}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion hphp/hack/src/server/serverExtractStandalone.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,9 @@ end = struct

let pp_typedef_visiblity ppf = function
| Aast_defs.Transparent -> Fmt.string ppf "type"
| Aast_defs.Opaque -> Fmt.string ppf "newtype"
| Aast_defs.Opaque
| Aast_defs.OpaqueModule ->
Fmt.string ppf "newtype"

let pp_fixme ppf code = Fmt.pf ppf "/* HH_FIXME[%d] */@." code

Expand Down
21 changes: 12 additions & 9 deletions hphp/hack/src/typing/typing_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,14 @@ let env_with_constructor_droot_member env =
let decl_env = { env.decl_env with droot_member = Some member } in
{ env with decl_env }

let set_module env m = { env with genv = { env.genv with this_module = m } }

let get_module env = Option.map env.genv.this_module ~f:snd

let set_internal env b = { env with genv = { env.genv with this_internal = b } }

let get_internal env = env.genv.this_internal

let get_typedef env x =
let res =
Decl_provider.get_typedef
Expand All @@ -623,13 +631,16 @@ let is_typedef env x =
| _ -> false

let is_typedef_visible env ?(expand_visible_newtype = true) td =
let { Typing_defs.td_vis; td_pos; _ } = td in
let { Typing_defs.td_vis; td_pos; td_module; _ } = td in
match td_vis with
| Aast.Opaque ->
expand_visible_newtype
&& Relative_path.equal
(Pos.filename (Pos_or_decl.unsafe_to_raw_pos td_pos))
(get_file env)
| Aast.OpaqueModule ->
expand_visible_newtype
&& Option.equal String.equal (get_module env) (Option.map td_module ~f:snd)
| Aast.Transparent -> true

let get_class (env : env) (name : Decl_provider.type_key) : Cls.t option =
Expand Down Expand Up @@ -961,14 +972,6 @@ let set_fn_kind env fn_type =
let genv = { genv with fun_kind = fn_type } in
{ env with genv }

let set_module env m = { env with genv = { env.genv with this_module = m } }

let get_module env = Option.map env.genv.this_module ~f:snd

let set_internal env b = { env with genv = { env.genv with this_internal = b } }

let get_internal env = env.genv.this_internal

let set_support_dynamic_type env b =
{ env with genv = { env.genv with this_support_dynamic_type = b } }

Expand Down
4 changes: 3 additions & 1 deletion hphp/hack/src/typing/typing_type_wellformedness.ml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ let typedef tenv t =
* references.
*)
t.t_tparams
| Opaque -> []);
| Opaque
| OpaqueModule ->
[]);
tenv;
}
in
Expand Down
4 changes: 3 additions & 1 deletion hphp/hack/src/typing/write_symbol_info/symbol_add_fact.ml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ let typedef_defn ctx source_text elem decl_id progress =
let is_transparent =
match elem.t_vis with
| Transparent -> true
| Opaque -> false
| Opaque
| OpaqueModule ->
false
in
let tparams =
List.map
Expand Down

0 comments on commit cf3f1a9

Please sign in to comment.