Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ssa refactor): Brillig main #1561

Merged
merged 27 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6184f52
remove mac runner
kevaundray Jun 6, 2023
823bd84
chore: generate brillig opcode for simple identity unconstrained func…
guipublic Jun 6, 2023
545d333
feat(brillig): added arithmetic operations on brillig (#1565)
sirasistant Jun 6, 2023
f6810af
make ranges be polymorphic integers
kevaundray Jun 6, 2023
c5e34c5
chore(brillig): Clean up handling of Binary operations (#1571)
kevaundray Jun 6, 2023
06543b5
chore(ssa refactor): Rename Brillig example (#1563)
kevaundray Jun 6, 2023
3c9f106
chore(brillig): added tests for all field binary operations (#1586)
sirasistant Jun 7, 2023
9a9c461
chore(brillig): added tests for brillig integer operations (#1590)
sirasistant Jun 7, 2023
043c3c4
feat: process blocks and jumps when compiling brillig (#1591)
guipublic Jun 7, 2023
e51d3c6
feat: process blocks and jumps when compiling brillig (#1591)
guipublic Jun 7, 2023
cd39144
feat(brillig): parsing oracles/foreign calls (#1596)
ludamad Jun 7, 2023
cf393ff
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 8, 2023
4644da9
self.data -> self.vars
kevaundray Jun 8, 2023
d50c69f
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 8, 2023
398ddf9
chore(brillig): Add handling of the not instruction (#1609)
kevaundray Jun 8, 2023
1d52f5e
make behavior consistent
kevaundray Jun 8, 2023
2d3ab61
remove closure
kevaundray Jun 8, 2023
801a739
change index_type
kevaundray Jun 8, 2023
2bcfc24
Update crates/noirc_frontend/src/hir/type_check/expr.rs
jfecher Jun 8, 2023
49a151d
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 8, 2023
5247a48
Merge remote-tracking branch 'origin/kw/polymorphic-integers-on-for-l…
kevaundray Jun 8, 2023
5995b30
feat(brillig): loops (#1610)
sirasistant Jun 8, 2023
1a9d33c
chore: resolve immutable array merge differences (#1617)
joss-aztec Jun 9, 2023
2787cc9
chore(ssa refactor): Add more documentation for truncation (#1607)
kevaundray Jun 9, 2023
8713a89
Merge remote-tracking branch 'origin/master' into kw/brillig-main
kevaundray Jun 9, 2023
70f8fe2
Update .github/workflows/test.yml
kevaundray Jun 9, 2023
91defbc
Update .github/workflows/test.yml
kevaundray Jun 9, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
- os: ubuntu
runner: ubuntu-large
target: x86_64-linux
- os: mac
runner: macos-latest
target: x86_64-darwin
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
# - os: mac
# runner: macos-latest
# target: x86_64-darwin
kevaundray marked this conversation as resolved.
Show resolved Hide resolved

steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "3"

10 changes: 10 additions & 0 deletions crates/nargo_cli/tests/test_data_ssa_refactor/brillig/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Tests a very simple program.
//
// The features being tested is assertion
fn main(x : Field) {
assert(x == identity(x));
}

unconstrained fn identity(x : Field) -> Field {
x
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::ssa_refactor::ir::types::Type as SsaType;
use crate::ssa_refactor::ir::{instruction::Endian, types::NumericType};
use acvm::acir::brillig_vm::Opcode as BrilligOpcode;
use acvm::acir::{
brillig_vm::Opcode as BrilligOpcode,
circuit::brillig::{BrilligInputs, BrilligOutputs},
};

use super::{
errors::AcirGenError,
Expand Down Expand Up @@ -727,8 +730,21 @@ impl AcirContext {
id
}

pub(crate) fn brillig(&mut self, _code: Vec<BrilligOpcode>) {
todo!();
pub(crate) fn brillig(
&mut self,
code: Vec<BrilligOpcode>,
inputs: Vec<AcirVar>,
output_len: usize,
) -> Vec<AcirVar> {
let b_inputs =
vecmap(inputs, |i| BrilligInputs::Single(self.data[&i].to_expression().into_owned()));
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
let outputs = vecmap(0..output_len, |_| self.acir_ir.next_witness_index());
let outputs_var =
vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index)));
let b_outputs = vecmap(outputs, BrilligOutputs::Simple);
self.acir_ir.brillig(code, b_inputs, b_outputs);

outputs_var
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//! program as it is being converted from SSA form.
use super::errors::AcirGenError;
use acvm::acir::{
brillig_vm::Opcode as BrilligOpcode,
circuit::{
brillig::{Brillig as AcvmBrillig, BrilligInputs, BrilligOutputs},
directives::{LogInfo, QuotientDirective},
opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode},
},
Expand Down Expand Up @@ -464,6 +466,22 @@ impl GeneratedAcir {

Ok(q_witness)
}

pub(crate) fn brillig(
&mut self,
code: Vec<BrilligOpcode>,
inputs: Vec<BrilligInputs>,
outputs: Vec<BrilligOutputs>,
) {
let opcode = AcirOpcode::Brillig(AcvmBrillig {
inputs,
outputs,
foreign_call_results: Vec::new(),
bytecode: code,
predicate: None,
});
self.push_opcode(opcode);
}
}

/// This function will return the number of inputs that a blackbox function
Expand Down
11 changes: 4 additions & 7 deletions crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use super::{
ssa_gen::Ssa,
};
use crate::brillig::{artifact::BrilligArtifact, Brillig};
use iter_extended::vecmap;
use noirc_abi::{AbiType, FunctionSignature, Sign};

pub(crate) use acir_ir::generated_acir::GeneratedAcir;
Expand Down Expand Up @@ -90,11 +91,6 @@ impl Context {
brillig: Brillig,
allow_log_ops: bool,
) -> GeneratedAcir {
assert_eq!(
ssa.functions.len(),
1,
"expected only a single function to be present with all other functions being inlined."
);
let main_func = ssa.main();
let dfg = &main_func.dfg;
let entry_block = &dfg[main_func.entry_block()];
Expand Down Expand Up @@ -214,10 +210,11 @@ impl Context {
"expected an intrinsic/brillig call, but found {func:?}. All ACIR methods should be inlined"
),
RuntimeType::Brillig => {
let inputs = vecmap(arguments, |&a| {self.convert_ssa_value(a, dfg)});
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
// Generate the brillig code of the function
let code = BrilligArtifact::default().link(&brillig[*id]);
self.acir_context.brillig(code);
(result_ids.to_vec(), Vec::new())
let outputs = self.acir_context.brillig(code, inputs, result_ids.len());
(result_ids.to_vec(), outputs)
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions crates/noirc_evaluator/src/ssa_refactor/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,7 @@ impl<'function> PerFunctionContext<'function> {
match self.context.builder[id] {
Value::Function(id) => Some(id),
Value::Intrinsic(_) => None,
_ => {
self.context.failed_to_inline_a_call = true;
None
}
_ => None,
}
}

Expand Down Expand Up @@ -326,9 +323,15 @@ impl<'function> PerFunctionContext<'function> {
Instruction::Call { func, arguments } => match self.get_function(*func) {
Some(function) => match ssa.functions[&function].runtime() {
RuntimeType::Acir => self.inline_function(ssa, *id, function, arguments),
RuntimeType::Brillig => self.push_instruction(*id),
RuntimeType::Brillig => {
self.context.failed_to_inline_a_call = true;
self.push_instruction(*id);
}
},
None => self.push_instruction(*id),
None => {
self.context.failed_to_inline_a_call = true;
self.push_instruction(*id);
}
},
_ => self.push_instruction(*id),
}
Expand Down