Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pkg/
# Noir.js
tooling/noir_js/lib

# fuzzing inputs (generated from 'test_programs')
tooling/nargo_fuzz_target/draft_inputs

# Nargo output
*.proof
*.acir
Expand Down
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"tooling/nargo_fmt",
"tooling/nargo_cli",
"tooling/nargo_toml",
"tooling/nargo_fuzz_target",
"tooling/noirc_artifacts",
"tooling/noirc_artifacts_info",
"tooling/noirc_abi",
Expand Down Expand Up @@ -92,6 +93,7 @@ noirc_printable_type = { path = "compiler/noirc_printable_type" }
# Noir tooling workspace dependencies
noir_greybox_fuzzer = { path = "tooling/greybox_fuzzer" }
nargo = { path = "tooling/nargo" }
nargo_cli = { path = "tooling/nargo_cli" }
nargo_fmt = { path = "tooling/nargo_fmt" }
nargo_toml = { path = "tooling/nargo_toml" }
noir_lsp = { path = "tooling/lsp" }
Expand Down
4 changes: 4 additions & 0 deletions test_programs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Integration tests for the Noir compiler are broken down into the following direc
- `execution_panic`: a temporary location for tests that panic, but may or may not be valid or satisfiable Noir code. These tests should:
+ Each have a corresponding open issue
+ Be moved into another test folder once the panic is addressed
- `execution_stack_overflow`: a temporary location for tests that stack overflow, but may or may not be valid or satisfiable Noir code. These tests should:
+ Each have a corresponding open issue
+ Be moved into another test folder once the stack overflow is addressed
+ NOTE: these tests are not currently run, either locally or CI

