Skip to content

Commit

Permalink
Rename Alias.t to RawAlias.t to signify that aliases are an imple…
Browse files Browse the repository at this point in the history
…mentation detail

Summary: Please review the stack summary for context. Here we are just improving the alias naming convension to show that the alias varient is an implementation detail

Reviewed By: stroxler

Differential Revision: D59769593

fbshipit-source-id: 57e589ff652cb302f0b301f36703fb6724854f21
  • Loading branch information
migeed-z authored and facebook-github-bot committed Jul 16, 2024
1 parent 60705b1 commit 7229b70
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 90 deletions.
8 changes: 4 additions & 4 deletions source/analysis/attributeResolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ module Queries = struct
parse_annotation_without_validating_type_parameters:
?modify_aliases:
(?replace_unbound_parameters_with_any:bool ->
TypeAliasEnvironment.Alias.t ->
TypeAliasEnvironment.Alias.t) ->
TypeAliasEnvironment.RawAlias.t ->
TypeAliasEnvironment.RawAlias.t) ->
?allow_untracked:bool ->
Ast.Expression.t ->
Type.t;
Expand Down Expand Up @@ -2471,13 +2471,13 @@ class base ~queries:(Queries.{ controls; _ } as queries) =
expression =
let { Queries.parse_annotation_without_validating_type_parameters; _ } = queries in
let modify_aliases ?replace_unbound_parameters_with_any = function
| TypeAliasEnvironment.Alias.TypeAlias alias ->
| TypeAliasEnvironment.RawAlias.TypeAlias alias ->
self#check_invalid_type_parameters
?replace_unbound_parameters_with_any
alias
~assumptions
|> snd
|> fun alias -> TypeAliasEnvironment.Alias.TypeAlias alias
|> fun alias -> TypeAliasEnvironment.RawAlias.TypeAlias alias
| result -> result
in
let allow_untracked =
Expand Down
10 changes: 5 additions & 5 deletions source/analysis/classHierarchyEnvironment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ module IncomingDataComputation = struct
get_type_alias:
?replace_unbound_parameters_with_any:bool ->
Type.Primitive.t ->
TypeAliasEnvironment.Alias.t option;
TypeAliasEnvironment.RawAlias.t option;
parse_annotation_without_validating_type_parameters:
?modify_aliases:
(?replace_unbound_parameters_with_any:bool ->
TypeAliasEnvironment.Alias.t ->
TypeAliasEnvironment.Alias.t) ->
TypeAliasEnvironment.RawAlias.t ->
TypeAliasEnvironment.RawAlias.t) ->
?allow_untracked:bool ->
Ast.Expression.t ->
Type.t;
Expand Down Expand Up @@ -230,7 +230,7 @@ module IncomingDataComputation = struct
in
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match get_type_alias name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
let has_placeholder_stub_parent =
Expand Down Expand Up @@ -319,7 +319,7 @@ module Edges = Environment.EnvironmentTable.WithCache (struct

let variable_aliases name =
match queries.get_type_alias ?replace_unbound_parameters_with_any:(Some true) name with
| Some (TypeAliasEnvironment.Alias.VariableAlias variable) -> Some variable
| Some (TypeAliasEnvironment.RawAlias.VariableAlias variable) -> Some variable
| _ -> None
in

Expand Down
2 changes: 1 addition & 1 deletion source/analysis/globalResolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ let immediate_parents resolution = ClassHierarchy.immediate_parents (class_hiera
let base_is_from_placeholder_stub variable_aliases resolution =
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match (get_type_alias resolution) name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
AnnotatedBases.base_is_from_placeholder_stub
Expand Down
6 changes: 3 additions & 3 deletions source/analysis/globalResolution.mli
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ val get_type_alias
: t ->
?replace_unbound_parameters_with_any:bool ->
Type.Primitive.t ->
TypeAliasEnvironment.Alias.t option
TypeAliasEnvironment.RawAlias.t option

val parse_annotation_without_validating_type_parameters
: t ->
?modify_aliases:
(?replace_unbound_parameters_with_any:bool ->
TypeAliasEnvironment.Alias.t ->
TypeAliasEnvironment.Alias.t) ->
TypeAliasEnvironment.RawAlias.t ->
TypeAliasEnvironment.RawAlias.t) ->
?allow_untracked:bool ->
Expression.t ->
Type.t
Expand Down
2 changes: 1 addition & 1 deletion source/analysis/resolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ let get_type_alias resolution =

let variables resolution name =
match get_type_alias ?replace_unbound_parameters_with_any:(Some true) resolution name with
| Some (TypeAliasEnvironment.Alias.VariableAlias variable) -> Some variable
| Some (TypeAliasEnvironment.RawAlias.VariableAlias variable) -> Some variable
| _ -> None


Expand Down
8 changes: 4 additions & 4 deletions source/analysis/test/constraintsSetTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let ( ! ) concretes = List.map concretes ~f:(fun single -> Type.Parameter.Single

let variable_aliases aliases name =
match aliases ?replace_unbound_parameters_with_any:(Some true) name with
| Some (TypeAliasEnvironment.Alias.VariableAlias variable) -> Some variable
| Some (TypeAliasEnvironment.RawAlias.VariableAlias variable) -> Some variable
| _ -> None


Expand Down Expand Up @@ -199,13 +199,13 @@ let make_assert_functions context =
|> Type.Primitive.Set.of_list
in
if Set.mem s a then
Some (TypeAliasEnvironment.Alias.TypeAlias (Type.Primitive ("test." ^ a)))
Some (TypeAliasEnvironment.RawAlias.TypeAlias (Type.Primitive ("test." ^ a)))
else
GlobalResolution.get_type_alias resolution a
in
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match aliases name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in

Expand Down Expand Up @@ -301,7 +301,7 @@ let make_assert_functions context =
in
let global_resolution = GlobalResolution.create environment in
match GlobalResolution.get_type_alias global_resolution primitive with
| Some (TypeAliasEnvironment.Alias.VariableAlias variable_declaration) -> (
| Some (TypeAliasEnvironment.RawAlias.VariableAlias variable_declaration) -> (
match
Type.Variable.of_declaration
~create_type:(GlobalResolution.parse_annotation global_resolution)
Expand Down
4 changes: 2 additions & 2 deletions source/analysis/test/environmentTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ let test_register_aliases context =
let global_resolution = GlobalResolution.create environment in
let assert_alias (alias, target) =
match GlobalResolution.get_type_alias global_resolution alias with
| Some alias -> assert_equal ~printer:TypeAliasEnvironment.Alias.show target alias
| Some alias -> assert_equal ~printer:TypeAliasEnvironment.RawAlias.show target alias
| None -> failwith "Alias is missing"
in
List.iter aliases ~f:assert_alias
Expand All @@ -389,7 +389,7 @@ let test_register_aliases context =
|}]
[
( "test.Tparams",
TypeAliasEnvironment.Alias.VariableAlias
TypeAliasEnvironment.RawAlias.VariableAlias
(Type.Variable.Declaration.DParamSpec { name = "test.Tparams" }) );
];
()
Expand Down
28 changes: 14 additions & 14 deletions source/analysis/test/typeAliasEnvironmentTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ let test_simple_registration =
|> ErrorsEnvironment.Testing.ReadOnly.alias_environment
in
let expected =
expected >>| fun expected -> TypeAliasEnvironment.Alias.TypeAlias (Type.Primitive expected)
expected >>| fun expected -> TypeAliasEnvironment.RawAlias.TypeAlias (Type.Primitive expected)
in
let printer v = v >>| TypeAliasEnvironment.Alias.show |> Option.value ~default:"none" in
let printer v = v >>| TypeAliasEnvironment.RawAlias.show |> Option.value ~default:"none" in
assert_equal ~printer expected (TypeAliasEnvironment.ReadOnly.get_type_alias read_only name)
in
test_list
Expand Down Expand Up @@ -84,7 +84,7 @@ let test_harder_registrations =
in
let printer alias =
alias
>>| TypeAliasEnvironment.Alias.sexp_of_t
>>| TypeAliasEnvironment.RawAlias.sexp_of_t
>>| Sexp.to_string_hum
|> Option.value ~default:"none"
in
Expand All @@ -99,12 +99,12 @@ let test_harder_registrations =
|> Type.create ~variables:variable_aliases ~aliases:Type.resolved_empty_aliases
in
let expected_alias =
expected >>| parser >>| fun alias -> TypeAliasEnvironment.Alias.TypeAlias alias
expected >>| parser >>| fun alias -> TypeAliasEnvironment.RawAlias.TypeAlias alias
in
assert_registers ~expected_alias source name
in
let unparsed_assert_registers source name expected =
let expected_alias = expected >>| fun alias -> TypeAliasEnvironment.Alias.TypeAlias alias in
let expected_alias = expected >>| fun alias -> TypeAliasEnvironment.RawAlias.TypeAlias alias in
assert_registers ~expected_alias source name
in
test_list
Expand Down Expand Up @@ -169,7 +169,7 @@ let test_harder_registrations =
Y: typing_extensions.TypeAlias = "X"
|}
"test.Y"
~expected_alias:(Some (TypeAliasEnvironment.Alias.TypeAlias Type.integer));
~expected_alias:(Some (TypeAliasEnvironment.RawAlias.TypeAlias Type.integer));
(* Recursive alias. *)
labeled_test_case __FUNCTION__ __LINE__
@@ assert_registers
Expand All @@ -181,7 +181,7 @@ let test_harder_registrations =
"test.Tree"
~expected_alias:
(Some
(TypeAliasEnvironment.Alias.TypeAlias
(TypeAliasEnvironment.RawAlias.TypeAlias
(Type.RecursiveType.create
~name:"test.Tree"
~body:
Expand Down Expand Up @@ -238,7 +238,7 @@ let test_harder_registrations =
"test.Y"
~expected_alias:
(Some
(TypeAliasEnvironment.Alias.TypeAlias
(TypeAliasEnvironment.RawAlias.TypeAlias
(Type.list
(Type.RecursiveType.create
~name:"test.X"
Expand All @@ -257,7 +257,7 @@ let test_harder_registrations =
"test.Y"
~expected_alias:
(Some
(TypeAliasEnvironment.Alias.TypeAlias
(TypeAliasEnvironment.RawAlias.TypeAlias
(Type.union
[
Type.integer;
Expand Down Expand Up @@ -287,7 +287,7 @@ let test_harder_registrations =
"test.Z"
~expected_alias:
(Some
(TypeAliasEnvironment.Alias.TypeAlias
(TypeAliasEnvironment.RawAlias.TypeAlias
(Type.list
(Type.union
[
Expand Down Expand Up @@ -320,7 +320,7 @@ let test_harder_registrations =
"test.FloatTensor"
~expected_alias:
(Some
(TypeAliasEnvironment.Alias.TypeAlias
(TypeAliasEnvironment.RawAlias.TypeAlias
(Type.parametric
"test.Tensor"
[
Expand All @@ -346,7 +346,7 @@ let test_harder_registrations =
"test.F"
~expected_alias:
(Some
(TypeAliasEnvironment.Alias.TypeAlias
(TypeAliasEnvironment.RawAlias.TypeAlias
(Type.Callable.create ~annotation:Type.integer ())));
(* Allow the union syntax in type aliases. *)
labeled_test_case __FUNCTION__ __LINE__
Expand Down Expand Up @@ -385,15 +385,15 @@ let test_updates context =
let execute_action (alias_name, dependency, expectation) =
let printer v =
v
>>| TypeAliasEnvironment.Alias.sexp_of_t
>>| TypeAliasEnvironment.RawAlias.sexp_of_t
>>| Sexp.to_string_hum
|> Option.value ~default:"none"
in
let expectation =
expectation
>>| parse_single_expression
>>| Type.create ~variables:variable_aliases ~aliases:Type.resolved_empty_aliases
>>| fun alias -> TypeAliasEnvironment.Alias.TypeAlias alias
>>| fun alias -> TypeAliasEnvironment.RawAlias.TypeAlias alias
in
TypeAliasEnvironment.ReadOnly.get_type_alias read_only ~dependency alias_name
|> assert_equal ~printer expectation
Expand Down
10 changes: 5 additions & 5 deletions source/analysis/test/typeOrderTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ let test_less_or_equal =
let aliases = create_type_alias_table aliases in
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match aliases name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
parse_callable ~aliases:resolved_aliases
Expand Down Expand Up @@ -683,7 +683,7 @@ let test_less_or_equal =
let aliases = create_type_alias_table aliases in
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match aliases name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
less_or_equal
Expand All @@ -702,7 +702,7 @@ let test_less_or_equal =
let aliases = create_type_alias_table aliases in
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match aliases name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
parse_callable ~aliases:resolved_aliases
Expand Down Expand Up @@ -1983,7 +1983,7 @@ let test_join =
let aliases = create_type_alias_table aliases in
let resolved_aliases ?replace_unbound_parameters_with_any:_ name =
match aliases name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
parse_callable ~aliases:resolved_aliases
Expand Down Expand Up @@ -2027,7 +2027,7 @@ let test_join =
let variance_aliases = create_type_alias_table variance_aliases in
let variance_aliases ?replace_unbound_parameters_with_any:_ name =
match variance_aliases name with
| Some (TypeAliasEnvironment.Alias.TypeAlias t) -> Some t
| Some (TypeAliasEnvironment.RawAlias.TypeAlias t) -> Some t
| _ -> None
in
assert_join
Expand Down
Loading

0 comments on commit 7229b70

Please sign in to comment.