Skip to content

Commit

Permalink
feat: add mutating FunctionDefinition functions (#5685)
Browse files Browse the repository at this point in the history
# Description

## Problem

Part of #5668

## Summary

## Additional Context

I think we are missing a `FunctionDefinition::body`, but that could come
later.

I had to get a `FuncMeta` many times in some functions because Rust
wouldn't let me get two mutable borrows of interner.

Generics handling is missing... but I think right now generics can't
appear in these functions, as attributes only run on top-level
functions, not on impl or trait impl functions, but let me know if this
is not the case.

## Documentation\*

Check one:
- [x] 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.
  • Loading branch information
asterite authored Aug 8, 2024
1 parent 500eba0 commit 2882eae
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 151 deletions.
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/elaborator/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'context> Elaborator<'context> {

/// Equivalent to `elaborate_pattern`, this version just also
/// adds any new DefinitionIds that were created to the given Vec.
pub(super) fn elaborate_pattern_and_store_ids(
pub fn elaborate_pattern_and_store_ids(
&mut self,
pattern: Pattern,
expected_type: Type,
Expand Down
11 changes: 11 additions & 0 deletions compiler/noirc_frontend/src/hir/comptime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ pub enum InterpreterError {
FailedToResolveTraitDefinition {
location: Location,
},
FunctionAlreadyResolved {
location: Location,
},

Unimplemented {
item: String,
Expand Down Expand Up @@ -255,6 +258,7 @@ impl InterpreterError {
| InterpreterError::TraitDefinitionMustBeAPath { location }
| InterpreterError::FailedToResolveTraitDefinition { location }
| InterpreterError::FailedToResolveTraitBound { location, .. } => *location,
InterpreterError::FunctionAlreadyResolved { location, .. } => *location,

InterpreterError::FailedToParseMacro { error, file, .. } => {
Location::new(error.span(), *file)
Expand Down Expand Up @@ -516,6 +520,13 @@ impl<'a> From<&'a InterpreterError> for CustomDiagnostic {
let msg = "Failed to resolve to a trait definition".to_string();
CustomDiagnostic::simple_error(msg, String::new(), location.span)
}
InterpreterError::FunctionAlreadyResolved { location } => {
let msg = "Function already resolved".to_string();
let secondary =
"The function was previously called at compile-time or is in another crate"
.to_string();
CustomDiagnostic::simple_error(msg, secondary, location.span)
}
}
}
}
Loading

0 comments on commit 2882eae

Please sign in to comment.