colored backtrace reports, full and 1 for leo backtrace

This commit is contained in:
gluaxspeed 2021-08-04 14:19:19 -07:00
parent b1f93e95b3
commit 2a99a87da7
146 changed files with 875 additions and 1289 deletions

22
Cargo.lock generated
View File

@ -340,6 +340,17 @@ dependencies = [
"vec_map",
]
[[package]]
name = "color-backtrace"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6c04463c99389fff045d2b90ce84f5131332712c7ffbede020f5e9ad1ed685"
dependencies = [
"atty",
"backtrace",
"termcolor",
]
[[package]]
name = "colored"
version = "2.0.0"
@ -1263,6 +1274,7 @@ name = "leo-errors"
version = "1.5.3"
dependencies = [
"backtrace",
"color-backtrace",
"derivative",
"eyre",
"leo-input",
@ -1304,6 +1316,7 @@ dependencies = [
"ansi_term 0.12.1",
"assert_cmd",
"clap",
"color-backtrace",
"colored",
"console",
"dirs",
@ -2802,6 +2815,15 @@ dependencies = [
"utf-8",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.1.17"

View File

@ -102,6 +102,9 @@ version = "0.3"
[dependencies.clap]
version = "2.33.3"
[dependencies]
color-backtrace = "0.5.1"
[dependencies.colored]
version = "2.0"

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Circuit, Identifier, IntegerType, Type};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use indexmap::IndexMap;
use num_bigint::BigInt;
@ -316,56 +316,16 @@ impl ConstInt {
pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result<ConstInt> {
Ok(match int_type {
IntegerType::I8 => ConstInt::I8(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::I16 => ConstInt::I16(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::I32 => ConstInt::I32(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::I64 => ConstInt::I64(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::I128 => ConstInt::I128(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::U8 => ConstInt::U8(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::U16 => ConstInt::U16(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::U32 => ConstInt::U32(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::U64 => ConstInt::U64(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::U128 => ConstInt::U128(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
})
}
}

View File

@ -16,7 +16,7 @@
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_ast::IntegerType;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -97,7 +97,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<'
"array",
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}
@ -115,12 +114,9 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<'
.flatten()
{
if index >= array_len {
return Err(AsgError::array_index_out_of_bounds(
index,
&array.span().cloned().unwrap_or_default(),
new_backtrace(),
)
.into());
return Err(
AsgError::array_index_out_of_bounds(index, &array.span().cloned().unwrap_or_default()).into(),
);
}
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -74,7 +74,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
None => (None, None),
Some(type_) => {
return Err(AsgError::unexpected_type(type_, "array", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(type_, "array", &value.span).into());
}
};
let dimensions = value
@ -84,20 +84,19 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
.map(|x| {
Ok(x.value
.parse::<usize>()
.map_err(|_| AsgError::parse_dimension_error(&value.span, new_backtrace()))?)
.map_err(|_| AsgError::parse_dimension_error(&value.span))?)
})
.collect::<Result<Vec<_>>>()?;
let len = *dimensions
.get(0)
.ok_or_else(|| AsgError::parse_dimension_error(&value.span, new_backtrace()))?;
.ok_or_else(|| AsgError::parse_dimension_error(&value.span))?;
if let Some(expected_len) = expected_len {
if expected_len != len {
return Err(AsgError::unexpected_type(
format!("array of length {}", expected_len),
format!("array of length {}", len),
&value.span,
new_backtrace(),
)
.into());
}
@ -112,7 +111,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
format!("array of length {}", dimension),
format!("array of length {}", len),
&value.span,
new_backtrace(),
)
.into());
}
@ -122,7 +120,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> {
}
None => None,
Some(type_) => {
return Err(AsgError::unexpected_type("array", type_, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type("array", type_, &value.span).into());
}
}
}

View File

@ -16,7 +16,7 @@
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_ast::SpreadOrExpression;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -109,7 +109,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<'
Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims),
None => (None, None),
Some(type_) => {
return Err(AsgError::unexpected_type(type_, "array", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(type_, "array", &value.span).into());
}
};
@ -174,7 +174,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<'
.unwrap_or("unknown"),
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}
@ -190,7 +189,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<'
format!("array of length {}", expected_len),
format!("array of length {}", len),
&value.span,
new_backtrace(),
)
.into());
}

View File

@ -16,7 +16,7 @@
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_ast::IntegerType;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -108,7 +108,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
Some(PartialType::Array(element, len)) => (Some(PartialType::Array(element, None)), len),
None => (None, None),
Some(x) => {
return Err(AsgError::unexpected_type(x, "array", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, "array", &value.span).into());
}
};
let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array)?;
@ -120,7 +120,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
"array",
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}
@ -156,9 +155,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
} else {
value.span.clone()
};
return Err(
AsgError::array_index_out_of_bounds(inner_value, &error_span, new_backtrace()).into(),
);
return Err(AsgError::array_index_out_of_bounds(inner_value, &error_span).into());
} else if let Some(left) = const_left {
if left > inner_value {
let error_span = if let Some(right) = right {
@ -166,9 +163,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
} else {
value.span.clone()
};
return Err(
AsgError::array_index_out_of_bounds(inner_value, &error_span, new_backtrace()).into(),
);
return Err(AsgError::array_index_out_of_bounds(inner_value, &error_span).into());
}
}
}
@ -188,13 +183,9 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
if let Some(length) = length {
if length != expected_len {
let concrete_type = Type::Array(parent_element, length);
return Err(AsgError::unexpected_type(
expected_type.as_ref().unwrap(),
concrete_type,
&value.span,
new_backtrace(),
)
.into());
return Err(
AsgError::unexpected_type(expected_type.as_ref().unwrap(), concrete_type, &value.span).into(),
);
}
}
if let Some(left_value) = const_left {
@ -204,13 +195,13 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx
} else {
value.span.clone()
};
return Err(AsgError::array_index_out_of_bounds(left_value, &error_span, new_backtrace()).into());
return Err(AsgError::array_index_out_of_bounds(left_value, &error_span).into());
}
}
length = Some(expected_len);
}
if length.is_none() {
return Err(AsgError::unknown_array_size(&value.span, new_backtrace()).into());
return Err(AsgError::unknown_array_size(&value.span).into());
}
Ok(ArrayRangeAccessExpression {

View File

@ -16,7 +16,7 @@
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
pub use leo_ast::{BinaryOperation, BinaryOperationClass};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -123,7 +123,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
BinaryOperationClass::Boolean => match expected_type {
Some(PartialType::Type(Type::Boolean)) | None => None,
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into());
}
},
BinaryOperationClass::Numeric => match expected_type {
@ -131,9 +131,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
Some(x @ PartialType::Type(Type::Field)) => Some(x),
Some(x @ PartialType::Type(Type::Group)) => Some(x),
Some(x) => {
return Err(
AsgError::unexpected_type(x, "integer, field, or group", &value.span, new_backtrace()).into(),
);
return Err(AsgError::unexpected_type(x, "integer, field, or group", &value.span).into());
}
None => None,
},
@ -186,7 +184,6 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
"integer",
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}
@ -195,14 +192,14 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
BinaryOperation::And | BinaryOperation::Or => match left_type {
Some(Type::Boolean) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into());
}
},
BinaryOperation::Eq | BinaryOperation::Ne => (), // all types allowed
_ => match left_type {
Some(Type::Integer(_)) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, "integer", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, "integer", &value.span).into());
}
},
},
@ -213,11 +210,11 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> {
match (left_type, right_type) {
(Some(left_type), Some(right_type)) => {
if !left_type.is_assignable_from(&right_type) {
return Err(AsgError::unexpected_type(left_type, right_type, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(left_type, right_type, &value.span).into());
}
}
(None, None) => {
return Err(AsgError::unexpected_type("any type", "unknown type", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type("any type", "unknown type", &value.span).into());
}
(_, _) => (),
}

View File

@ -28,7 +28,7 @@ use crate::{
Type,
};
pub use leo_ast::{BinaryOperation, Node as AstNode};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -94,7 +94,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
None,
scope
.resolve_function(&name.name)
.ok_or_else(|| AsgError::unresolved_function(&name.name, &name.span, new_backtrace()))?,
.ok_or_else(|| AsgError::unresolved_function(&name.name, &name.span))?,
),
leo_ast::Expression::CircuitMemberAccess(leo_ast::CircuitMemberAccessExpression {
circuit: ast_circuit,
@ -109,41 +109,28 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
"circuit",
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
span,
new_backtrace(),
)
.into());
}
};
let circuit_name = circuit.name.borrow().name.clone();
let member = circuit.members.borrow();
let member = member.get(name.name.as_ref()).ok_or_else(|| {
AsgError::unresolved_circuit_member(&circuit_name, &name.name, span, new_backtrace())
})?;
let member = member
.get(name.name.as_ref())
.ok_or_else(|| AsgError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
match member {
CircuitMember::Function(body) => {
if body.qualifier == FunctionQualifier::Static {
return Err(AsgError::circuit_static_call_invalid(
&circuit_name,
&name.name,
span,
new_backtrace(),
)
.into());
return Err(AsgError::circuit_static_call_invalid(&circuit_name, &name.name, span).into());
} else if body.qualifier == FunctionQualifier::MutSelfRef && !target.is_mut_ref() {
return Err(AsgError::circuit_member_mut_call_invalid(
circuit_name,
&name.name,
span,
new_backtrace(),
)
.into());
return Err(
AsgError::circuit_member_mut_call_invalid(circuit_name, &name.name, span).into(),
);
}
(Some(target), *body)
}
CircuitMember::Variable(_) => {
return Err(
AsgError::circuit_variable_call(circuit_name, &name.name, span, new_backtrace()).into(),
);
return Err(AsgError::circuit_variable_call(circuit_name, &name.name, span).into());
}
}
}
@ -153,35 +140,27 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
span,
}) => {
let circuit = if let leo_ast::Expression::Identifier(circuit_name) = &**ast_circuit {
scope.resolve_circuit(&circuit_name.name).ok_or_else(|| {
AsgError::unresolved_circuit(&circuit_name.name, &circuit_name.span, new_backtrace())
})?
scope
.resolve_circuit(&circuit_name.name)
.ok_or_else(|| AsgError::unresolved_circuit(&circuit_name.name, &circuit_name.span))?
} else {
return Err(AsgError::unexpected_type("circuit", "unknown", span, new_backtrace()).into());
return Err(AsgError::unexpected_type("circuit", "unknown", span).into());
};
let circuit_name = circuit.name.borrow().name.clone();
let member = circuit.members.borrow();
let member = member.get(name.name.as_ref()).ok_or_else(|| {
AsgError::unresolved_circuit_member(&circuit_name, &name.name, span, new_backtrace())
})?;
let member = member
.get(name.name.as_ref())
.ok_or_else(|| AsgError::unresolved_circuit_member(&circuit_name, &name.name, span))?;
match member {
CircuitMember::Function(body) => {
if body.qualifier != FunctionQualifier::Static {
return Err(AsgError::circuit_member_call_invalid(
circuit_name,
&name.name,
span,
new_backtrace(),
)
.into());
return Err(AsgError::circuit_member_call_invalid(circuit_name, &name.name, span).into());
}
(None, *body)
}
CircuitMember::Variable(_) => {
return Err(
AsgError::circuit_variable_call(circuit_name, &name.name, span, new_backtrace()).into(),
);
return Err(AsgError::circuit_variable_call(circuit_name, &name.name, span).into());
}
}
}
@ -189,7 +168,6 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
return Err(AsgError::illegal_ast_structure(
"non Identifier/CircuitMemberAccess/CircuitStaticFunctionAccess as call target",
&value.span,
new_backtrace(),
)
.into());
}
@ -197,7 +175,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
if let Some(expected) = expected_type {
let output: Type = function.output.clone();
if !expected.matches(&output) {
return Err(AsgError::unexpected_type(expected, output, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(expected, output, &value.span).into());
}
}
if value.arguments.len() != function.arguments.len() {
@ -205,7 +183,6 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
function.arguments.len(),
value.arguments.len(),
&value.span,
new_backtrace(),
)
.into());
}
@ -218,14 +195,14 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> {
let argument = argument.get().borrow();
let converted = <&Expression<'a>>::from_ast(scope, expr, Some(argument.type_.clone().partial()))?;
if argument.const_ && !converted.is_consty() {
return Err(AsgError::unexpected_nonconst(expr.span(), new_backtrace()).into());
return Err(AsgError::unexpected_nonconst(expr.span()).into());
}
Ok(Cell::new(converted))
})
.collect::<Result<Vec<_>>>()?;
if function.is_test() {
return Err(AsgError::call_test_function(&value.span, new_backtrace()).into());
return Err(AsgError::call_test_function(&value.span).into());
}
Ok(CallExpression {
parent: Cell::new(None),

View File

@ -16,7 +16,7 @@
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
pub use leo_ast::UnaryOperation;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -80,7 +80,7 @@ impl<'a> FromAst<'a, leo_ast::CastExpression> for CastExpression<'a> {
let target_type = scope.resolve_ast_type(&value.target_type, &value.span)?;
if let Some(expected_type) = &expected_type {
if !expected_type.matches(&target_type) {
return Err(AsgError::unexpected_type(expected_type, target_type, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(expected_type, target_type, &value.span).into());
}
}

View File

@ -28,7 +28,7 @@ use crate::{
Type,
};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
#[derive(Clone)]
@ -111,7 +111,6 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
"circuit",
x.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}
@ -124,9 +123,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
if let CircuitMember::Variable(type_) = &member {
let type_: Type = type_.clone();
if !expected_type.matches(&type_) {
return Err(
AsgError::unexpected_type(expected_type, type_, &value.span, new_backtrace()).into(),
);
return Err(AsgError::unexpected_type(expected_type, type_, &value.span).into());
}
} // used by call expression
}
@ -146,20 +143,15 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx
CircuitMember::Variable(expected_type.clone()),
);
} else {
return Err(AsgError::input_ref_needs_type(
&circuit.name.borrow().name,
&value.name.name,
&value.span,
new_backtrace(),
)
.into());
return Err(
AsgError::input_ref_needs_type(&circuit.name.borrow().name, &value.name.name, &value.span).into(),
);
}
} else {
return Err(AsgError::unresolved_circuit_member(
&circuit.name.borrow().name,
&value.name.name,
&value.span,
new_backtrace(),
)
.into());
}
@ -183,14 +175,14 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit
let circuit = match &*value.circuit {
leo_ast::Expression::Identifier(name) => scope
.resolve_circuit(&name.name)
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span, new_backtrace()))?,
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?,
_ => {
return Err(AsgError::unexpected_type("circuit", "unknown", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type("circuit", "unknown", &value.span).into());
}
};
if let Some(expected_type) = expected_type {
return Err(AsgError::unexpected_type(expected_type, "none", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(expected_type, "none", &value.span).into());
}
if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(value.name.name.as_ref()) {
@ -200,7 +192,6 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit
&circuit.name.borrow().name,
&value.name.name,
&value.span,
new_backtrace(),
)
.into());
}

