Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #400 from noir-lang/zpedro/road_to_0.16
Browse files Browse the repository at this point in the history
merging this big boi πŸ•
  • Loading branch information
signorecello authored Oct 10, 2023
2 parents 7e01e21 + 9342791 commit 06b8be5
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 28 deletions.
28 changes: 3 additions & 25 deletions docs/getting_started/00_nargo_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,33 +153,11 @@ Commands:
help Print this message or the help of the given subcommand(s)
```
### Option 3: Install via Nix
### Option 3: Compile from Source
Due to the large number of native dependencies, Noir projects can be installed via [Nix](https://nixos.org/).
Due to the large number of native dependencies, Noir projects uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience. It helps mitigating ssues commonly associated with dependency management, such as conflicts between required package versions for different projects (often referred to as "dependency hell").
#### Installing Nix
For the best experience, please follow these instructions to setup Nix:
1. Install Nix following [their guide](https://nixos.org/download.html) for your operating system.
2. Create the file `~/.config/nix/nix.conf` with the contents:
```ini
experimental-features = nix-command
extra-experimental-features = flakes
```
#### Install Nargo into your Nix profile
1. Use `nix profile` to install Nargo
```sh
nix profile install github:noir-lang/noir
```
### Option 4: Compile from Source
Due to the large number of native dependencies, Noir projects uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience.
Combined with direnv, which automatically sets or unsets environment variables based on the directory, it further simplifies the development process by seamlessly integrating with the developer's shell, facilitating an efficient and reliable workflow for managing and deploying Noir projects with multiple dependencies.

#### Setting up your environment

Expand Down
2 changes: 0 additions & 2 deletions docs/getting_started/02_breakdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,3 @@ verify the proof submitted against it. If the verification passes, additional fu
verifier contract could trigger (e.g. approve the asset transfer).

Now that you understand the concepts, you'll probably want some editor feedback while you are writing more complex code.

In the [next section](language_server), we will explain how to utilize the Noir Language Server.
6 changes: 6 additions & 0 deletions docs/language_concepts/01_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ To declare a function the `fn` keyword is used.
fn foo() {}
```

