Skip to content

Commit 937b652

Browse files
authored
[move-compiler][sui-mode] Added struct declaration, private generics, and global storage checks (#13482)
## Description - Added checks for structs with key (id field naming+type) - Added checks for private generics in sui::transfer and sui::event - Added checks banning global storage operations ## Test Plan - Migrated tests --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [X] 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 Move now provides errors for all custom rules present in Sui
1 parent a86c40c commit 937b652

34 files changed

+1250
-34
lines changed

move-compiler/src/expansion/ast.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,14 @@ impl AbilitySet {
669669
self.0.contains_(&a)
670670
}
671671

672+
pub fn ability_loc(&self, sp!(_, a_): &Ability) -> Option<Loc> {
673+
self.0.get_loc_(a_).copied()
674+
}
675+
676+
pub fn ability_loc_(&self, a: Ability_) -> Option<Loc> {
677+
self.0.get_loc_(&a).copied()
678+
}
679+
672680
// intersection of two sets. Keeps the loc of the first set
673681
pub fn intersect(&self, other: &Self) -> Self {
674682
Self(self.0.intersect(&other.0))

move-compiler/src/sui_mode/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod id_leak;
99
pub mod typing;
1010

1111
pub const INIT_FUNCTION_NAME: Symbol = symbol!("init");
12+
pub const ID_FIELD_NAME: Symbol = symbol!("id");
1213

1314
pub const STD_ADDR_NAME: Symbol = symbol!("std");
1415
pub const OPTION_MODULE_NAME: Symbol = symbol!("option");
@@ -41,6 +42,20 @@ pub const AUTHENTICATOR_STATE_MODULE_NAME: Symbol = symbol!("authenticator_state
4142
pub const AUTHENTICATOR_STATE_TYPE_NAME: Symbol = symbol!("AuthenticatorState");
4243
pub const AUTHENTICATOR_STATE_CREATE: Symbol = symbol!("create");
4344

45+
pub const EVENT_MODULE_NAME: Symbol = symbol!("event");
46+
pub const EVENT_FUNCTION_NAME: Symbol = symbol!("emit");
47+
48+
pub const TRANSFER_MODULE_NAME: Symbol = symbol!("transfer");
49+
pub const TRANSFER_FUNCTION_NAME: Symbol = symbol!("transfer");
50+
pub const FREEZE_FUNCTION_NAME: Symbol = symbol!("freeze_object");
51+
pub const SHARE_FUNCTION_NAME: Symbol = symbol!("share_object");
52+
53+
pub const PRIVATE_TRANSFER_FUNCTIONS: &[Symbol] = &[
54+
TRANSFER_FUNCTION_NAME,
55+
FREEZE_FUNCTION_NAME,
56+
SHARE_FUNCTION_NAME,
57+
];
58+
4459
//**************************************************************************************************
4560
// Diagnostics
4661
//**************************************************************************************************
@@ -101,3 +116,31 @@ pub const INIT_CALL_DIAG: DiagnosticInfo = custom(
101116
/* code */ 6,
102117
"invalid 'init' call",
103118
);
119+
pub const OBJECT_DECL_DIAG: DiagnosticInfo = custom(
120+
SUI_DIAG_PREFIX,
121+
Severity::NonblockingError,
122+
/* category */ TYPING,
123+
/* code */ 7,
124+
"invalid object declaration",
125+
);
126+
pub const EVENT_EMIT_CALL_DIAG: DiagnosticInfo = custom(
127+
SUI_DIAG_PREFIX,
128+
Severity::NonblockingError,
129+
/* category */ TYPING,
130+
/* code */ 8,
131+
"invalid event",
132+
);
133+
pub const PRIVATE_TRANSFER_CALL_DIAG: DiagnosticInfo = custom(
134+
SUI_DIAG_PREFIX,
135+
Severity::NonblockingError,
136+
/* category */ TYPING,
137+
/* code */ 9,
138+
"invalid private transfer call",
139+
);
140+
pub const GLOBAL_STORAGE_DIAG: DiagnosticInfo = custom(
141+
SUI_DIAG_PREFIX,
142+
Severity::NonblockingError,
143+
/* category */ TYPING,
144+
/* code */ 9,
145+
"global storage is not supported in Sui",
146+
);

0 commit comments

Comments
 (0)