View File

@ -28,7 +28,7 @@ use crate::{
Type,
};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use indexmap::{IndexMap, IndexSet};
use std::cell::Cell;
@ -96,18 +96,12 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
) -> Result<CircuitInitExpression<'a>> {
let circuit = scope
.resolve_circuit(&value.name.name)
.ok_or_else(|| AsgError::unresolved_circuit(&value.name.name, &value.name.span, new_backtrace()))?;
.ok_or_else(|| AsgError::unresolved_circuit(&value.name.name, &value.name.span))?;
match expected_type {
Some(PartialType::Type(Type::Circuit(expected_circuit))) if expected_circuit == circuit => (),
None => (),
Some(x) => {
return Err(AsgError::unexpected_type(
x,
circuit.name.borrow().name.to_string(),
&value.span,
new_backtrace(),
)
.into());
return Err(AsgError::unexpected_type(x, circuit.name.borrow().name.to_string(), &value.span).into());
}
}
let members: IndexMap<&str, (&Identifier, Option<&leo_ast::Expression>)> = value
@ -123,13 +117,9 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
let circuit_members = circuit.members.borrow();
for (name, member) in circuit_members.iter() {
if defined_variables.contains(name) {
return Err(AsgError::overridden_circuit_member(
&circuit.name.borrow().name,
name,
&value.span,
new_backtrace(),
)
.into());
return Err(
AsgError::overridden_circuit_member(&circuit.name.borrow().name, name, &value.span).into(),
);
}
defined_variables.insert(name.clone());
let type_: Type = if let CircuitMember::Variable(type_) = &member {
@ -149,25 +139,17 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<'
};
values.push(((*identifier).clone(), Cell::new(received)));
} else {
return Err(AsgError::missing_circuit_member(
&circuit.name.borrow().name,
name,
&value.span,
new_backtrace(),
)
.into());
return Err(
AsgError::missing_circuit_member(&circuit.name.borrow().name, name, &value.span).into(),
);
}
}
for (name, (identifier, _expression)) in members.iter() {
if circuit_members.get(*name).is_none() {
return Err(AsgError::extra_circuit_member(
&circuit.name.borrow().name,
name,
&identifier.span,
new_backtrace(),
)
.into());
return Err(
AsgError::extra_circuit_member(&circuit.name.borrow().name, name, &identifier.span).into(),
);
}
}
}

View File

@ -28,7 +28,7 @@ use crate::{
Type,
};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -85,7 +85,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
match expected_type.map(PartialType::full).flatten() {
Some(Type::Address) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Address, span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Address, span).into());
}
}
Constant {
@ -98,7 +98,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
match expected_type.map(PartialType::full).flatten() {
Some(Type::Boolean) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Boolean, span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Boolean, span).into());
}
}
Constant {
@ -107,7 +107,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
value: ConstValue::Boolean(
value
.parse::<bool>()
.map_err(|_| AsgError::invalid_boolean(value, span, new_backtrace()))?,
.map_err(|_| AsgError::invalid_boolean(value, span))?,
),
}
}
@ -115,7 +115,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
match expected_type.map(PartialType::full).flatten() {
Some(Type::Char) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Char, value.span(), new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Char, value.span()).into());
}
}
@ -129,24 +129,20 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
match expected_type.map(PartialType::full).flatten() {
Some(Type::Field) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Field, span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Field, span).into());
}
}
Constant {
parent: Cell::new(None),
span: Some(span.clone()),
value: ConstValue::Field(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
value: ConstValue::Field(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
}
}
Group(value) => {
match expected_type.map(PartialType::full).flatten() {
Some(Type::Group) | None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, Type::Group, value.span(), new_backtrace()).into());
return Err(AsgError::unexpected_type(x, Type::Group, value.span()).into());
}
}
Constant {
@ -163,7 +159,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
}
}
Implicit(value, span) => match expected_type {
None => return Err(AsgError::unresolved_type("unknown", span, new_backtrace()).into()),
None => return Err(AsgError::unresolved_type("unknown", span).into()),
Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => {
Constant {
parent: Cell::new(None),
@ -174,11 +170,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
Some(PartialType::Type(Type::Field)) => Constant {
parent: Cell::new(None),
span: Some(span.clone()),
value: ConstValue::Field(
value
.parse()
.map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?,
),
value: ConstValue::Field(value.parse().map_err(|_| AsgError::invalid_int(value, span))?),
},
Some(PartialType::Type(Type::Group)) => Constant {
parent: Cell::new(None),
@ -191,7 +183,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
value: ConstValue::Address(value.clone()),
},
Some(x) => {
return Err(AsgError::unexpected_type(x, "unknown", span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, "unknown", span).into());
}
},
Integer(int_type, value, span) => {
@ -200,7 +192,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
Some(PartialType::Integer(None, Some(_))) => (),
None => (),
Some(x) => {
return Err(AsgError::unexpected_type(x, int_type, span, new_backtrace()).into());
return Err(AsgError::unexpected_type(x, int_type, span).into());
}
}
Constant {

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -91,7 +91,7 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> {
let right = if_false.get().get_type().unwrap().into();
if left != right {
return Err(AsgError::ternary_different_types(left, right, &value.span, new_backtrace()).into());
return Err(AsgError::ternary_different_types(left, right, &value.span).into());
}
Ok(TernaryExpression {

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -80,7 +80,7 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<'
.index
.value
.parse::<usize>()
.map_err(|_| AsgError::parse_index_error(&value.span, new_backtrace()))?;
.map_err(|_| AsgError::parse_index_error(&value.span))?;
let mut expected_tuple = vec![None; index + 1];
expected_tuple[index] = expected_type;
@ -95,7 +95,6 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<'
.map(|x| x.to_string())
.unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -90,7 +90,6 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> {
"tuple",
x.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&value.span,
new_backtrace(),
)
.into());
}
@ -104,7 +103,6 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> {
format!("tuple of length {}", tuple_types.len()),
format!("tuple of length {}", value.elements.len()),
&value.span,
new_backtrace(),
)
.into());
}

View File

@ -16,7 +16,7 @@
use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type};
pub use leo_ast::UnaryOperation;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -95,7 +95,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> {
UnaryOperation::Not => match expected_type.map(|x| x.full()).flatten() {
Some(Type::Boolean) | None => Some(Type::Boolean),
Some(type_) => {
return Err(AsgError::unexpected_type(type_, Type::Boolean, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(type_, Type::Boolean, &value.span).into());
}
},
UnaryOperation::Negate => match expected_type.map(|x| x.full()).flatten() {
@ -104,20 +104,14 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> {
Some(Type::Field) => Some(Type::Field),
None => None,
Some(type_) => {
return Err(AsgError::unexpected_type(
type_,
"integer, group, field",
&value.span,
new_backtrace(),
)
.into());
return Err(AsgError::unexpected_type(type_, "integer, group, field", &value.span).into());
}
},
UnaryOperation::BitNot => match expected_type.map(|x| x.full()).flatten() {
Some(type_ @ Type::Integer(_)) => Some(type_),
None => None,
Some(type_) => {
return Err(AsgError::unexpected_type(type_, "integer", &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(type_, "integer", &value.span).into());
}
},
};
@ -132,7 +126,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> {
})
.unwrap_or(false);
if is_expr_unsigned {
return Err(AsgError::unsigned_negation(&value.span, new_backtrace()).into());
return Err(AsgError::unsigned_negation(&value.span).into());
}
}
Ok(UnaryExpression {

View File

@ -29,7 +29,7 @@ use crate::{
Variable,
};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -143,7 +143,6 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
return Err(AsgError::illegal_input_variable_reference(
"attempted to reference input when none is in scope",
&value.span,
new_backtrace(),
)
.into());
}
@ -158,7 +157,7 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
value: ConstValue::Address(value.name.clone()),
})));
}
return Err(AsgError::unresolved_reference(&value.name, &value.span, new_backtrace()).into());
return Err(AsgError::unresolved_reference(&value.name, &value.span).into());
}
}
};
@ -173,9 +172,9 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> {
if let Some(expected_type) = expected_type {
let type_ = expression
.get_type()
.ok_or_else(|| AsgError::unresolved_reference(&value.name, &value.span, new_backtrace()))?;
.ok_or_else(|| AsgError::unresolved_reference(&value.name, &value.span))?;
if !expected_type.matches(&type_) {
return Err(AsgError::unexpected_type(expected_type, type_, &value.span, new_backtrace()).into());
return Err(AsgError::unexpected_type(expected_type, type_, &value.span).into());
}
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Function, Identifier, Node, Scope, Type};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use indexmap::IndexMap;
use std::cell::RefCell;
@ -71,13 +71,9 @@ impl<'a> Circuit<'a> {
for member in value.members.iter() {
if let leo_ast::CircuitMember::CircuitVariable(name, type_) = member {
if members.contains_key(name.name.as_ref()) {
return Err(AsgError::redefined_circuit_member(
&value.circuit_name.name,
&name.name,
&name.span,
new_backtrace(),
)
.into());
return Err(
AsgError::redefined_circuit_member(&value.circuit_name.name, &name.name, &name.span).into(),
);
}
members.insert(
name.name.to_string(),
@ -104,14 +100,13 @@ impl<'a> Circuit<'a> {
&value.circuit_name.name,
&function.identifier.name,
&function.identifier.span,
new_backtrace(),
)
.into());
}
let asg_function = Function::init(new_scope, function)?;
asg_function.circuit.replace(Some(circuit));
if asg_function.is_test() {
return Err(AsgError::circuit_test_function(&function.identifier.span, new_backtrace()).into());
return Err(AsgError::circuit_test_function(&function.identifier.span).into());
}
members.insert(
function.identifier.name.to_string(),

View File

@ -29,7 +29,7 @@ use crate::{
use indexmap::IndexMap;
pub use leo_ast::Annotation;
use leo_ast::FunctionInput;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::{Cell, RefCell};
@ -107,7 +107,7 @@ impl<'a> Function<'a> {
}
}
if qualifier != FunctionQualifier::Static && scope.circuit_self.get().is_none() {
return Err(AsgError::invalid_self_in_global(&value.span, new_backtrace()).into());
return Err(AsgError::invalid_self_in_global(&value.span).into());
}
let function = scope.context.alloc_function(Function {
id: scope.context.get_id(),
@ -151,16 +151,12 @@ impl<'a> Function<'a> {
let main_block = BlockStatement::from_ast(self.scope, &value.block, None)?;
let mut director = MonoidalDirector::new(ReturnPathReducer::new());
if !director.reduce_block(&main_block).0 && !self.output.is_unit() {
return Err(
AsgError::function_missing_return(&self.name.borrow().name, &value.span, new_backtrace()).into(),
);
return Err(AsgError::function_missing_return(&self.name.borrow().name, &value.span).into());
}
#[allow(clippy::never_loop)] // TODO @Protryon: How should we return multiple errors?
for (span, error) in director.reducer().errors {
return Err(
AsgError::function_return_validation(&self.name.borrow().name, error, &span, new_backtrace()).into(),
);
return Err(AsgError::function_return_validation(&self.name.borrow().name, error, &span).into());
}
self.body

View File

@ -26,7 +26,7 @@ pub use function::*;
use crate::{node::FromAst, ArenaNode, AsgContext, DefinitionStatement, ImportResolver, Input, Scope, Statement};
use leo_ast::{Identifier, PackageAccess, PackageOrPackages};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use indexmap::IndexMap;
use std::cell::{Cell, RefCell};
@ -164,7 +164,7 @@ impl<'a> Program<'a> {
)? {
Some(x) => x,
None => {
return Err(AsgError::unresolved_import(pretty_package, &Span::default(), new_backtrace()).into());
return Err(AsgError::unresolved_import(pretty_package, &Span::default()).into());
}
};
@ -196,12 +196,7 @@ impl<'a> Program<'a> {
} else if let Some(global_const) = resolved_package.global_consts.get(&name) {
imported_global_consts.insert(name.clone(), *global_const);
} else {
return Err(AsgError::unresolved_import(
format!("{}.{}", pretty_package, name),
&span,
new_backtrace(),
)
.into());
return Err(AsgError::unresolved_import(format!("{}.{}", pretty_package, name), &span).into());
}
}
ImportSymbol::Alias(name, alias) => {
@ -212,12 +207,7 @@ impl<'a> Program<'a> {
} else if let Some(global_const) = resolved_package.global_consts.get(&name) {
imported_global_consts.insert(alias.clone(), *global_const);
} else {
return Err(AsgError::unresolved_import(
format!("{}.{}", pretty_package, name),
&span,
new_backtrace(),
)
.into());
return Err(AsgError::unresolved_import(format!("{}.{}", pretty_package, name), &span).into());
}
}
}
@ -308,7 +298,7 @@ impl<'a> Program<'a> {
let name = name.name.to_string();
if functions.contains_key(&name) {
return Err(AsgError::duplicate_function_definition(name, &function.span, new_backtrace()).into());
return Err(AsgError::duplicate_function_definition(name, &function.span).into());
}
functions.insert(name, asg_function);

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{AsgContext, Circuit, DefinitionStatement, Function, Input, Type, Variable};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use indexmap::IndexMap;
use std::cell::{Cell, RefCell};
@ -189,7 +189,7 @@ impl<'a> Scope<'a> {
let dimension = dimension
.value
.parse::<usize>()
.map_err(|_| AsgError::parse_index_error(span, new_backtrace()))?;
.map_err(|_| AsgError::parse_index_error(span))?;
item = Box::new(Type::Array(item, dimension));
}
*item
@ -202,15 +202,15 @@ impl<'a> Scope<'a> {
),
Circuit(name) if name.name.as_ref() == "Self" => Type::Circuit(
self.resolve_circuit_self()
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span, new_backtrace()))?,
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?,
),
SelfType => Type::Circuit(
self.resolve_circuit_self()
.ok_or_else(|| AsgError::reference_self_outside_circuit(span, new_backtrace()))?,
.ok_or_else(|| AsgError::reference_self_outside_circuit(span))?,
),
Circuit(name) => Type::Circuit(
self.resolve_circuit(&name.name)
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span, new_backtrace()))?,
.ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?,
),
})
}

View File