By default, functions are visible only within the package they are defined. To make them visible outside of that package (for example, as part of a [library](../modules_packages_crates/crates_and_packages.md#libraries)), you should mark them as `pub`:

```rust
pub fn foo() {}
```

All parameters in a function must have a type and all types are known at compile time. The parameter
is pre-pended with a colon and the parameter type. Multiple parameters are separated using a comma.

Expand Down
2 changes: 2 additions & 0 deletions docs/language_concepts/02_control_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ for i in 0..10 {
};
```

The index for loops is of type `u64`.

## If Expressions

Noir supports `if-else` statements. The syntax is most similar to Rust's where it is not required
Expand Down
20 changes: 20 additions & 0 deletions docs/language_concepts/data_types/03_strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ fn main() {
assert(message_bytes[0] == message_vec.get(0));
}
```

## Escape characters

You can use escape characters for your strings:

| Escape Sequence | Description |
|-----------------|-----------------|
| `\r` | Carriage Return |
| `\n` | Newline |
| `\t` | Tab |
| `\0` | Null Character |
| `\"` | Double Quote |
| `\\` | Backslash |

Example:

```rust
let s = "Hello \"world" // prints "Hello "world"
let s = "hey \tyou"; // prints "hey you"
```
7 changes: 7 additions & 0 deletions docs/language_concepts/data_types/04_arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ let array: [Field; 32] = [0; 32];
let sl = array.as_slice()
```

You can define multidimensional arrays:

```rust
let array : [[Field; 2]; 2];
let element = array[0][0];
```

## Types

You can create arrays of primitive types or structs. There is not yet support for nested arrays
Expand Down
149 changes: 149 additions & 0 deletions docs/language_concepts/data_types/06_vectors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,152 @@ for i in 0..5 {
}
assert(vector.len() == 5);
```

## Methods

### new

Creates a new, empty vector.

```rust
pub fn new() -> Self {
Self { slice: [] }
}
```

Example:

```rust
let empty_vector: Vec<Field> = Vec::new();
assert(empty_vector.len() == 0);
```

### from_slice

Creates a vector containing each element from a given slice. Mutations to the resulting vector will not affect the original slice.

```rust
pub fn from_slice(slice: [T]) -> Self {
Self { slice }
}
```

Example:

```rust
let arr: [Field] = [1, 2, 3];
let vector_from_slice = Vec::from_slice(arr);
assert(vector_from_slice.len() == 3);
```

### get

Retrieves an element from the vector at a given index. Panics if the index points beyond the vector's end.

```rust
pub fn get(self, index: Field) -> T {
self.slice[index]
}
```

Example:

```rust
let vector: Vec<Field> = Vec::from_slice([10, 20, 30]);
assert(vector.get(1) == 20);
```

### push

Adds a new element to the vector's end, returning a new vector with a length one greater than the original unmodified vector.

```rust
pub fn push(&mut self, elem: T) {
self.slice = self.slice.push_back(elem);
}
```

Example:

```rust
let mut vector: Vec<Field> = Vec::new();
vector.push(10);
assert(vector.len() == 1);
```

### pop

Removes an element from the vector's end, returning a new vector with a length one less than the original vector, along with the removed element. Panics if the vector's length is zero.

```rust
pub fn pop(&mut self) -> T {
let (popped_slice, last_elem) = self.slice.pop_back();
self.slice = popped_slice;
last_elem
}
```

Example:

```rust
let mut vector = Vec::from_slice([10, 20]);
let popped_elem = vector.pop();
assert(popped_elem == 20);
assert(vector.len() == 1);
```

### insert

Inserts an element at a specified index, shifting subsequent elements to the right.

```rust
pub fn insert(&mut self, index: Field, elem: T) {
self.slice = self.slice.insert(index, elem);
}
```

Example:

```rust
let mut vector = Vec::from_slice([10, 30]);
vector.insert(1, 20);
assert(vector.get(1) == 20);
```

### remove

Removes an element at a specified index, shifting subsequent elements to the left, and returns the removed element.

```rust
pub fn remove(&mut self, index: Field) -> T {
let (new_slice, elem) = self.slice.remove(index);
self.slice = new_slice;
elem
}
```

Example:

```rust
let mut vector = Vec::from_slice([10, 20, 30]);
let removed_elem = vector.remove(1);
assert(removed_elem == 20);
assert(vector.len() == 2);
```

### len

Returns the number of elements in the vector.

```rust
pub fn len(self) -> Field {
self.slice.len()
}
```

Example:

```rust
let empty_vector: Vec<Field> = Vec::new();
assert(empty_vector.len() == 0);
```
12 changes: 11 additions & 1 deletion docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ keywords: [Noir, notes, migration, updating, upgrading]

Noir is in full-speed development. Things break fast, wild, and often. This page attempts to leave some notes on errors you might encounter when upgrading and how to resolve them until proper patches are built.

## β‰₯0.14

The index of the [for loops](./language_concepts/02_control_flow.md#loops) is now of type `u64` instead of `Field`. An example refactor would be:

```rust
for i in 0..10 {
let i = i as Field;
}
```

## β‰₯v0.11.0 and Nargo backend

From this version onwards, Nargo starts managing backends through the `nargo backend` command. Upgrading to the versions per usual steps might lead to:
Expand Down Expand Up @@ -60,7 +70,7 @@ nargo backend install acvm-backend-barretenberg https://github.com/noir-lang/bar

This downloads and installs a specific bb.js based version of barretenberg binary from GitHub.

The gzipped filed is running this bash script: https://github.com/noir-lang/barretenberg-js-binary/blob/master/run-bb-js.sh, where we need to gzip it as the Nargo currently expect the backend to be zipped up.
The gzipped filed is running this bash script: <https://github.com/noir-lang/barretenberg-js-binary/blob/master/run-bb-js.sh>, where we need to gzip it as the Nargo currently expect the backend to be zipped up.

Then run:

Expand Down
19 changes: 19 additions & 0 deletions docs/nargo/02_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,22 @@ fn test_add() {
assert(add(2,2) == 5);
}
```

You can be more specific and make it fail with a specific reason by using `should_fail_with = "<the reason for failure>`:

```rust
fn main(african_swallow_avg_speed : Field) {
assert(african_swallow_avg_speed == 65, "What is the airspeed velocity of an unladen swallow");
}

#[test]
fn test_king_arthur() {
main(65);
}

#[test(should_fail_with = "What is the airspeed velocity of an unladen swallow")]
fn test_bridgekeeper() {
main(32);
}

```
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ When you language server is running correctly and the VSCode plugin is installed
![Compile and Execute](./../../static/img/codelens_compile_execute.png)
![Run test](../../static/img/codelens_run_test.png)

You should also see your tests in the `testing` panel:

![Testing panel](./../../static/img/codelens_testing_panel.png)

### Configuration

* __Noir: Enable LSP__ - If checked, the extension will launch the Language Server via `nargo lsp` and communicate with it.
Expand Down
Binary file added static/img/codelens_testing_panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06b8be5

Please sign in to comment.