Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sync from noir #6332

Merged
merged 4 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95d4d133d1eb5e0eb44cd928d8183d890e970a13
b541e793e20fa3c991e0328ec2ff7926bdcdfd45
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
#require_command wasm-opt
# require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
25 changes: 20 additions & 5 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ pub struct CompileOptions {
/// Force Brillig output (for step debugging)
#[arg(long, hide = true)]
pub force_brillig: bool,

/// Enable the experimental elaborator pass
#[arg(long, hide = true)]
pub use_elaborator: bool,
}

fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
Expand Down Expand Up @@ -245,12 +249,13 @@ pub fn check_crate(
crate_id: CrateId,
deny_warnings: bool,
disable_macros: bool,
use_elaborator: bool,
) -> CompilationResult<()> {
let macros: &[&dyn MacroProcessor] =
if disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] };

let mut errors = vec![];
let diagnostics = CrateDefMap::collect_defs(crate_id, context, macros);
let diagnostics = CrateDefMap::collect_defs(crate_id, context, use_elaborator, macros);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
let diagnostic = CustomDiagnostic::from(&error);
diagnostic.in_file(file_id)
Expand Down Expand Up @@ -282,8 +287,13 @@ pub fn compile_main(
options: &CompileOptions,
cached_program: Option<CompiledProgram>,
) -> CompilationResult<CompiledProgram> {
let (_, mut warnings) =
check_crate(context, crate_id, options.deny_warnings, options.disable_macros)?;
let (_, mut warnings) = check_crate(
context,
crate_id,
options.deny_warnings,
options.disable_macros,
options.use_elaborator,
)?;

let main = context.get_main_function(&crate_id).ok_or_else(|| {
// TODO(#2155): This error might be a better to exist in Nargo
Expand Down Expand Up @@ -318,8 +328,13 @@ pub fn compile_contract(
crate_id: CrateId,
options: &CompileOptions,
) -> CompilationResult<CompiledContract> {
let (_, warnings) =
check_crate(context, crate_id, options.deny_warnings, options.disable_macros)?;
let (_, warnings) = check_crate(
context,
crate_id,
options.deny_warnings,
options.disable_macros,
options.use_elaborator,
)?;

// TODO: We probably want to error if contracts is empty
let contracts = context.get_all_contracts(&crate_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fn stdlib_does_not_produce_constant_warnings() -> Result<(), ErrorsAndWarnings>
let mut context = Context::new(file_manager, parsed_files);
let root_crate_id = prepare_crate(&mut context, file_name);

let ((), warnings) = noirc_driver::check_crate(&mut context, root_crate_id, false, false)?;
let ((), warnings) =
noirc_driver::check_crate(&mut context, root_crate_id, false, false, false)?;

assert_eq!(warnings, Vec::new(), "stdlib is producing warnings");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::ssa::{
ir::{
basic_block::BasicBlockId,
dfg::{CallStack, InsertInstructionResult},
function::{Function, FunctionId},
function::{Function, FunctionId, RuntimeType},
instruction::{Instruction, InstructionId, TerminatorInstruction},
value::{Value, ValueId},
},
Expand Down Expand Up @@ -392,10 +392,11 @@ impl<'function> PerFunctionContext<'function> {
Some(func_id) => {
let function = &ssa.functions[&func_id];
// If we have not already finished the flattening pass, functions marked
// to not have predicates should be marked as entry points.
// to not have predicates should be marked as entry points unless we are inlining into brillig.
let no_predicates_is_entry_point =
self.context.no_predicates_is_entry_point
&& function.is_no_predicates();
&& function.is_no_predicates()
&& !matches!(self.source_function.runtime(), RuntimeType::Brillig);
if function.runtime().is_entry_point() || no_predicates_is_entry_point {
self.push_instruction(*id);
} else {
Expand Down
9 changes: 9 additions & 0 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub enum FunctionKind {
Recursive,
}

impl FunctionKind {
pub fn can_ignore_return_type(self) -> bool {
match self {
FunctionKind::LowLevel | FunctionKind::Builtin | FunctionKind::Oracle => true,
FunctionKind::Normal | FunctionKind::Recursive => false,
}
}
}

impl NoirFunction {
pub fn normal(def: FunctionDefinition) -> NoirFunction {
NoirFunction { kind: FunctionKind::Normal, def }
Expand Down
5 changes: 3 additions & 2 deletions noir/noir-repo/compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ impl ForRange {
identifier: Ident,
block: Expression,
for_loop_span: Span,
) -> StatementKind {
) -> Statement {
/// Counter used to generate unique names when desugaring
/// code in the parser requires the creation of fresh variables.
/// The parser is stateless so this is a static global instead.
Expand Down Expand Up @@ -662,7 +662,8 @@ impl ForRange {
let block = ExpressionKind::Block(BlockExpression {
statements: vec![let_array, for_loop],
});
StatementKind::Expression(Expression::new(block, for_loop_span))
let kind = StatementKind::Expression(Expression::new(block, for_loop_span));
Statement { kind, span: for_loop_span }
}
}
}
Expand Down
Loading
Loading