@ -32,7 +32,7 @@ use crate::{
};
pub use leo_ast::AssignOperation;
use leo_ast::AssigneeAccess as AstAssigneeAccess;
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::Cell;
@ -78,18 +78,17 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
return Err(AsgError::illegal_input_variable_reference(
"attempted to reference input when none is in scope",
&statement.span,
new_backtrace(),
)
.into());
}
} else {
scope
.resolve_variable(name)
.ok_or_else(|| AsgError::unresolved_reference(name, span, new_backtrace()))?
.ok_or_else(|| AsgError::unresolved_reference(name, span))?
};
if !variable.borrow().mutable {
return Err(AsgError::immutable_assignment(name, &statement.span, new_backtrace()).into());
return Err(AsgError::immutable_assignment(name, &statement.span).into());
}
let mut target_type: Option<PartialType> = Some(variable.borrow().type_.clone().into());
@ -124,23 +123,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
) {
let left = match left {
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
AsgError::invalid_assign_index(
name,
x.to_string(),
&statement.span,
new_backtrace(),
)
AsgError::invalid_assign_index(name, x.to_string(), &statement.span)
})?,
_ => unimplemented!(),
};
let right = match right {
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
AsgError::invalid_assign_index(
name,
x.to_string(),
&statement.span,
new_backtrace(),
)
AsgError::invalid_assign_index(name, x.to_string(), &statement.span)
})?,
_ => unimplemented!(),
};
@ -152,13 +141,12 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
left,
right,
&statement.span,
new_backtrace(),
)
.into());
}
}
}
_ => return Err(AsgError::index_into_non_array(name, &statement.span, new_backtrace()).into()),
_ => return Err(AsgError::index_into_non_array(name, &statement.span).into()),
}
AssignAccess::ArrayRange(Cell::new(left), Cell::new(right))
@ -166,7 +154,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
AstAssigneeAccess::ArrayIndex(index) => {
target_type = match target_type.clone() {
Some(PartialType::Array(item, _)) => item.map(|x| *x),
_ => return Err(AsgError::index_into_non_array(name, &statement.span, new_backtrace()).into()),
_ => return Err(AsgError::index_into_non_array(name, &statement.span).into()),
};
AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast(
scope,
@ -178,12 +166,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
let index = index
.value
.parse::<usize>()
.map_err(|_| AsgError::parse_index_error(span, new_backtrace()))?;
.map_err(|_| AsgError::parse_index_error(span))?;
target_type = match target_type {
Some(PartialType::Tuple(types)) => types.get(index).cloned().ok_or_else(|| {
AsgError::tuple_index_out_of_bounds(index, &statement.span, new_backtrace())
})?,
_ => return Err(AsgError::index_into_non_tuple(name, &statement.span, new_backtrace()).into()),
Some(PartialType::Tuple(types)) => types
.get(index)
.cloned()
.ok_or_else(|| AsgError::tuple_index_out_of_bounds(index, &statement.span))?,
_ => return Err(AsgError::index_into_non_tuple(name, &statement.span).into()),
};
AssignAccess::Tuple(index)
}
@ -198,19 +187,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
&circuit.name.borrow().name,
&name.name,
&statement.span,
new_backtrace(),
)
})?;
let x = match &member {
CircuitMember::Variable(type_) => type_.clone(),
CircuitMember::Function(_) => {
return Err(AsgError::illegal_function_assign(
&name.name,
&statement.span,
new_backtrace(),
)
.into());
return Err(AsgError::illegal_function_assign(&name.name, &statement.span).into());
}
};
Some(x.partial())
@ -219,7 +202,6 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
return Err(AsgError::index_into_non_tuple(
&statement.assignee.identifier.name,
&statement.span,
new_backtrace(),
)
.into());
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Statement, Type, Variable};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::{Cell, RefCell};
@ -71,7 +71,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
.collect::<Vec<String>>()
.join(" ,");
return Err(AsgError::invalid_const_assign(var_names, &statement.span, new_backtrace()).into());
return Err(AsgError::invalid_const_assign(var_names, &statement.span).into());
}
let type_ = type_.or_else(|| value.get_type());
@ -83,7 +83,6 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
return Err(AsgError::illegal_ast_structure(
"cannot have 0 variable names in destructuring tuple",
&statement.span,
new_backtrace(),
)
.into());
}
@ -101,7 +100,6 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
format!("{}-ary tuple", statement.variable_names.len()),
type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()),
&statement.span,
new_backtrace(),
)
.into());
}
@ -112,9 +110,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
variables.push(&*scope.context.alloc_variable(RefCell::new(InnerVariable {
id: scope.context.get_id(),
name: variable.identifier.clone(),
type_: type_.ok_or_else(|| {
AsgError::unresolved_type(&variable.identifier.name, &statement.span, new_backtrace())
})?,
type_: type_.ok_or_else(|| AsgError::unresolved_type(&variable.identifier.name, &statement.span))?,
mutable: variable.mutable,
const_: false,
declaration: crate::VariableDeclaration::Definition,
@ -127,7 +123,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
let mut variables = scope.variables.borrow_mut();
let var_name = variable.borrow().name.name.to_string();
if variables.contains_key(&var_name) {
return Err(AsgError::duplicate_variable_definition(var_name, &statement.span, new_backtrace()).into());
return Err(AsgError::duplicate_variable_definition(var_name, &statement.span).into());
}
variables.insert(var_name, *variable);

View File

@ -17,7 +17,7 @@
use leo_ast::IntegerType;
use crate::{Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Statement, Variable};
use leo_errors::{new_backtrace, AsgError, Result, Span};
use leo_errors::{AsgError, Result, Span};
use std::cell::{Cell, RefCell};
@ -50,14 +50,10 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
// Return an error if start or stop is not constant.
if !start.is_consty() {
return Err(
AsgError::unexpected_nonconst(&start.span().cloned().unwrap_or_default(), new_backtrace()).into(),
);
return Err(AsgError::unexpected_nonconst(&start.span().cloned().unwrap_or_default()).into());
}
if !stop.is_consty() {
return Err(
AsgError::unexpected_nonconst(&stop.span().cloned().unwrap_or_default(), new_backtrace()).into(),
);
return Err(AsgError::unexpected_nonconst(&stop.span().cloned().unwrap_or_default()).into());
}
let variable = scope.context.alloc_variable(RefCell::new(InnerVariable {
@ -65,7 +61,7 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> {
name: statement.variable.clone(),
type_: start
.get_type()
.ok_or_else(|| AsgError::unresolved_type(&statement.variable.name, &statement.span, new_backtrace()))?,
.ok_or_else(|| AsgError::unresolved_type(&statement.variable.name, &statement.span))?,
mutable: false,
const_: true,
declaration: crate::VariableDeclaration::IterationDefinition,

View File

@ -62,7 +62,7 @@ pub use self::types::*;
mod node;
pub use node::*;
use leo_errors::{new_backtrace, AstError, Result};
use leo_errors::{AstError, Result};
/// The abstract syntax tree (AST) for a Leo program.
///
@ -98,31 +98,27 @@ impl Ast {
/// Serializes the ast into a JSON string.
pub fn to_json_string(&self) -> Result<String> {
Ok(serde_json::to_string_pretty(&self.ast)
.map_err(|e| AstError::failed_to_convert_ast_to_json_string(&e, new_backtrace()))?)
Ok(serde_json::to_string_pretty(&self.ast).map_err(|e| AstError::failed_to_convert_ast_to_json_string(&e))?)
}
/// Serializes the ast into a JSON file.
pub fn to_json_file(&self, mut path: std::path::PathBuf, file_name: &str) -> Result<()> {
path.push(file_name);
let file = std::fs::File::create(&path)
.map_err(|e| AstError::failed_to_create_ast_json_file(&path, &e, new_backtrace()))?;
let file = std::fs::File::create(&path).map_err(|e| AstError::failed_to_create_ast_json_file(&path, &e))?;
let writer = std::io::BufWriter::new(file);
Ok(serde_json::to_writer_pretty(writer, &self.ast)
.map_err(|e| AstError::failed_to_write_ast_to_json_file(&path, &e, new_backtrace()))?)
.map_err(|e| AstError::failed_to_write_ast_to_json_file(&path, &e))?)
}
/// Deserializes the JSON string into a ast.
pub fn from_json_string(json: &str) -> Result<Self> {
let ast: Program =
serde_json::from_str(json).map_err(|e| AstError::failed_to_read_json_string_to_ast(&e, new_backtrace()))?;
let ast: Program = serde_json::from_str(json).map_err(|e| AstError::failed_to_read_json_string_to_ast(&e))?;
Ok(Self { ast })
}
/// Deserializes the JSON string into a ast from a file.
pub fn from_json_file(path: std::path::PathBuf) -> Result<Self> {
let data = std::fs::read_to_string(&path)
.map_err(|e| AstError::failed_to_read_json_file(&path, &e, new_backtrace()))?;
let data = std::fs::read_to_string(&path).map_err(|e| AstError::failed_to_read_json_file(&path, &e))?;
Self::from_json_string(&data)
}
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use leo_errors::{new_backtrace, AstError, Result, Span};
use leo_errors::{AstError, Result, Span};
/// Replace Self when it is in a enclosing circuit type.
/// Error when Self is outside an enclosing circuit type.
@ -469,7 +469,7 @@ impl ReconstructingReducer for Canonicalizer {
match new {
Type::Array(type_, mut dimensions) => {
if dimensions.is_zero() {
return Err(AstError::invalid_array_dimension_size(span, new_backtrace()).into());
return Err(AstError::invalid_array_dimension_size(span).into());
}
let mut next = Type::Array(type_, ArrayDimensions(vec![dimensions.remove_last().unwrap()]));
@ -486,16 +486,14 @@ impl ReconstructingReducer for Canonicalizer {
Ok(array)
}
Type::SelfType if !self.in_circuit => {
Err(AstError::big_self_outside_of_circuit(span, new_backtrace()).into())
}
Type::SelfType if !self.in_circuit => Err(AstError::big_self_outside_of_circuit(span).into()),
_ => Ok(new.clone()),
}
}
fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result<Expression> {
if string.is_empty() {
return Err(AstError::empty_string(span, new_backtrace()).into());
return Err(AstError::empty_string(span).into());
}
let mut elements = Vec::new();
@ -554,7 +552,7 @@ impl ReconstructingReducer for Canonicalizer {
element: Expression,
) -> Result<ArrayInitExpression> {
if array_init.dimensions.is_zero() {
return Err(AstError::invalid_array_dimension_size(&array_init.span, new_backtrace()).into());
return Err(AstError::invalid_array_dimension_size(&array_init.span).into());
}
let element = Box::new(element);

View File

@ -19,7 +19,7 @@
use crate::*;
use indexmap::IndexMap;
use leo_errors::{new_backtrace, AstError, Result, Span};
use leo_errors::{AstError, Result, Span};
pub struct ReconstructingDirector<R: ReconstructingReducer> {
reducer: R,
@ -386,7 +386,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
match &console_function_call.function {
ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted),
ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted),
_ => return Err(AstError::impossible_console_assert_call(&args.span, new_backtrace()).into()),
_ => return Err(AstError::impossible_console_assert_call(&args.span).into()),
}
}
};

View File

@ -27,7 +27,7 @@ use crate::{
pub use leo_asg::{new_context, AsgContext as Context, AsgContext};
use leo_asg::{Asg, AsgPass, Program as AsgProgram};
use leo_ast::{Input, MainInput, Program as AstProgram};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use leo_input::LeoInputParser;
use leo_package::inputs::InputPairs;
use leo_parser::parse_ast;
@ -226,7 +226,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
pub fn parse_program(&mut self) -> Result<()> {
// Load the program file.
let content = fs::read_to_string(&self.main_file_path)
.map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e, new_backtrace()))?;
.map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e))?;
self.parse_program_from_string(&content)
}
@ -324,7 +324,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
pub fn checksum(&self) -> Result<String> {
// Read in the main file as string
let unparsed_file = fs::read_to_string(&self.main_file_path)
.map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e, new_backtrace()))?;
.map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e))?;
// Hash the file contents
let mut hasher = Sha256::new();

View File

@ -18,7 +18,7 @@
use crate::{get_indicator_value, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Expression;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -45,14 +45,13 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let result_option = match assert_expression {
ConstrainedValue::Boolean(boolean) => boolean.get_value(),
_ => {
return Err(CompilerError::console_assertion_must_be_boolean(span, new_backtrace()).into());
return Err(CompilerError::console_assertion_must_be_boolean(span).into());
}
};
let result_bool =
result_option.ok_or_else(|| CompilerError::console_assertion_depends_on_input(span, new_backtrace()))?;
let result_bool = result_option.ok_or_else(|| CompilerError::console_assertion_depends_on_input(span))?;
if !result_bool {
return Err(CompilerError::console_assertion_failed(span, new_backtrace()).into());
return Err(CompilerError::console_assertion_failed(span).into());
}
Ok(())

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, GroupType};
use leo_asg::{CharValue, ConsoleArgs};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -55,7 +55,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
arg_index + 1,
args.parameters.len(),
&args.span,
new_backtrace(),
)
.into());
}
@ -69,20 +68,12 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
substring.push('}');
escape_right_bracket = true;
} else {
return Err(CompilerError::console_fmt_expected_escaped_right_brace(
&args.span,
new_backtrace(),
)
.into());
return Err(CompilerError::console_fmt_expected_escaped_right_brace(&args.span).into());
}
}
}
_ if in_container => {
return Err(CompilerError::console_fmt_expected_left_or_right_brace(
&args.span,
new_backtrace(),
)
.into());
return Err(CompilerError::console_fmt_expected_left_or_right_brace(&args.span).into());
}
_ => substring.push(*scalar),
},
@ -100,7 +91,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
arg_index,
args.parameters.len(),
&args.span,
new_backtrace(),
)
.into());
}

View File

@ -19,7 +19,7 @@
use crate::{ConstrainedProgram, GroupType, Output, OutputFile};
use leo_asg::Program;
use leo_ast::Input;
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use leo_input::LeoInputParser;
use leo_package::inputs::InputPairs;
@ -48,7 +48,7 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSy
let result = resolved_program.enforce_main_function(cs, function, input)?;
Ok(result)
}
_ => Err(CompilerError::no_main_function(new_backtrace()).into()),
_ => Err(CompilerError::no_main_function().into()),
}
}
@ -103,11 +103,11 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType<F>>(
{
Some(pair) => pair.to_owned(),
None => {
return Err(CompilerError::invalid_test_context(file_name, new_backtrace()).into());
return Err(CompilerError::invalid_test_context(file_name).into());
}
}
}
None => default.ok_or_else(|| CompilerError::no_test_input(new_backtrace()))?,
None => default.ok_or_else(|| CompilerError::no_test_input())?,
};
// parse input files to abstract syntax trees

View File

