Skip to content

Commit

Permalink
feat: suggest trait methods in LSP completion (noir-lang/noir#5735)
Browse files Browse the repository at this point in the history
feat: LSP autocomplete constructor fields (noir-lang/noir#5732)
feat: add `Expr::as_unary` (noir-lang/noir#5731)
chore: count brillig opcodes in nargo info (noir-lang/noir#5189)
feat: suggest tuple fields in LSP completion (noir-lang/noir#5730)
feat: add `Expr::as_bool` (noir-lang/noir#5729)
feat: add `Expr` methods: `as_tuple`, `as_parenthesized`, `as_index`, `as_if` (noir-lang/noir#5726)
feat: LSP signature help (noir-lang/noir#5725)
chore: split LSP completion.rs into several files (noir-lang/noir#5723)
feat: add `TraitImpl::trait_generic_args` and `TraitImpl::methods` (noir-lang/noir#5722)
fix: let LSP autocompletion work in more contexts (noir-lang/noir#5719)
fix(frontend): Continue type check if we are missing an unsafe block (noir-lang/noir#5720)
feat: add `unsafe` blocks for calling unconstrained code from constrained functions (noir-lang/noir#4429)
  • Loading branch information
AztecBot committed Aug 16, 2024
2 parents 9346baa + e6354cf commit 76e6166
Show file tree
Hide file tree
Showing 28 changed files with 1,522 additions and 348 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5730e678d3b5aedacf327b1a9c2b69cc6916c176
e2f7e950c44883228d5e1230b04c83e479de7ed0
4 changes: 3 additions & 1 deletion noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ pub fn compile_no_check(
let force_compile = force_compile
|| options.print_acir
|| options.show_brillig
|| options.force_brillig
|| options.show_ssa
|| options.emit_ssa;

Expand All @@ -578,7 +579,7 @@ pub fn compile_no_check(
emit_ssa: if options.emit_ssa { Some(context.package_build_path.clone()) } else { None },
};

let SsaProgramArtifact { program, debug, warnings, names, error_types, .. } =
let SsaProgramArtifact { program, debug, warnings, names, brillig_names, error_types, .. } =
create_program(program, &ssa_evaluator_options)?;

let abi = abi_gen::gen_abi(context, &main_function, return_visibility, error_types);
Expand All @@ -593,5 +594,6 @@ pub fn compile_no_check(
noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(),
warnings,
names,
brillig_names,
})
}
2 changes: 2 additions & 0 deletions noir/noir-repo/compiler/noirc_driver/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ pub struct CompiledProgram {
pub warnings: Vec<SsaReport>,
/// Names of the functions in the program. These are used for more informative debugging and benchmarking.
pub names: Vec<String>,
/// Names of the unconstrained functions in the program.
pub brillig_names: Vec<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ pub(crate) fn convert_ssa_function(
BrilligBlock::compile(&mut function_context, &mut brillig_context, block, &func.dfg);
}

brillig_context.artifact()
let mut artifact = brillig_context.artifact();
artifact.name = func.name().to_string();
artifact
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub(crate) fn directive_invert<F: AcirField>() -> GeneratedBrillig<F> {
],
assert_messages: Default::default(),
locations: Default::default(),
name: "directive_invert".to_string(),
}
}

Expand Down Expand Up @@ -109,5 +110,6 @@ pub(crate) fn directive_quotient<F: AcirField>() -> GeneratedBrillig<F> {
],
assert_messages: Default::default(),
locations: Default::default(),
name: "directive_integer_quotient".to_string(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) struct GeneratedBrillig<F> {
pub(crate) byte_code: Vec<BrilligOpcode<F>>,
pub(crate) locations: BTreeMap<OpcodeLocation, CallStack>,
pub(crate) assert_messages: BTreeMap<OpcodeLocation, String>,
pub(crate) name: String,
}

#[derive(Default, Debug, Clone)]
Expand Down Expand Up @@ -49,6 +50,8 @@ pub(crate) struct BrilligArtifact<F> {
locations: BTreeMap<OpcodeLocation, CallStack>,
/// The current call stack. All opcodes that are pushed will be associated with this call stack.
call_stack: CallStack,
/// Name of the function, only used for debugging purposes.
pub(crate) name: String,
}

/// A pointer to a location in the opcode.
Expand Down Expand Up @@ -81,6 +84,7 @@ impl<F: Clone + std::fmt::Debug> BrilligArtifact<F> {
byte_code: self.byte_code,
locations: self.locations,
assert_messages: self.assert_messages,
name: self.name,
}
}

Expand Down
9 changes: 7 additions & 2 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub struct SsaProgramArtifact {
pub main_input_witnesses: Vec<Witness>,
pub main_return_witnesses: Vec<Witness>,
pub names: Vec<String>,
pub brillig_names: Vec<String>,
pub error_types: BTreeMap<ErrorSelector, HirType>,
}

Expand All @@ -167,6 +168,7 @@ impl SsaProgramArtifact {
main_input_witnesses: Vec::default(),
main_return_witnesses: Vec::default(),
names: Vec::default(),
brillig_names: Vec::default(),
error_types,
}
}
Expand Down Expand Up @@ -202,8 +204,10 @@ pub fn create_program(
let func_sigs = program.function_signatures.clone();

let recursive = program.recursive;
let ArtifactsAndWarnings((generated_acirs, generated_brillig, error_types), ssa_level_warnings) =
optimize_into_acir(program, options)?;
let ArtifactsAndWarnings(
(generated_acirs, generated_brillig, brillig_function_names, error_types),
ssa_level_warnings,
) = optimize_into_acir(program, options)?;
if options.force_brillig_output {
assert_eq!(
generated_acirs.len(),
Expand Down Expand Up @@ -236,6 +240,7 @@ pub fn create_program(
program_artifact.add_circuit(circuit_artifact, is_main);
is_main = false;
}
program_artifact.brillig_names = brillig_function_names;

Ok(program_artifact)
}
Expand Down
27 changes: 16 additions & 11 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ impl AcirValue {
pub(crate) type Artifacts = (
Vec<GeneratedAcir<FieldElement>>,
Vec<BrilligBytecode<FieldElement>>,
Vec<String>,
BTreeMap<ErrorSelector, ErrorType>,
);

Expand Down Expand Up @@ -334,11 +335,13 @@ impl Ssa {
}
}

let brillig = vecmap(shared_context.generated_brillig, |brillig| BrilligBytecode {
bytecode: brillig.byte_code,
});
let (brillig_bytecode, brillig_names) = shared_context
.generated_brillig
.into_iter()
.map(|brillig| (BrilligBytecode { bytecode: brillig.byte_code }, brillig.name))
.unzip();

Ok((acirs, brillig, self.error_selector_to_type))
Ok((acirs, brillig_bytecode, brillig_names, self.error_selector_to_type))
}
}

Expand Down Expand Up @@ -955,6 +958,8 @@ impl<'a> Context<'a> {
BrilligFunctionContext::return_values(func),
BrilligFunctionContext::function_id_to_function_label(func.id()),
);
entry_point.name = func.name().to_string();

// Link the entry point with all dependencies
while let Some(unresolved_fn_label) = entry_point.first_unresolved_function_call() {
let artifact = &brillig.find_by_function_label(unresolved_fn_label.clone());
Expand Down Expand Up @@ -2966,7 +2971,7 @@ mod test {

let ssa = builder.finish();

let (acir_functions, _, _) = ssa
let (acir_functions, _, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");
// Expected result:
Expand Down Expand Up @@ -3061,7 +3066,7 @@ mod test {

let ssa = builder.finish();

let (acir_functions, _, _) = ssa
let (acir_functions, _, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");
// The expected result should look very similar to the above test expect that the input witnesses of the `Call`
Expand Down Expand Up @@ -3151,7 +3156,7 @@ mod test {

let ssa = builder.finish();

let (acir_functions, _, _) = ssa
let (acir_functions, _, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3265,7 +3270,7 @@ mod test {
let ssa = builder.finish();
let brillig = ssa.to_brillig(false);

let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3329,7 +3334,7 @@ mod test {

// The Brillig bytecode we insert for the stdlib is hardcoded so we do not need to provide any
// Brillig artifacts to the ACIR gen pass.
let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&Brillig::default(), ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3403,7 +3408,7 @@ mod test {
let brillig = ssa.to_brillig(false);
println!("{}", ssa);

let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down Expand Up @@ -3491,7 +3496,7 @@ mod test {
let brillig = ssa.to_brillig(false);
println!("{}", ssa);

let (acir_functions, brillig_functions, _) = ssa
let (acir_functions, brillig_functions, _, _) = ssa
.into_acir(&brillig, ExpressionWidth::default())
.expect("Should compile manually written SSA into ACIR");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
(Value::U16(lhs), Value::U16(rhs)) => Ok(Value::Bool(lhs == rhs)),
(Value::U32(lhs), Value::U32(rhs)) => Ok(Value::Bool(lhs == rhs)),
(Value::U64(lhs), Value::U64(rhs)) => Ok(Value::Bool(lhs == rhs)),
(Value::Bool(lhs), Value::Bool(rhs)) => Ok(Value::Bool(lhs == rhs)),
(lhs, rhs) => make_error(self, lhs, rhs, "=="),
},
BinaryOpKind::NotEqual => match (lhs, rhs) {
Expand All @@ -909,6 +910,7 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
(Value::U16(lhs), Value::U16(rhs)) => Ok(Value::Bool(lhs != rhs)),
(Value::U32(lhs), Value::U32(rhs)) => Ok(Value::Bool(lhs != rhs)),
(Value::U64(lhs), Value::U64(rhs)) => Ok(Value::Bool(lhs != rhs)),
(Value::Bool(lhs), Value::Bool(rhs)) => Ok(Value::Bool(lhs != rhs)),
(lhs, rhs) => make_error(self, lhs, rhs, "!="),
},
BinaryOpKind::Less => match (lhs, rhs) {
Expand Down
Loading

0 comments on commit 76e6166

Please sign in to comment.