Skip to content

Commit

Permalink
Add a cycle_detection parameter to the variance_map
Browse files Browse the repository at this point in the history
Summary:
We need `cycle_detection` so that we can parse annotations. For example, to get the base classes, we find them in the class summary and use `parse_annotation` to convert them to a type, so we can extract the type parameters and their variance.

I don't think we should expose `cycle_detection` to other files, which is why the mli file of attributeResolution is unmodified.

I initialize `cycle_detection` to the empty cycle delection when invoking the `variance_map` method.

Wondering if this is the right way of doing it, hence RFC.

Reviewed By: stroxler

Differential Revision: D63658565

fbshipit-source-id: ad2e769977a73f8185662a5f2e2b1505bef49e5c
  • Loading branch information
Zeina Migeed authored and facebook-github-bot committed Oct 1, 2024
1 parent 58c792c commit 1929040
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions source/analysis/attributeResolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2877,7 +2877,8 @@ class base ~queries:(Queries.{ controls; _ } as queries) =
| _ -> None

(* We will expose this interface as the variance map *)
method variance_map ~class_name ~parameters =
method variance_map ~cycle_detections ~class_name ~parameters =
let _cycle_detections = cycle_detections in
(* Creates a function from generic type parameters for a given class to post variance
inference *)
let infer_variance_for_one_param ~generic_type_param =
Expand Down Expand Up @@ -3026,7 +3027,7 @@ class base ~queries:(Queries.{ controls; _ } as queries) =
get_typed_dictionary = self#get_typed_dictionary ~cycle_detections;
get_named_tuple_fields;
metaclass;
variance_map = self#variance_map;
variance_map = self#variance_map ~cycle_detections;
}

(* Given an expression, produce a Type.t where literal type information - that is,
Expand Down Expand Up @@ -4197,10 +4198,8 @@ module ReadOnly = struct
~dependency:None
~class_metadata_environment:(class_metadata_environment read_only)
in

let implementation = new base ~queries in

implementation#variance_map
implementation#variance_map ~cycle_detections:empty_cycle_detections


let instantiate_attribute =
Expand Down

0 comments on commit 1929040

Please sign in to comment.