Skip to content

Commit 7d4e38c

Browse files
author
Mohammad Fawaz
committed
A few fixes
1 parent 614721c commit 7d4e38c

4 files changed

Lines changed: 31 additions & 91 deletions

File tree

documentation/language/02_structure.md

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,11 @@ If you need a declaration from another Leo file, you must import it.
1515

1616
### Program
1717

18-
A program is a collection of code (its functions) and data (its types) that resides at a
19-
[program ID](#program-id) on the Aleo blockchain. A program is declared as `program {name}.{network} { ... }`.
20-
The body of the program is delimited by curly braces `{}`.
18+
A program is a collection of code (its functions) and data (its types) that resides at a program ID on the Aleo blockchain. A program is declared as `program {name}.{network} { ... }`, with the body delimited by curly braces.
2119

22-
```leo file=../code_snippets/layout/main_example/src/main.leo#file
23-
```
24-
25-
The following must be declared inside the scope of a program in a Leo file:
26-
27-
- mappings
28-
- storage variables
29-
- record types
30-
- entry point `fn` declarations
31-
32-
The following must be declared outside the scope of a program in a Leo file:
33-
34-
- imports
35-
- struct types
36-
- helper `fn` definitions
37-
- `final fn` definitions
38-
- `interface` definitions
20+
For the canonical list of which declarations belong inside vs. outside the `program { ... }` block, the program-ID naming rules, and import semantics, see [Project Layout](./01_layout.md#programs).
3921

40-
#### Program ID
41-
42-
A program ID is declared as `{name}.{network}`.
43-
44-
The first character of a `name` must be a lowercase letter.
45-
`name` can only contain lowercase letters, numbers, and underscores, and must not contain a double underscore (`__`) or the keyword `aleo` in it.
46-
47-
Currently, `aleo` is the only supported `network` domain.
48-
49-
```leo showLineNumbers
50-
program hello.aleo; // valid
51-
52-
program Foo.aleo; // invalid
53-
program baR.aleo; // invalid
54-
program 0foo.aleo; // invalid
55-
program 0_foo.aleo; // invalid
56-
program _foo.aleo; // invalid
22+
```leo file=../code_snippets/layout/main_example/src/main.leo#file
5723
```
5824

5925
### Constant
@@ -63,10 +29,10 @@ Constants are immutable, and the right-hand side must be an expression evaluatab
6329

6430
Constants can be declared in four scopes:
6531

66-
- **Global scope** (outside all program blocks in a program file): accessible anywhere in the same file.
32+
- **Global scope** (outside the `program` block in `main.leo`): accessible anywhere in the same file.
6733
- **Program scope** (inside a `program` block, outside any function): accessible within that program.
6834
- **Local scope** (inside a function body): accessible only within that function.
69-
- **Module scope** (in a module file within the same package, i.e. a `.leo` file with no `program` block): accessible within the same package via `path::to::module::CONST_NAME`. See [Modules](./01_layout.md#modules) for details.
35+
- **Module scope** (any non-`main.leo` source file in the package; module files do not contain a `program` block and may only declare `const`, `struct`, `fn`, and `interface`): accessible within the same package via `path::to::module::CONST_NAME`. See [Modules](./01_layout.md#modules) for details.
7036

7137
Constants are also supported in [libraries](./06_libraries.md), which are separate packages containing reusable code. A library's root file and its submodules may declare constants, accessible from any dependent package as `library::CONST_NAME` or `library::path::to::submodule::CONST_NAME`.
7238

@@ -94,9 +60,7 @@ See [ProvableHQ/leo#29274](https://github.com/ProvableHQ/leo/issues/29274).
9460

9561
### Import
9662

97-
You can import dependencies that are downloaded to the `imports` directory.
98-
An import is declared as `import {filename}.aleo;`
99-
The dependency resolver will pull the imported program from the network or the local filesystem.
63+
An import is declared as `import {filename}.aleo;`. See [Imports](./01_layout.md#imports) for resolution rules and the `imports/` directory layout.
10064

10165
```leo file=../code_snippets/layout/import_only/src/main.leo#snippet showLineNumbers
10266
```
@@ -131,7 +95,7 @@ Structs contain component declarations `{name}: {type},`.
13195

13296
### Record
13397

134-
A [record](https://developer.aleo.org/concepts/fundamentals/records) data type is declared as `record {name} {}`. A record name must not contain the keyword `aleo`, and must not be a prefix of any other record name.
98+
A [record](https://developer.aleo.org/concepts/fundamentals/records) data type is declared as `record {name} {}`. A record name must not contain the keyword `aleo`, and must not be a prefix of any other record name **declared in the same program** (the check does not extend across imported programs). The constraint exists because records lower to Aleo identifiers with a `.record` suffix, and prefix collisions would produce ambiguous lowered names.
13599

136100
Records contain component declarations `{visibility} {name}: {type},`. Names of record components must not contain the keyword `aleo`.
137101

documentation/language/07_style.md

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ The goal is to only have the interface of the program in `main.leo`. Every funct
128128

129129
### Blank lines
130130

131-
A single blank line should separate the top-level declarations in a `program` scope,
132-
namely `fn`, `record`, and `mapping` declarations, as well as module-level `struct` and helper `fn` declarations.
133-
Multiple imports can be optionally separated by a single blank line;
134-
the last import at the top of the file should be followed by a blank line.
131+
A single blank line should separate top-level declarations within a `program` scope (entry `fn`, `record`, and `mapping` declarations) and module-level declarations (`struct`, helper `fn`, `final fn`, `interface`). For the canonical ordering of these categories within a file, see [Layout](#layout) below. Multiple imports may optionally be separated by a single blank line; the last import at the top of the file should be followed by a blank line.
135132

136133
```leo title="Yes:"
137134
import std.io.Write;
@@ -237,37 +234,17 @@ Start by forking off of the `mainnet` branch to make your changes. Commit messag
237234
If you need to pull in any changes from the `mainnet` branch after making your fork (for example, to resolve potential merge conflicts),
238235
please avoid using git merge and instead, git rebase your branch. Rebasing will help us review your changes easily.
239236

240-
#### Tools Required
237+
For build, formatting, test, and grammar conventions, see [`CONTRIBUTING.md`](https://github.com/ProvableHQ/leo/blob/mainnet/CONTRIBUTING.md) in the repository root. The canonical commands for validation are:
241238

242-
To build Leo from source you will need the following tools:
243-
244-
- The latest Rust stable version and nightly version.
245-
- Recommend that you install multiple versions using `rustup`.
246-
- Cargo
247-
- Rusty Hook install via `cargo install rusty-hook`.
248-
- Clippy
249-
- Via rustup, if you didn't do the default rustup install `rustup component add clippy`.
250-
251-
#### Formatting
252-
253-
Please do the following before opening a PR.
254-
255-
- `cargo +nightly fmt --all` will format all your code.
256-
- `cargo clippy --all-features --examples --all --benches`
257-
258-
#### Tests
259-
260-
If your code adds new functionality, please write tests to confirm the new features function as expected. Refer to existing tests for examples of how tests are expected to be written. Please refer to the [parser tests section](#parser-tests). To run the tests please use the following command `cargo test --all --features ci_skip --no-fail-fast`.
261-
262-
##### **Parser Tests**
263-
264-
In the root directory of the repository, there is a "tests" directory.
265-
To add a parser test, look at the Example Leo files in the parser sub-directory.
266-
Then when running the test command, make sure you have the environment variable `CLEAR_LEO_TEST_EXPECTATIONS` set to true. For example, on a UNIX environment, you could run the following command `CLEAR_LEO_TEST_EXPECTATIONS=true cargo test --all --features ci_skip --no-fail-fast`.
239+
```bash
240+
cargo check
241+
cargo clippy -- -D warnings
242+
cargo +nightly fmt --check
243+
cargo test
244+
```
267245

268-
#### Grammar
246+
To update parser expectation files after intentional grammar changes, run `UPDATE_EXPECT=1 cargo test -p leo-parser`.
269247

270-
[The `grammars` repository](https://github.com/ProvableHQ/grammars) contains a file [`leo.abnf`](https://github.com/ProvableHQ/grammars/blob/master/leo.abnf) that has the Leo grammar rules in the ABNF format.
271-
If your changes affect a grammar rule, we may ask you to modify it in that `.abnf` file.
248+
The Leo grammar is maintained in the [`grammars` repository](https://github.com/ProvableHQ/grammars) (`leo.abnf`).
272249

273250
We appreciate your hard work!

documentation/language/operators/standard_operators.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ height in a program.
983983

984984
:::info
985985

986-
- The `block.height` operator can only be used inside a `final { }` block or inside a `final fn`. Using it outside will result in a compilation error.
986+
- The `block.height` operator can only be used inside a `final { }` block or a `final fn`. It is rejected in entry `fn` bodies, helper `fn`s, and constant initialisers, since chain state is only observable in the finalization context.
987987
- The `block.height` operator doesn't take any parameters.
988988

989989
:::
@@ -1001,7 +1001,7 @@ The `block.timestamp` operator is used to fetch the UNIX timestamp of the latest
10011001

10021002
:::info
10031003

1004-
- The `block.timestamp` operator can only be used inside a `final { }` block or inside a `final fn`. Using it outside will result in a compilation error.
1004+
- The `block.timestamp` operator can only be used inside a `final { }` block or a `final fn`. It is rejected in entry `fn` bodies, helper `fn`s, and constant initialisers, since chain state is only observable in the finalization context.
10051005
- The `block.timestamp` operator doesn't take any parameters.
10061006

10071007
:::

documentation/language/programs_in_practice/limitations.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@ toc_max_heading_level: 3
88

99
snarkVM imposes the following limits on Aleo programs:
1010

11-
- the maximum size of the program is 100 KB, by the number of characters.
12-
- the maximum number of mappings is 31.
13-
- the maximum number of imports is 64.
14-
- the maximum length of a program name is 30 characters (excluding the `.aleo` suffix).
15-
- the maximum import depth is 64.
16-
- the maximum call depth is 31.
17-
- the maximum number of functions is 31.
18-
- the maximum number of structs is 310.
19-
- the maximum number of records is 310.
20-
- the maximum number of closures is 62.
11+
- the maximum size of the compiled program is **512 KB** by character count (was 100 KB before consensus version V14).
12+
- the maximum number of mappings is **31**. Each `storage` singleton consumes one mapping slot, and each `storage` vector consumes two (one for values, one for length), so storage declarations share this budget with explicit `mapping` declarations.
13+
- the maximum number of imports is **64**.
14+
- the maximum length of a program name is **30 characters** (excluding the `.aleo` suffix). Identifiers (including struct, record, mapping, and function names) are limited to **31 ASCII alphanumeric or underscore characters** by the Aleo identifier rules.
15+
- the maximum number of functions is **31** (entry `fn`s plus the synthesised on-chain functions produced by `final { }` blocks and `constructor`).
16+
- the maximum number of structs is **310** (`10 × MAX_FUNCTIONS`).
17+
- the maximum number of records is **310**.
18+
- the maximum number of closures is **62** (`2 × MAX_FUNCTIONS`).
19+
- the maximum number of inputs and outputs **per entry point** is **16** each.
2120

2221
**If your _compiled_ Leo program exceeds these limits, then consider modularizing or rearchitecting your program.** The only way these limits can be increased is through a formal protocol upgrade via the governance process defined by the Aleo Network Foundation.
2322

2423
Some other protocol-level limits to be aware of are:
2524

26-
- **the maximum transaction size is 128 KB.** If your program exceeds this, perhaps by requiring large inputs or producing large outputs, consider optimizing the data types in your Leo code.
27-
- **the maximum number of micro-credits your transaction can consume for on-chain execution is `100_000_000`.**. If your program exceeds this, consider optimizing on-chain components of your Leo code.
25+
- **the maximum transaction size is 768 KB** (was 128 KB before consensus version V14). If your program exceeds this — for example by requiring large inputs or producing large outputs consider optimizing the data types in your Leo code.
26+
- **the maximum number of micro-credits your transaction can consume for on-chain execution is `100_000_000`.** If your program exceeds this, consider optimizing on-chain components of your Leo code.
2827

29-
As with the above restrictions, these limits can only be increased via the governance process.
28+
As with the above restrictions, these limits can only be increased via the governance process. Authoritative values live in `snarkvm-console-network` (`MAX_PROGRAM_SIZE`, `MAX_MAPPINGS`, `MAX_FUNCTIONS`, etc.).
3029

3130
## Compiling Conditional On-Chain Code
3231

0 commit comments

Comments
 (0)