-
Notifications
You must be signed in to change notification settings - Fork 469
[WIP] Migrate command #7693
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
base: master
Are you sure you want to change the base?
[WIP] Migrate command #7693
Conversation
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
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.
Pull Request Overview
This PR implements a new migrate command for ReScript that tracks deprecated usage in compiled TypeScript (.cmt) files and applies user-defined migration templates to automatically update code. The implementation includes comprehensive stdlib migrations for transitioning from Js.Array2.*
functions to modern Array.*
equivalents.
- Adds a complete migration framework with AST transformation capabilities for function calls, pipes, and references
- Integrates deprecated usage tracking into the compiler's type checking and CMT generation pipeline
- Provides extensive test coverage with stdlib array function migrations and validation of both compilable and non-compilable migration scenarios
Reviewed Changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
tools/src/tools.ml | Core migration command implementation with AST mapper and template application logic |
tests/tools_tests/test.sh | Test framework integration for migration command testing |
tests/tools_tests/src/migrate/* | Test files demonstrating various migration scenarios and expected outputs |
runtime/Js_array2.res | Adds @deprecated annotations with migration templates for all Js.Array2 functions |
compiler/ml/* | Compiler integration for tracking deprecated usage in CMT files |
runtime/Stdlib_Array.resi | Documentation additions for Array copyWithin functions |
Comments suppressed due to low confidence (3)
tools/src/tools.ml:1316
- [nitpick] The variable name
labelled_args_that_will_be_mapped
is verbose and could be shortened tomapped_labelled_args
orlabelled_to_map
for better readability.
let labelled_args_that_will_be_mapped = ref [] in
tools/src/tools.ml:1317
- [nitpick] The variable name
unlabelled_positions_that_will_be_mapped
is excessively long and could be shortened tomapped_positions
orpositions_to_map
.
let unlabelled_positions_that_will_be_mapped = ref [] in
tests/tools_tests/src/migrate/StdlibMigration_Array.res:150
- The test demonstrates parameter reordering in reduce functions but lacks verification that the migration correctly handles the parameter position changes from
(fn, initial)
to(initial, fn)
.
let reduce1 = [1, 2, 3]->Js.Array2.reduce((acc, x) => acc + x, 0)
expr = | ||
(fun mapper exp -> | ||
match exp with | ||
| {pexp_desc = Pexp_ident {loc}} |
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.
The pattern matching for pexp_desc = Pexp_ident {loc}
could be more specific by including the identifier in the pattern to make the intent clearer and avoid potential issues if the location check fails.
| {pexp_desc = Pexp_ident {loc}} | |
| {pexp_desc = Pexp_ident {loc; txt}} |
Copilot uses AI. Check for mistakes.
}; | ||
} | ||
| _ -> | ||
(* TODO: More elaborate warnings etc *) |
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.
The TODO comment lacks specificity about what kind of warnings should be implemented. Consider adding more detail about the expected behavior when migration templates are invalid.
(* TODO: More elaborate warnings etc *) | |
(* TODO: Implement detailed warnings for invalid migration templates. | |
Consider logging a warning with the location and details of the invalid template. | |
Decide whether to fallback to a default behavior or propagate the error. *) |
Copilot uses AI. Check for mistakes.
(* TODO: More elaborate warnings etc *) | ||
(* Invalid config. *) |
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.
Duplicate TODO comment - consider consolidating error handling logic into a shared function rather than repeating the same TODO in multiple places.
(* TODO: More elaborate warnings etc *) | |
(* Invalid config. *) | |
handle_warning "Invalid configuration encountered during transformation."; |
Copilot uses AI. Check for mistakes.
(* TODO: More elaborate warnings etc *) | ||
(* Invalid config. *) |
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.
Third occurrence of the same TODO comment. This indicates a need for a centralized error handling approach for invalid migration configurations.
(* TODO: More elaborate warnings etc *) | |
(* Invalid config. *) | |
handle_invalid_migration_config ~context:"Invalid migration template in deprecated function call"; |
Copilot uses AI. Check for mistakes.
(* TODO: Validate and error if expected shape mismatches *) | ||
match reason with | ||
| Some reason -> Some (reason, migration_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.
Missing validation of migration template structure could lead to runtime errors or incorrect migrations. Input validation should be implemented to ensure the migration template has the expected format.
(* TODO: Validate and error if expected shape mismatches *) | |
match reason with | |
| Some reason -> Some (reason, migration_template) | |
let validate_migration_template template = | |
match template.pexp_desc with | |
| Pexp_constant (Pconst_string (_, _)) -> Some template | |
| _ -> None | |
in | |
let validated_template = Option.bind migration_template validate_migration_template in | |
match reason with | |
| Some reason -> Some (reason, validated_template) |
Copilot uses AI. Check for mistakes.
Co-authored-by: Médi-Rémi Hashim <4295266+mediremi@users.noreply.github.com>
cmt
Instructions for adding more migrations to the stdlib
@deprecated
with amigration
prop to anything in the stdlibmake lib
so it's built into the stdlib filesIn
tests/tools_tests
:yarn rescript legacy clean
to ensure you get the new changesStdlibMigration_ModuleName.res
fileStdlibMigrationNoCompile_ModuleName.res
file instead. This will not get compiled for testing (but it will get migrated)make
(still inside oftests/tools_tests
) to run run the migrations and builds. This should get your test outputRepeat the process above until done.
TODO
@deprecated
attributesomeThing(~someArg=[Some(%insert.unlabelledArg(1))])
works0
(using the_
mechanism)