Skip to content

Commit

Permalink
Merge branch 'master' into new-docs-version-v0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Savio-Sou authored Nov 6, 2023
2 parents 82849d1 + c7da833 commit 624a4c9
Show file tree
Hide file tree
Showing 136 changed files with 1,842 additions and 629 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/auto-pr-rebuild-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Check if artifacts should be published
runs-on: ubuntu-22.04
outputs:
publish: ${{ steps.check.outputs.publish }}
publish: ${{ steps.check.outputs.result }}

steps:
- name: Check if artifacts should be published
Expand All @@ -22,20 +22,24 @@ jobs:
script: |
const { REF_NAME } = process.env;
if (REF_NAME == "master") {
console.log(`publish = true`)
return true;
}
const labels = context.payload.pull_request.labels.map(label => label.name);
return labels.includes('publish-acir');
const publish = labels.includes('publish-acir');
console.log(`publish = ${publish}`)
return publish;
result-encoding: string
env:
REF_NAME: ${{ github.ref_name }}

build-nargo:
name: Build nargo binary
if: ${{ needs.check-artifacts-requested.outputs.publish == 'true' }}
runs-on: ubuntu-22.04
needs: [check-artifacts-requested]
if: ${{ needs.check-artifacts-requested.outputs.publish == true }}
strategy:
matrix:
target: [x86_64-unknown-linux-gnu]
Expand Down Expand Up @@ -76,7 +80,7 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Download nargo binary
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -112,7 +116,6 @@ jobs:
if: ${{ github.ref_name }} == "master"
run: |
git diff --quiet tooling/nargo_cli/tests/acir_artifacts/ || echo "::set-output name=changes::true"
- name: Create or Update PR
if: steps.check_changes.outputs.changes == 'true'
Expand Down
31 changes: 29 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build docs

on:
pull_request:
workflow_dispatch:

jobs:
add_label:
Expand Down Expand Up @@ -62,11 +63,37 @@ jobs:
with:
node-version: '18'

- name: Install wasm-bindgen-cli
uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@0.2.86

- name: Install wasm-opt
run: |
npm i wasm-opt -g
- name: Install dependencies
run: yarn


- name: Build acvm_js
run: yarn workspace @noir-lang/acvm_js build

- name: Build noirc_abi
run: yarn workspace @noir-lang/noirc_abi build

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

- name: Build barretenberg wrapper
run: yarn workspace @noir-lang/backend_barretenberg build

- name: Run noir_js
run: |
yarn workspace @noir-lang/noir_js build
- name: Build docs
run: yarn workspace docs build
run:
yarn workspace docs build

- name: Remove pre-releases
working-directory: docs
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ jobs:
if: ${{ inputs.tag != '' }}
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}

- name: Create new branch
run: |
git checkout -b new-docs-version-${{ github.event.inputs.tag }}
- name: Setup Node.js
uses: actions/setup-node@v2
with:
Expand All @@ -33,12 +38,33 @@ jobs:
- name: Cut a new version
working-directory: ./docs
run: yarn docusaurus docs:version ${{ inputs.tag }}

- name: Remove pre-releases
id: get_version
run: |
cd docs && yarn setStable
- name: Commit new documentation version
run: |
git config --local user.name 'signorecello'
git config --local user.email 'github@zepedro.me'
git add .
git commit -m "chore(docs): cut new docs version for tag ${{ github.event.inputs.tag }}"
- name: Push changes to new branch
run: git push origin new-docs-version-${{ github.event.inputs.tag }}

- name: Create Pull Request
run: |
gh pr create \
--title "chore(docs): docs for ${{ github.event.inputs.tag }}" \
--body "Updates documentation to new version for tag ${{ github.event.inputs.tag }}." \
--base master \
--head new-docs-version-${{ github.event.inputs.tag }} \
--label documentation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build docs
run: yarn workspace docs build

Expand All @@ -55,3 +81,4 @@ jobs:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1

