Skip to content

Commit 9495123

Browse files
authored
Fix determination of scripts in Move model to work for 32-byte addresses (#14149)
## Description Fixes an issue from #14112 where docgen was improperly formatting scripts since these are identified with an address of `MAX_ADDR` but to get this in `BigUint` which is what the Move model uses it passes the address value string. ## Test Plan Ran tests locally and updated.
1 parent 4756235 commit 9495123

11 files changed

+85
-149
lines changed

move-model/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ move-prover-test-utils = { path = "../move-prover/test-utils" }
3636
[[test]]
3737
name = "testsuite"
3838
harness = false
39+
40+
[features]
41+
default = ["address32"]
42+
address32 = ["move-core-types/address32"]

move-model/src/ast.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ use crate::{
3434
ty::{Type, TypeDisplayContext},
3535
};
3636

37+
#[cfg(feature = "address32")]
38+
const MAX_ADDR_STRING: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
39+
#[cfg(not(feature = "address32"))]
40+
const MAX_ADDR_STRING: &str = "ffffffffffffffffffffffffffffffff";
41+
3742
// =================================================================================================
3843
/// # Declarations
3944
@@ -1106,9 +1111,8 @@ impl ModuleName {
11061111
/// Determine whether this is a script. The move-compiler infrastructure uses MAX_ADDR
11071112
/// for pseudo modules created from scripts, so use this address to check.
11081113
pub fn is_script(&self) -> bool {
1109-
static MAX_ADDR: Lazy<BigUint> = Lazy::new(|| {
1110-
BigUint::from_str_radix("ffffffffffffffffffffffffffffffff", 16).expect("valid hex")
1111-
});
1114+
static MAX_ADDR: Lazy<BigUint> =
1115+
Lazy::new(|| BigUint::from_str_radix(MAX_ADDR_STRING, 16).expect("valid hex"));
11121116
self.0 == *MAX_ADDR
11131117
}
11141118
}

move-prover/move-docgen/tests/sources/code_block_test.spec_inline.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11

2-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main"></a>
2+
<a name="main"></a>
33

4-
# Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::main`
4+
# Script `main`
55

66

77

8-
- [Function `main`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main_main)
9-
- [Explanation of the algorithm](#@Explanation_of_the_algorithm_0)
8+
- [Explanation of the algorithm](#@Explanation_of_the_algorithm_0)
109

1110

1211
<pre><code></code></pre>
1312

1413

1514

16-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main_main"></a>
17-
18-
## Function `main`
19-
20-
2115
<a name="@Explanation_of_the_algorithm_0"></a>
2216

23-
### Explanation of the algorithm
17+
## Explanation of the algorithm
2418

2519
```
2620
code block
2721
```
2822
then <code>inline code</code>
2923

3024

31-
<pre><code><b>public</b> entry <b>fun</b> <a href="code_block_test.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main">main</a>()
25+
<pre><code><b>public</b> <b>fun</b> <a href="code_block_test.md#main">main</a>()
3226
</code></pre>
3327

3428

@@ -37,7 +31,7 @@ then <code>inline code</code>
3731
<summary>Implementation</summary>
3832

3933

40-
<pre><code><b>fun</b> <a href="code_block_test.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main">main</a>() { }
34+
<pre><code><b>fun</b> <a href="code_block_test.md#main">main</a>() { }
4135
</code></pre>
4236

4337

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11

2-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main"></a>
2+
<a name="main"></a>
33

4-
# Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::main`
4+
# Script `main`
55

66

77

8-
- [Function `main`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main_main)
9-
- [Explanation of the algorithm](#@Explanation_of_the_algorithm_0)
8+
- [Explanation of the algorithm](#@Explanation_of_the_algorithm_0)
109

1110

1211
<pre><code></code></pre>
1312

1413

1514

16-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main_main"></a>
17-
18-
## Function `main`
19-
20-
2115
<a name="@Explanation_of_the_algorithm_0"></a>
2216

23-
### Explanation of the algorithm
17+
## Explanation of the algorithm
2418

2519
```
2620
code block
2721
```
2822
then <code>inline code</code>
2923

3024

31-
<pre><code><b>public</b> entry <b>fun</b> <a href="code_block_test.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main">main</a>()
25+
<pre><code><b>public</b> <b>fun</b> <a href="code_block_test.md#main">main</a>()
3226
</code></pre>
3327

3428

3529

3630
##### Implementation
3731

3832

39-
<pre><code><b>fun</b> <a href="code_block_test.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main">main</a>() { }
33+
<pre><code><b>fun</b> <a href="code_block_test.md#main">main</a>() { }
4034
</code></pre>

move-prover/move-docgen/tests/sources/code_block_test.spec_separate.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11

2-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main"></a>
2+
<a name="main"></a>
33

4-
# Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::main`
4+
# Script `main`
55

66

77

8-
- [Function `main`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main_main)
9-
- [Explanation of the algorithm](#@Explanation_of_the_algorithm_0)
8+
- [Explanation of the algorithm](#@Explanation_of_the_algorithm_0)
109

1110

1211
<pre><code></code></pre>
1312

1413

1514

16-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main_main"></a>
17-
18-
## Function `main`
19-
20-
2115
<a name="@Explanation_of_the_algorithm_0"></a>
2216

23-
### Explanation of the algorithm
17+
## Explanation of the algorithm
2418

2519
```
2620
code block
2721
```
2822
then <code>inline code</code>
2923

3024

31-
<pre><code><b>public</b> entry <b>fun</b> <a href="code_block_test.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main">main</a>()
25+
<pre><code><b>public</b> <b>fun</b> <a href="code_block_test.md#main">main</a>()
3226
</code></pre>
3327

3428

@@ -37,7 +31,7 @@ then <code>inline code</code>
3731
<summary>Implementation</summary>
3832

3933

40-
<pre><code><b>fun</b> <a href="code_block_test.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_main">main</a>() { }
34+
<pre><code><b>fun</b> <a href="code_block_test.md#main">main</a>() { }
4135
</code></pre>
4236

4337

move-prover/move-docgen/tests/sources/root_template.spec_inline.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
This document contains the description of multiple move scripts.
99

10-
The script <code><a href="root_template_script3.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_yet_another">yet_another</a></code> is documented in its own file.
10+
The script <code><a href="root_template_script3.md#yet_another">yet_another</a></code> is documented in its own file.
1111

1212
- [Some Scripts](#@Some_Scripts_1)
13-
- [Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::some`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some)
14-
- [Function `some`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some_some)
13+
- [Script `some`](#some)
1514
- [Other Scripts](#@Other_Scripts_2)
16-
- [Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::other`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other)
17-
- [Function `other`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other_other)
15+
- [Script `other`](#other)
1816
- [Some other scripts from a module](#@Some_other_scripts_from_a_module_3)
1917
- [Module `0x1::OneTypeOfScript`](#0x1_OneTypeOfScript)
2018
- [Function `script1`](#0x1_OneTypeOfScript_script1)
@@ -32,24 +30,19 @@ The script <code><a href="root_template_script3.md#0xfffffffffffffffffffffffffff
3230

3331

3432

35-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some"></a>
33+
<a name="some"></a>
3634

37-
### Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::some`
35+
### Script `some`
3836

3937

4038

4139
<pre><code></code></pre>
4240

4341

44-
45-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some_some"></a>
46-
47-
#### Function `some`
48-
4942
This script does really nothing but just aborts.
5043

5144

52-
<pre><code><b>public</b> entry <b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some">some</a>&lt;T&gt;(_account: signer)
45+
<pre><code><b>public</b> <b>fun</b> <a href="root.md#some">some</a>&lt;T&gt;(_account: signer)
5346
</code></pre>
5447

5548

@@ -58,7 +51,7 @@ This script does really nothing but just aborts.
5851
<summary>Implementation</summary>
5952

6053

61-
<pre><code><b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some">some</a>&lt;T&gt;(_account: signer) {
54+
<pre><code><b>fun</b> <a href="root.md#some">some</a>&lt;T&gt;(_account: signer) {
6255
<b>abort</b> 1
6356
}
6457
</code></pre>
@@ -87,24 +80,19 @@ This script does really nothing but just aborts.
8780

8881

8982

90-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other"></a>
83+
<a name="other"></a>
9184

92-
### Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::other`
85+
### Script `other`
9386

9487

9588

9689
<pre><code></code></pre>
9790

9891

99-
100-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other_other"></a>
101-
102-
#### Function `other`
103-
10492
This script does also abort.
10593

10694

107-
<pre><code><b>public</b> entry <b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other">other</a>&lt;T&gt;(_account: signer)
95+
<pre><code><b>public</b> <b>fun</b> <a href="root.md#other">other</a>&lt;T&gt;(_account: signer)
10896
</code></pre>
10997

11098

@@ -113,7 +101,7 @@ This script does also abort.
113101
<summary>Implementation</summary>
114102

115103

116-
<pre><code><b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other">other</a>&lt;T&gt;(_account: signer) {
104+
<pre><code><b>fun</b> <a href="root.md#other">other</a>&lt;T&gt;(_account: signer) {
117105
<b>abort</b> 2
118106
}
119107
</code></pre>
@@ -267,6 +255,6 @@ This is another script
267255

268256
- [`0x1::AnotherTypeOfScript`](root.md#0x1_AnotherTypeOfScript)
269257
- [`0x1::OneTypeOfScript`](root.md#0x1_OneTypeOfScript)
270-
- [`0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::other`](root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other)
271-
- [`0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::some`](root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some)
272-
- [`0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::yet_another`](root_template_script3.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_yet_another)
258+
- [`other`](root.md#other)
259+
- [`some`](root.md#some)
260+
- [`yet_another`](root_template_script3.md#yet_another)

move-prover/move-docgen/tests/sources/root_template.spec_inline_no_fold.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

88
This document contains the description of multiple move scripts.
99

10-
The script <code><a href="root_template_script3.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_yet_another">yet_another</a></code> is documented in its own file.
10+
The script <code><a href="root_template_script3.md#yet_another">yet_another</a></code> is documented in its own file.
1111

1212
- [Some Scripts](#@Some_Scripts_1)
13-
- [Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::some`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some)
14-
- [Function `some`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some_some)
13+
- [Script `some`](#some)
1514
- [Other Scripts](#@Other_Scripts_2)
16-
- [Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::other`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other)
17-
- [Function `other`](#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other_other)
15+
- [Script `other`](#other)
1816
- [Some other scripts from a module](#@Some_other_scripts_from_a_module_3)
1917
- [Module `0x1::OneTypeOfScript`](#0x1_OneTypeOfScript)
2018
- [Function `script1`](#0x1_OneTypeOfScript_script1)
@@ -32,32 +30,27 @@ The script <code><a href="root_template_script3.md#0xfffffffffffffffffffffffffff
3230

3331

3432

35-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some"></a>
33+
<a name="some"></a>
3634

37-
### Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::some`
35+
### Script `some`
3836

3937

4038

4139
<pre><code></code></pre>
4240

4341

44-
45-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some_some"></a>
46-
47-
#### Function `some`
48-
4942
This script does really nothing but just aborts.
5043

5144

52-
<pre><code><b>public</b> entry <b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some">some</a>&lt;T&gt;(_account: signer)
45+
<pre><code><b>public</b> <b>fun</b> <a href="root.md#some">some</a>&lt;T&gt;(_account: signer)
5346
</code></pre>
5447

5548

5649

5750
##### Implementation
5851

5952

60-
<pre><code><b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some">some</a>&lt;T&gt;(_account: signer) {
53+
<pre><code><b>fun</b> <a href="root.md#some">some</a>&lt;T&gt;(_account: signer) {
6154
<b>abort</b> 1
6255
}
6356
</code></pre>
@@ -81,32 +74,27 @@ This script does really nothing but just aborts.
8174

8275

8376

84-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other"></a>
77+
<a name="other"></a>
8578

86-
### Module `0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::other`
79+
### Script `other`
8780

8881

8982

9083
<pre><code></code></pre>
9184

9285

93-
94-
<a name="0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other_other"></a>
95-
96-
#### Function `other`
97-
9886
This script does also abort.
9987

10088

101-
<pre><code><b>public</b> entry <b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other">other</a>&lt;T&gt;(_account: signer)
89+
<pre><code><b>public</b> <b>fun</b> <a href="root.md#other">other</a>&lt;T&gt;(_account: signer)
10290
</code></pre>
10391

10492

10593

10694
##### Implementation
10795

10896

109-
<pre><code><b>fun</b> <a href="root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other">other</a>&lt;T&gt;(_account: signer) {
97+
<pre><code><b>fun</b> <a href="root.md#other">other</a>&lt;T&gt;(_account: signer) {
11098
<b>abort</b> 2
11199
}
112100
</code></pre>
@@ -243,6 +231,6 @@ This is another script
243231

244232
- [`0x1::AnotherTypeOfScript`](root.md#0x1_AnotherTypeOfScript)
245233
- [`0x1::OneTypeOfScript`](root.md#0x1_OneTypeOfScript)
246-
- [`0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::other`](root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_other)
247-
- [`0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::some`](root.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_some)
248-
- [`0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff::yet_another`](root_template_script3.md#0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_yet_another)
234+
- [`other`](root.md#other)
235+
- [`some`](root.md#some)
236+
- [`yet_another`](root_template_script3.md#yet_another)

0 commit comments

Comments
 (0)