@ -17,7 +17,7 @@
//! Enforces an arithmetic `+` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -39,9 +39,7 @@ pub fn enforce_add<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
Ok(ConstrainedValue::Group(point_1.add(cs, &point_2, span)?))
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} + {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} + {}", val_1, val_2), span).into());
}
}
}

View File

@ -17,7 +17,7 @@
//! Enforces a logical `!` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
@ -25,5 +25,5 @@ pub fn evaluate_bit_not<'a, F: PrimeField, G: GroupType<F>>(
value: ConstrainedValue<'a, F, G>,
span: &Span,
) -> Result<ConstrainedValue<'a, F, G>> {
return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span, new_backtrace()).into());
return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span).into());
}

View File

@ -17,7 +17,7 @@
//! Enforces an arithmetic `/` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -36,9 +36,7 @@ pub fn enforce_div<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
Ok(ConstrainedValue::Field(field_1.div(cs, &field_2, span)?))
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} / {}", val_1, val_2,), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} / {}", val_1, val_2,), span).into());
}
}
}

View File

@ -17,7 +17,7 @@
//! Enforces an arithmetic `*` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -36,9 +36,7 @@ pub fn enforce_mul<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
Ok(ConstrainedValue::Field(field_1.mul(cs, &field_2, span)?))
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} * {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} * {}", val_1, val_2), span).into());
}
}
}

View File

@ -17,7 +17,7 @@
//! Enforces a unary negate `-` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -31,6 +31,6 @@ pub fn enforce_negate<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F
ConstrainedValue::Integer(integer) => Ok(ConstrainedValue::Integer(integer.negate(cs, span)?)),
ConstrainedValue::Field(field) => Ok(ConstrainedValue::Field(field.negate(cs, span)?)),
ConstrainedValue::Group(group) => Ok(ConstrainedValue::Group(group.negate(cs, span)?)),
value => return Err(CompilerError::incompatible_types(format!("-{}", value), span, new_backtrace()).into()),
value => return Err(CompilerError::incompatible_types(format!("-{}", value), span).into()),
}
}

View File

@ -17,7 +17,7 @@
//! Enforces an arithmetic `**` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -33,9 +33,7 @@ pub fn enforce_pow<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
Ok(ConstrainedValue::Integer(num_1.pow(cs, num_2, span)?))
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} ** {}", val_1, val_2,), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} ** {}", val_1, val_2,), span).into());
}
}
}

View File

@ -17,7 +17,7 @@
//! Enforces an arithmetic `-` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -39,9 +39,7 @@ pub fn enforce_sub<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
Ok(ConstrainedValue::Group(point_1.sub(cs, &point_2, span)?))
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} - {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} - {}", val_1, val_2), span).into());
}
}
}

View File

@ -26,7 +26,7 @@ use crate::{
GroupType,
};
use leo_asg::{ConstInt, Expression};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{
@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let mut unique_namespace = cs.ns(|| namespace_string);
bounds_check
.enforce_equal(&mut unique_namespace, &Boolean::Constant(true))
.map_err(|e| CompilerError::cannot_enforce_expression("array bounds check", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::cannot_enforce_expression("array bounds check", e, span))?;
Ok(())
}
@ -76,25 +76,25 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
) -> Result<ConstrainedValue<'a, F, G>> {
let mut array = match self.enforce_expression(cs, array)? {
ConstrainedValue::Array(array) => array,
value => return Err(CompilerError::undefined_array(value.to_string(), span, new_backtrace()).into()),
value => return Err(CompilerError::undefined_array(value.to_string(), span).into()),
};
let index_resolved = self.enforce_index(cs, index, span)?;
if let Some(resolved) = index_resolved.to_usize() {
if resolved >= array.len() {
return Err(CompilerError::array_index_out_of_bounds(resolved, span, new_backtrace()).into());
return Err(CompilerError::array_index_out_of_bounds(resolved, span).into());
}
Ok(array[resolved].to_owned())
} else {
if array.is_empty() {
return Err(CompilerError::array_index_out_of_bounds(0, span, new_backtrace()).into());
return Err(CompilerError::array_index_out_of_bounds(0, span).into());
}
{
let array_len: u32 = array
.len()
.try_into()
.map_err(|_| CompilerError::array_length_out_of_bounds(span, new_backtrace()))?;
.map_err(|_| CompilerError::array_length_out_of_bounds(span))?;
self.array_bounds_check(cs, &index_resolved, array_len, span)?;
}
@ -105,19 +105,17 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let index_bounded = i
.try_into()
.map_err(|_| CompilerError::array_index_out_of_legal_bounds(span, new_backtrace()))?;
.map_err(|_| CompilerError::array_index_out_of_legal_bounds(span))?;
let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type());
let index_comparison = index_resolved
.evaluate_equal(eq_namespace, &Integer::new(&const_index))
.map_err(|_| CompilerError::cannot_evaluate_expression("==", span, new_backtrace()))?;
.map_err(|_| CompilerError::cannot_evaluate_expression("==", span))?;
let unique_namespace =
cs.ns(|| format!("select array access {} {}:{}", i, span.line_start, span.col_start));
let value =
ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &item, &current_value)
.map_err(|e| {
CompilerError::cannot_enforce_expression("conditional select", e, span, new_backtrace())
})?;
.map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span))?;
current_value = value;
}
Ok(current_value)
@ -136,7 +134,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
) -> Result<ConstrainedValue<'a, F, G>> {
let array = match self.enforce_expression(cs, array)? {
ConstrainedValue::Array(array) => array,
value => return Err(CompilerError::undefined_array(value, span, new_backtrace()).into()),
value => return Err(CompilerError::undefined_array(value, span).into()),
};
let from_resolved = match left {
@ -149,7 +147,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let index_bounded: u32 = array
.len()
.try_into()
.map_err(|_| CompilerError::array_length_out_of_bounds(span, new_backtrace()))?;
.map_err(|_| CompilerError::array_length_out_of_bounds(span))?;
Integer::new(&ConstInt::U32(index_bounded))
} // Array slice ends at array length
};
@ -161,10 +159,10 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
};
Ok(if let Some((left, right)) = const_dimensions {
if right - left != length {
return Err(CompilerError::array_invalid_slice_length(span, new_backtrace()).into());
return Err(CompilerError::array_invalid_slice_length(span).into());
}
if right > array.len() {
return Err(CompilerError::array_index_out_of_bounds(right, span, new_backtrace()).into());
return Err(CompilerError::array_index_out_of_bounds(right, span).into());
}
ConstrainedValue::Array(array[left..right].to_owned())
} else {
@ -186,9 +184,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let mut unique_namespace = cs.ns(|| namespace_string);
calc_len
.enforce_equal(&mut unique_namespace, &Integer::new(&ConstInt::U32(length as u32)))
.map_err(|e| {
CompilerError::cannot_enforce_expression("array length check", e, span, new_backtrace())
})?;
.map_err(|e| CompilerError::cannot_enforce_expression("array length check", e, span))?;
}
{
let bounds_check = evaluate_le::<F, G, _>(
@ -208,9 +204,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let mut unique_namespace = cs.ns(|| namespace_string);
bounds_check
.enforce_equal(&mut unique_namespace, &Boolean::Constant(true))
.map_err(|e| {
CompilerError::cannot_enforce_expression("array bounds check", e, span, new_backtrace())
})?;
.map_err(|e| CompilerError::cannot_enforce_expression("array bounds check", e, span))?;
}
let mut windows = array.windows(length);
let mut result = ConstrainedValue::Array(vec![]);
@ -239,9 +233,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let unique_namespace =
unique_namespace.ns(|| format!("array index {} {}:{}", i, span.line_start, span.col_start));
result = ConstrainedValue::conditionally_select(unique_namespace, &equality, &array_value, &result)
.map_err(|e| {
CompilerError::cannot_enforce_expression("conditional select", e, span, new_backtrace())
})?;
.map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span))?;
}
result
})

View File

@ -20,7 +20,7 @@ use std::cell::Cell;
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Expression;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -52,9 +52,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
if let Some(dimension) = expected_dimension {
// Return an error if the expected dimension != the actual dimension.
if dimension != result.len() {
return Err(
CompilerError::unexpected_array_length(dimension, result.len(), span, new_backtrace()).into(),
);
return Err(CompilerError::unexpected_array_length(dimension, result.len(), span).into());
}
}

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType, Integer};
use leo_asg::Expression;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -32,7 +32,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
) -> Result<Integer> {
match self.enforce_expression(cs, index)? {
ConstrainedValue::Integer(number) => Ok(number),
value => Err(CompilerError::invalid_index_expression(value, span, new_backtrace()).into()),
value => Err(CompilerError::invalid_index_expression(value, span).into()),
}
}
}

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::{CircuitAccessExpression, Node};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -43,27 +43,18 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
expr.circuit.get().name.borrow(),
&expr.member.name,
&expr.member.span,
new_backtrace(),
)
.into());
}
}
value => {
return Err(CompilerError::undefined_circuit(
value,
&target.span().cloned().unwrap_or_default(),
new_backtrace(),
)
.into());
return Err(
CompilerError::undefined_circuit(value, &target.span().cloned().unwrap_or_default()).into(),
);
}
}
} else {
Err(CompilerError::invalid_circuit_static_member_access(
&expr.member.name,
&expr.member.span,
new_backtrace(),
)
.into())
Err(CompilerError::invalid_circuit_static_member_access(&expr.member.name, &expr.member.span).into())
}
}
}

View File

@ -22,7 +22,7 @@ use crate::{
GroupType,
};
use leo_asg::{CircuitInitExpression, CircuitMember};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -50,7 +50,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
resolved_members.push(ConstrainedCircuitMember(name.clone(), variable_value));
}
_ => {
return Err(CompilerError::expected_circuit_member(name, span, new_backtrace()).into());
return Err(CompilerError::expected_circuit_member(name, span).into());
}
}
}

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Expression;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::select::CondSelectGadget;
@ -38,12 +38,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let conditional_value = match self.enforce_expression(cs, conditional)? {
ConstrainedValue::Boolean(resolved) => resolved,
value => {
return Err(CompilerError::conditional_boolean_expression_fails_to_resolve_to_bool(
value,
span,
new_backtrace(),
)
.into());
return Err(CompilerError::conditional_boolean_expression_fails_to_resolve_to_bool(value, span).into());
}
};
@ -60,7 +55,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
Ok(
ConstrainedValue::conditionally_select(unique_namespace, &conditional_value, &first_value, &second_value)
.map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span, new_backtrace()))?,
.map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span))?,
)
}
}

View File

@ -17,7 +17,7 @@
//! Enforces a logical `&&` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -37,10 +37,10 @@ pub fn enforce_and<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
&left_bool,
&right_bool,
)
.map_err(|e| CompilerError::cannot_enforce_expression("&&", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::cannot_enforce_expression("&&", e, span))?;
return Ok(ConstrainedValue::Boolean(result));
}
Err(CompilerError::cannot_evaluate_expression(name, span, new_backtrace()).into())
Err(CompilerError::cannot_evaluate_expression(name, span).into())
}

View File

@ -17,7 +17,7 @@
//! Enforces a logical `!` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
@ -28,7 +28,7 @@ pub fn evaluate_not<'a, F: PrimeField, G: GroupType<F>>(
match value {
ConstrainedValue::Boolean(boolean) => Ok(ConstrainedValue::Boolean(boolean.not())),
value => {
return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span, new_backtrace()).into());
return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span).into());
}
}
}

View File

@ -17,7 +17,7 @@
//! Enforces a logical `||` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -37,10 +37,10 @@ pub fn enforce_or<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
&left_bool,
&right_bool,
)
.map_err(|e| CompilerError::cannot_enforce_expression("||", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::cannot_enforce_expression("||", e, span))?;
return Ok(ConstrainedValue::Boolean(result));
}
Err(CompilerError::cannot_evaluate_expression(name, span, new_backtrace()).into())
Err(CompilerError::cannot_evaluate_expression(name, span).into())
}

View File

@ -17,7 +17,7 @@
//! Enforces a relational `==` operator in a resolved Leo program.
use crate::{enforce_and, value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{boolean::Boolean, traits::eq::EvaluateEqGadget};
@ -75,14 +75,11 @@ pub fn evaluate_eq<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
return Ok(current);
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} == {}", val_1, val_2,), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} == {}", val_1, val_2,), span).into());
}
};
let boolean =
constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("==", span, new_backtrace()))?;
let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("==", span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -17,7 +17,7 @@
//! Enforces a relational `>=` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::bits::ComparatorGadget;
@ -35,14 +35,11 @@ pub fn evaluate_ge<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
num_1.greater_than_or_equal(unique_namespace, &num_2)
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} >= {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} >= {}", val_1, val_2), span).into());
}
};
let boolean =
constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">=", span, new_backtrace()))?;
let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">=", span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -17,7 +17,7 @@
//! Enforces a relational `>` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::bits::ComparatorGadget;
@ -35,14 +35,11 @@ pub fn evaluate_gt<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
num_1.greater_than(unique_namespace, &num_2)
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} > {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} > {}", val_1, val_2), span).into());
}
};
let boolean =
constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">", span, new_backtrace()))?;
let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">", span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -17,7 +17,7 @@
//! Enforces a relational `<=` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::bits::ComparatorGadget;
@ -35,14 +35,11 @@ pub fn evaluate_le<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
num_1.less_than_or_equal(unique_namespace, &num_2)
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} <= {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} <= {}", val_1, val_2), span).into());
}
};
let boolean =
constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<=", span, new_backtrace()))?;
let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<=", span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -17,7 +17,7 @@
//! Enforces a relational `<` operator in a resolved Leo program.
use crate::{value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::bits::EvaluateLtGadget;
@ -35,14 +35,11 @@ pub fn evaluate_lt<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
num_1.less_than(unique_namespace, &num_2)
}
(val_1, val_2) => {
return Err(
CompilerError::incompatible_types(format!("{} < {}", val_1, val_2), span, new_backtrace()).into(),
);
return Err(CompilerError::incompatible_types(format!("{} < {}", val_1, val_2), span).into());
}
};
let boolean =
constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<", span, new_backtrace()))?;
let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<", span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Expression;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -35,13 +35,13 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
// Get the tuple values.
let tuple = match self.enforce_expression(cs, tuple)? {
ConstrainedValue::Tuple(tuple) => tuple,
value => return Err(CompilerError::undefined_array(value, span, new_backtrace()).into()),
value => return Err(CompilerError::undefined_array(value, span).into()),
};
// Check for out of bounds access.
if index > tuple.len() - 1 {
// probably safe to be a panic here
return Err(CompilerError::tuple_index_out_of_bounds(index, span, new_backtrace()).into());
return Err(CompilerError::tuple_index_out_of_bounds(index, span).into());
}
Ok(tuple[index].to_owned())

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::VariableRef;
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
@ -32,12 +32,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let result_value = if let Some(value) = self.get(variable.id) {
value.clone()
} else {
return Err(CompilerError::undefined_identifier(
&variable.name.clone().name,
&span.unwrap_or_default(),
new_backtrace(),
)
.into());
return Err(
CompilerError::undefined_identifier(&variable.name.clone().name, &span.unwrap_or_default()).into(),
);
// todo: probably can be a panic here instead
};

