forked from move-language/move-sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move-2024] Add support for migrating keywords (#16598)
## Description This sets up a (mildly hacky) solution to migrate newly-reserved keywords when they appear in existing code by maing them restricted identifiers (e.g., "type" -> "`type`"). ## Test Plan New test case for migration, plus attempting to run it against the sui framework locally which does similar things. --- If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
Showing
24 changed files
with
509 additions
and
47 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
crates/move-cli/tests/build_tests/migration_names/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
# TOML FILE | ||
|
||
[package] | ||
name = "A" | ||
|
||
# this is a comment | ||
[addresses] | ||
A = "0x42" | ||
std = "0x1" | ||
|
||
[dependencies] | ||
MoveStdlib = { local = "../../../../move-stdlib" } |
14 changes: 14 additions & 0 deletions
14
crates/move-cli/tests/build_tests/migration_names/Move.toml.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# TOML FILE | ||
|
||
[package] | ||
name = "A" | ||
edition = "2024.beta" | ||
|
||
# this is a comment | ||
[addresses] | ||
A = "0x42" | ||
std = "0x1" | ||
|
||
[dependencies] | ||
MoveStdlib = { local = "../../../../move-stdlib" } |
129 changes: 129 additions & 0 deletions
129
crates/move-cli/tests/build_tests/migration_names/args.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
Command `migrate`: | ||
Package toml does not specify an edition. As of 2024, Move requires all packages to define a language edition. | ||
|
||
Please select one of the following editions: | ||
|
||
1) 2024.beta | ||
2) legacy | ||
|
||
Selection (default=1): Recorded edition in 'Move.toml' | ||
|
||
Would you like the Move compiler to migrate your code to Move 2024? (Y/n) | ||
Generated changes . . . | ||
INCLUDING DEPENDENCY MoveStdlib | ||
BUILDING A | ||
|
||
The following changes will be made. | ||
============================================================ | ||
|
||
--- sources/mod0.move | ||
+++ sources/mod0.move | ||
@@ -3,1 +3,1 @@ | ||
- struct S { n: u64 } | ||
+ public struct S { n: u64 } | ||
@@ -5,1 +5,1 @@ | ||
- fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
+ fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
@@ -6,1 +6,1 @@ | ||
- if (type == match) { | ||
+ if (`type` == `match`) { | ||
@@ -7,1 +7,1 @@ | ||
- type | ||
+ `type` | ||
@@ -8,1 +8,1 @@ | ||
- } else if (mut) { | ||
+ } else if (`mut`) { | ||
@@ -9,1 +9,1 @@ | ||
- match | ||
+ `match` | ||
@@ -11,1 +11,1 @@ | ||
- enum.n | ||
+ `enum`.n | ||
--- sources/mod_intermodule_errors.move | ||
+++ sources/mod_intermodule_errors.move | ||
@@ -3,1 +3,1 @@ | ||
- struct S { n: u64 } | ||
+ public struct S { n: u64 } | ||
@@ -5,1 +5,1 @@ | ||
- public fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
+ public fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
@@ -6,1 +6,1 @@ | ||
- if (type == match) { | ||
+ if (`type` == `match`) { | ||
@@ -7,1 +7,1 @@ | ||
- type | ||
+ `type` | ||
@@ -8,1 +8,1 @@ | ||
- } else if (mut) { | ||
+ } else if (`mut`) { | ||
@@ -9,1 +9,1 @@ | ||
- match | ||
+ `match` | ||
@@ -11,1 +11,1 @@ | ||
- enum.n | ||
+ `enum`.n | ||
--- sources/mod_let.move | ||
+++ sources/mod_let.move | ||
@@ -3,1 +3,1 @@ | ||
- struct S has drop { n: u64 } | ||
+ public struct S has drop { n: u64 } | ||
@@ -5,1 +5,1 @@ | ||
- fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
+ fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
@@ -6,1 +6,1 @@ | ||
- let type = 0; | ||
+ let `type` = 0; | ||
@@ -7,1 +7,1 @@ | ||
- let enum = 1; | ||
+ let `enum` = 1; | ||
@@ -8,1 +8,1 @@ | ||
- let mut = 2; | ||
+ let `mut` = 2; | ||
@@ -9,1 +9,1 @@ | ||
- let match = 3; | ||
+ let `match` = 3; | ||
@@ -10,1 +10,1 @@ | ||
- type + enum + mut + match | ||
+ `type` + `enum` + `mut` + `match` | ||
--- sources/mod_let_errors.move | ||
+++ sources/mod_let_errors.move | ||
@@ -3,1 +3,1 @@ | ||
- struct S { n: u64 } | ||
+ public struct S { n: u64 } | ||
@@ -5,1 +5,1 @@ | ||
- fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
+ fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
@@ -6,1 +6,1 @@ | ||
- let type = 0; | ||
+ let `type` = 0; | ||
@@ -7,1 +7,1 @@ | ||
- let enum = 1; | ||
+ let `enum` = 1; | ||
@@ -8,1 +8,1 @@ | ||
- let mut = 2; | ||
+ let `mut` = 2; | ||
@@ -9,1 +9,1 @@ | ||
- let match = 3; | ||
+ let `match` = 3; | ||
@@ -10,1 +10,1 @@ | ||
- type + enum + mut + match | ||
+ `type` + `enum` + `mut` + `match` | ||
|
||
|
||
============================================================ | ||
Apply changes? (Y/n) | ||
Updating "sources/mod0.move" . . . | ||
Updating "sources/mod_intermodule_errors.move" . . . | ||
Updating "sources/mod_let.move" . . . | ||
Updating "sources/mod_let_errors.move" . . . | ||
|
||
Changes complete | ||
Wrote patchfile out to: ./migration.patch | ||
|
||
External Command `diff -r -s sources migration_sources`: | ||
Files sources/mod0.move and migration_sources/mod0.move are identical | ||
Files sources/mod_intermodule_errors.move and migration_sources/mod_intermodule_errors.move are identical | ||
Files sources/mod_let.move and migration_sources/mod_let.move are identical | ||
Files sources/mod_let_errors.move and migration_sources/mod_let_errors.move are identical | ||
External Command `diff -s Move.toml Move.toml.expected`: | ||
Files Move.toml and Move.toml.expected are identical |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
migrate | ||
> diff -r -s sources migration_sources | ||
> diff -s Move.toml Move.toml.expected |
15 changes: 15 additions & 0 deletions
15
crates/move-cli/tests/build_tests/migration_names/migration_sources/mod0.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module A::mod0 { | ||
|
||
public struct S { n: u64 } | ||
|
||
fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
if (`type` == `match`) { | ||
`type` | ||
} else if (`mut`) { | ||
`match` | ||
} else { | ||
`enum`.n | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../move-cli/tests/build_tests/migration_names/migration_sources/mod_intermodule_errors.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module A::mod1 { | ||
|
||
public struct S { n: u64 } | ||
|
||
public fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
if (`type` == `match`) { | ||
`type` | ||
} else if (`mut`) { | ||
`match` | ||
} else { | ||
`enum`.n | ||
} | ||
} | ||
|
||
} | ||
|
||
module A::mod2 { | ||
|
||
use A::mod1::t0; | ||
use A::mod1::S; | ||
|
||
public fun t1(t: u64, e: S, m: bool, m2: u64): u64 { t0(t, e, m, m2) } | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
crates/move-cli/tests/build_tests/migration_names/migration_sources/mod_let.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module A::mod_let { | ||
|
||
public struct S has drop { n: u64 } | ||
|
||
fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
let `type` = 0; | ||
let `enum` = 1; | ||
let `mut` = 2; | ||
let `match` = 3; | ||
`type` + `enum` + `mut` + `match` | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
crates/move-cli/tests/build_tests/migration_names/migration_sources/mod_let_errors.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module A::mod_let_errors { | ||
|
||
public struct S { n: u64 } | ||
|
||
fun t0(`type`: u64, `enum`: S, `mut`: bool, `match`: u64): u64 { | ||
let `type` = 0; | ||
let `enum` = 1; | ||
let `mut` = 2; | ||
let `match` = 3; | ||
`type` + `enum` + `mut` + `match` | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
crates/move-cli/tests/build_tests/migration_names/sources/mod0.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module A::mod0 { | ||
|
||
struct S { n: u64 } | ||
|
||
fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
if (type == match) { | ||
type | ||
} else if (mut) { | ||
match | ||
} else { | ||
enum.n | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
crates/move-cli/tests/build_tests/migration_names/sources/mod_intermodule_errors.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module A::mod1 { | ||
|
||
struct S { n: u64 } | ||
|
||
public fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
if (type == match) { | ||
type | ||
} else if (mut) { | ||
match | ||
} else { | ||
enum.n | ||
} | ||
} | ||
|
||
} | ||
|
||
module A::mod2 { | ||
|
||
use A::mod1::t0; | ||
use A::mod1::S; | ||
|
||
public fun t1(t: u64, e: S, m: bool, m2: u64): u64 { t0(t, e, m, m2) } | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
crates/move-cli/tests/build_tests/migration_names/sources/mod_let.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module A::mod_let { | ||
|
||
struct S has drop { n: u64 } | ||
|
||
fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
let type = 0; | ||
let enum = 1; | ||
let mut = 2; | ||
let match = 3; | ||
type + enum + mut + match | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
crates/move-cli/tests/build_tests/migration_names/sources/mod_let_errors.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module A::mod_let_errors { | ||
|
||
struct S { n: u64 } | ||
|
||
fun t0(type: u64, enum: S, mut: bool, match: u64): u64 { | ||
let type = 0; | ||
let enum = 1; | ||
let mut = 2; | ||
let match = 3; | ||
type + enum + mut + match | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
crates/move-cli/tests/build_tests/migration_names_mut_allowed/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
# TOML FILE | ||
|
||
[package] | ||
name = "A" | ||
|
||
# this is a comment | ||
[addresses] | ||
A = "0x42" | ||
std = "0x1" | ||
|
||
[dependencies] | ||
MoveStdlib = { local = "../../../../move-stdlib" } |
14 changes: 14 additions & 0 deletions
14
crates/move-cli/tests/build_tests/migration_names_mut_allowed/Move.toml.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# TOML FILE | ||
|
||
[package] | ||
name = "A" | ||
edition = "2024.beta" | ||
|
||
# this is a comment | ||
[addresses] | ||
A = "0x42" | ||
std = "0x1" | ||
|
||
[dependencies] | ||
MoveStdlib = { local = "../../../../move-stdlib" } |
42 changes: 42 additions & 0 deletions
42
crates/move-cli/tests/build_tests/migration_names_mut_allowed/args.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Command `migrate`: | ||
Package toml does not specify an edition. As of 2024, Move requires all packages to define a language edition. | ||
|
||
Please select one of the following editions: | ||
|
||
1) 2024.beta | ||
2) legacy | ||
|
||
Selection (default=1): Recorded edition in 'Move.toml' | ||
|
||
Would you like the Move compiler to migrate your code to Move 2024? (Y/n) | ||
Generated changes . . . | ||
INCLUDING DEPENDENCY MoveStdlib | ||
BUILDING A | ||
|
||
The following changes will be made. | ||
============================================================ | ||
|
||
--- sources/mut_name.move | ||
+++ sources/mut_name.move | ||
@@ -3,1 +3,1 @@ | ||
- fun dumpster_fire(mut x: u64, mut: u64): u64 { | ||
+ fun dumpster_fire(mut x: u64, `mut`: u64): u64 { | ||
@@ -5,1 +5,1 @@ | ||
- let mut: u64 = mut + 2; | ||
+ let `mut`: u64 = `mut` + 2; | ||
@@ -6,1 +6,1 @@ | ||
- mut + y + x | ||
+ `mut` + y + x | ||
|
||
|
||
============================================================ | ||
Apply changes? (Y/n) | ||
Updating "sources/mut_name.move" . . . | ||
|
||
Changes complete | ||
Wrote patchfile out to: ./migration.patch | ||
|
||
External Command `diff -r -s sources migration_sources`: | ||
Files sources/mut_name.move and migration_sources/mut_name.move are identical | ||
External Command `diff -s Move.toml Move.toml.expected`: | ||
Files Move.toml and Move.toml.expected are identical |
3 changes: 3 additions & 0 deletions
3
crates/move-cli/tests/build_tests/migration_names_mut_allowed/args.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
migrate | ||
> diff -r -s sources migration_sources | ||
> diff -s Move.toml Move.toml.expected |
9 changes: 9 additions & 0 deletions
9
...es/move-cli/tests/build_tests/migration_names_mut_allowed/migration_sources/mut_name.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0x42::m { | ||
|
||
fun dumpster_fire(mut x: u64, `mut`: u64): u64 { | ||
let mut y: u64 = 10; | ||
let `mut`: u64 = `mut` + 2; | ||
`mut` + y + x | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
crates/move-cli/tests/build_tests/migration_names_mut_allowed/sources/mut_name.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0x42::m { | ||
|
||
fun dumpster_fire(mut x: u64, mut: u64): u64 { | ||
let mut y: u64 = 10; | ||
let mut: u64 = mut + 2; | ||
mut + y + x | ||
} | ||
|
||
} |
Oops, something went wrong.