Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces
forc-migrate
, a Forc tool for migrating Sway projects to the next breaking change version of Sway.The tool addresses two points crucial for code updates caused by breaking changes:
Besides adding the
forc-migrate
tool, the PR:Diagnostic
to support migration diagnostics aside with errors and warnings.swayfmt
to support generating source code from arbitrary lexed trees. The change is a minimal one done only in the parts ofswayfmt
that are executed by migration steps written in this PR. Adaptingswayfmt
to fully support arbitrary lexed trees will be done in Refactorswayfmt
to generate code from arbitrary lexed trees, not necessarily backed by source code #6779.The migration for the
references
feature, migratingref mut
to&mut
, is added only temporarily, to demonstrate the development and usage of automatic migrations that alter the original source code. This migration will be removed before the next breaking change release, because thereferences
feature will not be a part of it.The intended usage of the tool is documented in detail in the "forc migrate" chapter of The Sway Book: Forc reference > Plugins > forc_migrate. (The generated documentation has issues that are caused by the documentation generation bug explained in #6792. These issues will be fixed in a separate PR that will fix it for all the plugins.)
We expect the
forc-migrate
to evolve based on the developer's feedback. Some of the possible extensions of the tool are:forc-migrate
also showed a clear need for better infrastructure for writing static analyzers and transforming Sway code. The approach used in the implementation of this PR should be seen as a pragmatic beginning, based on the reuse of what we currently have. Some future options are discussed in the comments of #6779.Demo
forc migrate show
Shows the breaking change features and related migration steps. This command can be run anywhere and does not require a Sway project.
forc migrate check
Performs a dry-run of the migration on a concrete Sway project. It outputs all the occurrences in code that need to be reviewed or changed, as well as the migration time effort:
forc migrate run
Runs the migration steps and guides developers through the migration process.
Checklist
Breaking*
orNew Feature
labels where relevant.