Skip to content

Commit

Permalink
improve comments, format type params within structs and enums (#20874)
Browse files Browse the repository at this point in the history
## Description 

- improves comments
- format type params within structs
- remove dead code
- refactor formatting fields

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
jordanjennings-mysten authored Jan 15, 2025
1 parent 2166353 commit ca155f3
Show file tree
Hide file tree
Showing 18 changed files with 497 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module upgrades::upgrades {
A, // add u8
B(u8), // to be changed to u16
C(u8, u8), // remove u8
D(u8) // remove last u8
D(u8) // remove u8 from last variant
}

public struct ChangeFieldA {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ module upgrades::upgrades {

public enum EnumChangePositionalType {
A(u8), // add u8
B(u16), // to be changed to u16
B(u16), // changed to u16
C(u8), // removed u8
D, // removed last u8
D, // removed u8 from variant
}

public struct ChangeFieldA {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,17 @@ module upgrades::upgrades {
public struct ChangeNameNestedStruct {
a: ChangeFieldA, // change to ChangeFieldB
}

// nested struct type param field mismatch
public struct NamedBox<A> { x: A }
public struct NamedTwoBox<B, C> { x: B, y: C }

public struct NamedBoxInBox<D> { x: NamedBox<NamedBox<D>> }
public struct NamedBoxInTwoBox<E, F> { x: NamedTwoBox<NamedBox<E>, NamedBox<F>> }

public struct PositionalBox<G>(G)
public struct PositionalTwoBox<H, I>(H, I)

public struct PositionalBoxInBox<J>(PositionalBox<PositionalBox<J>>)
public struct PositionalBoxInTwoBox<K, L>(PositionalTwoBox<PositionalBox<K>, PositionalBox<L>>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,17 @@ module upgrades::upgrades {
public struct ChangeNameNestedStruct {
a: ChangeFieldB, // changed to ChangeFieldB
}


public struct NamedBox<A> { x: u32 }
public struct NamedTwoBox<B, C> { x: u32, y: u32 }

public struct NamedBoxInBox<D> { x: u32 }
public struct NamedBoxInTwoBox<E, F> { x: u32 }

public struct PositionalBox<G>(u32)
public struct PositionalTwoBox<H, I>(u32, u32)

public struct PositionalBoxInBox<J>(u32)
public struct PositionalBoxInTwoBox<K, L>(u32)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(err.to_string())
---
error[Compatibility E01008]: missing declaration
error[Compatibility E01007]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
Expand All @@ -11,7 +11,7 @@ error[Compatibility E01008]: missing declaration
= enums cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing enum 'EnumToRemove' back to the module 'upgrades'.

error[Compatibility E01008]: missing declaration
error[Compatibility E01007]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
Expand All @@ -20,7 +20,7 @@ error[Compatibility E01008]: missing declaration
= functions cannot be removed or changed during an 'additive' or 'dependency only' upgrade.
= add missing function 'function_to_remove' back to the module 'upgrades'.

error[Compatibility E01008]: missing declaration
error[Compatibility E01007]: missing declaration
┌─ /fixtures/upgrade_errors/additive_errors_v2/sources/UpgradeErrors.move:4:18
4 │ module upgrades::upgrades {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: output
---
error[Compatibility E01007]: module missing
error[Compatibility E01006]: module missing
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/addresses_first/Move.toml:4:1
4 │ ╭ [package]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ error[Compatibility E01001]: missing public declaration
= structs are part of a module's public interface and cannot be removed or changed during a 'compatible' upgrade.
= add missing struct 'StructToBeRemoved' back to the module 'struct_'.

error[Compatibility E01007]: module missing
error[Compatibility E01006]: module missing
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/declaration_errors_v2/Move.toml:1:1
1 │ ╭ [package]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: output
---
error[Compatibility E01007]: module missing
error[Compatibility E01006]: module missing
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/emoji/Move.toml:2:2
2 │ 😀[package]😀
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: output
---
error[Compatibility E01007]: module missing
error[Compatibility E01006]: module missing
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/empty/Move.toml:1:1
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ error[Compatibility E02001]: variant mismatch
│ ----------------- Enum definition
32 │ A,
33 │ C, // changed from B
│ ^ Mismatched variant name 'C', expected 'B'.
│ ^ Mismatched variant 'C', expected 'B'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangeVariant' including the ordering.
Expand All @@ -69,7 +69,7 @@ error[Compatibility E02001]: variant mismatch
│ ----------------------- Enum definition
37 │ A,
38 │ C, // to be changed to C
│ ^ Mismatched variant name 'C', expected 'B'.
│ ^ Mismatched variant 'C', expected 'B'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangeAndAddVariant' including the ordering.
Expand Down Expand Up @@ -114,7 +114,7 @@ error[Compatibility E02001]: variant mismatch
│ -------------------------- Enum definition
43 │ A,
44 │ C, // changed to C
│ ^ Mismatched variant name 'C', expected 'B'.
│ ^ Mismatched variant 'C', expected 'B'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangeAndRemoveVariant' including the ordering.
Expand Down Expand Up @@ -165,7 +165,7 @@ error[Compatibility E02001]: variant mismatch
│ -------------------------- Enum definition
68 │ A { a: u8 },
69C { b: u8 }, // changed to C
^^^^^^^^^^^ Mismatched variant name 'C', expected 'B'.
^^^^^^^^^^^ Mismatched variant 'C', expected 'B'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangeVariantWithTypes' including the ordering.
Expand All @@ -177,7 +177,7 @@ error[Compatibility E02001]: variant mismatch
│ -------------------------------- Enum definition
73 │ A { a: u8 },
74C { b: u8 }, // to be changed to C
^^^^^^^^^^^ Mismatched variant name 'C', expected 'B'.
^^^^^^^^^^^ Mismatched variant 'C', expected 'B'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangeAndAddVariantWithTypes' including the ordering.
Expand Down Expand Up @@ -222,7 +222,7 @@ error[Compatibility E02001]: variant mismatch
│ --------------------------------------------- Enum definition
79 │ A(u8),
80 │ C(u8), // changed to C
│ ^^^^^ Mismatched variant name 'C', expected 'B'.
│ ^^^^^ Mismatched variant 'C', expected 'B'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangeAndRemoveVariantWithPositionalTypes' including the ordering.
Expand All @@ -238,14 +238,14 @@ error[Compatibility E01004]: field mismatch
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangePositionalType' including the ordering.

error[Compatibility E01004]: field mismatch
error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/enum_errors_v2/sources/UpgradeErrors.move:86:9
84 │ public enum EnumChangePositionalType {
│ ------------------------ Enum definition
85 │ A(u8), // add u8
86 │ B(u16), // to be changed to u16
│ ^^^^^^ Mismatched field 'u8' at position 0, expected 'u16'.
86 │ B(u16), // changed to u16
│ ^^^^^^ Mismatched field type 'u16', expected 'u8'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangePositionalType' including the ordering.
Expand All @@ -268,24 +268,24 @@ error[Compatibility E01004]: field mismatch
84 │ public enum EnumChangePositionalType {
│ ------------------------ Enum definition
·
88 │ D, // removed last u8
88 │ D, // removed u8 from variant
│ ^ Mismatched variant field count, expected 1, found 0.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variants for enum 'EnumChangePositionalType' including the ordering.

error[Compatibility E01004]: field mismatch
error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/enum_errors_v2/sources/UpgradeErrors.move:100:9
99 │ public enum EnumWithPositionalChanged {
│ ------------------------- Enum definition
100 │ A(ChangeFieldB), // changed to ChangeFieldB
│ ^^^^^^^^^^^^^^^ Mismatched field '0x0::upgrades::ChangeFieldA' at position 0, expected '0x0::upgrades::ChangeFieldB'.
│ ^^^^^^^^^^^^^^^ Mismatched field type '0x0::upgrades::ChangeFieldB', expected '0x0::upgrades::ChangeFieldA'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variant for enum 'EnumWithPositionalChanged' including the ordering.

error[Compatibility E01004]: field mismatch
error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/enum_errors_v2/sources/UpgradeErrors.move:104:9
103 │ public enum EnumWithNamedChanged {
Expand All @@ -295,7 +295,7 @@ error[Compatibility E01004]: field mismatch
106 │ │ y: ChangeFieldA,
107 │ │ z: ChangeFieldB, // changed to ChangeFieldB
108 │ │ },
│ ╰─────────^ Mismatched field 'z: 0x0::upgrades::ChangeFieldA', expected '0x0::upgrades::ChangeFieldB'.
│ ╰─────────^ Mismatched field type '0x0::upgrades::ChangeFieldB', expected '0x0::upgrades::ChangeFieldA'.
= Enums are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original enum's variant for enum 'EnumWithNamedChanged' including the ordering.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: output
---
error[Compatibility E01007]: module missing
error[Compatibility E01006]: module missing
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/package_no_name/Move.toml:1:1
1 │ [package]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: output
---
error[Compatibility E01007]: module missing
error[Compatibility E01006]: module missing
┌─ /Users/jordanjennings/code/sui/crates/sui/src/unit_tests/fixtures/upgrade_errors/missing_module_toml/starts_second_line/Move.toml:2:1
2 │ ╭ [package]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ error[Compatibility E01004]: field mismatch
│ --------------- Struct definition
41 │ a: u64,
42 │ c: u64, // changed from b to c
│ ^ Mismatched field name 'c', expected 'b'.
│ ^ Mismatched field 'c', expected 'b'.
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'ChangeFieldName' including the ordering.
Expand Down Expand Up @@ -170,7 +170,7 @@ error[Compatibility E01004]: field mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:73:38
73public struct PositionalToNamed{ a: u64 } // changed to named from positional
----------------- ^ Mismatched field name 'a', expected at position 0.
----------------- ^ Mismatched field 'a', expected a positional field.
│ │
Struct definition
Expand Down Expand Up @@ -210,5 +210,115 @@ error[Compatibility E01002]: type mismatch
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'ChangeNameNestedStruct' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:95:33
95 │ public struct NamedBox<A> { x: u32 }
│ -------- ^ Mismatched field type 'u32', expected 'A'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'NamedBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:96:39
96 │ public struct NamedTwoBox<B, C> { x: u32, y: u32 }
│ ----------- ^ Mismatched field type 'u32', expected 'B'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'NamedTwoBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:96:47
96 │ public struct NamedTwoBox<B, C> { x: u32, y: u32 }
│ ----------- ^ Mismatched field type 'u32', expected 'C'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'NamedTwoBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:98:38
98 │ public struct NamedBoxInBox<D> { x: u32 }
│ ------------- ^ Mismatched field type 'u32', expected '0x0::upgrades::NamedBox<0x0::upgrades::NamedBox<D>>'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'NamedBoxInBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:99:44
99 │ public struct NamedBoxInTwoBox<E, F> { x: u32 }
│ ---------------- ^ Mismatched field type 'u32', expected '0x0::upgrades::NamedTwoBox<0x0::upgrades::NamedBox<E>, 0x0::upgrades::NamedBox<F>>'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'NamedBoxInTwoBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:101:36
101 │ public struct PositionalBox<G>(u32)
│ ------------- ^^^ Mismatched field type 'u32', expected 'G'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'PositionalBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:102:42
102 │ public struct PositionalTwoBox<H, I>(u32, u32)
│ ---------------- ^^^ Mismatched field type 'u32', expected 'H'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'PositionalTwoBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:102:47
102 │ public struct PositionalTwoBox<H, I>(u32, u32)
│ ---------------- ^^^ Mismatched field type 'u32', expected 'I'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's fields for struct 'PositionalTwoBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:104:41
104 │ public struct PositionalBoxInBox<J>(u32)
│ ------------------ ^^^ Mismatched field type 'u32', expected '0x0::upgrades::PositionalBox<0x0::upgrades::PositionalBox<J>>'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'PositionalBoxInBox' including the ordering.

error[Compatibility E01002]: type mismatch
┌─ /fixtures/upgrade_errors/struct_errors_v2/sources/UpgradeErrors.move:105:47
105 │ public struct PositionalBoxInTwoBox<K, L>(u32)
│ --------------------- ^^^ Mismatched field type 'u32', expected '0x0::upgrades::PositionalTwoBox<0x0::upgrades::PositionalBox<K>, 0x0::upgrades::PositionalBox<L>>'.
│ │
│ Struct definition
= Structs are part of a module's public interface and cannot be removed or changed during an upgrade.
= Restore the original struct's field for struct 'PositionalBoxInTwoBox' including the ordering.


Upgrade failed, this package requires changes to be compatible with the existing package. Its upgrade policy is set to 'compatible'.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/sui/src/unit_tests/upgrade_compatibility_tests.rs
expression: normalize_path(result.unwrap_err().to_string())
---
error[Compatibility E01009]: file format version downgrade
error[Compatibility E01008]: file format version downgrade
┌─ /fixtures/upgrade_errors/deponly_errors_v2/sources/UpgradeErrors.move:4:18
4module upgrades::upgrades {
Expand Down
Loading

0 comments on commit ca155f3

Please sign in to comment.