Skip to content

Commit

Permalink
Merge branch 'master' into jf/add-pub
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Sep 21, 2023
2 parents 089b6fc + 2107ebc commit 0b06e50
Show file tree
Hide file tree
Showing 66 changed files with 1,299 additions and 405 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- ./compiler/integration-tests
- ./compiler/integration-tests/**
schedule:
- cron: "0 2 * * *" # Run nightly at 2 AM UTC

Expand Down
1 change: 1 addition & 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 @@ -14,6 +14,7 @@ members = [
# Crates related to tooling built ontop of the Noir compiler
"tooling/backend_interface",
"tooling/bb_abstraction_leaks",
"tooling/lsp",
"tooling/nargo",
"tooling/nargo_cli",
"tooling/nargo_toml",
Expand Down Expand Up @@ -71,3 +72,4 @@ url = "2.2.0"
wasm-bindgen = { version = "=0.2.86", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3.33"
base64 = "0.21.2"
fxhash = "0.2.1"
2 changes: 1 addition & 1 deletion compiler/fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cfg-if.workspace = true
rust-embed = "6.6.0"
serde.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies]
wasm-bindgen.workspace = true

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion compiler/fm/src/file_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(super) fn is_stdlib_asset(path: &Path) -> bool {
}

cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
if #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] {
use wasm_bindgen::{prelude::*, JsValue};

#[wasm_bindgen(module = "@noir-lang/source-resolver")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ test_cases.forEach((testInfo) => {

const noir_source_url = new URL(
`${base_relative_path}/${test_case}/src/main.nr`,
import.meta.url
import.meta.url,
);
const prover_toml_url = new URL(
`${base_relative_path}/${test_case}/Prover.toml`,
import.meta.url
import.meta.url,
);

const noir_source = await getFile(noir_source_url);
Expand Down Expand Up @@ -101,15 +101,15 @@ test_cases.forEach((testInfo) => {
try {
compressedByteCode = Uint8Array.from(
atob(compile_output.circuit),
(c) => c.charCodeAt(0)
(c) => c.charCodeAt(0),
);

solvedWitness = await executeCircuit(
compressedByteCode,
witnessMap,
() => {
throw Error("unexpected oracle");
}
},
);
} catch (e) {
expect(e, "Abi Encoding Step").to.not.be.an("error");
Expand All @@ -130,7 +130,7 @@ test_cases.forEach((testInfo) => {
await api.srsInitSrs(
new RawBuffer(crs.getG1Data()),
crs.numPoints,
new RawBuffer(crs.getG2Data())
new RawBuffer(crs.getG2Data()),
);

const acirComposer = await api.acirNewAcirComposer(CIRCUIT_SIZE);
Expand All @@ -140,22 +140,22 @@ test_cases.forEach((testInfo) => {
acirComposer,
acirUint8Array,
witnessUint8Array,
isRecursive
isRecursive,
);

// And this took ~5 minutes!
const verified = await api.acirVerifyProof(
acirComposer,
proof,
isRecursive
isRecursive,
);

expect(verified).to.be.true;
} catch (e) {
expect(e, "Proving and Verifying").to.not.be.an("error");
throw e;
}
}
},
);

suite.addTest(mochaTest);
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ acvm.workspace = true
fm.workspace = true
serde.workspace = true
base64.workspace = true
fxhash.workspace = true
17 changes: 13 additions & 4 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type CompilationResult<T> = Result<(T, Warnings), ErrorsAndWarnings>;
// with the restricted version which only uses one file
pub fn compile_file(context: &mut Context, root_file: &Path) -> CompilationResult<CompiledProgram> {
let crate_id = prepare_crate(context, root_file);
compile_main(context, crate_id, &CompileOptions::default())
compile_main(context, crate_id, &CompileOptions::default(), None)
}

/// Adds the file from the file system at `Path` to the crate graph as a root file
Expand Down Expand Up @@ -143,6 +143,7 @@ pub fn compile_main(
context: &mut Context,
crate_id: CrateId,
options: &CompileOptions,
cached_program: Option<CompiledProgram>,
) -> CompilationResult<CompiledProgram> {
let (_, warnings) = check_crate(context, crate_id, options.deny_warnings)?;

Expand All @@ -158,7 +159,7 @@ pub fn compile_main(
}
};

let compiled_program = compile_no_check(context, options, main)?;
let compiled_program = compile_no_check(context, options, main, cached_program)?;

if options.print_acir {
println!("Compiled ACIR for main (unoptimized):");
Expand Down Expand Up @@ -252,7 +253,7 @@ fn compile_contract_inner(
continue;
}

let function = match compile_no_check(context, options, function_id) {
let function = match compile_no_check(context, options, function_id, None) {
Ok(function) => function,
Err(new_error) => {
errors.push(new_error);
Expand Down Expand Up @@ -295,13 +296,21 @@ pub fn compile_no_check(
context: &Context,
options: &CompileOptions,
main_function: FuncId,
cached_program: Option<CompiledProgram>,
) -> Result<CompiledProgram, FileDiagnostic> {
let program = monomorphize(main_function, &context.def_interner);

let hash = fxhash::hash64(&program);
if let Some(cached_program) = cached_program {
if hash == cached_program.hash {
return Ok(cached_program);
}
}

let (circuit, debug, abi) =
create_circuit(context, program, options.show_ssa, options.show_brillig)?;

let file_map = filter_relevant_files(&[debug.clone()], &context.file_manager);

Ok(CompiledProgram { circuit, debug, abi, file_map })
Ok(CompiledProgram { hash, circuit, debug, abi, file_map })
}
6 changes: 6 additions & 0 deletions compiler/noirc_driver/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ use super::debug::DebugFile;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CompiledProgram {
/// Hash of the [`Program`][noirc_frontend::monomorphization::ast::Program] from which this [`CompiledProgram`]
/// was compiled.
///
/// Used to short-circuit compilation in the case of the source code not changing since the last compilation.
pub hash: u64,

#[serde(serialize_with = "serialize_circuit", deserialize_with = "deserialize_circuit")]
pub circuit: Circuit,
pub abi: noirc_abi::Abi,
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ noirc_frontend.workspace = true
noirc_errors.workspace = true
noirc_abi.workspace = true
acvm.workspace = true
fxhash = "0.2.1"
fxhash.workspace = true
iter-extended.workspace = true
thiserror.workspace = true
num-bigint = "0.4"
Expand Down
20 changes: 10 additions & 10 deletions compiler/noirc_frontend/src/ast/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;
use noirc_errors::Span;

use crate::{
token::{Attributes, PrimaryAttribute, SecondaryAttribute},
token::{Attributes, FunctionAttribute, SecondaryAttribute},
FunctionReturnType, Ident, Pattern, Visibility,
};

Expand Down Expand Up @@ -65,8 +65,8 @@ impl NoirFunction {
pub fn attributes(&self) -> &Attributes {
&self.def.attributes
}
pub fn primary_attribute(&self) -> Option<&PrimaryAttribute> {
self.def.attributes.primary.as_ref()
pub fn function_attribute(&self) -> Option<&FunctionAttribute> {
self.def.attributes.function.as_ref()
}
pub fn secondary_attributes(&self) -> &Vec<SecondaryAttribute> {
self.def.attributes.secondary.as_ref()
Expand All @@ -89,19 +89,19 @@ impl NoirFunction {
FunctionKind::LowLevel => {}
_ => return None,
}
assert!(self.primary_attribute().unwrap().is_foreign());
assert!(self.function_attribute().unwrap().is_foreign());
Some(&self.def)
}
}

impl From<FunctionDefinition> for NoirFunction {
fn from(fd: FunctionDefinition) -> Self {
// The function type is determined by the existence of a primary attribute
let kind = match fd.attributes.primary {
Some(PrimaryAttribute::Builtin(_)) => FunctionKind::Builtin,
Some(PrimaryAttribute::Foreign(_)) => FunctionKind::LowLevel,
Some(PrimaryAttribute::Test { .. }) => FunctionKind::Normal,
Some(PrimaryAttribute::Oracle(_)) => FunctionKind::Oracle,
// The function type is determined by the existence of a function attribute
let kind = match fd.attributes.function {
Some(FunctionAttribute::Builtin(_)) => FunctionKind::Builtin,
Some(FunctionAttribute::Foreign(_)) => FunctionKind::LowLevel,
Some(FunctionAttribute::Test { .. }) => FunctionKind::Normal,
Some(FunctionAttribute::Oracle(_)) => FunctionKind::Oracle,
None => FunctionKind::Normal,
};

Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl UnresolvedTypeExpression {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// Represents whether the parameter is public or known only to the prover.
pub enum Visibility {
Public,
Expand All @@ -277,7 +277,7 @@ impl std::fmt::Display for Visibility {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// Represents whether the return value should compromise of unique witness indices such that no
/// index occurs within the program's abi more than once.
///
Expand Down
6 changes: 4 additions & 2 deletions compiler/noirc_frontend/src/ast/structure.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::fmt::Display;

use crate::{Ident, UnresolvedGenerics, UnresolvedType};
use crate::{token::SecondaryAttribute, Ident, UnresolvedGenerics, UnresolvedType};
use iter_extended::vecmap;
use noirc_errors::Span;

/// Ast node for a struct
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NoirStruct {
pub name: Ident,
pub attributes: Vec<SecondaryAttribute>,
pub generics: UnresolvedGenerics,
pub fields: Vec<(Ident, UnresolvedType)>,
pub span: Span,
Expand All @@ -16,11 +17,12 @@ pub struct NoirStruct {
impl NoirStruct {
pub fn new(
name: Ident,
attributes: Vec<SecondaryAttribute>,
generics: Vec<Ident>,
fields: Vec<(Ident, UnresolvedType)>,
span: Span,
) -> NoirStruct {
NoirStruct { name, generics, fields, span }
NoirStruct { name, attributes, generics, fields, span }
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::hir::def_collector::dc_crate::DefCollector;
use crate::hir::Context;
use crate::node_interner::{FuncId, NodeInterner};
use crate::parser::{parse_program, ParsedModule};
use crate::token::{PrimaryAttribute, TestScope};
use crate::token::{FunctionAttribute, TestScope};
use arena::{Arena, Index};
use fm::{FileId, FileManager};
use noirc_errors::{FileDiagnostic, Location};
Expand Down Expand Up @@ -140,8 +140,8 @@ impl CrateDefMap {
module.value_definitions().filter_map(|id| {
if let Some(func_id) = id.as_function() {
let attributes = interner.function_attributes(&func_id);
match &attributes.primary {
Some(PrimaryAttribute::Test(scope)) => {
match &attributes.function {
Some(FunctionAttribute::Test(scope)) => {
let location = interner.function_meta(&func_id).name.location;
Some(TestFunction::new(func_id, scope.clone(), location))
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use crate::hir_def::expr::{
HirIfExpression, HirIndexExpression, HirInfixExpression, HirLambda, HirLiteral,
HirMemberAccess, HirMethodCallExpression, HirPrefixExpression,
};

use crate::hir_def::traits::{Trait, TraitConstraint};
use crate::token::PrimaryAttribute;
use crate::token::FunctionAttribute;
use regex::Regex;
use std::collections::{BTreeMap, HashSet};
use std::rc::Rc;
Expand Down Expand Up @@ -737,7 +738,7 @@ impl<'a> Resolver<'a> {
self.push_err(ResolverError::DistinctNotAllowed { ident: func.name_ident().clone() });
}

if matches!(attributes.primary, Some(PrimaryAttribute::Test { .. }))
if matches!(attributes.function, Some(FunctionAttribute::Test { .. }))
&& !parameters.is_empty()
{
self.push_err(ResolverError::TestFunctionHasParameters {
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir_def/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl HirExpression {
}

/// Corresponds to a variable in the source code
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct HirIdent {
pub location: Location,
pub id: DefinitionId,
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir_def/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct HirAssignStatement {
#[derive(Debug, Clone)]
pub struct HirConstrainStatement(pub ExprId, pub FileId, pub Option<String>);

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Hash)]
pub enum HirPattern {
Identifier(HirIdent),
Mutable(Box<HirPattern>, Span),
Expand Down
Loading

0 comments on commit 0b06e50

Please sign in to comment.