View File

@ -19,7 +19,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::{Expression, Function, FunctionQualifier};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use std::cell::Cell;
use snarkvm_fields::PrimeField;
@ -52,7 +52,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
&function.name.borrow().name.to_string(),
"arguments length invalid",
&function.span.clone().unwrap_or_default(),
new_backtrace(),
)
.into());
}

View File

@ -20,7 +20,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Type;
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -41,13 +41,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
match input_value {
Some(InputValue::Array(arr)) => {
if array_len != arr.len() {
return Err(CompilerError::invalid_input_array_dimensions(
arr.len(),
array_len,
span,
new_backtrace(),
)
.into());
return Err(CompilerError::invalid_input_array_dimensions(arr.len(), array_len, span).into());
}
// Allocate each value in the current row
@ -72,9 +66,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
}
}
_ => {
return Err(
CompilerError::invalid_function_input_array(input_value.unwrap(), span, new_backtrace()).into(),
);
return Err(CompilerError::invalid_function_input_array(input_value.unwrap(), span).into());
}
}

View File

@ -17,7 +17,7 @@
use crate::{ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType};
use leo_asg::{Circuit, CircuitMember};
use leo_ast::{Identifier, InputValue, Parameter};
use leo_errors::{new_backtrace, AsgError, Result};
use leo_errors::{AsgError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -43,9 +43,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
};
let declared_type = self.asg.scope.resolve_ast_type(&parameter.type_, &parameter.span)?;
if !expected_type.is_assignable_from(&declared_type) {
return Err(
AsgError::unexpected_type(expected_type, declared_type, &identifier.span, new_backtrace()).into(),
);
return Err(AsgError::unexpected_type(expected_type, declared_type, &identifier.span).into());
}
let member_name = parameter.variable.clone();
let member_value = self.allocate_main_function_input(

View File

@ -33,7 +33,7 @@ use crate::{
};
use leo_asg::{ConstInt, Type};
use leo_ast::{Char, InputValue};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -78,8 +78,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
input_option: Option<InputValue>,
span: &Span,
) -> Result<ConstrainedValue<'a, F, G>> {
let input =
input_option.ok_or_else(|| CompilerError::function_input_not_found("main", name, span, new_backtrace()))?;
let input = input_option.ok_or_else(|| CompilerError::function_input_not_found("main", name, span))?;
match (type_, input) {
(Type::Address, InputValue::Address(addr)) => Ok(ConstrainedValue::Address(Address::constant(addr, span)?)),
@ -109,25 +108,15 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let parsed_type = parsed.get_int_type();
let input_type = input_type.into();
if std::mem::discriminant(&parsed_type) != std::mem::discriminant(&input_type) {
return Err(CompilerError::integer_value_integer_type_mismatch(
input_type,
parsed_type,
span,
new_backtrace(),
)
.into());
return Err(
CompilerError::integer_value_integer_type_mismatch(input_type, parsed_type, span).into(),
);
}
Ok(ConstrainedValue::Integer(Integer::new(&parsed)))
}
(Type::Array(type_, arr_len), InputValue::Array(values)) => {
if *arr_len != values.len() {
return Err(CompilerError::invalid_input_array_dimensions(
*arr_len,
values.len(),
span,
new_backtrace(),
)
.into());
return Err(CompilerError::invalid_input_array_dimensions(*arr_len, values.len(), span).into());
}
Ok(ConstrainedValue::Array(
@ -139,13 +128,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
}
(Type::Tuple(types), InputValue::Tuple(values)) => {
if values.len() != types.len() {
return Err(CompilerError::input_tuple_size_mismatch(
types.len(),
values.len(),
span,
new_backtrace(),
)
.into());
return Err(CompilerError::input_tuple_size_mismatch(types.len(), values.len(), span).into());
}
Ok(ConstrainedValue::Tuple(
@ -161,9 +144,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
(Type::Circuit(_), _) => unimplemented!("main function input not implemented for type {}", type_), // Should not happen.
// Return an error if the input type and input value do not match.
(_, input) => {
Err(CompilerError::input_variable_type_mismatch(type_, input, name, span, new_backtrace()).into())
}
(_, input) => Err(CompilerError::input_variable_type_mismatch(type_, input, name, span).into()),
}
}
}

View File

@ -20,7 +20,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Type;
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -39,13 +39,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
match input_value {
Some(InputValue::Tuple(values)) => {
if values.len() != types.len() {
return Err(CompilerError::input_tuple_size_mismatch(
types.len(),
values.len(),
span,
new_backtrace(),
)
.into());
return Err(CompilerError::input_tuple_size_mismatch(types.len(), values.len(), span).into());
}
// Allocate each value in the tuple.
@ -64,9 +58,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
}
}
_ => {
return Err(
CompilerError::invalid_function_input_tuple(input_value.unwrap(), span, new_backtrace()).into(),
);
return Err(CompilerError::invalid_function_input_tuple(input_value.unwrap(), span).into());
}
}

View File

@ -20,7 +20,7 @@ use crate::{program::ConstrainedProgram, GroupType, Output};
use leo_asg::{Expression, Function, FunctionQualifier};
use leo_ast::Input;
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use std::cell::Cell;
use snarkvm_fields::PrimeField;
@ -66,12 +66,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
) {
// If variable is in both [main] and [constants] sections - error.
(_, Some(_), Some(_)) => {
return Err(CompilerError::double_input_declaration(
name,
&input_variable.name.span,
new_backtrace(),
)
.into());
return Err(CompilerError::double_input_declaration(name, &input_variable.name.span).into());
}
// If input option is found in [main] section and input is not const.
(false, Some(input_option), _) => self.allocate_main_function_input(
@ -91,21 +86,15 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
)?,
// Function argument is const, input is not.
(true, Some(_), None) => {
return Err(CompilerError::expected_const_input_variable(
name,
&input_variable.name.span,
new_backtrace(),
)
.into());
return Err(
CompilerError::expected_const_input_variable(name, &input_variable.name.span).into(),
);
}
// Input is const, function argument is not.
(false, None, Some(_)) => {
return Err(CompilerError::expected_non_const_input_variable(
name,
&input_variable.name.span,
new_backtrace(),
)
.into());
return Err(
CompilerError::expected_non_const_input_variable(name, &input_variable.name.span).into(),
);
}
// When not found - Error out.
(_, _, _) => {
@ -113,7 +102,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
function.name.borrow().name.to_string(),
name,
&input_variable.name.span,
new_backtrace(),
)
.into());
}

View File

@ -19,7 +19,7 @@
use crate::{get_indicator_value, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Type;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{boolean::Boolean, traits::select::CondSelectGadget};
@ -55,7 +55,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
if get_indicator_value(&indicator) {
// Error if we already have a return value.
if return_value.is_some() {
return Err(CompilerError::statement_multiple_returns(span, new_backtrace()).into());
return Err(CompilerError::statement_multiple_returns(span).into());
} else {
// Set the function return value.
return_value = Some(result);
@ -79,7 +79,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
&result,
value,
)
.map_err(|_| CompilerError::statement_select_fail(result, value, span, new_backtrace()))?,
.map_err(|_| CompilerError::statement_select_fail(result, value, span))?,
);
} else {
return_value = Some(result); // we ignore indicator for default -- questionable
@ -89,9 +89,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
if expected_return.is_unit() {
Ok(ConstrainedValue::Tuple(vec![]))
} else {
Ok(return_value.ok_or_else(|| {
CompilerError::statement_no_returns(expected_return.to_string(), span, new_backtrace())
})?)
Ok(return_value.ok_or_else(|| CompilerError::statement_no_returns(expected_return.to_string(), span))?)
}
}
}

View File

@ -25,7 +25,7 @@ pub use self::output_bytes::*;
use crate::{Char, CharType, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME};
use leo_asg::Program;
use leo_ast::{Parameter, Registers};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
@ -106,7 +106,7 @@ impl Output {
// Return an error if we do not have enough return registers
if register_values.len() < return_values.len() {
return Err(CompilerError::output_not_enough_registers(span, new_backtrace()).into());
return Err(CompilerError::output_not_enough_registers(span).into());
}
let mut registers = BTreeMap::new();
@ -119,13 +119,7 @@ impl Output {
let return_value_type = value.to_type(span)?;
if !register_type.is_assignable_from(&return_value_type) {
return Err(CompilerError::output_mismatched_types(
register_type,
return_value_type,
span,
new_backtrace(),
)
.into());
return Err(CompilerError::output_mismatched_types(register_type, return_value_type, span).into());
}
let value = match value {

View File

@ -17,7 +17,7 @@
use crate::{ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME};
use leo_asg::Program;
use leo_ast::{Parameter, Registers};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
@ -55,7 +55,7 @@ impl OutputBytes {
// Return an error if we do not have enough return registers
if register_values.len() < return_values.len() {
return Err(CompilerError::output_not_enough_registers(span, new_backtrace()).into());
return Err(CompilerError::output_not_enough_registers(span).into());
}
// Manually construct result string
@ -73,13 +73,7 @@ impl OutputBytes {
let return_value_type = value.to_type(span)?;
if !register_type.is_assignable_from(&return_value_type) {
return Err(CompilerError::output_mismatched_types(
register_type,
return_value_type,
span,
new_backtrace(),
)
.into());
return Err(CompilerError::output_mismatched_types(register_type, return_value_type, span).into());
}
let value = value.to_string();

View File

@ -16,7 +16,7 @@
//! The `program.out` file.
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use std::{
borrow::Cow,
@ -46,11 +46,11 @@ impl OutputFile {
pub fn write(&self, path: &Path, bytes: &[u8]) -> Result<()> {
// create output file
let path = self.setup_file_path(path);
let mut file = File::create(&path).map_err(|e| CompilerError::output_file_io_error(e, new_backtrace()))?;
let mut file = File::create(&path).map_err(|e| CompilerError::output_file_io_error(e))?;
Ok(file
.write_all(bytes)
.map_err(|e| CompilerError::output_file_io_error(e, new_backtrace()))?)
.map_err(|e| CompilerError::output_file_io_error(e))?)
}
/// Removes the output file at the given path if it exists. Returns `true` on success,
@ -61,7 +61,7 @@ impl OutputFile {
return Ok(false);
}
fs::remove_file(&path).map_err(|_| CompilerError::output_file_cannot_remove(path, new_backtrace()))?;
fs::remove_file(&path).map_err(|_| CompilerError::output_file_cannot_remove(path))?;
Ok(true)
}

View File

@ -97,7 +97,7 @@ use leo_ast::{
UnaryExpression as AstUnaryExpression,
ValueExpression,
};
use leo_errors::{new_backtrace, AstError, Result, Span};
use leo_errors::{AstError, Result, Span};
use tendril::StrTendril;
pub trait CombinerOptions {
@ -542,7 +542,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
if let AsgStatement::Block(asg_block) = asg.result.get() {
block = self.reduce_block(&ast.block, asg_block)?;
} else {
return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap(), new_backtrace()).into());
return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap()).into());
}
let next = match (ast.next.as_ref(), asg.next.get()) {
(Some(ast_next), Some(asg_next)) => Some(self.reduce_statement(ast_next, asg_next)?),
@ -580,9 +580,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
AstConsoleFunction::Error(_) => AstConsoleFunction::Error(args),
AstConsoleFunction::Log(_) => AstConsoleFunction::Log(args),
_ => {
return Err(
AstError::impossible_console_assert_call(&ast_console_args.span, new_backtrace()).into(),
);
return Err(AstError::impossible_console_assert_call(&ast_console_args.span).into());
}
}
}
@ -650,7 +648,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
if let AsgStatement::Block(asg_block) = asg.body.get() {
block = self.reduce_block(&ast.block, asg_block)?;
} else {
return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap(), new_backtrace()).into());
return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap()).into());
}
self.ast_reducer

View File

