Skip to content

Commit

Permalink
Merge branch 'master' into tf/execution-refactor
Browse files Browse the repository at this point in the history
* master:
  fix: fix compilation using `aztec` feature flag (#2663)
  fix: remove duplicate file extension in stack trace (#2655)
  chore: use `DebugArtifact`s instead of `FileManager` to report errors (#2641)
  chore: Fix clippy warnings for rust version 1.67.0 (#2661)
  • Loading branch information
TomAFrench committed Sep 12, 2023
2 parents 3ec540f + 7f6fe46 commit 4ca16ab
Show file tree
Hide file tree
Showing 28 changed files with 148 additions and 107 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compiler/fm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
mod file_map;
mod file_reader;

pub use file_map::{File, FileId, FileMap};
pub use file_map::{File, FileId, FileMap, PathString};
use file_reader::is_stdlib_asset;

use std::{
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn stack_trace<'files>(
let source = files.source(call_item.file).expect("should get file source");

let (line, column) = location(source.as_ref(), call_item.span.start());
result += &format!("{}. {}.nr:{}:{}\n", i + 1, path, line, column);
result += &format!("{}. {}:{}:{}\n", i + 1, path, line, column);
}

result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'block> BrilligBlock<'block> {
///
/// This is so that during linking there are no duplicates or labels being overwritten.
fn create_block_label(function_id: FunctionId, block_id: BasicBlockId) -> String {
format!("{}-{}", function_id, block_id)
format!("{function_id}-{block_id}")
}

/// Converts an SSA terminator instruction into the necessary opcodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl DebugToString for BrilligBinaryOp {
if *bit_size >= BRILLIG_MEMORY_ADDRESSING_BIT_SIZE {
op.into()
} else {
format!("{}:{}", op, bit_size)
format!("{op}:{bit_size}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum RuntimeError {
// assert(foo < bar) fails with "failed constraint: 0 = 1."
fn format_failed_constraint(message: &Option<String>) -> String {
match message {
Some(message) => format!("Failed constraint: '{}'", message),
Some(message) => format!("Failed constraint: '{message}'"),
None => "Failed constraint".to_owned(),
}
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,7 @@ impl Context {
// If either side is a numeric type, then we expect their types to be
// the same.
(Type::Numeric(lhs_type), Type::Numeric(rhs_type)) => {
assert_eq!(
lhs_type, rhs_type,
"lhs and rhs types in {:?} are not the same",
binary
);
assert_eq!(lhs_type, rhs_type, "lhs and rhs types in {binary:?} are not the same");
Type::Numeric(lhs_type)
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ fn create_apply_functions(
for (signature, variants) in variants_map.into_iter() {
assert!(
!variants.is_empty(),
"ICE: at least one variant should exist for a dynamic call {:?}",
signature
"ICE: at least one variant should exist for a dynamic call {signature:?}"
);
let dispatches_to_multiple_functions = variants.len() > 1;

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Display for UseTree {
write!(f, "{name}")?;

while let Some(alias) = alias {
write!(f, " as {}", alias)?;
write!(f, " as {alias}")?;
}

Ok(())
Expand Down
11 changes: 5 additions & 6 deletions compiler/noirc_frontend/src/ast/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,20 @@ impl Display for TraitItem {

write!(
f,
"fn {name}<{}>({}) -> {} where {}",
generics, parameters, return_type, where_clause
"fn {name}<{generics}>({parameters}) -> {return_type} where {where_clause}"
)?;

if let Some(body) = body {
write!(f, "{}", body)
write!(f, "{body}")
} else {
write!(f, ";")
}
}
TraitItem::Constant { name, typ, default_value } => {
write!(f, "let {}: {}", name, typ)?;
write!(f, "let {name}: {typ}")?;

if let Some(default_value) = default_value {
write!(f, "{};", default_value)
write!(f, "{default_value};")
} else {
write!(f, ";")
}
Expand Down Expand Up @@ -209,7 +208,7 @@ impl Display for TraitImplItem {
TraitImplItem::Function(function) => function.fmt(f),
TraitImplItem::Type { name, alias } => write!(f, "type {name} = {alias};"),
TraitImplItem::Constant(name, typ, value) => {
write!(f, "let {}: {} = {};", name, typ, value)
write!(f, "let {name}: {typ} = {value};")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/def_collector/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl From<DefCollectorErrorKind> for Diagnostic {
),
DefCollectorErrorKind::NonStructTraitImpl { trait_ident, span } => {
Diagnostic::simple_error(
format!("Only struct types may implement trait `{}`", trait_ident),
format!("Only struct types may implement trait `{trait_ident}`"),
"Only struct types may implement traits".into(),
span,
)
Expand All @@ -129,7 +129,7 @@ impl From<DefCollectorErrorKind> for Diagnostic {
span,
),
DefCollectorErrorKind::TraitNotFound { trait_ident } => Diagnostic::simple_error(
format!("Trait {} not found", trait_ident),
format!("Trait {trait_ident} not found"),
"".to_string(),
trait_ident.span(),
),
Expand Down
33 changes: 18 additions & 15 deletions compiler/noirc_frontend/src/hir/def_map/aztec_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use acvm::FieldElement;
use noirc_errors::{CustomDiagnostic, Span};

use crate::graph::CrateId;
use crate::token::SecondaryAttribute;
use crate::{
hir::Context, token::Attribute, BlockExpression, CallExpression, CastExpression, Distinctness,
Expression, ExpressionKind, ForExpression, FunctionReturnType, Ident, ImportStatement,
IndexExpression, LetStatement, Literal, MemberAccessExpression, MethodCallExpression,
NoirFunction, ParsedModule, Path, PathKind, Pattern, Statement, UnresolvedType,
UnresolvedTypeData, Visibility,
hir::Context, BlockExpression, CallExpression, CastExpression, Distinctness, Expression,
ExpressionKind, ForExpression, FunctionReturnType, Ident, ImportStatement, IndexExpression,
LetStatement, Literal, MemberAccessExpression, MethodCallExpression, NoirFunction,
ParsedModule, Path, PathKind, Pattern, Statement, UnresolvedType, UnresolvedTypeData,
Visibility,
};
use noirc_errors::FileDiagnostic;

Expand Down Expand Up @@ -188,17 +189,19 @@ fn check_for_aztec_dependency(
fn transform_module(functions: &mut [NoirFunction]) -> bool {
let mut has_annotated_functions = false;
for func in functions.iter_mut() {
if let Some(Attribute::Custom(custom_attribute)) = func.def.attribute.as_ref() {
match custom_attribute.as_str() {
"aztec(private)" => {
transform_function("Private", func);
has_annotated_functions = true;
for secondary_attribute in func.def.attributes.secondary.clone() {
if let SecondaryAttribute::Custom(custom_attribute) = secondary_attribute {
match custom_attribute.as_str() {
"aztec(private)" => {
transform_function("Private", func);
has_annotated_functions = true;
}
"aztec(public)" => {
transform_function("Public", func);
has_annotated_functions = true;
}
_ => continue,
}
"aztec(public)" => {
transform_function("Public", func);
has_annotated_functions = true;
}
_ => continue,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/lexer/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl LexerErrorKind {

(
"an unexpected character was found".to_string(),
format!(" expected {expected} , but got {}", found),
format!(" expected {expected} , but got {found}"),
*span,
)
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl fmt::Display for TestScope {
match self {
TestScope::None => write!(f, ""),
TestScope::ShouldFailWith { reason } => match reason {
Some(failure_reason) => write!(f, "(should_fail_with = ({}))", failure_reason),
Some(failure_reason) => write!(f, "(should_fail_with = ({failure_reason}))"),
None => write!(f, "should_fail"),
},
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/parser/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl fmt::Display for ParsingRuleLabel {
ParsingRuleLabel::Statement => write!(f, "statement"),
ParsingRuleLabel::Term => write!(f, "term"),
ParsingRuleLabel::TypeExpression => write!(f, "type expression"),
ParsingRuleLabel::TokenKind(token_kind) => write!(f, "{:?}", token_kind),
ParsingRuleLabel::TokenKind(token_kind) => write!(f, "{token_kind:?}"),
}
}
}
4 changes: 2 additions & 2 deletions tooling/acvm_backend_barretenberg/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ fn main() -> Result<(), String> {
let os = match build_target::target_os().unwrap() {
os @ (Os::Linux | Os::MacOs) => os,
Os::Windows => todo!("Windows is not currently supported"),
os_name => panic!("Unsupported OS {}", os_name),
os_name => panic!("Unsupported OS {os_name}"),
};

let arch = match build_target::target_arch().unwrap() {
arch @ (Arch::X86_64 | Arch::AARCH64) => arch,
arch_name => panic!("Unsupported Architecture {}", arch_name),
arch_name => panic!("Unsupported Architecture {arch_name}"),
};

// Arm builds of linux are not supported
Expand Down
8 changes: 4 additions & 4 deletions tooling/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn on_code_lens_request(
// We can reconsider this when we can build a file without the need for a Nargo.toml file to resolve deps
let _ = state.client.log_message(LogMessageParams {
typ: MessageType::WARNING,
message: format!("{}", err),
message: format!("{err}"),
});
return future::ready(Ok(None));
}
Expand All @@ -181,7 +181,7 @@ fn on_code_lens_request(
// If we found a manifest, but the workspace is invalid, we raise an error about it
return future::ready(Err(ResponseError::new(
ErrorCode::REQUEST_FAILED,
format!("{}", err),
format!("{err}"),
)));
}
};
Expand Down Expand Up @@ -388,7 +388,7 @@ fn on_did_save_text_document(
// We can reconsider this when we can build a file without the need for a Nargo.toml file to resolve deps
let _ = state.client.log_message(LogMessageParams {
typ: MessageType::WARNING,
message: format!("{}", err),
message: format!("{err}"),
});
return ControlFlow::Continue(());
}
Expand All @@ -399,7 +399,7 @@ fn on_did_save_text_document(
// If we found a manifest, but the workspace is invalid, we raise an error about it
return ControlFlow::Break(Err(ResponseError::new(
ErrorCode::REQUEST_FAILED,
format!("{}", err),
format!("{err}"),
)
.into()));
}
Expand Down
1 change: 1 addition & 0 deletions tooling/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ iter-extended.workspace = true
serde.workspace = true
thiserror.workspace = true
base64.workspace = true
codespan-reporting.workspace = true
32 changes: 31 additions & 1 deletion tooling/nargo/src/artifacts/debug.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use codespan_reporting::files::{Error, Files, SimpleFile};
use noirc_errors::debug_info::DebugInfo;
use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, BTreeSet},
ops::Range,
path::PathBuf,
};

use fm::{FileId, FileManager};
use fm::{FileId, FileManager, PathString};

/// For a given file, we store the source code and the path to the file
/// so consumers of the debug artifact can reconstruct the original source code structure.
Expand Down Expand Up @@ -52,3 +54,31 @@ impl DebugArtifact {
Self { debug_symbols, file_map }
}
}

impl<'a> Files<'a> for DebugArtifact {
type FileId = FileId;
type Name = PathString;
type Source = &'a str;

fn name(&self, file_id: Self::FileId) -> Result<Self::Name, Error> {
self.file_map.get(&file_id).ok_or(Error::FileMissing).map(|file| file.path.clone().into())
}

fn source(&'a self, file_id: Self::FileId) -> Result<Self::Source, Error> {
self.file_map.get(&file_id).ok_or(Error::FileMissing).map(|file| file.source.as_ref())
}

fn line_index(&self, file_id: Self::FileId, byte_index: usize) -> Result<usize, Error> {
self.file_map.get(&file_id).ok_or(Error::FileMissing).and_then(|file| {
SimpleFile::new(PathString::from(file.path.clone()), file.source.clone())
.line_index((), byte_index)
})
}

fn line_range(&self, file_id: Self::FileId, line_index: usize) -> Result<Range<usize>, Error> {
self.file_map.get(&file_id).ok_or(Error::FileMissing).and_then(|file| {
SimpleFile::new(PathString::from(file.path.clone()), file.source.clone())
.line_range((), line_index)
})
}
}
2 changes: 1 addition & 1 deletion tooling/nargo/src/ops/foreign_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ForeignCall {
],
})
}
None => panic!("unexpected foreign call {:?}", foreign_call_name),
None => panic!("unexpected foreign call {foreign_call_name:?}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/backend_cmd/ls_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) struct LsCommand;

pub(crate) fn run(_args: LsCommand) -> Result<(), CliError> {
for backend in get_available_backends() {
println!("{}", backend);
println!("{backend}");
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn smart_contract_for_package(
let preprocessed_program = if circuit_build_path.exists() {
read_program_from_file(circuit_build_path)?
} else {
let (_, program) =
let (program, _) =
compile_package(package, compile_options, np_language, &is_opcode_supported)?;

PreprocessedProgram {
Expand Down
Loading

0 comments on commit 4ca16ab

Please sign in to comment.