Skip to content

Commit

Permalink
chore: let add_definition_location take a Location (noir-lang/noir#…
Browse files Browse the repository at this point in the history
…7185)

fix(LSP): correct signature for assert and assert_eq (noir-lang/noir#7184)
chore(experimental): Prevent enum panics by returning Options where possible instead of panicking (noir-lang/noir#7180)
feat(experimental): Construct enum variants in expressions (noir-lang/noir#7174)
feat: add `noir-inspector` (noir-lang/noir#7136)
fix: ensure canonical bits decomposition (noir-lang/noir#7168)
fix: Keep `inc_rc` for array inputs during preprocessing  (noir-lang/noir#7163)
fix(docs): Update broken links to EC lib (noir-lang/noir#7141)
feat: inline simple functions (noir-lang/noir#7160)
feat(ssa): Expand feature set of the Brillig constraint check (noir-lang/noir#7060)
fix(ssa): Resolve value before fetching from DFG in a couple cases (noir-lang/noir#7169)
fix: `Function::is_no_predicates` always returned false for brillig f… (noir-lang/noir#7167)
chore(refactor): Remove globals field on Ssa object and use only the shared globals graph (noir-lang/noir#7156)
chore: let `Function::inlined` take a `should_inline_call` function (noir-lang/noir#7149)
chore: add compile-time assertions on generic arguments of stdlib functions (noir-lang/noir#6981)
fix: LSP hover over function with `&mut self` (noir-lang/noir#7155)
feat(brillig): Set global memory size at program compile time (noir-lang/noir#7151)
feat: LSP autocomplete module declaration (noir-lang/noir#7154)
feat(ssa): Reuse constants from the globals graph when making constants in a function DFG (noir-lang/noir#7153)
feat: LSP chain inlay hints (noir-lang/noir#7152)
chore: turn on overflow checks in CI rust tests (noir-lang/noir#7145)
fix(ssa): Use post order when mapping instructions in loop invariant pass (noir-lang/noir#7140)
fix: preserve types when reading from calldata arrays (noir-lang/noir#7144)
feat: Resolve enums & prepare type system (noir-lang/noir#7115)
feat: `loop` must have at least one `break` (noir-lang/noir#7126)
feat: parse globals in SSA parser (noir-lang/noir#7112)
fix: allow calling trait impl method from struct if multiple impls exist (noir-lang/noir#7124)
fix: avoid creating unnecessary memory blocks (noir-lang/noir#7114)
chore: relax threshold for reporting regressions (noir-lang/noir#7130)
fix: proper cleanup when breaking from comptime loop on error (noir-lang/noir#7125)
fix: Prevent overlapping associated types impls (noir-lang/noir#7047)
feat: unconstrained optimizations for BoundedVec (noir-lang/noir#7119)
chore: mark libs good (noir-lang/noir#7123)
chore: remove comments for time/memory benchmarks (noir-lang/noir#7121)
fix: don't always use an exclusive lock in `nargo check` (noir-lang/noir#7120)
feat(ssa): Pass to preprocess functions (noir-lang/noir#7072)
chore: Formatting issues / minor errors in the docs (noir-lang/noir#7105)
fix: defunctionalize pass on the caller runtime to apply (noir-lang/noir#7100)
feat: Parser and formatter support for `enum`s (noir-lang/noir#7110)
feat(brillig): SSA globals code gen (noir-lang/noir#7021)
feat: `loop` keyword in runtime and comptime code (noir-lang/noir#7096)
chore: Add benchmarking dashboard (noir-lang/noir#7068)
feat(experimental): try to infer lambda argument types inside calls (noir-lang/noir#7088)
feat(ssa): Add flag to DIE pass to be able to keep `store` instructions (noir-lang/noir#7106)
chore: Cookbook Onboard integration (noir-lang/noir#7044)
chore: lock to ubuntu 22.04 (noir-lang/noir#7098)
fix: Remove unused brillig functions (noir-lang/noir#7102)
chore(ssa): Use correct prefix when printing array values in global space (noir-lang/noir#7095)
  • Loading branch information
AztecBot committed Jan 26, 2025
2 parents d672928 + 0d1bd03 commit feee294
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 205 deletions.
8 changes: 0 additions & 8 deletions noir/noir-repo/compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ use crate::{
usage_tracker::UsageTracker,
DataType, StructField, TypeBindings,
};
use crate::{
ast::{ItemVisibility, UnresolvedType},
graph::CrateGraph,
hir_def::traits::ResolvedTraitBound,
node_interner::GlobalValue,
usage_tracker::UsageTracker,
DataType, StructField, TypeBindings,
};

mod comptime;
mod enums;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,101 +1214,6 @@ pub fn collect_enum(
Some((id, unresolved))
}

#[allow(clippy::too_many_arguments)]
pub fn collect_enum(
interner: &mut NodeInterner,
def_map: &mut CrateDefMap,
usage_tracker: &mut UsageTracker,
enum_def: Documented<NoirEnumeration>,
file_id: FileId,
module_id: LocalModuleId,
krate: CrateId,
definition_errors: &mut Vec<(CompilationError, FileId)>,
) -> Option<(TypeId, UnresolvedEnum)> {
let doc_comments = enum_def.doc_comments;
let enum_def = enum_def.item;

check_duplicate_variant_names(&enum_def, file_id, definition_errors);

let name = enum_def.name.clone();

let unresolved = UnresolvedEnum { file_id, module_id, enum_def };

let resolved_generics = Context::resolve_generics(
interner,
&unresolved.enum_def.generics,
definition_errors,
file_id,
);

// Create the corresponding module for the enum namespace
let location = Location::new(name.span(), file_id);
let id = match push_child_module(
interner,
def_map,
module_id,
&name,
ItemVisibility::Public,
location,
Vec::new(),
Vec::new(),
false, // add to parent scope
false, // is contract
true, // is type
) {
Ok(module_id) => {
let name = unresolved.enum_def.name.clone();
let span = unresolved.enum_def.span;
let attributes = unresolved.enum_def.attributes.clone();
let local_id = module_id.local_id;
interner.new_type(name, span, attributes, resolved_generics, krate, local_id, file_id)
}
Err(error) => {
definition_errors.push((error.into(), file_id));
return None;
}
};

interner.set_doc_comments(ReferenceId::Enum(id), doc_comments);

for (index, variant) in unresolved.enum_def.variants.iter().enumerate() {
if !variant.doc_comments.is_empty() {
let id = ReferenceId::EnumVariant(id, index);
interner.set_doc_comments(id, variant.doc_comments.clone());
}
}

// Add the enum to scope so its path can be looked up later
let visibility = unresolved.enum_def.visibility;
let result = def_map.modules[module_id.0].declare_type(name.clone(), visibility, id);

let parent_module_id = ModuleId { krate, local_id: module_id };

if !unresolved.enum_def.is_abi() {
usage_tracker.add_unused_item(
parent_module_id,
name.clone(),
UnusedItem::Enum(id),
visibility,
);
}

if let Err((first_def, second_def)) = result {
let error = DefCollectorErrorKind::Duplicate {
typ: DuplicateType::TypeDefinition,
first_def,
second_def,
};
definition_errors.push((error.into(), file_id));
}

if interner.is_in_lsp_mode() {
interner.register_enum(id, name.to_string(), visibility, parent_module_id);
}

Some((id, unresolved))
}

pub fn collect_impl(
interner: &mut NodeInterner,
items: &mut CollectedItems,
Expand Down
11 changes: 0 additions & 11 deletions noir/noir-repo/compiler/noirc_frontend/src/locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,6 @@ impl NodeInterner {
self.register_name_for_auto_import(name, ModuleDefId::TypeId(id), visibility, None);
}

pub(crate) fn register_enum(
&mut self,
id: TypeId,
name: String,
visibility: ItemVisibility,
parent_module_id: ModuleId,
) {
self.add_definition_location(ReferenceId::Enum(id), Some(parent_module_id));
self.register_name_for_auto_import(name, ModuleDefId::TypeId(id), visibility, None);
}

pub(crate) fn register_trait(
&mut self,
id: TraitId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,64 +421,6 @@ impl<'a> NodeFinder<'a> {
None
}

fn auto_import_trait_if_trait_method(
&self,
func_id: FuncId,
trait_info: Option<(TraitId, Option<&TraitReexport>)>,
completion_item: &mut CompletionItem,
) -> Option<()> {
// If this is a trait method, check if the trait is in scope
let (trait_id, trait_reexport) = trait_info?;

let trait_name = if let Some(trait_reexport) = trait_reexport {
trait_reexport.name
} else {
let trait_ = self.interner.get_trait(trait_id);
&trait_.name
};

let module_data =
&self.def_maps[&self.module_id.krate].modules()[self.module_id.local_id.0];
if !module_data.scope().find_name(trait_name).is_none() {
return None;
}

// If not, automatically import it
let current_module_parent_id = self.module_id.parent(self.def_maps);
let module_full_path = if let Some(reexport_data) = trait_reexport {
relative_module_id_path(
*reexport_data.module_id,
&self.module_id,
current_module_parent_id,
self.interner,
)
} else {
relative_module_full_path(
ModuleDefId::FunctionId(func_id),
self.module_id,
current_module_parent_id,
self.interner,
)?
};
let full_path = format!("{}::{}", module_full_path, trait_name);
let mut label_details = completion_item.label_details.clone().unwrap();
label_details.detail = Some(format!("(use {})", full_path));
completion_item.label_details = Some(label_details);
completion_item.additional_text_edits = Some(use_completion_item_additional_text_edits(
UseCompletionItemAdditionTextEditsRequest {
full_path: &full_path,
files: self.files,
file: self.file,
lines: &self.lines,
nesting: self.nesting,
auto_import_line: self.auto_import_line,
},
&self.use_segment_positions,
));

None
}

fn compute_function_insert_text(
&self,
func_meta: &FuncMeta,
Expand Down
112 changes: 79 additions & 33 deletions noir/noir-repo/tooling/lsp/src/requests/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,39 +200,6 @@ fn format_enum(
string
}

fn format_enum(id: TypeId, args: &ProcessRequestCallbackArgs) -> String {
let typ = args.interner.get_type(id);
let typ = typ.borrow();

let mut string = String::new();
if format_parent_module(ReferenceId::Enum(id), args, &mut string) {
string.push('\n');
}
string.push_str(" ");
string.push_str("enum ");
string.push_str(&typ.name.0.contents);
format_generics(&typ.generics, &mut string);
string.push_str(" {\n");
for field in typ.get_variants_as_written() {
string.push_str(" ");
string.push_str(&field.name.0.contents);

if !field.params.is_empty() {
let types = field.params.iter().map(ToString::to_string).collect::<Vec<_>>();
string.push('(');
string.push_str(&types.join(", "));
string.push(')');
}

string.push_str(",\n");
}
string.push_str(" }");

append_doc_comments(args.interner, ReferenceId::Enum(id), &mut string);

string
}

fn format_struct_member(
id: TypeId,
field_index: usize,
Expand Down Expand Up @@ -1385,6 +1352,85 @@ mod hover_tests {
" two::Color
Red(Field)
---
Like a tomato"
));
}

#[test]
async fn hover_on_trait_impl_method_uses_docs_from_trait_method() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 92, character: 8 })
.await;
assert!(hover_text.contains("Some docs"));
}

#[test]
async fn hover_on_function_with_mut_self() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 96, character: 10 })
.await;
assert!(hover_text.contains("fn mut_self(&mut self)"));
}

#[test]
async fn hover_on_empty_enum_type() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 100, character: 8 })
.await;
assert!(hover_text.contains(
" two
enum EmptyColor {
}
---
Red, blue, etc."
));
}

#[test]
async fn hover_on_non_empty_enum_type() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 103, character: 8 })
.await;
assert!(hover_text.contains(
" two
enum Color {
Red(Field),
}
---
Red, blue, etc."
));
}

#[test]
async fn hover_on_enum_variant() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 105, character: 6 })
.await;
assert!(hover_text.contains(
" two::Color
Red(Field)
---
Like a tomato"
));
}

#[test]
async fn hover_on_enum_variant_in_call() {
let hover_text =
get_hover_text("workspace", "two/src/lib.nr", Position { line: 109, character: 12 })
.await;
assert!(hover_text.contains(
" two::Color
Red(Field)
---
Like a tomato"
Expand Down

0 comments on commit feee294

Please sign in to comment.