@ -17,7 +17,7 @@
use super::CoreCircuit;
use crate::{ConstrainedValue, GroupType, Integer};
use leo_asg::Function;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{
@ -62,15 +62,13 @@ impl<'a, F: PrimeField, G: GroupType<F>> CoreCircuit<'a, F, G> for Blake2s {
let input = unwrap_argument(arguments.remove(1));
let seed = unwrap_argument(arguments.remove(0));
let digest =
Blake2sGadget::check_evaluation_gadget(cs.ns(|| "blake2s hash"), &seed[..], &input[..]).map_err(|e| {
CompilerError::cannot_enforce_expression("Blake2s check evaluation gadget", e, span, new_backtrace())
})?;
let digest = Blake2sGadget::check_evaluation_gadget(cs.ns(|| "blake2s hash"), &seed[..], &input[..])
.map_err(|e| CompilerError::cannot_enforce_expression("Blake2s check evaluation gadget", e, span))?;
Ok(ConstrainedValue::Array(
digest
.to_bytes(cs)
.map_err(|e| CompilerError::cannot_enforce_expression("Vec<UInt8> ToBytes", e, span, new_backtrace()))?
.map_err(|e| CompilerError::cannot_enforce_expression("Vec<UInt8> ToBytes", e, span))?
.into_iter()
.map(Integer::U8)
.map(ConstrainedValue::Integer)

View File

@ -18,7 +18,7 @@
use crate::{arithmetic::*, program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::{AssignOperation, AssignStatement};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{boolean::Boolean, traits::select::CondSelectGadget};
@ -59,7 +59,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
_ => unimplemented!("unimplemented assign operator"),
};
let selected_value = ConstrainedValue::conditionally_select(cs.ns(|| scope), condition, &new_value, target)
.map_err(|_| CompilerError::statement_select_fail(new_value, target.clone(), span, new_backtrace()))?;
.map_err(|_| CompilerError::statement_select_fail(new_value, target.clone(), span))?;
*target = selected_value;
Ok(())

View File

@ -20,7 +20,7 @@ use std::convert::TryInto;
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType, Integer};
use leo_asg::{ConstInt, Expression, Node};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::{eq::EvaluateEqGadget, select::CondSelectGadget};
@ -43,13 +43,10 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
ConstrainedValue::Array(input) => {
if let Some(index) = index_resolved.to_usize() {
if index >= input.len() {
Err(CompilerError::statement_array_assign_index_bounds(
index,
input.len(),
&context.span,
new_backtrace(),
Err(
CompilerError::statement_array_assign_index_bounds(index, input.len(), &context.span)
.into(),
)
.into())
} else {
let target = input.get_mut(index).unwrap();
if context.remaining_accesses.is_empty() {
@ -65,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let array_len: u32 = input
.len()
.try_into()
.map_err(|_| CompilerError::array_length_out_of_bounds(&span, new_backtrace()))?;
.map_err(|_| CompilerError::array_length_out_of_bounds(&span))?;
self.array_bounds_check(cs, &index_resolved, array_len, &span)?;
}
@ -78,11 +75,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let index_bounded = i
.try_into()
.map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span, new_backtrace()))?;
.map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span))?;
let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type());
let index_comparison = index_resolved
.evaluate_equal(eq_namespace, &Integer::new(&const_index))
.map_err(|_| CompilerError::cannot_evaluate_expression("==", &span, new_backtrace()))?;
.map_err(|_| CompilerError::cannot_evaluate_expression("==", &span))?;
let mut unique_namespace = cs.ns(|| {
format!(
@ -115,32 +112,21 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
&temp_item,
item,
)
.map_err(|e| {
CompilerError::cannot_enforce_expression(
"conditional select",
e,
&span,
new_backtrace(),
)
})?;
.map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, &span))?;
*item = value;
}
Ok(())
}
}
_ => Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into()),
_ => Err(CompilerError::statement_array_assign_interior_index(&context.span).into()),
}
} else if context.from_range && input_len != 0 {
context.from_range = false;
if let Some(index) = index_resolved.to_usize() {
if index >= input_len {
return Err(CompilerError::statement_array_assign_index_bounds(
index,
input_len,
&context.span,
new_backtrace(),
)
.into());
return Err(
CompilerError::statement_array_assign_index_bounds(index, input_len, &context.span).into(),
);
}
let target = context.input.remove(index);
@ -158,7 +144,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
.input
.len()
.try_into()
.map_err(|_| CompilerError::array_length_out_of_bounds(&span, new_backtrace()))?;
.map_err(|_| CompilerError::array_length_out_of_bounds(&span))?;
self.array_bounds_check(cs, &index_resolved, array_len, &span)?;
}
@ -171,11 +157,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let index_bounded = i
.try_into()
.map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span, new_backtrace()))?;
.map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span))?;
let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type());
let index_comparison = index_resolved
.evaluate_equal(eq_namespace, &Integer::new(&const_index))
.map_err(|_| CompilerError::cannot_evaluate_expression("==", &span, new_backtrace()))?;
.map_err(|_| CompilerError::cannot_evaluate_expression("==", &span))?;
let mut unique_namespace = cs.ns(|| {
format!(
@ -204,15 +190,13 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
};
let value =
ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, item)
.map_err(|e| {
CompilerError::cannot_enforce_expression("conditional select", e, &span, new_backtrace())
})?;
.map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, &span))?;
**item = value;
}
Ok(())
}
} else {
Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into())
Err(CompilerError::statement_array_assign_interior_index(&context.span).into())
}
}
}

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Expression;
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -38,7 +38,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
.transpose()?
.map(|x| {
x.to_usize()
.ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span, new_backtrace()))
.ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span))
})
.transpose()?;
let stop_index = stop
@ -46,7 +46,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
.transpose()?
.map(|x| {
x.to_usize()
.ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span, new_backtrace()))
.ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span))
})
.transpose()?;
let start_index = start_index.unwrap_or(0);
@ -75,7 +75,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
}
Ok(())
}
_ => Err(CompilerError::statement_array_assign_index(&context.span, new_backtrace()).into()),
_ => Err(CompilerError::statement_array_assign_index(&context.span).into()),
}
} else {
// range of a range

View File

@ -16,7 +16,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::Identifier;
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -31,7 +31,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
name: &Identifier,
) -> Result<()> {
if context.input.len() != 1 {
return Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into());
return Err(CompilerError::statement_array_assign_interior_index(&context.span).into());
}
match context.input.remove(0) {
ConstrainedValue::CircuitExpression(_variable, members) => {
@ -45,15 +45,12 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
}
None => {
// Throw an error if the circuit variable does not exist in the circuit
Err(
CompilerError::statement_undefined_circuit_variable(name, &context.span, new_backtrace())
.into(),
)
Err(CompilerError::statement_undefined_circuit_variable(name, &context.span).into())
}
}
}
// Throw an error if the circuit definition does not exist in the file
x => Err(CompilerError::undefined_circuit(x, &context.span, new_backtrace()).into()),
x => Err(CompilerError::undefined_circuit(x, &context.span).into()),
}
}
}

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::{AssignAccess, AssignOperation, AssignStatement};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -111,14 +111,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
pub(crate) fn check_range_index(start_index: usize, stop_index: usize, len: usize, span: &Span) -> Result<()> {
if stop_index < start_index {
Err(
CompilerError::statement_array_assign_range_order(start_index, stop_index, len, span, new_backtrace())
.into(),
)
Err(CompilerError::statement_array_assign_range_order(start_index, stop_index, len, span).into())
} else if start_index > len {
Err(CompilerError::statement_array_assign_index_bounds(start_index, len, span, new_backtrace()).into())
Err(CompilerError::statement_array_assign_index_bounds(start_index, len, span).into())
} else if stop_index > len {
Err(CompilerError::statement_array_assign_index_bounds(stop_index, len, span, new_backtrace()).into())
Err(CompilerError::statement_array_assign_index_bounds(stop_index, len, span).into())
} else {
Ok(())
}

View File

@ -15,7 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -30,24 +30,18 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
index: usize,
) -> Result<()> {
if context.input.len() != 1 {
return Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into());
return Err(CompilerError::statement_array_assign_interior_index(&context.span).into());
}
match context.input.remove(0) {
ConstrainedValue::Tuple(old) => {
if index > old.len() {
Err(CompilerError::statement_tuple_assign_index_bounds(
index,
old.len(),
&context.span,
new_backtrace(),
)
.into())
Err(CompilerError::statement_tuple_assign_index_bounds(index, old.len(), &context.span).into())
} else {
context.input = vec![&mut old[index]];
self.resolve_target_access(cs, context)
}
}
_ => Err(CompilerError::statement_tuple_assign_index(&context.span, new_backtrace()).into()),
_ => Err(CompilerError::statement_tuple_assign_index(&context.span).into()),
}
}
}

View File

@ -24,7 +24,7 @@ use crate::{
StatementResult,
};
use leo_asg::ConditionalStatement;
use leo_errors::{new_backtrace, CompilerError};
use leo_errors::CompilerError;
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -60,7 +60,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
return Err(CompilerError::conditional_boolean_expression_fails_to_resolve_to_bool(
value.to_string(),
&span,
new_backtrace(),
)
.into());
}
@ -78,7 +77,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
outer_indicator,
&inner_indicator,
)
.map_err(|_| CompilerError::statement_indicator_calculation(branch_1_name, &span, new_backtrace()))?;
.map_err(|_| CompilerError::statement_indicator_calculation(branch_1_name, &span))?;
let mut results = vec![];
@ -99,7 +98,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
outer_indicator,
&inner_indicator,
)
.map_err(|_| CompilerError::statement_indicator_calculation(branch_2_name, &span, new_backtrace()))?;
.map_err(|_| CompilerError::statement_indicator_calculation(branch_2_name, &span))?;
// Evaluate branch 2
let mut branch_2_result = match statement.next.get() {

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, ConstrainedValue, GroupType};
use leo_asg::{DefinitionStatement, Variable};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::ConstraintSystem;
@ -35,7 +35,6 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
values.len(),
variable_names.len(),
span,
new_backtrace(),
)
.into());
}
@ -67,7 +66,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
// ConstrainedValue::Return(values) => values,
ConstrainedValue::Tuple(values) => values,
value => {
return Err(CompilerError::statement_multiple_definition(value, &span, new_backtrace()).into());
return Err(CompilerError::statement_multiple_definition(value, &span).into());
}
};

View File

@ -26,7 +26,7 @@ use crate::{
StatementResult,
};
use leo_asg::IterationStatement;
use leo_errors::{new_backtrace, CompilerError};
use leo_errors::CompilerError;
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{boolean::Boolean, integers::uint::UInt32};
@ -47,11 +47,11 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
let from = self
.enforce_index(cs, statement.start.get(), &span)?
.to_usize()
.ok_or_else(|| CompilerError::statement_loop_index_const(&span, new_backtrace()))?;
.ok_or_else(|| CompilerError::statement_loop_index_const(&span))?;
let to = self
.enforce_index(cs, statement.stop.get(), &span)?
.to_usize()
.ok_or_else(|| CompilerError::statement_loop_index_const(&span, new_backtrace()))?;
.ok_or_else(|| CompilerError::statement_loop_index_const(&span))?;
let iter: Box<dyn Iterator<Item = usize>> = match (from < to, statement.inclusive) {
(true, true) => Box::new(from..=to),

View File

@ -18,7 +18,7 @@
use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType};
use leo_asg::{Node, Statement};
use leo_errors::{new_backtrace, CompilerError, Result};
use leo_errors::{CompilerError, Result};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::boolean::Boolean;
@ -82,11 +82,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
}
}
_ => {
return Err(CompilerError::statement_unassigned(
&statement.span.clone().unwrap_or_default(),
new_backtrace(),
)
.into());
return Err(
CompilerError::statement_unassigned(&statement.span.clone().unwrap_or_default()).into(),
);
}
}
}

View File

@ -16,7 +16,7 @@
use crate::{ConstrainedValue, GroupType, IntegerTrait};
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_dpc::{account::Address as AleoAddress, testnet1::instantiated::Components};
use snarkvm_fields::PrimeField;
@ -42,8 +42,8 @@ pub struct Address {
impl Address {
pub(crate) fn constant(address: String, span: &Span) -> Result<Self> {
let address = AleoAddress::from_str(&address)
.map_err(|e| CompilerError::address_value_account_error(e, span, new_backtrace()))?;
let address =
AleoAddress::from_str(&address).map_err(|e| CompilerError::address_value_account_error(e, span))?;
let mut address_bytes = vec![];
address.write_le(&mut address_bytes).unwrap();
@ -72,7 +72,7 @@ impl Address {
if let InputValue::Address(string) = input {
Some(string)
} else {
return Err(CompilerError::address_value_invalid_address(name, span, new_backtrace()).into());
return Err(CompilerError::address_value_invalid_address(name, span).into());
}
}
None => None,
@ -82,7 +82,7 @@ impl Address {
cs.ns(|| format!("`{}: address` {}:{}", name, span.line_start, span.col_start)),
|| address_value.ok_or(SynthesisError::AssignmentMissing),
)
.map_err(|_| CompilerError::address_value_missing_address(span, new_backtrace()))?;
.map_err(|_| CompilerError::address_value_missing_address(span))?;
Ok(ConstrainedValue::Address(address))
}

View File

@ -18,7 +18,7 @@
use crate::{value::ConstrainedValue, GroupType};
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{boolean::Boolean, traits::alloc::AllocGadget};
@ -34,7 +34,7 @@ pub(crate) fn allocate_bool<F: PrimeField, CS: ConstraintSystem<F>>(
cs.ns(|| format!("`{}: bool` {}:{}", name, span.line_start, span.col_start)),
|| option.ok_or(SynthesisError::AssignmentMissing),
)
.map_err(|_| CompilerError::boolean_value_missing_boolean(format!("{}: bool", name), span, new_backtrace()))?)
.map_err(|_| CompilerError::boolean_value_missing_boolean(format!("{}: bool", name), span))?)
}
pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
@ -49,7 +49,7 @@ pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType<F>, CS: Constraint
if let InputValue::Boolean(bool) = input {
Some(bool)
} else {
return Err(CompilerError::boolean_value_invalid_boolean(name, span, new_backtrace()).into());
return Err(CompilerError::boolean_value_invalid_boolean(name, span).into());
}
}
None => None,

View File

@ -21,7 +21,7 @@ use crate::{
};
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{
@ -155,7 +155,7 @@ pub(crate) fn char_from_input<'a, F: PrimeField, G: GroupType<F>, CS: Constraint
}
}
} else {
return Err(CompilerError::char_value_invalid_char(input, span, new_backtrace()).into());
return Err(CompilerError::char_value_invalid_char(input, span).into());
}
}
None => (CharType::Scalar(0 as char), None),

View File

@ -17,7 +17,7 @@
//! A data type that represents a field value
use crate::number_string_typing;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::{
@ -50,14 +50,16 @@ impl<F: PrimeField> FieldType<F> {
let number_info = number_string_typing(&string);
let value = match number_info {
(number, neg) if neg => -F::from_str(&number)
.map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span, new_backtrace()))?,
(number, _) => F::from_str(&number)
.map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span, new_backtrace()))?,
(number, neg) if neg => {
-F::from_str(&number).map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span))?
}
(number, _) => {
F::from_str(&number).map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span))?
}
};
let value = FpGadget::alloc_constant(cs, || Ok(value))
.map_err(|_| CompilerError::field_value_invalid_field(string, span, new_backtrace()))?;
.map_err(|_| CompilerError::field_value_invalid_field(string, span))?;
Ok(FieldType(value))
}
@ -67,7 +69,7 @@ impl<F: PrimeField> FieldType<F> {
let result = self
.0
.negate(cs)
.map_err(|e| CompilerError::field_value_negate_operation(e, span, new_backtrace()))?;
.map_err(|e| CompilerError::field_value_negate_operation(e, span))?;
Ok(FieldType(result))
}
@ -77,7 +79,7 @@ impl<F: PrimeField> FieldType<F> {
let value = self
.0
.add(cs, &other.0)
.map_err(|e| CompilerError::field_value_binary_operation("+", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::field_value_binary_operation("+", e, span))?;
Ok(FieldType(value))
}
@ -87,7 +89,7 @@ impl<F: PrimeField> FieldType<F> {
let value = self
.0
.sub(cs, &other.0)
.map_err(|e| CompilerError::field_value_binary_operation("-", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::field_value_binary_operation("-", e, span))?;
Ok(FieldType(value))
}
@ -97,7 +99,7 @@ impl<F: PrimeField> FieldType<F> {
let value = self
.0
.mul(cs, &other.0)
.map_err(|e| CompilerError::field_value_binary_operation("*", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::field_value_binary_operation("*", e, span))?;
Ok(FieldType(value))
}
@ -107,7 +109,7 @@ impl<F: PrimeField> FieldType<F> {
let value = self
.0
.inverse(cs)
.map_err(|e| CompilerError::field_value_binary_operation("inv", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::field_value_binary_operation("inv", e, span))?;
Ok(FieldType(value))
}

View File

@ -18,7 +18,7 @@
use crate::{number_string_typing, value::ConstrainedValue, FieldType, GroupType};
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_gadgets::traits::alloc::AllocGadget;
@ -40,22 +40,16 @@ pub(crate) fn allocate_field<F: PrimeField, CS: ConstraintSystem<F>>(
|| Some(number).ok_or(SynthesisError::AssignmentMissing),
)
.map(|value| value.negate(cs, span))
.map_err(|_| {
CompilerError::field_value_missing_field(format!("{}: field", name), span, new_backtrace())
})?,
.map_err(|_| CompilerError::field_value_missing_field(format!("{}: field", name), span))?,
(number, _) => Ok(FieldType::alloc(
cs.ns(|| format!("`{}: field` {}:{}", name, span.line_start, span.col_start)),
|| Some(number).ok_or(SynthesisError::AssignmentMissing),
)
.map_err(|_| {
CompilerError::field_value_missing_field(format!("{}: field", name), span, new_backtrace())
})?),
.map_err(|_| CompilerError::field_value_missing_field(format!("{}: field", name), span))?),
}
}
None => {
return Err(
CompilerError::field_value_missing_field(format!("{}: field", name), span, new_backtrace()).into(),
);
return Err(CompilerError::field_value_missing_field(format!("{}: field", name), span).into());
}
}
}
@ -72,7 +66,7 @@ pub(crate) fn field_from_input<'a, F: PrimeField, G: GroupType<F>, CS: Constrain
if let InputValue::Field(string) = input {
Some(string)
} else {
return Err(CompilerError::field_value_invalid_field(input, span, new_backtrace()).into());
return Err(CompilerError::field_value_invalid_field(input, span).into());
}
}
None => None,

