Skip to content

Commit

Permalink
Merge branch 'master' into rk/directed-graph-ssa-check
Browse files Browse the repository at this point in the history
  • Loading branch information
rkarabut authored Dec 11, 2024
2 parents 4034a1d + f9abf72 commit 329a131
Show file tree
Hide file tree
Showing 31 changed files with 489 additions and 219 deletions.
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.

5 changes: 5 additions & 0 deletions acvm-repo/acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ pub fn compile<F: AcirField>(
acir: Circuit<F>,
expression_width: ExpressionWidth,
) -> (Circuit<F>, AcirTransformationMap) {
if MAX_OPTIMIZER_PASSES == 0 {
let acir_opcode_positions = (0..acir.opcodes.len()).collect::<Vec<_>>();
let transformation_map = AcirTransformationMap::new(&acir_opcode_positions);
return (acir, transformation_map);
}
let mut pass = 0;
let mut prev_opcodes_hash = fxhash::hash64(&acir.opcodes);
let mut prev_acir = acir;
Expand Down
54 changes: 50 additions & 4 deletions acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ impl<F: AcirField> MergeExpressionsOptimizer<F> {
self.resolved_blocks.clear();

// Keep track, for each witness, of the gates that use it
let circuit_inputs = circuit.circuit_arguments();
let circuit_io: BTreeSet<Witness> =
circuit.circuit_arguments().union(&circuit.public_inputs().0).cloned().collect();

let mut used_witness: BTreeMap<Witness, BTreeSet<usize>> = BTreeMap::new();
for (i, opcode) in circuit.opcodes.iter().enumerate() {
let witnesses = self.witness_inputs(opcode);
if let Opcode::MemoryInit { block_id, .. } = opcode {
self.resolved_blocks.insert(*block_id, witnesses.clone());
}
for w in witnesses {
// We do not simplify circuit inputs
if !circuit_inputs.contains(&w) {
// We do not simplify circuit inputs and outputs
if !circuit_io.contains(&w) {
used_witness.entry(w).or_default().insert(i);
}
}
Expand Down Expand Up @@ -102,7 +104,7 @@ impl<F: AcirField> MergeExpressionsOptimizer<F> {
let mut witness_list = CircuitSimulator::expr_wit(&expr_use);
witness_list.extend(CircuitSimulator::expr_wit(&expr_define));
for w2 in witness_list {
if !circuit_inputs.contains(&w2) {
if !circuit_io.contains(&w2) {
used_witness.entry(w2).and_modify(|v| {
v.insert(target);
v.remove(&source);
Expand Down Expand Up @@ -326,6 +328,50 @@ mod tests {
check_circuit(circuit);
}

#[test]
fn does_not_eliminate_witnesses_returned_from_circuit() {
let opcodes = vec![
Opcode::AssertZero(Expression {
mul_terms: vec![(FieldElement::from(-1i128), Witness(0), Witness(0))],
linear_combinations: vec![(FieldElement::from(1i128), Witness(1))],
q_c: FieldElement::zero(),
}),
Opcode::AssertZero(Expression {
mul_terms: Vec::new(),
linear_combinations: vec![
(FieldElement::from(-1i128), Witness(1)),
(FieldElement::from(1i128), Witness(2)),
],
q_c: FieldElement::zero(),
}),
];
// Witness(1) could be eliminated because it's only used by 2 opcodes.

let mut private_parameters = BTreeSet::new();
private_parameters.insert(Witness(0));

let mut return_values = BTreeSet::new();
return_values.insert(Witness(1));
return_values.insert(Witness(2));

let circuit = Circuit {
current_witness_index: 2,
expression_width: ExpressionWidth::Bounded { width: 4 },
opcodes,
private_parameters,
public_parameters: PublicInputs::default(),
return_values: PublicInputs(return_values),
assert_messages: Default::default(),
};

let mut merge_optimizer = MergeExpressionsOptimizer::new();
let acir_opcode_positions = vec![0; 20];
let (opcodes, _) =
merge_optimizer.eliminate_intermediate_variable(&circuit, acir_opcode_positions);

assert_eq!(opcodes.len(), 2);
}

#[test]
fn does_not_attempt_to_merge_into_previous_opcodes() {
let opcodes = vec![
Expand Down
1 change: 0 additions & 1 deletion acvm-repo/acvm/src/pwg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver<F>> ACVM<'a, F, B> {

pub fn solve_opcode(&mut self) -> ACVMStatus<F> {
let opcode = &self.opcodes[self.instruction_pointer];

let resolution = match opcode {
Opcode::AssertZero(expr) => ExpressionSolver::solve(&mut self.witness_map, expr),
Opcode::BlackBoxFuncCall(bb_func) => blackbox::solve(
Expand Down
10 changes: 9 additions & 1 deletion compiler/noirc_frontend/src/parser/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<'a> Parser<'a> {
typ
} else {
self.expected_label(ParsingRuleLabel::Type);
self.unspecified_type_at_previous_token_end()
UnresolvedTypeData::Error.with_span(self.span_at_previous_token_end())
}
}

Expand Down Expand Up @@ -660,6 +660,14 @@ mod tests {
assert!(unconstrained);
}

#[test]
fn parses_function_type_with_colon_in_parameter() {
let src = "fn(value: T) -> Field";
let mut parser = Parser::for_str(src);
let _ = parser.parse_type_or_error();
assert!(!parser.errors.is_empty());
}

#[test]
fn parses_trait_as_type_no_generics() {
let src = "impl foo::Bar";
Expand Down
13 changes: 11 additions & 2 deletions docs/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ sidebar_position: 0

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<img src={require("@site/static/img/logo.png").default} style={{display: "block", width: "50%", margin: "2rem auto"}} alt="Noir Logo" />
import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';

<ThemedImage
sources={{
light: useBaseUrl("/img/logoDark.png"),
dark: useBaseUrl("/img/logo.png"),
}}
style={{display: "block", width: "50%", margin: "2rem auto"}}
alt="Noir Logo"
/>

Noir is an open-source Domain-Specific Language for safe and seamless construction of privacy-preserving Zero-Knowledge programs, requiring no previous knowledge on the underlying mathematics or cryptography.

Expand Down
6 changes: 5 additions & 1 deletion docs/docs/noir/modules_packages_crates/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ members = ["crates/a", "crates/b"]
default-member = "crates/a"
```

`members` indicates which packages are included in the workspace. As such, all member packages of a workspace will be processed when the `--workspace` flag is used with various commands or if a `default-member` is not specified.
`members` indicates which packages are included in the workspace. As such, all member packages of a workspace will be processed when the `--workspace` flag is used with various commands or if a `default-member` is not specified. The `--package` option can be used to limit
the scope of some commands to a specific member of the workspace; otherwise these commands run on the package nearest on the path to the
current directory where `nargo` was invoked.

`default-member` indicates which package various commands process by default.

Libraries can be defined in a workspace. Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml.

Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml.

Please note that nesting regular packages is not supported: certain commands work on the workspace level and will use the topmost Nargo.toml file they can find on the path; unless this is a workspace configuration with `members`, the command might run on some unintended package.
4 changes: 2 additions & 2 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default {
navbar: {
logo: {
alt: 'Noir Logo',
src: 'img/logo.svg',
srcDark: 'img/logoDark.svg',
src: 'img/logoDark.svg',
srcDark: 'img/logo.svg',
href: '/',
},
items: [
Expand Down
Binary file modified docs/static/img/favicon.ico
Binary file not shown.
Binary file modified docs/static/img/homepage_header_pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/static/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 14 additions & 29 deletions docs/static/img/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/img/logoDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 13 additions & 29 deletions docs/static/img/logoDark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions docs/versioned_docs/version-v0.36.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ sidebar_position: 0

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<img src={require("@site/static/img/logo.png").default} style={{display: "block", width: "50%", margin: "2rem auto"}} alt="Noir Logo" />
import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';

<ThemedImage
sources={{
light: useBaseUrl("/img/logoDark.png"),
dark: useBaseUrl("/img/logo.png"),
}}
style={{display: "block", width: "50%", margin: "2rem auto"}}
alt="Noir Logo"
/>

Noir is an open-source Domain-Specific Language for safe and seamless construction of privacy-preserving Zero-Knowledge programs, requiring no previous knowledge on the underlying mathematics or cryptography.

Expand Down
13 changes: 11 additions & 2 deletions docs/versioned_docs/version-v0.37.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ sidebar_position: 0

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<img src={require("@site/static/img/logo.png").default} style={{display: "block", width: "50%", margin: "2rem auto"}} alt="Noir Logo" />
import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';

<ThemedImage
sources={{
light: useBaseUrl("/img/logoDark.png"),
dark: useBaseUrl("/img/logo.png"),
}}
style={{display: "block", width: "50%", margin: "2rem auto"}}
alt="Noir Logo"
/>

Noir is an open-source Domain-Specific Language for safe and seamless construction of privacy-preserving Zero-Knowledge programs, requiring no previous knowledge on the underlying mathematics or cryptography.

Expand Down
13 changes: 11 additions & 2 deletions docs/versioned_docs/version-v0.38.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ sidebar_position: 0

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<img src={require("@site/static/img/logo.png").default} style={{display: "block", width: "50%", margin: "2rem auto"}} alt="Noir Logo" />
import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';

<ThemedImage
sources={{
light: useBaseUrl("/img/logoDark.png"),
dark: useBaseUrl("/img/logo.png"),
}}
style={{display: "block", width: "50%", margin: "2rem auto"}}
alt="Noir Logo"
/>

Noir is an open-source Domain-Specific Language for safe and seamless construction of privacy-preserving Zero-Knowledge programs, requiring no previous knowledge on the underlying mathematics or cryptography.

Expand Down
13 changes: 11 additions & 2 deletions docs/versioned_docs/version-v0.39.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ sidebar_position: 0

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<img src={require("@site/static/img/logo.png").default} style={{display: "block", width: "50%", margin: "2rem auto"}} alt="Noir Logo" />
import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';

<ThemedImage
sources={{
light: useBaseUrl("/img/logoDark.png"),
dark: useBaseUrl("/img/logo.png"),
}}
style={{display: "block", width: "50%", margin: "2rem auto"}}
alt="Noir Logo"
/>

Noir is an open-source Domain-Specific Language for safe and seamless construction of privacy-preserving Zero-Knowledge programs, requiring no previous knowledge on the underlying mathematics or cryptography.

Expand Down
13 changes: 11 additions & 2 deletions docs/versioned_docs/version-v1.0.0-beta.0/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ sidebar_position: 0

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<img src={require("@site/static/img/logo.png").default} style={{display: "block", width: "50%", margin: "2rem auto"}} alt="Noir Logo" />
import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';

<ThemedImage
sources={{
light: useBaseUrl("/img/logoDark.png"),
dark: useBaseUrl("/img/logo.png"),
}}
style={{display: "block", width: "50%", margin: "2rem auto"}}
alt="Noir Logo"
/>

Noir is an open-source Domain-Specific Language for safe and seamless construction of privacy-preserving Zero-Knowledge programs, requiring no previous knowledge on the underlying mathematics or cryptography.

Expand Down
Binary file modified noir-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 329a131

Please sign in to comment.