Skip to content

Commit

Permalink
[1 changes] chore: split LSP completion.rs into several files (noir-l…
Browse files Browse the repository at this point in the history
…ang/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 15, 2024
1 parent 91042c7 commit 9aca22f
Show file tree
Hide file tree
Showing 154 changed files with 3,906 additions and 2,405 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0ebf1fee471641db0bffcc8307d20327613c78c1
5730e678d3b5aedacf327b1a9c2b69cc6916c176
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
Loading

0 comments on commit 9aca22f

Please sign in to comment.