Skip to content

Commit

Permalink
[move-compiler][sui-mode] Added struct declaration, private generics,…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
tnowacki committed Sep 11, 2023
1 parent ef40ce4 commit df0b128
Show file tree
Hide file tree
Showing 34 changed files with 1,250 additions and 34 deletions.
8 changes: 8 additions & 0 deletions external-crates/move/move-compiler/src/expansion/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,14 @@ impl AbilitySet {
self.0.contains_(&a)
}

pub fn ability_loc(&self, sp!(_, a_): &Ability) -> Option<Loc> {
self.0.get_loc_(a_).copied()
}

pub fn ability_loc_(&self, a: Ability_) -> Option<Loc> {
self.0.get_loc_(&a).copied()
}

// intersection of two sets. Keeps the loc of the first set
pub fn intersect(&self, other: &Self) -> Self {
Self(self.0.intersect(&other.0))
Expand Down
43 changes: 43 additions & 0 deletions external-crates/move/move-compiler/src/sui_mode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod id_leak;
pub mod typing;

pub const INIT_FUNCTION_NAME: Symbol = symbol!("init");
pub const ID_FIELD_NAME: Symbol = symbol!("id");

pub const STD_ADDR_NAME: Symbol = symbol!("std");
pub const OPTION_MODULE_NAME: Symbol = symbol!("option");
Expand Down Expand Up @@ -41,6 +42,20 @@ pub const AUTHENTICATOR_STATE_MODULE_NAME: Symbol = symbol!("authenticator_state
pub const AUTHENTICATOR_STATE_TYPE_NAME: Symbol = symbol!("AuthenticatorState");
pub const AUTHENTICATOR_STATE_CREATE: Symbol = symbol!("create");

pub const EVENT_MODULE_NAME: Symbol = symbol!("event");
pub const EVENT_FUNCTION_NAME: Symbol = symbol!("emit");

pub const TRANSFER_MODULE_NAME: Symbol = symbol!("transfer");
pub const TRANSFER_FUNCTION_NAME: Symbol = symbol!("transfer");
pub const FREEZE_FUNCTION_NAME: Symbol = symbol!("freeze_object");
pub const SHARE_FUNCTION_NAME: Symbol = symbol!("share_object");

pub const PRIVATE_TRANSFER_FUNCTIONS: &[Symbol] = &[
TRANSFER_FUNCTION_NAME,
FREEZE_FUNCTION_NAME,
SHARE_FUNCTION_NAME,
];

//**************************************************************************************************
// Diagnostics
//**************************************************************************************************
Expand Down Expand Up @@ -101,3 +116,31 @@ pub const INIT_CALL_DIAG: DiagnosticInfo = custom(
/* code */ 6,
"invalid 'init' call",
);
pub const OBJECT_DECL_DIAG: DiagnosticInfo = custom(
SUI_DIAG_PREFIX,
Severity::NonblockingError,
/* category */ TYPING,
/* code */ 7,
"invalid object declaration",
);
pub const EVENT_EMIT_CALL_DIAG: DiagnosticInfo = custom(
SUI_DIAG_PREFIX,
Severity::NonblockingError,
/* category */ TYPING,
/* code */ 8,
"invalid event",
);
pub const PRIVATE_TRANSFER_CALL_DIAG: DiagnosticInfo = custom(
SUI_DIAG_PREFIX,
Severity::NonblockingError,
/* category */ TYPING,
/* code */ 9,
"invalid private transfer call",
);
pub const GLOBAL_STORAGE_DIAG: DiagnosticInfo = custom(
SUI_DIAG_PREFIX,
Severity::NonblockingError,
/* category */ TYPING,
/* code */ 9,
"global storage is not supported in Sui",
);
Loading

1 comment on commit df0b128

@vercel
Copy link

@vercel vercel bot commented on df0b128 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.