-
Notifications
You must be signed in to change notification settings - Fork 471
Automatic migrations #7829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic migrations #7829
Changes from all commits
22ab286
a151b5e
f4016a9
86e2d21
c9bd01c
0d6e631
35eeb19
11407a1
7be3461
4ca31f7
b9c14bf
8b46d23
6f23477
5a35bb9
1955bf8
865e9e5
7df7cec
4511313
1c9497c
3b89ae1
6d9c817
74405a7
c811257
3d1f924
c86e3b3
4cf2a73
e076439
22157ff
3b4a909
e7c6e1f
210f276
c22c54b
c474077
ef53158
7deb03a
33e1b29
b7d8f1f
2a8f562
fb7bc7f
5b7d723
75ec80d
f5d2d8c
743d636
8cc3c0e
a6de19d
a3acab0
42242a4
0f54714
af7459e
aaa17dd
9203c68
7674b50
75554f3
3f74930
8ae6340
b69aa6c
e8331b8
8636091
94b9a75
5b3c6d1
c160a71
b71abc1
bd23e6f
2b81e1d
8ea5696
062cc1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,10 +79,64 @@ let rec deprecated_of_attrs = function | |
Some (string_of_opt_payload p) | ||
| _ :: tl -> deprecated_of_attrs tl | ||
|
||
let check_deprecated loc attrs s = | ||
match deprecated_of_attrs attrs with | ||
let rec deprecated_of_attrs_with_migrate = function | ||
| [] -> None | ||
| ( {txt = "deprecated"; _}, | ||
PStr [{pstr_desc = Pstr_eval ({pexp_desc = Pexp_record (fields, _)}, _)}] | ||
) | ||
:: _ -> ( | ||
let reason = | ||
fields | ||
|> List.find_map (fun field -> | ||
match field with | ||
| { | ||
lid = {txt = Lident "reason"}; | ||
x = {pexp_desc = Pexp_constant (Pconst_string (reason, _))}; | ||
} -> | ||
Some reason | ||
| _ -> None) | ||
in | ||
let migration_template = | ||
fields | ||
|> List.find_map (fun field -> | ||
match field with | ||
| {lid = {txt = Lident "migrate"}; x = migration_template} -> | ||
Some migration_template | ||
| _ -> None) | ||
in | ||
let migration_in_pipe_chain_template = | ||
fields | ||
|> List.find_map (fun field -> | ||
match field with | ||
| { | ||
lid = {txt = Lident "migrateInPipeChain"}; | ||
x = migration_in_pipe_chain_template; | ||
} -> | ||
Some migration_in_pipe_chain_template | ||
| _ -> None) | ||
in | ||
|
||
(* TODO: Validate and error if expected shape mismatches *) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll leave this in for now, and do proper errors and validations if/when we decide this should be a first class feature in the language itself. For now it's just an internal migration tool for the library (although anyone can use it of course, at their own risk). |
||
match reason with | ||
| Some reason -> | ||
Some (reason, migration_template, migration_in_pipe_chain_template) | ||
| None -> None) | ||
| ({txt = "ocaml.deprecated" | "deprecated"; _}, p) :: _ -> | ||
Some (string_of_opt_payload p, None, None) | ||
| _ :: tl -> deprecated_of_attrs_with_migrate tl | ||
|
||
let check_deprecated ?deprecated_context loc attrs s = | ||
match deprecated_of_attrs_with_migrate attrs with | ||
| None -> () | ||
| Some txt -> Location.deprecated loc (cat s txt) | ||
| Some (txt, migration_template, migration_in_pipe_chain_template) -> | ||
!Cmt_utils.record_deprecated_used | ||
?deprecated_context ?migration_template ?migration_in_pipe_chain_template | ||
loc txt; | ||
Location.deprecated | ||
~can_be_automigrated: | ||
(Option.is_some migration_template | ||
|| Option.is_some migration_in_pipe_chain_template) | ||
loc (cat s txt) | ||
|
||
let check_deprecated_inclusion ~def ~use loc attrs1 attrs2 s = | ||
match (deprecated_of_attrs attrs1, deprecated_of_attrs attrs2) with | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ type cmt_infos = { | |
cmt_imports : (string * Digest.t option) list; | ||
cmt_interface_digest : Digest.t option; | ||
cmt_use_summaries : bool; | ||
cmt_extra_info: Cmt_utils.cmt_extra_info; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK yes they are new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually I think I want to move this to a separate sidecar file, probably the one I've added in the Actions PR. But for now (and maybe always) it can live in here, since it has minimal impact. |
||
} | ||
|
||
type error = | ||
|
@@ -154,15 +155,30 @@ let read_cmi filename = | |
|
||
let saved_types = ref [] | ||
let value_deps = ref [] | ||
let deprecated_used = ref [] | ||
|
||
let clear () = | ||
saved_types := []; | ||
value_deps := [] | ||
value_deps := []; | ||
deprecated_used := [] | ||
|
||
let add_saved_type b = saved_types := b :: !saved_types | ||
let get_saved_types () = !saved_types | ||
let set_saved_types l = saved_types := l | ||
|
||
let record_deprecated_used ?deprecated_context ?migration_template ?migration_in_pipe_chain_template source_loc deprecated_text = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these going to be reversed at some point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reversed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's constructed backwards There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't follow 😄 |
||
deprecated_used := | ||
{ | ||
Cmt_utils.source_loc; | ||
deprecated_text; | ||
migration_template; | ||
migration_in_pipe_chain_template; | ||
context = deprecated_context; | ||
} | ||
:: !deprecated_used | ||
|
||
let _ = Cmt_utils.record_deprecated_used := record_deprecated_used | ||
|
||
let record_value_dependency vd1 vd2 = | ||
if vd1.Types.val_loc <> vd2.Types.val_loc then | ||
value_deps := (vd1, vd2) :: !value_deps | ||
|
@@ -197,8 +213,9 @@ let save_cmt filename modname binary_annots sourcefile initial_env cmi = | |
cmt_imports = List.sort compare (Env.imports ()); | ||
cmt_interface_digest = this_crc; | ||
cmt_use_summaries = need_to_clear_env; | ||
cmt_extra_info = {deprecated_used = !deprecated_used}; | ||
} in | ||
output_cmt oc cmt) | ||
end; | ||
clear () | ||
#endif | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
type deprecated_used_context = FunctionCall | Reference | ||
|
||
type deprecated_used = { | ||
source_loc: Location.t; | ||
deprecated_text: string; | ||
migration_template: Parsetree.expression option; | ||
migration_in_pipe_chain_template: Parsetree.expression option; | ||
context: deprecated_used_context option; | ||
} | ||
|
||
type cmt_extra_info = {deprecated_used: deprecated_used list} | ||
|
||
let record_deprecated_used : | ||
(?deprecated_context:deprecated_used_context -> | ||
?migration_template:Parsetree.expression -> | ||
?migration_in_pipe_chain_template:Parsetree.expression -> | ||
Location.t -> | ||
string -> | ||
unit) | ||
ref = | ||
ref | ||
(fun | ||
?deprecated_context | ||
?migration_template | ||
?migration_in_pipe_chain_template | ||
_ | ||
_ | ||
-> | ||
ignore deprecated_context; | ||
ignore migration_template; | ||
ignore migration_in_pipe_chain_template) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are infos new here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, since we don't need to process the CMT as we do in analysis, this just loads the CMT and accesses the new prop.