Skip to content

Commit

Permalink
chore: Disable return constant error (noir-lang#3128)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored and Sakapoi committed Oct 19, 2023
1 parent f0ad8ee commit 1a8fcfa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 64 deletions.
56 changes: 7 additions & 49 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ impl Context {
terminator: &TerminatorInstruction,
dfg: &DataFlowGraph,
) -> Result<(), InternalError> {
let (return_values, call_stack) = match terminator {
let (return_values, _call_stack) = match terminator {
TerminatorInstruction::Return { return_values, call_stack } => {
(return_values, call_stack)
}
Expand All @@ -1259,9 +1259,12 @@ impl Context {
// will expand the array if there is one.
let return_acir_vars = self.flatten_value_list(return_values, dfg);
for acir_var in return_acir_vars {
if self.acir_context.is_constant(&acir_var) {
return Err(InternalError::ReturnConstant { call_stack: call_stack.clone() });
}
// TODO(Guillaume) -- disabled as it has shown to break
// TODO with important programs. We will add it back once
// TODO we change it to a warning.
// if self.acir_context.is_constant(&acir_var) {
// return Err(InternalError::ReturnConstant { call_stack: call_stack.clone() });
// }
self.acir_context.return_var(acir_var)?;
}
Ok(())
Expand Down Expand Up @@ -1859,48 +1862,3 @@ impl Context {
}
}
}

#[cfg(test)]
mod tests {
use std::{collections::HashMap, rc::Rc};

use acvm::FieldElement;

use crate::{
brillig::Brillig,
errors::{InternalError, RuntimeError},
ssa::{
function_builder::FunctionBuilder,
ir::{function::RuntimeType, map::Id, types::Type},
},
};

use super::Context;

#[test]
fn returns_body_scoped_arrays() {
// fn main {
// b0():
// return [Field 1]
// }
let func_id = Id::test_new(0);
let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir);

let one = builder.field_constant(FieldElement::one());

let element_type = Rc::new(vec![Type::field()]);
let array_type = Type::Array(element_type, 1);
let array = builder.array_constant(im::Vector::unit(one), array_type);

builder.terminate_with_return(vec![array]);

let ssa = builder.finish();

let context = Context::new();
let acir = context
.convert_ssa(ssa, Brillig::default(), &HashMap::default())
.expect_err("Return constant value");
assert!(matches!(acir, RuntimeError::InternalError(InternalError::ReturnConstant { .. })));
}
}
//

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 1a8fcfa

Please sign in to comment.