Skip to content

Commit

Permalink
[1 changes] feat: suggest trait methods in LSP completion (noir-lang/…
Browse files Browse the repository at this point in the history
…noir#5735)

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
1 parent 91042c7 commit c1e585e
Show file tree
Hide file tree
Showing 174 changed files with 5,278 additions and 2,603 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0ebf1fee471641db0bffcc8307d20327613c78c1
e2f7e950c44883228d5e1230b04c83e479de7ed0
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
#require_command wasm-opt
require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
176 changes: 90 additions & 86 deletions noir/noir-repo/aztec_macros/src/transforms/contract_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,101 +324,105 @@ pub fn update_fn_signatures_in_contract_interface(
});

if let Some(interface_struct) = maybe_interface_struct {
let methods = context.def_interner.get_struct_methods(interface_struct.borrow().id);

for func_id in methods.iter().flat_map(|methods| methods.direct.iter()) {
let name = context.def_interner.function_name(func_id);
let fn_parameters = &context.def_interner.function_meta(func_id).parameters.clone();

if name == "at" || name == "interface" || name == "storage" {
continue;
}

let fn_signature_hash = compute_fn_signature_hash(
name,
&fn_parameters
.iter()
.skip(1)
.map(|(_, typ, _)| typ.clone())
.collect::<Vec<Type>>(),
);
let hir_func = context.def_interner.function(func_id).block(&context.def_interner);

let function_selector_statement = context.def_interner.statement(
hir_func.statements().get(hir_func.statements().len() - 2).ok_or((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function signature statement not found, invalid body length"
.to_string(),
),
},
file_id,
))?,
);
let function_selector_expression_id = match function_selector_statement {
HirStatement::Let(let_statement) => Ok(let_statement.expression),
_ => Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function selector statement must be an expression".to_string(),
),
},
file_id,
)),
}?;
let function_selector_expression =
context.def_interner.expression(&function_selector_expression_id);

let current_fn_signature_expression_id = match function_selector_expression {
HirExpression::Call(call_expr) => Ok(call_expr.arguments[0]),
_ => Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function selector argument expression must be call expression"
.to_string(),
),
},
file_id,
)),
}?;

let current_fn_signature_expression =
context.def_interner.expression(&current_fn_signature_expression_id);
if let Some(methods) =
context.def_interner.get_struct_methods(interface_struct.borrow().id).cloned()
{
for func_id in methods.iter().flat_map(|(_name, methods)| methods.direct.iter()) {
let name = context.def_interner.function_name(func_id);
let fn_parameters =
&context.def_interner.function_meta(func_id).parameters.clone();

if name == "at" || name == "interface" || name == "storage" {
continue;
}

match current_fn_signature_expression {
HirExpression::Literal(HirLiteral::Integer(value, _)) => {
if !value.is_zero() {
Err((
let fn_signature_hash = compute_fn_signature_hash(
name,
&fn_parameters
.iter()
.skip(1)
.map(|(_, typ, _)| typ.clone())
.collect::<Vec<Type>>(),
);
let hir_func =
context.def_interner.function(func_id).block(&context.def_interner);

let function_selector_statement = context.def_interner.statement(
hir_func.statements().get(hir_func.statements().len() - 2).ok_or((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function signature statement not found, invalid body length"
.to_string(),
),
},
file_id,
))?,
);
let function_selector_expression_id = match function_selector_statement {
HirStatement::Let(let_statement) => Ok(let_statement.expression),
_ => Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function selector statement must be an expression".to_string(),
),
},
file_id,
)),
}?;
let function_selector_expression =
context.def_interner.expression(&function_selector_expression_id);

let current_fn_signature_expression_id = match function_selector_expression {
HirExpression::Call(call_expr) => Ok(call_expr.arguments[0]),
_ => Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function selector argument expression must be call expression"
.to_string(),
),
},
file_id,
)),
}?;

let current_fn_signature_expression =
context.def_interner.expression(&current_fn_signature_expression_id);

match current_fn_signature_expression {
HirExpression::Literal(HirLiteral::Integer(value, _)) => {
if !value.is_zero() {
Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function signature argument must be a placeholder with value 0".to_string()),
},
file_id,
))
} else {
Ok(())
} else {
Ok(())
}
}
}
_ => Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function signature argument must be a literal field element"
.to_string(),
),
_ => Err((
AztecMacroError::CouldNotGenerateContractInterface {
secondary_message: Some(
"Function signature argument must be a literal field element"
.to_string(),
),
},
file_id,
)),
}?;

context.def_interner.update_expression(
current_fn_signature_expression_id,
|expr| {
*expr = HirExpression::Literal(HirLiteral::Integer(
FieldElement::from(fn_signature_hash as u128),
false,
))
},
file_id,
)),
}?;

context.def_interner.update_expression(
current_fn_signature_expression_id,
|expr| {
*expr = HirExpression::Literal(HirLiteral::Integer(
FieldElement::from(fn_signature_hash as u128),
false,
))
},
);
);
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion noir/noir-repo/aztec_macros/src/utils/parse_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ fn empty_expression(expression: &mut Expression) {
ExpressionKind::Comptime(block_expression, _span) => {
empty_block_expression(block_expression);
}
ExpressionKind::Unsafe(block_expression, _span) => {
empty_block_expression(block_expression);
}
ExpressionKind::Quote(..) | ExpressionKind::Resolved(_) | ExpressionKind::Error => (),
ExpressionKind::AsTraitPath(path) => {
empty_unresolved_type(&mut path.typ);
Expand Down Expand Up @@ -325,7 +328,7 @@ fn empty_unresolved_type(unresolved_type: &mut UnresolvedType) {
empty_unresolved_type(unresolved_type)
}
UnresolvedTypeData::Tuple(unresolved_types) => empty_unresolved_types(unresolved_types),
UnresolvedTypeData::Function(args, ret, _env) => {
UnresolvedTypeData::Function(args, ret, _env, _) => {
empty_unresolved_types(args);
empty_unresolved_type(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/compiler/noirc_driver/src/abi_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub(super) fn abi_type_from_hir_type(context: &Context, typ: &Type) -> AbiType {
| Type::Forall(..)
| Type::Quoted(_)
| Type::Slice(_)
| Type::Function(_, _, _) => unreachable!("{typ} cannot be used in the abi"),
| Type::Function(_, _, _, _) => unreachable!("{typ} cannot be used in the abi"),
Type::FmtString(_, _) => unreachable!("format strings cannot be used in the abi"),
Type::MutableReference(_) => unreachable!("&mut cannot be used in the abi"),
}
Expand Down
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
Loading

0 comments on commit c1e585e

Please sign in to comment.