Skip to content

Commit

Permalink
macro visibility (#18280)
Browse files Browse the repository at this point in the history
## Description 

Make core macro public

## Test plan 

Existing tests

---

## 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): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
dariorussi authored Jun 27, 2024
1 parent a025ca0 commit 2bb6bc1
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 130 deletions.
20 changes: 10 additions & 10 deletions crates/sui-framework/packages/move-stdlib/sources/macros.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@

/// This module holds shared implementation of macros used in `std`
module std::macros {
public(package) macro fun num_max($x: _, $y: _): _ {
public macro fun num_max($x: _, $y: _): _ {
let x = $x;
let y = $y;
if (x > y) x
else y
}

public(package) macro fun num_min($x: _, $y: _): _ {
public macro fun num_min($x: _, $y: _): _ {
let x = $x;
let y = $y;
if (x < y) x
else y
}

public(package) macro fun num_diff($x: _, $y: _): _ {
public macro fun num_diff($x: _, $y: _): _ {
let x = $x;
let y = $y;
if (x > y) x - y
else y - x
}

public(package) macro fun num_divide_and_round_up($x: _, $y: _): _ {
public macro fun num_divide_and_round_up($x: _, $y: _): _ {
let x = $x;
let y = $y;
if (x % y == 0) x / y
else x / y + 1
}


public(package) macro fun num_pow($base: _, $exponent: u8): _ {
public macro fun num_pow($base: _, $exponent: u8): _ {
let mut base = $base;
let mut exponent = $exponent;
let mut res = 1;
Expand All @@ -50,7 +50,7 @@ module std::macros {
res
}

public(package) macro fun num_sqrt<$T, $U>($x: $T, $bitsize: u8): $T {
public macro fun num_sqrt<$T, $U>($x: $T, $bitsize: u8): $T {
let x = $x;
let mut bit = (1: $U) << $bitsize;
let mut res = (0: $U);
Expand All @@ -69,7 +69,7 @@ module std::macros {
res as $T
}

public(package) macro fun range_do($start: _, $stop: _, $f: |_|) {
public macro fun range_do($start: _, $stop: _, $f: |_|) {
let mut i = $start;
let stop = $stop;
while (i < stop) {
Expand All @@ -78,7 +78,7 @@ module std::macros {
}
}

public(package) macro fun range_do_eq($start: _, $stop: _, $f: |_|) {
public macro fun range_do_eq($start: _, $stop: _, $f: |_|) {
let mut i = $start;
let stop = $stop;
// we check `i >= stop` inside the loop instead of `i <= stop` as `while` condition to avoid
Expand All @@ -93,11 +93,11 @@ module std::macros {
}
}

public(package) macro fun do($stop: _, $f: |_|) {
public macro fun do($stop: _, $f: |_|) {
range_do!(0, $stop, $f)
}

public(package) macro fun do_eq($stop: _, $f: |_|) {
public macro fun do_eq($stop: _, $f: |_|) {
range_do_eq!(0, $stop, $f)
}
}
212 changes: 106 additions & 106 deletions crates/sui-framework/published_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4165,6 +4165,111 @@ sha2_256
sha3_256
public fun
0x1::hash
max
public fun
0x1::u128
min
public fun
0x1::u128
diff
public fun
0x1::u128
divide_and_round_up
public fun
0x1::u128
pow
public fun
0x1::u128
sqrt
public fun
0x1::u128
max
public fun
0x1::u16
min
public fun
0x1::u16
diff
public fun
0x1::u16
divide_and_round_up
public fun
0x1::u16
pow
public fun
0x1::u16
sqrt
public fun
0x1::u16
max
public fun
0x1::u256
min
public fun
0x1::u256
diff
public fun
0x1::u256
divide_and_round_up
public fun
0x1::u256
pow
public fun
0x1::u256
max
public fun
0x1::u32
min
public fun
0x1::u32
diff
public fun
0x1::u32
divide_and_round_up
public fun
0x1::u32
pow
public fun
0x1::u32
sqrt
public fun
0x1::u32
max
public fun
0x1::u64
min
public fun
0x1::u64
diff
public fun
0x1::u64
divide_and_round_up
public fun
0x1::u64
pow
public fun
0x1::u64
sqrt
public fun
0x1::u64
max
public fun
0x1::u8
min
public fun
0x1::u8
diff
public fun
0x1::u8
divide_and_round_up
public fun
0x1::u8
pow
public fun
0x1::u8
sqrt
public fun
0x1::u8
empty
public fun
0x1::vector
Expand Down Expand Up @@ -4413,109 +4518,4 @@ get_module
0x1::type_name
into_string
public fun
0x1::type_name
max
public fun
0x1::u128
min
public fun
0x1::u128
diff
public fun
0x1::u128
divide_and_round_up
public fun
0x1::u128
pow
public fun
0x1::u128
sqrt
public fun
0x1::u128
max
public fun
0x1::u16
min
public fun
0x1::u16
diff
public fun
0x1::u16
divide_and_round_up
public fun
0x1::u16
pow
public fun
0x1::u16
sqrt
public fun
0x1::u16
max
public fun
0x1::u256
min
public fun
0x1::u256
diff
public fun
0x1::u256
divide_and_round_up
public fun
0x1::u256
pow
public fun
0x1::u256
max
public fun
0x1::u32
min
public fun
0x1::u32
diff
public fun
0x1::u32
divide_and_round_up
public fun
0x1::u32
pow
public fun
0x1::u32
sqrt
public fun
0x1::u32
max
public fun
0x1::u64
min
public fun
0x1::u64
diff
public fun
0x1::u64
divide_and_round_up
public fun
0x1::u64
pow
public fun
0x1::u64
sqrt
public fun
0x1::u64
max
public fun
0x1::u8
min
public fun
0x1::u8
diff
public fun
0x1::u8
divide_and_round_up
public fun
0x1::u8
pow
public fun
0x1::u8
sqrt
public fun
0x1::u8
0x1::type_name
1 change: 1 addition & 0 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const MAX_PROTOCOL_VERSION: u64 = 52;
// std::config native functions.
// Modified sui-system package to enable withdrawal of stake before it becomes active.
// Enable soft bundle in devnet and testnet.
// Core macro visibility in sui core framework.

#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down
Loading

0 comments on commit 2bb6bc1

Please sign in to comment.