Skip to content

Commit

Permalink
Merge branch 'master' into tf/use-debug-artifacts
Browse files Browse the repository at this point in the history
* master:
  chore: Move tooling related items into their own directory (#2644)
  chore: add `CompilationResult` helper type (#2639)
  fix: initialise arrays returned by brillig (#2048)
  • Loading branch information
TomAFrench committed Sep 11, 2023
2 parents a49bc88 + bc53432 commit 5cdba2e
Show file tree
Hide file tree
Showing 1,109 changed files with 141 additions and 97 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/abi_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ jobs:
- name: Set up test environment
uses: ./.github/actions/setup
with:
working-directory: ./crates/noirc_abi_wasm
working-directory: ./tooling/noirc_abi_wasm

- name: Run node tests
working-directory: ./crates/noirc_abi_wasm
run: yarn test
working-directory: ./tooling/noirc_abi_wasm
run: yarn install && yarn test

noirc-abi-wasm-test-browser:
needs: [noirc-abi-wasm-build]
Expand All @@ -110,7 +110,7 @@ jobs:
path: ./result

- name: Query playwright version
working-directory: ./crates/noirc_abi_wasm
working-directory: ./tooling/noirc_abi_wasm
run: echo "PLAYWRIGHT_VERSION=$(yarn info @web/test-runner-playwright --json | jq .children.Version)" >> $GITHUB_ENV

- name: Cache playwright binaries
Expand All @@ -124,15 +124,15 @@ jobs:
- name: Set up test environment
uses: ./.github/actions/setup
with:
working-directory: ./crates/noirc_abi_wasm
working-directory: ./tooling/noirc_abi_wasm

- name: Install playwright deps
if: steps.playwright-cache.outputs.cache-hit != 'true'
working-directory: ./crates/noirc_abi_wasm
working-directory: ./tooling/noirc_abi_wasm
run: |
npx playwright install
npx playwright install-deps
- name: Run browser tests
working-directory: ./crates/noirc_abi_wasm
run: yarn test:browser
working-directory: ./tooling/noirc_abi_wasm
run: yarn install && yarn test:browser
12 changes: 6 additions & 6 deletions .github/workflows/release-source-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v4

- name: Bump version
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
id: bump_version
run: |
if [ -z "${{ github.event.inputs.version }}" ]; then
Expand All @@ -27,15 +27,15 @@ jobs:
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Install dependencies
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
run: npm install

- name: Build noir-source-resolver
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
run: npm run build

- name: Publish to NPM
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
Expand All @@ -47,7 +47,7 @@ jobs:
- name: Commit updates
run: |
git add crates/source-resolver/package-lock.json
git add crates/source-resolver/package.json
git add compiler/source-resolver/package-lock.json
git add compiler/source-resolver/package.json
git commit -m "chore: Update source-resolver to ${{ env.NEW_VERSION }}"
git push
4 changes: 2 additions & 2 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ jobs:
retention-days: 3

- name: Install `integration-tests` dependencies
working-directory: ./crates/integration-tests
working-directory: ./compiler/integration-tests
run: yarn install

- name: Run `integration-tests`
working-directory: ./crates/integration-tests
working-directory: ./compiler/integration-tests
run: |
yarn test:browser
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test-source-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Test Source Resolver
on:
push:
paths:
- "crates/source-resolver/**"
- "compiler/source-resolver/**"
pull_request:
paths:
- "crates/source-resolver/**"
- "compiler/source-resolver/**"

jobs:
test:
Expand All @@ -17,13 +17,13 @@ jobs:
uses: actions/checkout@v3

- name: Install dependencies
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
run: npm install

- name: Build noir-source-resolver
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
run: npm run build

- name: Run tests
working-directory: ./crates/source-resolver
working-directory: ./compiler/source-resolver
run: npm run test
12 changes: 6 additions & 6 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
uses: actions/download-artifact@v3
with:
name: noir_wasm
path: ./crates/wasm/result
path: ./compiler/wasm/result

- name: Download nargo binary
uses: actions/download-artifact@v3
Expand All @@ -140,7 +140,7 @@ jobs:
path: ./nargo

- name: Compile test program with Nargo CLI
working-directory: ./crates/wasm/noir-script
working-directory: ./compiler/wasm/noir-script
run: |
nargo_binary=${{ github.workspace }}/nargo/nargo
chmod +x $nargo_binary
Expand All @@ -149,20 +149,20 @@ jobs:
- name: Set up test environment
uses: ./.github/actions/setup
with:
working-directory: ./crates/wasm
working-directory: ./compiler/wasm

- name: Install dependencies
working-directory: ./crates/wasm
working-directory: ./compiler/wasm
run: yarn install

- name: Install playwright deps
working-directory: ./crates/wasm
working-directory: ./compiler/wasm
run: |
npx playwright install
npx playwright install-deps
- name: Run tests
working-directory: ./crates/wasm
working-directory: ./compiler/wasm
run: |
yarn test:browser
yarn test:node
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ node_modules
pkg/

# Source resolver
crates/source-resolver/node_modules
crates/source-resolver/lib
crates/source-resolver/lib-node
compiler/source-resolver/node_modules
compiler/source-resolver/lib
compiler/source-resolver/lib-node

# Nix stuff
**/outputs
Expand All @@ -25,8 +25,8 @@ result
*.vk
**/Verifier.toml
**/target
!crates/nargo_cli/tests/acir_artifacts/*/target
!crates/nargo_cli/tests/acir_artifacts/*/target/witness.gz
!tooling/nargo_cli/tests/acir_artifacts/*/target
!tooling/nargo_cli/tests/acir_artifacts/*/target/witness.gz

# Github Actions scratch space
# This gives a location to download artifacts into the repository in CI without making git dirty.
Expand Down
67 changes: 36 additions & 31 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[workspace]

members = [
"crates/acvm_backend_barretenberg",
"crates/noirc_evaluator",
"crates/noirc_frontend",
"crates/noirc_errors",
"crates/noirc_driver",
"crates/noirc_printable_type",
"crates/nargo",
"crates/nargo_cli",
"crates/nargo_toml",
"crates/fm",
"crates/arena",
"crates/noirc_abi",
"crates/noirc_abi_wasm",
"crates/iter-extended",
"crates/wasm",
"compiler/noirc_evaluator",
"compiler/noirc_frontend",
"compiler/noirc_errors",
"compiler/noirc_driver",
"compiler/noirc_printable_type",
"compiler/fm",
"compiler/wasm",
# Utility crates used by the Noir compiler
"compiler/utils/arena",
"compiler/utils/iter-extended",
# Crates related to tooling built ontop of the Noir compiler
"tooling/acvm_backend_barretenberg",
"tooling/nargo",
"tooling/nargo_cli",
"tooling/nargo_toml",
"tooling/noirc_abi",
"tooling/noirc_abi_wasm",
]
default-members = ["crates/nargo_cli"]
default-members = ["tooling/nargo_cli"]
resolver = "2"

[workspace.package]
Expand All @@ -30,26 +32,29 @@ rust-version = "1.66"

[workspace.dependencies]
acvm = "0.26.0"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
nargo = { path = "crates/nargo" }
nargo_cli = { path = "crates/nargo_cli" }
nargo_toml = { path = "crates/nargo_toml" }
noir_lsp = { path = "crates/lsp" }
noirc_abi = { path = "crates/noirc_abi" }
noirc_driver = { path = "crates/noirc_driver" }
noirc_errors = { path = "crates/noirc_errors" }
noirc_evaluator = { path = "crates/noirc_evaluator" }
noirc_frontend = { path = "crates/noirc_frontend" }
noirc_printable_type = { path = "crates/noirc_printable_type" }
noir_wasm = { path = "crates/wasm" }
arena = { path = "compiler/utils/arena" }
fm = { path = "compiler/fm" }
iter-extended = { path = "compiler/utils/iter-extended" }
nargo = { path = "tooling/nargo" }
nargo_cli = { path = "tooling/nargo_cli" }
nargo_toml = { path = "tooling/nargo_toml" }
noir_lsp = { path = "tooling/lsp" }
noirc_abi = { path = "tooling/noirc_abi" }
noirc_driver = { path = "compiler/noirc_driver" }
noirc_errors = { path = "compiler/noirc_errors" }
noirc_evaluator = { path = "compiler/noirc_evaluator" }
noirc_frontend = { path = "compiler/noirc_frontend" }
noirc_printable_type = { path = "compiler/noirc_printable_type" }
noir_wasm = { path = "compiler/wasm" }
cfg-if = "1.0.0"
clap = { version = "4.3.19", features = ["derive"] }
codespan = { version = "0.11.1", features = ["serialization"] }
codespan-lsp = "0.11.1"
codespan-reporting = "0.11.1"
chumsky = { git = "https://github.com/jfecher/chumsky", rev = "ad9d312", default-features = false, features = ["ahash", "std"] }
chumsky = { git = "https://github.com/jfecher/chumsky", rev = "ad9d312", default-features = false, features = [
"ahash",
"std",
] }
dirs = "4"
lsp-types = "0.94"
serde = { version = "1.0.136", features = ["derive"] }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const CIRCUIT_SIZE = 2 ** 19;

const test_cases = [
{
case: "crates/nargo_cli/tests/execution_success/1_mul"
case: "tooling/nargo_cli/tests/execution_success/1_mul"
},
{
case: "crates/nargo_cli/tests/execution_success/double_verify_proof"
case: "tooling/nargo_cli/tests/execution_success/double_verify_proof"
}
];

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions crates/noirc_driver/src/lib.rs → compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ pub type Warnings = Vec<FileDiagnostic>;
/// Helper type used to signify where errors or warnings are expected in file diagnostics
pub type ErrorsAndWarnings = Vec<FileDiagnostic>;

/// Helper type for connecting a compilation artifact to the errors or warnings which were produced during compilation.
pub type CompilationResult<T> = Result<(T, Warnings), ErrorsAndWarnings>;

// This is here for backwards compatibility
// with the restricted version which only uses one file
pub fn compile_file(
context: &mut Context,
root_file: &Path,
) -> Result<(CompiledProgram, Warnings), ErrorsAndWarnings> {
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())
}
Expand Down Expand Up @@ -107,14 +107,14 @@ pub fn check_crate(
context: &mut Context,
crate_id: CrateId,
deny_warnings: bool,
) -> Result<Warnings, ErrorsAndWarnings> {
) -> CompilationResult<()> {
let mut errors = vec![];
CrateDefMap::collect_defs(crate_id, context, &mut errors);

if has_errors(&errors, deny_warnings) {
Err(errors)
} else {
Ok(errors)
Ok(((), errors))
}
}

Expand All @@ -140,8 +140,8 @@ pub fn compile_main(
context: &mut Context,
crate_id: CrateId,
options: &CompileOptions,
) -> Result<(CompiledProgram, Warnings), ErrorsAndWarnings> {
let warnings = check_crate(context, crate_id, options.deny_warnings)?;
) -> CompilationResult<CompiledProgram> {
let (_, warnings) = check_crate(context, crate_id, options.deny_warnings)?;

let main = match context.get_main_function(&crate_id) {
Some(m) => m,
Expand Down Expand Up @@ -170,8 +170,8 @@ pub fn compile_contracts(
context: &mut Context,
crate_id: CrateId,
options: &CompileOptions,
) -> Result<(Vec<CompiledContract>, Warnings), ErrorsAndWarnings> {
let warnings = check_crate(context, crate_id, options.deny_warnings)?;
) -> CompilationResult<Vec<CompiledContract>> {
let (_, warnings) = check_crate(context, crate_id, options.deny_warnings)?;

// TODO: We probably want to error if contracts is empty
let contracts = context.get_all_contracts(&crate_id);
Expand Down Expand Up @@ -218,7 +218,7 @@ fn compile_contract(
context: &Context,
contract: Contract,
options: &CompileOptions,
) -> Result<CompiledContract, Vec<FileDiagnostic>> {
) -> Result<CompiledContract, ErrorsAndWarnings> {
let mut functions = Vec::new();
let mut errors = Vec::new();
for function_id in &contract.functions {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1207,19 +1207,31 @@ impl AcirContext {
) -> Result<(), InternalError> {
// If the optional values are supplied, then we fill the initialized
// array with those values. If not, then we fill it with zeros.
let mut nested = false;
let initialized_values = match optional_values {
None => {
let zero = self.add_constant(FieldElement::zero());
let zero_witness = self.var_to_witness(zero)?;
vec![zero_witness; len]
}
Some(optional_values) => try_vecmap(optional_values, |value| {
let value = value.clone().into_var()?;
self.var_to_witness(value)
})?,
Some(optional_values) => {
let mut values = Vec::new();
for value in optional_values {
if let Ok(some_value) = value.clone().into_var() {
values.push(self.var_to_witness(some_value)?);
} else {
nested = true;
break;
}
}
values
}
};
// we do not initialize nested arrays. This means that non-const indexes are not supported for nested arrays
if !nested {
self.acir_ir.push_opcode(Opcode::MemoryInit { block_id, init: initialized_values });
}

self.acir_ir.push_opcode(Opcode::MemoryInit { block_id, init: initialized_values });
Ok(())
}
}
Expand Down
Loading

0 comments on commit 5cdba2e

Please sign in to comment.