22 changes: 14 additions & 8 deletions compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ impl From<SsaReport> for FileDiagnostic {
fn from(error: SsaReport) -> FileDiagnostic {
match error {
SsaReport::Warning(warning) => {
let InternalWarning::ReturnConstant { ref call_stack } = warning;
let call_stack = vecmap(call_stack, |location| *location);
let file_id = call_stack.last().map(|location| location.file).unwrap_or_default();
let message = warning.to_string();
let (secondary_message, call_stack) = match warning {
InternalWarning::ReturnConstant { call_stack } => {
("constant value".to_string(), call_stack)
},
InternalWarning::VerifyProof { call_stack } => {
("verify_proof(...) aggregates data for the verifier, the actual verification will be done when the full proof is verified using nargo verify. nargo prove may generate an invalid proof if bad data is used as input to verify_proof".to_string(), call_stack)
},
};
let call_stack = vecmap(call_stack, |location| location);
let file_id = call_stack.last().map(|location| location.file).unwrap_or_default();
let location = call_stack.last().expect("Expected RuntimeError to have a location");
let diagnostic = Diagnostic::simple_warning(
message,
"constant value".to_string(),
location.span,
);
let diagnostic =
Diagnostic::simple_warning(message, secondary_message, location.span);
diagnostic.in_file(file_id).with_call_stack(call_stack)
}
}
Expand All @@ -83,6 +87,8 @@ impl From<SsaReport> for FileDiagnostic {
pub enum InternalWarning {
#[error("Returning a constant value is not allowed")]
ReturnConstant { call_stack: CallStack },
#[error("Calling std::verify_proof(...) does not verify a proof")]
VerifyProof { call_stack: CallStack },
}

#[derive(Debug, PartialEq, Eq, Clone, Error)]
Expand Down
48 changes: 38 additions & 10 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
//! This module heavily borrows from Cranelift
#![allow(dead_code)]

use std::collections::BTreeSet;
use std::{
collections::{BTreeMap, BTreeSet},
ops::Range,
};

use crate::errors::{RuntimeError, SsaReport};
use crate::{
brillig::Brillig,
errors::{RuntimeError, SsaReport},
};
use acvm::acir::{
circuit::{Circuit, PublicInputs},
native_types::Witness,
Expand Down Expand Up @@ -39,7 +45,8 @@ pub(crate) fn optimize_into_acir(
print_brillig_trace: bool,
) -> Result<GeneratedAcir, RuntimeError> {
let abi_distinctness = program.return_distinctness;
let ssa = SsaBuilder::new(program, print_ssa_passes)?

let ssa_builder = SsaBuilder::new(program, print_ssa_passes)?
.run_pass(Ssa::defunctionalize, "After Defunctionalization:")
.run_pass(Ssa::inline_functions, "After Inlining:")
// Run mem2reg with the CFG separated into blocks
Expand All @@ -56,10 +63,17 @@ pub(crate) fn optimize_into_acir(
// Run mem2reg once more with the flattened CFG to catch any remaining loads/stores
.run_pass(Ssa::mem2reg, "After Mem2Reg:")
.run_pass(Ssa::fold_constants, "After Constant Folding:")
.run_pass(Ssa::dead_instruction_elimination, "After Dead Instruction Elimination:")
.run_pass(Ssa::dead_instruction_elimination, "After Dead Instruction Elimination:");

let brillig = ssa_builder.to_brillig(print_brillig_trace);

// Split off any passes the are not necessary for Brillig generation but are necessary for ACIR generation.
// We only need to fill out nested slices as we need to have a known length when dealing with memory operations
// in ACIR gen while this is not necessary in the Brillig IR.
let ssa = ssa_builder
.run_pass(Ssa::fill_internal_slices, "After Fill Internal Slice Dummy Data:")
.finish();

let brillig = ssa.to_brillig(print_brillig_trace);
let last_array_uses = ssa.find_last_array_uses();
ssa.into_acir(brillig, abi_distinctness, &last_array_uses)
}
Expand Down Expand Up @@ -87,14 +101,12 @@ pub fn create_circuit(
..
} = generated_acir;

let abi = gen_abi(context, func_sig, &input_witnesses, return_witnesses.clone());
let abi = gen_abi(context, func_sig, input_witnesses, return_witnesses.clone());
let public_abi = abi.clone().public_abi();

let public_parameters =
PublicInputs(public_abi.param_witnesses.values().flatten().copied().collect());
let public_parameters = PublicInputs(tree_to_set(&public_abi.param_witnesses));

let all_parameters: BTreeSet<Witness> =
abi.param_witnesses.values().flatten().copied().collect();
let all_parameters: BTreeSet<Witness> = tree_to_set(&abi.param_witnesses);
let private_parameters = all_parameters.difference(&public_parameters.0).copied().collect();

let return_values = PublicInputs(return_witnesses.into_iter().collect());
Expand Down Expand Up @@ -155,10 +167,26 @@ impl SsaBuilder {
Ok(self.print(msg))
}

fn to_brillig(&self, print_brillig_trace: bool) -> Brillig {
self.ssa.to_brillig(print_brillig_trace)
}

fn print(self, msg: &str) -> Self {
if self.print_ssa_passes {
println!("{msg}\n{}", self.ssa);
}
self
}
}

// Flatten the witnesses in the map into a BTreeSet
fn tree_to_set(input: &BTreeMap<String, Vec<Range<Witness>>>) -> BTreeSet<Witness> {
let mut result = BTreeSet::new();
for range in input.values().flatten() {
for i in range.start.witness_index()..range.end.witness_index() {
result.insert(Witness(i));
}
}

result
}
30 changes: 24 additions & 6 deletions compiler/noirc_evaluator/src/ssa/abi_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use noirc_frontend::{
},
node_interner::NodeInterner,
};
use std::ops::Range;

/// Attempts to retrieve the name of this parameter. Returns None
/// if this parameter is a tuple or struct pattern.
Expand Down Expand Up @@ -38,7 +39,7 @@ pub fn into_abi_params(context: &Context, params: Vec<Param>) -> Vec<AbiParamete
pub(crate) fn gen_abi(
context: &Context,
func_sig: FunctionSignature,
input_witnesses: &[Witness],
input_witnesses: Vec<Range<Witness>>,
return_witnesses: Vec<Witness>,
) -> Abi {
let (parameters, return_type) = func_sig;
Expand All @@ -52,16 +53,33 @@ pub(crate) fn gen_abi(
// parameter's constituent values live.
fn param_witnesses_from_abi_param(
abi_params: &Vec<AbiParameter>,
input_witnesses: &[Witness],
) -> BTreeMap<String, Vec<Witness>> {
input_witnesses: Vec<Range<Witness>>,
) -> BTreeMap<String, Vec<Range<Witness>>> {
let mut idx = 0_usize;
if input_witnesses.is_empty() {
return BTreeMap::new();
}
let mut processed_range = input_witnesses[idx].start.witness_index();

btree_map(abi_params, |param| {
let num_field_elements_needed = param.typ.field_count();
let mut wit = Vec::new();
for _ in 0..num_field_elements_needed {
wit.push(input_witnesses[idx]);
idx += 1;
let mut processed_fields = 0;
while processed_fields < num_field_elements_needed {
let end = input_witnesses[idx].end.witness_index();
if num_field_elements_needed <= end - processed_range {
wit.push(
Witness(processed_range)..Witness(processed_range + num_field_elements_needed),
);
processed_range += num_field_elements_needed;
processed_fields += num_field_elements_needed;
} else {
// consume the current range
wit.push(Witness(processed_range)..input_witnesses[idx].end);
processed_fields += end - processed_range;
idx += 1;
processed_range = input_witnesses[idx].start.witness_index();
}
}
(param.name.clone(), wit)
})
Expand Down
Loading

0 comments on commit 624a4c9

Please sign in to comment.