Skip to content

Commit

Permalink
feat!: remove dep:: prefix (#4946)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #2307

## Summary\*

`dep::` is unnecessary to distinguish between internal and external
crates, so this PR removes it.

## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
3 people committed Jun 17, 2024
1 parent 7de19f5 commit d6d0ae2
Show file tree
Hide file tree
Showing 190 changed files with 375 additions and 369 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source(
format!(
"
unconstrained fn compute_note_hash_and_optionally_a_nullifier(
contract_address: dep::aztec::protocol_types::address::AztecAddress,
contract_address: aztec::protocol_types::address::AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
Expand All @@ -194,7 +194,7 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source(

let if_statements: Vec<String> = note_types.iter().map(|note_type| format!(
"if (note_type_id == {0}::get_note_type_id()) {{
dep::aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note)
aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note)
}}"
, note_type)).collect();

Expand All @@ -208,14 +208,14 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source(
format!(
"
unconstrained fn compute_note_hash_and_optionally_a_nullifier(
contract_address: dep::aztec::protocol_types::address::AztecAddress,
contract_address: aztec::protocol_types::address::AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
compute_nullifier: bool,
serialized_note: [Field; {}],
) -> pub [Field; 4] {{
let note_header = dep::aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);
let note_header = aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);
{}
}}",
Expand Down
29 changes: 16 additions & 13 deletions aztec_macros/src/transforms/contract_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use crate::utils::{
// for i in 0..third_arg.len() {
// args_acc = args_acc.append(third_arg[i].serialize().as_slice());
// }
// let args_hash = dep::aztec::hash::hash_args(args_acc);
// assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));
// let args_hash = aztec::hash::hash_args(args_acc);
// assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc));
// PublicCallInterface {
// target_contract: self.target_contract,
// selector: FunctionSelector::from_signature("SELECTOR_PLACEHOLDER"),
Expand All @@ -56,7 +56,10 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call
.join(", ");
let fn_return_type: noirc_frontend::ast::UnresolvedType = func.return_type();

let fn_selector = format!("dep::aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature(\"{}\")", SELECTOR_PLACEHOLDER);
let fn_selector = format!(
"aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature(\"{}\")",
SELECTOR_PLACEHOLDER
);

let parameters = func.parameters();
let is_void = if matches!(fn_return_type.typ, UnresolvedTypeData::Unit) { "Void" } else { "" };
Expand Down Expand Up @@ -93,8 +96,8 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call
format!(
"let mut args_acc: [Field] = &[];
{}
let args_hash = dep::aztec::hash::hash_args(args_acc);
assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));",
let args_hash = aztec::hash::hash_args(args_acc);
assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc));",
call_args
)
} else {
Expand All @@ -103,15 +106,15 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call

let fn_body = format!(
"{}
dep::aztec::context::{}{}{}CallInterface {{
aztec::context::{}{}{}CallInterface {{
target_contract: self.target_contract,
selector: {},
args_hash,
}}",
args_hash, aztec_visibility, is_static, is_void, fn_selector,
);
format!(
"pub fn {}(self, {}) -> dep::aztec::context::{}{}{}CallInterface{} {{
"pub fn {}(self, {}) -> aztec::context::{}{}{}CallInterface{} {{
{}
}}",
fn_name, fn_parameters, aztec_visibility, is_static, is_void, return_type_hint, fn_body
Expand All @@ -125,16 +128,16 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call
);
let fn_body = format!(
"{}
dep::aztec::context::Public{}{}CallInterface {{
aztec::context::Public{}{}CallInterface {{
target_contract: self.target_contract,
selector: {},
args: args_acc,
gas_opts: dep::aztec::context::gas::GasOpts::default(),
gas_opts: aztec::context::gas::GasOpts::default(),
}}",
args, is_static, is_void, fn_selector,
);
format!(
"pub fn {}(self, {}) -> dep::aztec::context::Public{}{}CallInterface{} {{
"pub fn {}(self, {}) -> aztec::context::Public{}{}CallInterface{} {{
{}
}}",
fn_name, fn_parameters, is_static, is_void, return_type_hint, fn_body
Expand All @@ -153,22 +156,22 @@ pub fn generate_contract_interface(
let contract_interface = format!(
"
struct {0} {{
target_contract: dep::aztec::protocol_types::address::AztecAddress
target_contract: aztec::protocol_types::address::AztecAddress
}}
impl {0} {{
{1}
pub fn at(
target_contract: dep::aztec::protocol_types::address::AztecAddress
target_contract: aztec::protocol_types::address::AztecAddress
) -> Self {{
Self {{ target_contract }}
}}
}}
#[contract_library_method]
pub fn at(
target_contract: dep::aztec::protocol_types::address::AztecAddress
target_contract: aztec::protocol_types::address::AztecAddress
) -> {0} {{
{0} {{ target_contract }}
}}
Expand Down
20 changes: 7 additions & 13 deletions aztec_macros/src/transforms/note_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn generate_note_get_header(
) -> Result<NoirFunction, AztecMacroError> {
let function_source = format!(
"
fn get_header(note: {}) -> dep::aztec::note::note_header::NoteHeader {{
fn get_header(note: {}) -> aztec::note::note_header::NoteHeader {{
note.{}
}}
",
Expand Down Expand Up @@ -299,7 +299,7 @@ fn generate_note_set_header(
) -> Result<NoirFunction, AztecMacroError> {
let function_source = format!(
"
fn set_header(self: &mut {}, header: dep::aztec::note::note_header::NoteHeader) {{
fn set_header(self: &mut {}, header: aztec::note::note_header::NoteHeader) {{
self.{} = header;
}}
",
Expand Down Expand Up @@ -488,7 +488,7 @@ fn generate_note_properties_fn(

// Automatically generate the method to compute the note's content hash as:
// fn compute_note_content_hash(self: NoteType) -> Field {
// dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
// aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
// }
//
fn generate_compute_note_content_hash(
Expand All @@ -498,7 +498,7 @@ fn generate_compute_note_content_hash(
let function_source = format!(
"
fn compute_note_content_hash(self: {}) -> Field {{
dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
}}
",
note_type
Expand Down Expand Up @@ -557,10 +557,7 @@ fn generate_note_properties_struct_source(
.iter()
.filter_map(|(field_name, _)| {
if field_name != note_header_field_name {
Some(format!(
"{}: dep::aztec::note::note_getter_options::PropertySelector",
field_name
))
Some(format!("{}: aztec::note::note_getter_options::PropertySelector", field_name))
} else {
None
}
Expand Down Expand Up @@ -588,7 +585,7 @@ fn generate_note_properties_fn_source(
.filter_map(|(index, (field_name, _))| {
if field_name != note_header_field_name {
Some(format!(
"{}: dep::aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}",
"{}: aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}",
field_name,
index
))
Expand Down Expand Up @@ -665,10 +662,7 @@ fn generate_note_deserialize_content_source(
)
}
} else {
format!(
"{}: dep::aztec::note::note_header::NoteHeader::empty()",
note_header_field_name
)
format!("{}: aztec::note::note_header::NoteHeader::empty()", note_header_field_name)
}
})
.collect::<Vec<String>>()
Expand Down
4 changes: 2 additions & 2 deletions aztec_macros/src/transforms/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,10 @@ pub fn generate_storage_layout(
let mut storable_fields_impl = vec![];

definition.fields.iter().enumerate().for_each(|(index, (field_ident, field_type))| {
storable_fields.push(format!("{}: dep::aztec::prelude::Storable<N{}>", field_ident, index));
storable_fields.push(format!("{}: aztec::prelude::Storable<N{}>", field_ident, index));
generic_args.push(format!("N{}", index));
storable_fields_impl.push(format!(
"{}: dep::aztec::prelude::Storable {{ slot: 0, typ: \"{}\" }}",
"{}: aztec::prelude::Storable {{ slot: 0, typ: \"{}\" }}",
field_ident,
field_type.to_string().replace("plain::", "")
));
Expand Down
2 changes: 1 addition & 1 deletion aztec_macros/src/utils/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ macro_rules! chained_dep {
( $base:expr $(, $tail:expr)* ) => {
{
let mut base_path = ident_path($base);
base_path.kind = PathKind::Dep;
base_path.kind = PathKind::Plain;
$(
base_path.segments.push(ident($tail));
)*
Expand Down
3 changes: 0 additions & 3 deletions compiler/integration-tests/circuits/assert_lt/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use dep::std;

fn main(x: u64, y: pub u64) -> pub u64 {
// We include a println statement to show that noirJS will ignore this and continue execution
std::println("foo");


assert(x < y);
x + y
}
2 changes: 0 additions & 2 deletions compiler/integration-tests/circuits/recursion/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use dep::std;

fn main(
verification_key: [Field; 114],
proof: [Field; 93],
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl DebugInstrumenter {
.join(",\n");
let (program, errors) = parse_program(&format!(
r#"
use dep::__debug::{{
use __debug::{{
__debug_var_assign,
__debug_var_drop,
__debug_fn_enter,
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ fn inject_prelude(

let path = Path {
segments: segments.clone(),
kind: crate::ast::PathKind::Dep,
kind: crate::ast::PathKind::Plain,
span: Span::default(),
};

Expand All @@ -489,7 +489,7 @@ fn inject_prelude(
0,
ImportDirective {
module_id: crate_root,
path: Path { segments, kind: PathKind::Dep, span: Span::default() },
path: Path { segments, kind: PathKind::Plain, span: Span::default() },
alias: None,
is_prelude: true,
},
Expand Down
48 changes: 38 additions & 10 deletions compiler/noirc_frontend/src/hir/resolution/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,34 @@ fn resolve_path_to_ns(
allow_contracts,
)
}
crate::ast::PathKind::Dep => resolve_external_dep(
def_map,
import_directive,
def_maps,
allow_contracts,
importing_crate,
),
crate::ast::PathKind::Plain => {
// Plain paths are only used to import children modules. It's possible to allow import of external deps, but maybe this distinction is better?
// In Rust they can also point to external Dependencies, if no children can be found with the specified name
// There is a possibility that the import path is empty
// In that case, early return
if import_path.is_empty() {
return resolve_name_in_module(
crate_id,
importing_crate,
import_path,
import_directive.module_id,
def_maps,
allow_contracts,
);
}

let current_mod_id = ModuleId { krate: crate_id, local_id: import_directive.module_id };
let current_mod = &def_map.modules[current_mod_id.local_id.0];
let first_segment = import_path.first().expect("ice: could not fetch first segment");
if current_mod.find_name(first_segment).is_none() {
// Resolve externally when first segment is unresolved
return resolve_external_dep(
def_map,
import_directive,
def_maps,
allow_contracts,
importing_crate,
);
}

resolve_name_in_module(
crate_id,
importing_crate,
Expand All @@ -177,6 +195,14 @@ fn resolve_path_to_ns(
allow_contracts,
)
}

crate::ast::PathKind::Dep => resolve_external_dep(
def_map,
import_directive,
def_maps,
allow_contracts,
importing_crate,
),
}
}

Expand Down Expand Up @@ -302,7 +328,9 @@ fn resolve_external_dep(
.ok_or_else(|| PathResolutionError::Unresolved(crate_name.to_owned()))?;

// Create an import directive for the dependency crate
let path_without_crate_name = &path[1..]; // XXX: This will panic if the path is of the form `use dep::std` Ideal algorithm will not distinguish between crate and module
// XXX: This will panic if the path is of the form `use std`. Ideal algorithm will not distinguish between crate and module
// See `singleton_import.nr` test case for a check that such cases are handled elsewhere.
let path_without_crate_name = &path[1..];

let path = Path {
segments: path_without_crate_name.to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/noir_parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub(crate) Path: Path = {
},

<lo:@L> "dep" "::" <segments:PathSegments> <hi:@R> => {
let kind = PathKind::Dep;
let kind = PathKind::Plain;
let span = Span::from(lo as u32..hi as u32);
Path { segments, kind, span }
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ mod test {
"use foo::{bar, hello}",
"use foo::{bar as bar2, hello}",
"use foo::{bar as bar2, hello::{foo}, nested::{foo, bar}}",
"use dep::{std::println, bar::baz}",
"use std::{println, bar::baz}",
];

let invalid_use_statements = [
Expand Down
9 changes: 5 additions & 4 deletions compiler/noirc_frontend/src/parser/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn empty_path() -> impl NoirParser<Path> {
let make_path = |kind| move |_, span| Path { segments: Vec::new(), kind, span };
let path_kind = |key, kind| keyword(key).map_with_span(make_path(kind));

choice((path_kind(Keyword::Crate, PathKind::Crate), path_kind(Keyword::Dep, PathKind::Dep)))
choice((path_kind(Keyword::Crate, PathKind::Crate), path_kind(Keyword::Dep, PathKind::Plain)))
}

pub(super) fn maybe_empty_path() -> impl NoirParser<Path> {
Expand All @@ -43,7 +43,8 @@ mod test {
("std", vec!["std"]),
("std::hash", vec!["std", "hash"]),
("std::hash::collections", vec!["std", "hash", "collections"]),
("dep::foo::bar", vec!["foo", "bar"]),
("foo::bar", vec!["foo", "bar"]),
("foo::bar", vec!["foo", "bar"]),
("crate::std::hash", vec!["std", "hash"]),
];

Expand All @@ -61,7 +62,7 @@ mod test {
fn parse_path_kinds() {
let cases = vec![
("std", PathKind::Plain),
("dep::hash::collections", PathKind::Dep),
("hash::collections", PathKind::Plain),
("crate::std::hash", PathKind::Crate),
];

Expand All @@ -72,7 +73,7 @@ mod test {

parse_all_failing(
path(),
vec!["dep", "crate", "crate::std::crate", "foo::bar::crate", "foo::dep"],
vec!["crate", "crate::std::crate", "foo::bar::crate", "foo::dep"],
);
}
}
2 changes: 1 addition & 1 deletion compiler/wasm/test/fixtures/deps/lib-a/src/lib.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::lib_b::assert_non_zero;
use lib_b::assert_non_zero;

pub fn divide(a: u64, b: u64) -> u64 {
assert_non_zero(b);
Expand Down
Loading

0 comments on commit d6d0ae2

Please sign in to comment.