Skip to content

Commit

Permalink
Merge branch 'master' into gd/issue_5715
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic authored Sep 18, 2024
2 parents 0678b86 + 19eef30 commit dc4d992
Show file tree
Hide file tree
Showing 115 changed files with 1,831 additions and 858 deletions.
6 changes: 3 additions & 3 deletions aztec_macros/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn signature_of_type(typ: &Type) -> String {
Type::FieldElement => "Field".to_owned(),
Type::Bool => "bool".to_owned(),
Type::Array(len, typ) => {
if let Type::Constant(len) = **len {
if let Type::Constant(len, _) = **len {
format!("[{};{len}]", signature_of_type(typ))
} else {
unimplemented!("Cannot generate signature for array with length type {:?}", typ)
Expand All @@ -90,7 +90,7 @@ pub fn signature_of_type(typ: &Type) -> String {
format!("({})", fields.join(","))
}
Type::String(len_typ) => {
if let Type::Constant(len) = **len_typ {
if let Type::Constant(len, _) = **len_typ {
format!("str<{len}>")
} else {
unimplemented!(
Expand Down Expand Up @@ -326,7 +326,7 @@ pub fn get_serialized_length(
let serialized_trait_impl = serialized_trait_impl_shared.borrow();

match serialized_trait_impl.trait_generics.first().unwrap() {
Type::Constant(value) => Ok(*value),
Type::Constant(value, _) => Ok(*value),
_ => Err(MacroError {
primary_message: format!("{} length for {} must be a constant", trait_name, typ),
secondary_message: None,
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_driver/src/abi_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub(super) fn abi_type_from_hir_type(context: &Context, typ: &Type) -> AbiType {
}
Type::Error
| Type::Unit
| Type::Constant(_)
| Type::Constant(..)
| Type::InfixExpr(..)
| Type::TraitAsType(..)
| Type::TypeVariable(_, _)
Expand Down
11 changes: 1 addition & 10 deletions compiler/noirc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,11 @@ pub use reporter::{CustomDiagnostic, DiagnosticKind};
pub struct FileDiagnostic {
pub file_id: fm::FileId,
pub diagnostic: CustomDiagnostic,

/// An optional call stack to display the full runtime call stack
/// leading up to a runtime error. If this is empty it will not be displayed.
pub call_stack: Vec<Location>,
}

impl FileDiagnostic {
pub fn new(file_id: fm::FileId, diagnostic: CustomDiagnostic) -> FileDiagnostic {
FileDiagnostic { file_id, diagnostic, call_stack: Vec::new() }
}

pub fn with_call_stack(mut self, call_stack: Vec<Location>) -> Self {
self.call_stack = call_stack;
self
FileDiagnostic { file_id, diagnostic }
}
}

Expand Down
17 changes: 14 additions & 3 deletions compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub struct CustomDiagnostic {
pub kind: DiagnosticKind,
pub deprecated: bool,
pub unnecessary: bool,

/// An optional call stack to display the full runtime call stack
/// leading up to a runtime error. If this is empty it will not be displayed.
pub call_stack: Vec<Location>,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand All @@ -39,6 +43,7 @@ impl CustomDiagnostic {
kind: DiagnosticKind::Error,
deprecated: false,
unnecessary: false,
call_stack: Default::default(),
}
}

Expand All @@ -55,6 +60,7 @@ impl CustomDiagnostic {
kind,
deprecated: false,
unnecessary: false,
call_stack: Default::default(),
}
}

Expand Down Expand Up @@ -109,13 +115,19 @@ impl CustomDiagnostic {
kind: DiagnosticKind::Bug,
deprecated: false,
unnecessary: false,
call_stack: Default::default(),
}
}

pub fn in_file(self, file_id: fm::FileId) -> FileDiagnostic {
FileDiagnostic::new(file_id, self)
}

pub fn with_call_stack(mut self, call_stack: Vec<Location>) -> Self {
self.call_stack = call_stack;
self
}

pub fn add_note(&mut self, message: String) {
self.notes.push(message);
}
Expand Down Expand Up @@ -204,7 +216,7 @@ impl FileDiagnostic {
files: &'files impl Files<'files, FileId = fm::FileId>,
deny_warnings: bool,
) -> bool {
report(files, &self.diagnostic, Some(self.file_id), &self.call_stack, deny_warnings)
report(files, &self.diagnostic, Some(self.file_id), deny_warnings)
}
}

Expand All @@ -213,15 +225,14 @@ pub fn report<'files>(
files: &'files impl Files<'files, FileId = fm::FileId>,
custom_diagnostic: &CustomDiagnostic,
file: Option<fm::FileId>,
call_stack: &[Location],
deny_warnings: bool,
) -> bool {
let color_choice =
if std::io::stderr().is_terminal() { ColorChoice::Auto } else { ColorChoice::Never };
let writer = StandardStream::stderr(color_choice);
let config = codespan_reporting::term::Config::default();

let stack_trace = stack_trace(files, call_stack);
let stack_trace = stack_trace(files, &custom_diagnostic.call_stack);
let diagnostic = convert_diagnostic(custom_diagnostic, file, stack_trace, deny_warnings);
term::emit(&mut writer.lock(), &config, files, &diagnostic).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl From<SsaReport> for FileDiagnostic {
let location = call_stack.last().expect("Expected RuntimeError to have a location");
let diagnostic =
Diagnostic::simple_warning(message, secondary_message, location.span);
diagnostic.in_file(file_id).with_call_stack(call_stack)
diagnostic.with_call_stack(call_stack).in_file(file_id)
}
SsaReport::Bug(bug) => {
let message = bug.to_string();
Expand All @@ -101,7 +101,7 @@ impl From<SsaReport> for FileDiagnostic {
let file_id = call_stack.last().map(|location| location.file).unwrap_or_default();
let location = call_stack.last().expect("Expected RuntimeError to have a location");
let diagnostic = Diagnostic::simple_bug(message, secondary_message, location.span);
diagnostic.in_file(file_id).with_call_stack(call_stack)
diagnostic.with_call_stack(call_stack).in_file(file_id)
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ impl From<RuntimeError> for FileDiagnostic {
let call_stack = vecmap(error.call_stack(), |location| *location);
let file_id = call_stack.last().map(|location| location.file).unwrap_or_default();
let diagnostic = error.into_diagnostic();
diagnostic.in_file(file_id).with_call_stack(call_stack)
diagnostic.with_call_stack(call_stack).in_file(file_id)
}
}

Expand Down
8 changes: 8 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/function_inserter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ impl<'f> FunctionInserter<'f> {
self.function.dfg[block].set_terminator(terminator);
}

/// Maps the data bus in place, replacing any ValueId in the data bus with the
/// resolved version of that value id from this FunctionInserter's internal value mapping.
pub(crate) fn map_data_bus_in_place(&mut self) {
let data_bus = self.function.dfg.data_bus.clone();
let data_bus = data_bus.map_values(|value| self.resolve(value));
self.function.dfg.data_bus = data_bus;
}

/// Push a new instruction to the given block and return its new InstructionId.
/// If the instruction was simplified out of the program, None is returned.
pub(crate) fn push_instruction(
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ impl<'f> Context<'f> {
}
}
}
self.inserter.map_data_bus_in_place();
}

/// Returns the updated condition so that
Expand Down
Loading

0 comments on commit dc4d992

Please sign in to comment.