The current testing flow can be thought of as shown:
```mermaid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "invalid_attribute_span"
type = "bin"
authors = [""]

[dependencies]
Binary file not shown.
6 changes: 6 additions & 0 deletions test_programs/execution_panic/invalid_ident_unwrap/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "invalid_ident_unwrap"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#[make_bar]
pubunfn foo((((((((((((&(((((((((((((((((((((((((((((((()(((fn main() {
round::<3, = 2
// 3/2*2 2>([1, 2, 2, 3];
]);
}

fn rou
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "bracket_stack_overflow"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO(https://github.com/noir-lang/noir/issues/8354): stack overflow
#[oracle([[[t[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ assert_eq(st.methodfn fo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "parens_stack_overflow"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// TODO(https://github.com/noir-lang/noir/issues/8354): stack overflow
fn tr(n my_eqrSelf) -> bool {
ain(# {'  !Foo::<i32fnfoo(((((((((((9((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( ((((((-(ate( maiK(foo(((((()((((9((((((((1(((fn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "too_many_errors_to_report"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// TODO(https://github.com/noir-lang/noir/issues/8354): stack overflow
//
struct Foo<let F: Field5 {}fn foqn f(
#[oracle(oracleName)]
#[builtin({{{{{{{{{{{{{{global N: Field

pub fend<T, leoo() -> bool {
tr/fn main(mut x: i8, mut y: i8, z: i8) {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
let mut s1: i8 = 5{{{{{{{{{{{{{
let mut s1: i8 = 5;
let F: Fie let {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{s i8 ;
let F: Fie let {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{s i8 {{{{fn main(x: Field) {

4 changes: 4 additions & 0 deletions tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "nargo_cli"
path = "src/lib.rs"

# Rename binary from `nargo_cli` to `nargo`
[[bin]]
name = "nargo"
Expand Down
38 changes: 24 additions & 14 deletions tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rayon::prelude::*;

/// Compile the program and its secret execution trace into ACIR format
#[derive(Debug, Clone, Args)]
pub(crate) struct CompileCommand {
pub struct CompileCommand {
#[clap(flatten)]
pub(super) package_options: PackageOptions,

Expand Down Expand Up @@ -58,7 +58,8 @@ pub(crate) fn run(args: CompileCommand, workspace: Workspace) -> Result<(), CliE
watch_workspace(&workspace, &args.compile_options)
.map_err(|err| CliError::Generic(err.to_string()))?;
} else {
compile_workspace_full(&workspace, &args.compile_options)?;
let debug_compile_stdin = None;
compile_workspace_full(&workspace, &args.compile_options, debug_compile_stdin)?;
}
Ok(())
}
Expand All @@ -77,7 +78,8 @@ fn watch_workspace(workspace: &Workspace, compile_options: &CompileOptions) -> n
let mut screen = std::io::stdout();
write!(screen, "{}", termion::cursor::Save).unwrap();
screen.flush().unwrap();
let _ = compile_workspace_full(workspace, compile_options);
let debug_compile_stdin = None;
let _ = compile_workspace_full(workspace, compile_options, debug_compile_stdin);
for res in rx {
let debounced_events = res.map_err(|mut err| err.remove(0))?;

Expand All @@ -98,7 +100,8 @@ fn watch_workspace(workspace: &Workspace, compile_options: &CompileOptions) -> n
if noir_files_modified {
write!(screen, "{}{}", termion::cursor::Restore, termion::clear::AfterCursor).unwrap();
screen.flush().unwrap();
let _ = compile_workspace_full(workspace, compile_options);
let debug_compile_stdin = None;
let _ = compile_workspace_full(workspace, compile_options, debug_compile_stdin);
}
}

Expand All @@ -108,14 +111,13 @@ fn watch_workspace(workspace: &Workspace, compile_options: &CompileOptions) -> n
}

/// Parse all files in the workspace.
fn parse_workspace(workspace: &Workspace, debug_compile_stdin: bool) -> (FileManager, ParsedFiles) {
fn parse_workspace(
workspace: &Workspace,
debug_compile_stdin: Option<String>,
) -> (FileManager, ParsedFiles) {
let mut file_manager = workspace.new_file_manager();

if debug_compile_stdin {
let mut main_nr = String::new();
let stdin = std::io::stdin();
let mut stdin_handle = stdin.lock();
stdin_handle.read_to_string(&mut main_nr).expect("reading from stdin to succeed");
if let Some(main_nr) = debug_compile_stdin {
file_manager.add_file_with_source(Path::new("src/main.nr"), main_nr);
} else {
insert_all_files_for_workspace_into_file_manager(workspace, &mut file_manager);
Expand All @@ -127,12 +129,20 @@ fn parse_workspace(workspace: &Workspace, debug_compile_stdin: bool) -> (FileMan

/// Parse and compile the entire workspace, then report errors.
/// This is the main entry point used by all other commands that need compilation.
pub(super) fn compile_workspace_full(
pub fn compile_workspace_full(
workspace: &Workspace,
compile_options: &CompileOptions,
debug_compile_stdin: Option<String>, // use this String as STDIN if present
) -> Result<(), CliError> {
let (workspace_file_manager, parsed_files) =
parse_workspace(workspace, compile_options.debug_compile_stdin);
let mut debug_compile_stdin = debug_compile_stdin;
if compile_options.debug_compile_stdin && debug_compile_stdin.is_none() {
let mut main_nr = String::new();
let stdin = std::io::stdin();
let mut stdin_handle = stdin.lock();
stdin_handle.read_to_string(&mut main_nr).expect("reading from stdin to succeed");
debug_compile_stdin = Some(main_nr);
}
let (workspace_file_manager, parsed_files) = parse_workspace(workspace, debug_compile_stdin);

let compiled_workspace =
compile_workspace(&workspace_file_manager, &parsed_files, workspace, compile_options);
Expand Down Expand Up @@ -400,7 +410,7 @@ mod tests {

// This could be `.par_iter()` but then error messages are no longer reported
test_workspaces.iter().for_each(|workspace| {
let debug_compile_stdin = false;
let debug_compile_stdin = None;
let (file_manager, parsed_files) = parse_workspace(workspace, debug_compile_stdin);
let binary_packages = workspace.into_iter().filter(|package| package.is_binary());

Expand Down
3 changes: 2 additions & 1 deletion tooling/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ impl WorkspaceCommand for ExecuteCommand {

pub(crate) fn run(args: ExecuteCommand, workspace: Workspace) -> Result<(), CliError> {
// Compile the full workspace in order to generate any build artifacts.
compile_workspace_full(&workspace, &args.compile_options)?;
let debug_compile_stdin = None;
compile_workspace_full(&workspace, &args.compile_options, debug_compile_stdin)?;

let binary_packages = workspace.into_iter().filter(|package| package.is_binary());
for package in binary_packages {
Expand Down
3 changes: 2 additions & 1 deletion tooling/nargo_cli/src/cli/info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub(crate) fn run(mut args: InfoCommand, workspace: Workspace) -> Result<(), Cli
args.compile_options.force_brillig = true;
}
// Compile the full workspace in order to generate any build artifacts.
compile_workspace_full(&workspace, &args.compile_options)?;
let debug_compile_stdin = None;
compile_workspace_full(&workspace, &args.compile_options, debug_compile_stdin)?;

let binary_packages: Vec<(Package, ProgramArtifact)> = workspace
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use color_eyre::eyre;
use crate::errors::CliError;

mod check_cmd;
mod compile_cmd;
pub mod compile_cmd;
mod dap_cmd;
mod debug_cmd;
mod execute_cmd;
Expand Down Expand Up @@ -57,7 +57,7 @@ struct NargoCli {

#[non_exhaustive]
#[derive(Args, Clone, Debug)]
pub(crate) struct NargoConfig {
pub struct NargoConfig {
// REMINDER: Also change this flag in the LSP test lens if renamed
#[arg(long, hide = true, global = true, default_value = "./", value_parser = parse_path)]
program_dir: PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::PathBuf;
use thiserror::Error;

#[derive(Debug, Error)]
pub(crate) enum CliError {
pub enum CliError {
#[error("{0}")]
Generic(String),

Expand Down
5 changes: 5 additions & 0 deletions tooling/nargo_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// NOTE: this code should all be used in the 'bin' target
#![allow(dead_code)]

pub mod cli;
pub mod errors;
4 changes: 3 additions & 1 deletion tooling/nargo_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! This name was used because it sounds like `cargo` and
//! Noir Package Manager abbreviated is npm, which is already taken.

mod cli;
pub mod cli;
mod errors;

use std::env;
Expand All @@ -19,6 +19,8 @@ use tracing_subscriber::{EnvFilter, fmt::format::FmtSpan};

// TODO: Currently only used by benches.
use noir_artifact_cli as _;
// NOTE: Currently only used for fuzzing.
use nargo_cli as _;

const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml";

Expand Down
16 changes: 16 additions & 0 deletions tooling/nargo_fuzz_target/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "nargo_fuzz_target"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nargo.workspace = true
nargo_cli.workspace = true
noirc_driver.workspace = true
afl = "*"
Loading
Loading