View File

@ -19,7 +19,7 @@
use crate::{ConstrainedValue, GroupType};
use leo_asg::GroupValue;
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::PrimeField;
use snarkvm_r1cs::{ConstraintSystem, SynthesisError};
@ -34,7 +34,7 @@ pub(crate) fn allocate_group<F: PrimeField, G: GroupType<F>, CS: ConstraintSyste
cs.ns(|| format!("`{}: group` {}:{}", name, span.line_start, span.col_start)),
|| option.ok_or(SynthesisError::AssignmentMissing),
)
.map_err(|_| CompilerError::group_value_missing_group(format!("{}: group", name), span, new_backtrace()))?)
.map_err(|_| CompilerError::group_value_missing_group(format!("{}: group", name), span))?)
}
pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
@ -49,7 +49,7 @@ pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType<F>, CS: Constrain
if let InputValue::Group(string) = input {
Some(string)
} else {
return Err(CompilerError::group_value_missing_group(input, span, new_backtrace()).into());
return Err(CompilerError::group_value_missing_group(input, span).into());
}
}
None => None,

View File

@ -16,7 +16,7 @@
use crate::{number_string_typing, GroupType};
use leo_asg::{GroupCoordinate, GroupValue};
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_curves::{
edwards_bls12::{EdwardsAffine, EdwardsParameters, Fq},
@ -63,7 +63,7 @@ impl GroupType<Fq> for EdwardsGroupType {
Ok(self
.allocated(cs.ns(|| format!("allocate affine point {}:{}", span.line_start, span.col_start)))
.map(|ebg| EdwardsGroupType::Allocated(Box::new(ebg)))
.map_err(|e| CompilerError::group_value_synthesis_error(e, span, new_backtrace()))?)
.map_err(|e| CompilerError::group_value_synthesis_error(e, span))?)
}
fn negate<CS: ConstraintSystem<Fq>>(&self, cs: CS, span: &Span) -> Result<Self> {
@ -71,7 +71,7 @@ impl GroupType<Fq> for EdwardsGroupType {
EdwardsGroupType::Constant(group) => Ok(EdwardsGroupType::Constant(group.neg())),
EdwardsGroupType::Allocated(group) => {
let result = <EdwardsBls12Gadget as GroupGadget<Affine<EdwardsParameters>, Fq>>::negate(group, cs)
.map_err(|e| CompilerError::group_value_negate_operation(e, span, new_backtrace()))?;
.map_err(|e| CompilerError::group_value_negate_operation(e, span))?;
Ok(EdwardsGroupType::Allocated(Box::new(result)))
}
@ -90,7 +90,7 @@ impl GroupType<Fq> for EdwardsGroupType {
cs,
other_value,
)
.map_err(|e| CompilerError::group_value_binary_operation("+", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::group_value_binary_operation("+", e, span))?;
Ok(EdwardsGroupType::Allocated(Box::new(result)))
}
@ -100,7 +100,7 @@ impl GroupType<Fq> for EdwardsGroupType {
Ok(EdwardsGroupType::Allocated(Box::new(
allocated_value
.add_constant(cs, constant_value)
.map_err(|e| CompilerError::group_value_binary_operation("+", e, span, new_backtrace()))?,
.map_err(|e| CompilerError::group_value_binary_operation("+", e, span))?,
)))
}
}
@ -118,7 +118,7 @@ impl GroupType<Fq> for EdwardsGroupType {
cs,
other_value,
)
.map_err(|e| CompilerError::group_value_binary_operation("-", e, span, new_backtrace()))?;
.map_err(|e| CompilerError::group_value_binary_operation("-", e, span))?;
Ok(EdwardsGroupType::Allocated(Box::new(result)))
}
@ -128,7 +128,7 @@ impl GroupType<Fq> for EdwardsGroupType {
Ok(EdwardsGroupType::Allocated(Box::new(
allocated_value
.sub_constant(cs, constant_value)
.map_err(|e| CompilerError::group_value_binary_operation("-", e, span, new_backtrace()))?,
.map_err(|e| CompilerError::group_value_binary_operation("-", e, span))?,
)))
}
}
@ -151,10 +151,12 @@ impl EdwardsGroupType {
} else {
let one = edwards_affine_one();
let number_value = match number_info {
(number, neg) if neg => -Fp256::from_str(&number)
.map_err(|_| CompilerError::group_value_n_group(number, span, new_backtrace()))?,
(number, _) => Fp256::from_str(&number)
.map_err(|_| CompilerError::group_value_n_group(number, span, new_backtrace()))?,
(number, neg) if neg => {
-Fp256::from_str(&number).map_err(|_| CompilerError::group_value_n_group(number, span))?
}
(number, _) => {
Fp256::from_str(&number).map_err(|_| CompilerError::group_value_n_group(number, span))?
}
};
let result: EdwardsAffine = one.mul(number_value);
@ -202,9 +204,7 @@ impl EdwardsGroupType {
}
// Invalid
(x, y) => {
return Err(
CompilerError::group_value_invalid_group(format!("({}, {})", x, y), span, new_backtrace()).into(),
);
return Err(CompilerError::group_value_invalid_group(format!("({}, {})", x, y), span).into());
}
}
}
@ -216,16 +216,16 @@ impl EdwardsGroupType {
element_span: &Span,
) -> Result<EdwardsAffine> {
let x = match x_info {
(x_str, neg) if neg => -Fq::from_str(&x_str)
.map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?,
(x_str, _) => Fq::from_str(&x_str)
.map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?,
(x_str, neg) if neg => {
-Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))?
}
(x_str, _) => Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))?,
};
match greatest {
// Sign provided
Some(greatest) => Ok(EdwardsAffine::from_x_coordinate(x, greatest)
.ok_or_else(|| CompilerError::group_value_x_recover(element_span, new_backtrace()))?),
.ok_or_else(|| CompilerError::group_value_x_recover(element_span))?),
// Sign inferred
None => {
// Attempt to recover with a sign_low bit.
@ -239,7 +239,7 @@ impl EdwardsGroupType {
}
// Otherwise return error.
Err(CompilerError::group_value_x_recover(element_span, new_backtrace()).into())
Err(CompilerError::group_value_x_recover(element_span).into())
}
}
}
@ -251,16 +251,16 @@ impl EdwardsGroupType {
element_span: &Span,
) -> Result<EdwardsAffine> {
let y = match y_info {
(y_str, neg) if neg => -Fq::from_str(&y_str)
.map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?,
(y_str, _) => Fq::from_str(&y_str)
.map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?,
(y_str, neg) if neg => {
-Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))?
}
(y_str, _) => Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))?,
};
match greatest {
// Sign provided
Some(greatest) => Ok(EdwardsAffine::from_y_coordinate(y, greatest)
.ok_or_else(|| CompilerError::group_value_y_recover(element_span, new_backtrace()))?),
.ok_or_else(|| CompilerError::group_value_y_recover(element_span))?),
// Sign inferred
None => {
// Attempt to recover with a sign_low bit.
@ -274,7 +274,7 @@ impl EdwardsGroupType {
}
// Otherwise return error.
Err(CompilerError::group_value_y_recover(element_span, new_backtrace()).into())
Err(CompilerError::group_value_y_recover(element_span).into())
}
}
}
@ -287,17 +287,17 @@ impl EdwardsGroupType {
element_span: &Span,
) -> Result<EdwardsAffine> {
let x = match x_info {
(x_str, neg) if neg => -Fq::from_str(&x_str)
.map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?,
(x_str, _) => Fq::from_str(&x_str)
.map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?,
(x_str, neg) if neg => {
-Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))?
}
(x_str, _) => Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))?,
};
let y = match y_info {
(y_str, neg) if neg => -Fq::from_str(&y_str)
.map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?,
(y_str, _) => Fq::from_str(&y_str)
.map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?,
(y_str, neg) if neg => {
-Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))?
}
(y_str, _) => Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))?,
};
let element = EdwardsAffine::new(x, y);
@ -305,7 +305,7 @@ impl EdwardsGroupType {
if element.is_on_curve() {
Ok(element)
} else {
Err(CompilerError::group_value_not_on_curve(element, element_span, new_backtrace()).into())
Err(CompilerError::group_value_not_on_curve(element, element_span).into())
}
}

View File

@ -18,7 +18,7 @@
use crate::IntegerTrait;
use leo_asg::{ConstInt, IntegerType};
use leo_ast::InputValue;
use leo_errors::{new_backtrace, CompilerError, Result, Span};
use leo_errors::{CompilerError, Result, Span};
use snarkvm_fields::{Field, PrimeField};
use snarkvm_gadgets::{
@ -161,17 +161,13 @@ impl Integer {
if let InputValue::Integer(type_, number) = input {
let asg_type = IntegerType::from(type_);
if std::mem::discriminant(&asg_type) != std::mem::discriminant(integer_type) {
return Err(CompilerError::integer_value_integer_type_mismatch(
integer_type,
asg_type,
span,
new_backtrace(),
)
.into());
return Err(
CompilerError::integer_value_integer_type_mismatch(integer_type, asg_type, span).into(),
);
}
Some(number)
} else {
return Err(CompilerError::integer_value_invalid_integer(input, span, new_backtrace()).into());
return Err(CompilerError::integer_value_invalid_integer(input, span).into());
}
}
None => None,
@ -187,7 +183,7 @@ impl Integer {
let result = match_signed_integer!(a, span => a.neg(cs.ns(|| unique_namespace)));
Ok(result.ok_or_else(|| CompilerError::integer_value_negate_operation(span, new_backtrace()))?)
Ok(result.ok_or_else(|| CompilerError::integer_value_negate_operation(span))?)
}
pub fn add<F: PrimeField, CS: ConstraintSystem<F>>(self, cs: &mut CS, other: Self, span: &Span) -> Result<Self> {
@ -198,7 +194,7 @@ impl Integer {
let result = match_integers_span!((a, b), span => a.add(cs.ns(|| unique_namespace), &b));
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("+", span, new_backtrace()))?)
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("+", span))?)
}
pub fn sub<F: PrimeField, CS: ConstraintSystem<F>>(self, cs: &mut CS, other: Self, span: &Span) -> Result<Self> {
@ -209,7 +205,7 @@ impl Integer {
let result = match_integers_span!((a, b), span => a.sub(cs.ns(|| unique_namespace), &b));
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("-", span, new_backtrace()))?)
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("-", span))?)
}
pub fn mul<F: PrimeField, CS: ConstraintSystem<F>>(self, cs: &mut CS, other: Self, span: &Span) -> Result<Self> {
@ -220,7 +216,7 @@ impl Integer {
let result = match_integers_span!((a, b), span => a.mul(cs.ns(|| unique_namespace), &b));
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("*", span, new_backtrace()))?)
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("*", span))?)
}
pub fn div<F: PrimeField, CS: ConstraintSystem<F>>(self, cs: &mut CS, other: Self, span: &Span) -> Result<Self> {
@ -231,7 +227,7 @@ impl Integer {
let result = match_integers_span!((a, b), span => a.div(cs.ns(|| unique_namespace), &b));
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("÷", span, new_backtrace()))?)
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("÷", span))?)
}
pub fn pow<F: PrimeField, CS: ConstraintSystem<F>>(self, cs: &mut CS, other: Self, span: &Span) -> Result<Self> {
@ -242,7 +238,7 @@ impl Integer {
let result = match_integers_span!((a, b), span => a.pow(cs.ns(|| unique_namespace), &b));
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("**", span, new_backtrace()))?)
Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("**", span))?)
}
}

View File

@ -55,31 +55,21 @@ macro_rules! match_unsigned_integer {
macro_rules! match_signed_integer {
($integer: ident, $span: ident => $expression: expr) => {
match $integer {
Integer::I8($integer) => {
Some(Integer::I8($expression.map_err(|e| {
CompilerError::integer_value_signed(e, $span, new_backtrace())
})?))
}
Integer::I16($integer) => {
Some(Integer::I16($expression.map_err(|e| {
CompilerError::integer_value_signed(e, $span, new_backtrace())
})?))
}
Integer::I32($integer) => {
Some(Integer::I32($expression.map_err(|e| {
CompilerError::integer_value_signed(e, $span, new_backtrace())
})?))
}
Integer::I64($integer) => {
Some(Integer::I64($expression.map_err(|e| {
CompilerError::integer_value_signed(e, $span, new_backtrace())
})?))
}
Integer::I128($integer) => {
Some(Integer::I128($expression.map_err(|e| {
CompilerError::integer_value_signed(e, $span, new_backtrace())
})?))
}
Integer::I8($integer) => Some(Integer::I8(
$expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?,
)),
Integer::I16($integer) => Some(Integer::I16(
$expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?,
)),
Integer::I32($integer) => Some(Integer::I32(
$expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?,
)),
Integer::I64($integer) => Some(Integer::I64(
$expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?,
)),
Integer::I128($integer) => Some(Integer::I128(
$expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?,
)),
_ => None,
}
@ -110,57 +100,37 @@ macro_rules! match_integers {
macro_rules! match_integers_span {
(($a: ident, $b: ident), $span: ident => $expression:expr) => {
match ($a, $b) {
(Integer::U8($a), Integer::U8($b)) => {
Some(Integer::U8($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::U16($a), Integer::U16($b)) => {
Some(Integer::U16($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::U32($a), Integer::U32($b)) => {
Some(Integer::U32($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::U64($a), Integer::U64($b)) => {
Some(Integer::U64($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::U128($a), Integer::U128($b)) => {
Some(Integer::U128($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::U8($a), Integer::U8($b)) => Some(Integer::U8(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::U16($a), Integer::U16($b)) => Some(Integer::U16(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::U32($a), Integer::U32($b)) => Some(Integer::U32(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::U64($a), Integer::U64($b)) => Some(Integer::U64(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::U128($a), Integer::U128($b)) => Some(Integer::U128(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::I8($a), Integer::I8($b)) => {
Some(Integer::I8($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::I16($a), Integer::I16($b)) => {
Some(Integer::I16($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::I32($a), Integer::I32($b)) => {
Some(Integer::I32($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::I64($a), Integer::I64($b)) => {
Some(Integer::I64($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::I128($a), Integer::I128($b)) => {
Some(Integer::I128($expression.map_err(|e| {
CompilerError::integer_value_unsigned(e, $span, new_backtrace())
})?))
}
(Integer::I8($a), Integer::I8($b)) => Some(Integer::I8(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::I16($a), Integer::I16($b)) => Some(Integer::I16(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::I32($a), Integer::I32($b)) => Some(Integer::I32(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::I64($a), Integer::I64($b)) => Some(Integer::I64(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(Integer::I128($a), Integer::I128($b)) => Some(Integer::I128(
$expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?,
)),
(_, _) => None,
}
};
@ -171,7 +141,7 @@ macro_rules! allocate_type {
let option = $option
.map(|s| {
s.parse::<$rust_ty>()
.map_err(|_| CompilerError::integer_value_invalid_integer(s, $span, new_backtrace()))
.map_err(|_| CompilerError::integer_value_invalid_integer(s, $span))
})
.transpose()?;
@ -191,7 +161,6 @@ macro_rules! allocate_type {
CompilerError::integer_value_missing_integer(
format!("{}: {}", $name.to_string(), stringify!($rust_ty)),
$span,
new_backtrace(),
)
})?;

View File

@ -17,6 +17,9 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ]
license = "GPL-3.0"
edition = "2018"
[dependencies]
color-backtrace = "0.5.1"
[dependencies.leo-input]
path = "../input"
version = "1.5.3"

View File

@ -20,7 +20,7 @@ use std::fmt::{Debug, Display};
create_errors!(
AsgError,
exit_code_mask: 0u32,
exit_code_mask: 0i32,
error_code_prefix: "ASG",
@formatted

View File

@ -19,7 +19,7 @@ use std::{error::Error as ErrorArg, fmt::Debug};
create_errors!(
AstError,
exit_code_mask: 1000u32,
exit_code_mask: 1000i32,
error_code_prefix: "AST",
@backtraced

View File

@ -22,7 +22,7 @@ use std::{
create_errors!(
CliError,
exit_code_mask: 7000u32,
exit_code_mask: 7000i32,
error_code_prefix: "CLI",
@backtraced
@ -321,20 +321,20 @@ create_errors!(
);
impl CliError {
pub fn remove_token_and_username(error: std::io::Error, backtrace: Backtrace) -> Self {
pub fn remove_token_and_username(error: std::io::Error) -> Self {
use std::io::ErrorKind;
match error.kind() {
ErrorKind::NotFound => {
// tracing::info!("you are not logged in");
Self::not_logged_in(backtrace)
Self::not_logged_in()
}
ErrorKind::PermissionDenied => {
// tracing::error!("permission denied - check file permission in .leo folder");
Self::logout_permision_denied(backtrace)
Self::logout_permision_denied()
}
_ => {
// tracing::error!("something went wrong, can't access the file");
Self::cannot_access_logout_file(backtrace)
Self::cannot_access_logout_file()
}
}
}

View File

@ -17,6 +17,7 @@
use std::fmt;
use backtrace::Backtrace;
use color_backtrace::BacktracePrinter;
use derivative::Derivative;
pub const INDENT: &str = " ";
@ -34,8 +35,8 @@ pub const INDENT: &str = " ";
pub struct BacktracedError {
pub message: String,
pub help: Option<String>,
pub exit_code: u32,
pub code_identifier: u32,
pub exit_code: i32,
pub code_identifier: i8,
pub error_type: String,
#[derivative(PartialEq = "ignore")]
#[derivative(Hash = "ignore")]
@ -46,8 +47,8 @@ impl BacktracedError {
pub fn new_from_backtrace<S>(
message: S,
help: Option<String>,
exit_code: u32,
code_identifier: u32,
exit_code: i32,
code_identifier: i8,
error_type: String,
backtrace: Backtrace,
) -> Self
@ -64,8 +65,18 @@ impl BacktracedError {
}
}
pub fn exit_code(&self) -> u32 {
0
pub fn exit_code(&self) -> i32 {
let mut code: i32;
if self.code_identifier > 99 {
code = self.code_identifier as i32 * 111_000;
} else if self.code_identifier as i32 > 9 {
code = self.code_identifier as i32 * 11_000;
} else {
code = self.code_identifier as i32 * 1_000;
}
code += self.exit_code;
code
}
}
@ -87,8 +98,29 @@ impl fmt::Display for BacktracedError {
write!(f, "{indent } = {help}", indent = INDENT, help = help)?;
}
if std::env::var("LEO_BACKTRACE").unwrap_or_default().trim() == "1" {
write!(f, "stack backtrace:\n{:?}", self.backtrace)?;
let leo_backtrace = std::env::var("LEO_BACKTRACE").unwrap_or_default().trim().to_owned();
match leo_backtrace.as_ref() {
"1" => {
dbg!("1");
let mut printer = BacktracePrinter::default();
printer = printer.verbosity(Verbosity::Medium);
printer = printer.lib_verbosity(Verbosity::Medium);
let trace = printer
.format_trace_to_string(&self.backtrace.backtrace)
.map_err(|_| fmt::Error)?;
write!(f, "{}", trace)?;
}
"full" => {
dbg!("full");
let mut printer = BacktracePrinter::default();
printer = printer.verbosity(Verbosity::Full);
printer = printer.lib_verbosity(Verbosity::Full);
let trace = printer
.format_trace_to_string(&self.backtrace.backtrace)
.map_err(|_| fmt::Error)?;
write!(f, "{}", trace)?;
}
_ => {}
}
Ok(())

View File

@ -19,6 +19,7 @@ use crate::{BacktracedError, Span};
use std::{fmt, sync::Arc};
use backtrace::Backtrace;
use color_backtrace::{BacktracePrinter, Verbosity};
pub const INDENT: &str = " ";
@ -45,8 +46,8 @@ impl FormattedError {
pub fn new_from_span<S>(
message: S,
help: Option<String>,
exit_code: u32,
code_identifier: u32,
exit_code: i32,
code_identifier: i8,
error_type: String,
span: &Span,
backtrace: Backtrace,
@ -72,8 +73,8 @@ impl FormattedError {
}
}
pub fn exit_code(&self) -> u32 {
0
pub fn exit_code(&self) -> i32 {
self.backtrace.exit_code()
}
}
@ -138,8 +139,29 @@ impl fmt::Display for FormattedError {
write!(f, "{indent } = {help}", indent = INDENT, help = help)?;
}
if std::env::var("LEO_BACKTRACE").unwrap_or_default().trim() == "1" {
write!(f, "stack backtrace:\n{:?}", self.backtrace.backtrace)?;
let leo_backtrace = std::env::var("LEO_BACKTRACE").unwrap_or_default().trim().to_owned();
match leo_backtrace.as_ref() {
"1" => {
dbg!("1");
let mut printer = BacktracePrinter::default();
printer = printer.verbosity(Verbosity::Medium);
printer = printer.lib_verbosity(Verbosity::Medium);
let trace = printer
.format_trace_to_string(&self.backtrace.backtrace)
.map_err(|_| fmt::Error)?;
write!(f, "{}", trace)?;
}
"full" => {
dbg!("full");
let mut printer = BacktracePrinter::default();
printer = printer.verbosity(Verbosity::Full);
printer = printer.lib_verbosity(Verbosity::Full);
let trace = printer
.format_trace_to_string(&self.backtrace.backtrace)
.map_err(|_| fmt::Error)?;
write!(f, "{}", trace)?;
}
_ => {}
}
Ok(())

View File

@ -18,11 +18,11 @@
macro_rules! create_errors {
(@step $_code:expr,) => {};
($error_type:ident, exit_code_mask: $exit_code_mask:expr, error_code_prefix: $error_code_prefix:expr, $(@$formatted_or_backtraced_list:ident $names:ident { args: ($($arg_names:ident: $arg_types:ty$(,)?)*), msg: $messages:expr, help: $helps:expr, })*) => {
#[allow(unused_imports)]
use crate::{BacktracedError, ErrorCode, FormattedError, LeoErrorCode, Span};
use backtrace::Backtrace;
#[derive(Debug, Error)]
pub enum $error_type {
#[error(transparent)]
@ -36,7 +36,7 @@ macro_rules! create_errors {
impl ErrorCode for $error_type {
#[inline(always)]
fn exit_code(&self) -> u32 {
fn exit_code(&self) -> i32 {
match self {
Self::FormattedError(formatted) => {
formatted.exit_code()
@ -49,7 +49,7 @@ macro_rules! create_errors {
}
#[inline(always)]
fn exit_code_mask() -> u32 {
fn exit_code_mask() -> i32 {
$exit_code_mask
}
@ -57,53 +57,44 @@ macro_rules! create_errors {
fn error_type() -> String {
$error_code_prefix.to_string()
}
fn new_from_backtrace<S>(message: S, help: Option<String>, exit_code: u32, backtrace: Backtrace) -> Self
where
S: ToString {
BacktracedError::new_from_backtrace(
message,
help,
exit_code + Self::exit_code_mask(),
Self::code_identifier(),
Self::error_type(),
backtrace,
).into()
}
fn new_from_span<S>(message: S, help: Option<String>, exit_code: u32, span: &Span, backtrace: Backtrace) -> Self
where S: ToString {
FormattedError::new_from_span(
message,
help,
exit_code + Self::exit_code_mask(),
Self::code_identifier(),
Self::error_type(),
span,
backtrace,
).into()
}
}
impl $error_type {
create_errors!(@step 0u32, $(($formatted_or_backtraced_list, $names($($arg_names: $arg_types,)*), $messages, $helps),)*);
create_errors!(@step 0i32, $(($formatted_or_backtraced_list, $names($($arg_names: $arg_types,)*), $messages, $helps),)*);
}
};
(@step $code:expr, (formatted, $error_name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => {
pub fn $error_name($($arg_names: $arg_types,)* span: &Span, backtrace: Backtrace) -> Self {
Self::new_from_span($message, $help, $code, span, backtrace)
pub fn $error_name($($arg_names: $arg_types,)* span: &Span) -> Self {
Self::FormattedError(
FormattedError::new_from_span(
$message,
$help,
$code + Self::exit_code_mask(),
Self::code_identifier(),
Self::error_type(),
span,
Backtrace::new(),
)
)
}
create_errors!(@step $code + 1u32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
create_errors!(@step $code + 1i32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
};
(@step $code:expr, (backtraced, $error_name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => {
pub fn $error_name($($arg_names: $arg_types,)* backtrace: Backtrace) -> Self {
Self::new_from_backtrace($message, $help, $code, backtrace)
pub fn $error_name($($arg_names: $arg_types,)*) -> Self {
Self::BacktracedError(
BacktracedError::new_from_backtrace(
$message,
$help,
$code + Self::exit_code_mask(),
Self::code_identifier(),
Self::error_type(),
Backtrace::new(),
)
)
}
create_errors!(@step $code + 1u32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
create_errors!(@step $code + 1i32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*);
};
}

View File

@ -14,29 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::Span;
use backtrace::Backtrace;
pub trait ErrorCode: Sized {
fn exit_code(&self) -> u32;
fn exit_code(&self) -> i32;
fn exit_code_mask() -> u32;
fn exit_code_mask() -> i32;
fn error_type() -> String;
fn new_from_backtrace<S>(message: S, help: Option<String>, exit_code: u32, backtrace: Backtrace) -> Self
where
S: ToString;
fn new_from_span<S>(message: S, help: Option<String>, exit_code: u32, span: &Span, backtrace: Backtrace) -> Self
where
S: ToString;
}
pub trait LeoErrorCode: ErrorCode {
#[inline(always)]
fn code_identifier() -> u32 {
fn code_identifier() -> i8 {
37
}
}

View File

@ -23,7 +23,7 @@ use std::{
create_errors!(
CompilerError,
exit_code_mask: 2000u32,
exit_code_mask: 2000i32,
error_code_prefix: "CMP",
@backtraced

View File

@ -23,7 +23,7 @@ use std::{
create_errors!(
ImportError,
exit_code_mask: 3000u32,
exit_code_mask: 3000i32,
error_code_prefix: "IMP",
// An imported package has the same name as an imported core_package.

View File

@ -50,8 +50,6 @@ extern crate thiserror;
use leo_input::InputParserError;
use backtrace::Backtrace;
#[derive(Debug, Error)]
pub enum LeoError {
#[error(transparent)]
@ -86,7 +84,7 @@ pub enum LeoError {
}
impl LeoError {
pub fn exit_code(&self) -> u32 {
pub fn exit_code(&self) -> i32 {
use LeoError::*;
match self {
@ -106,11 +104,6 @@ impl LeoError {
pub type Result<T, E = LeoError> = core::result::Result<T, E>;
#[inline(always)]
pub fn new_backtrace() -> Backtrace {
Backtrace::new()
}
// #[test]
// fn test_error() {
// let err = FormattedError {

View File

@ -23,7 +23,7 @@ use std::{
create_errors!(
PackageError,
exit_code_mask: 4000u32,
exit_code_mask: 4000i32,
error_code_prefix: "PAK",
@backtraced

View File

@ -20,7 +20,7 @@ use std::fmt::Display;
create_errors!(
ParserError,
exit_code_mask: 5000u32,
exit_code_mask: 5000i32,
error_code_prefix: "PAR",
@formatted

View File

@ -18,6 +18,6 @@ use crate::create_errors;
create_errors!(
StateError,
exit_code_mask: 6000u32,
error_code_prefix: "S",
exit_code_mask: 6000i32,
error_code_prefix: "STA",
);

Some files were not shown because too many files have changed in this diff Show More