From 55d6dc5cc61423795eebc1c5d5f36fd0f183bc5b Mon Sep 17 00:00:00 2001 From: collin Date: Sun, 16 Aug 2020 23:13:10 -0700 Subject: [PATCH] fix stack overflow error caused by SynthesisError --- compiler/src/errors/expression.rs | 8 +++++++- compiler/src/errors/value/address.rs | 2 +- compiler/src/errors/value/boolean.rs | 2 +- compiler/src/errors/value/field.rs | 6 +++--- compiler/src/errors/value/group.rs | 6 +++--- compiler/src/errors/value/integer.rs | 2 +- compiler/src/expression/relational/eq.rs | 2 +- compiler/src/expression/relational/ge.rs | 3 +-- compiler/src/expression/relational/gt.rs | 3 +-- compiler/src/expression/relational/le.rs | 3 +-- compiler/src/expression/relational/lt.rs | 3 +-- 11 files changed, 21 insertions(+), 19 deletions(-) diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index b1c5a18641..ba82b9741b 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -51,13 +51,19 @@ impl ExpressionError { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { let message = format!( - "the gadget operation `{}` failed due to synthesis error `{}`", + "the gadget operation `{}` failed due to synthesis error `{:?}`", operation, error, ); Self::new_from_span(message, span) } + pub fn cannot_evaluate(operation: String, span: Span) -> Self { + let message = format!("Mismatched types found for operation `{}`", operation); + + Self::new_from_span(message, span) + } + pub fn conditional_boolean(actual: String, span: Span) -> Self { let message = format!("if, else conditional must resolve to a boolean, found `{}`", actual); diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index 9f9c131f17..68584aaa73 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -28,7 +28,7 @@ impl AddressError { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { let message = format!( - "the address operation `{}` failed due to the synthesis error `{}`", + "the address operation `{:?}` failed due to the synthesis error `{}`", operation, error, ); diff --git a/compiler/src/errors/value/boolean.rs b/compiler/src/errors/value/boolean.rs index 9b96b586b4..dc385c65c4 100644 --- a/compiler/src/errors/value/boolean.rs +++ b/compiler/src/errors/value/boolean.rs @@ -22,7 +22,7 @@ impl BooleanError { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { let message = format!( - "the boolean operation `{}` failed due to the synthesis error `{}`", + "the boolean operation `{}` failed due to the synthesis error `{:?}`", operation, error, ); diff --git a/compiler/src/errors/value/field.rs b/compiler/src/errors/value/field.rs index 84c0a49979..d33d8408b8 100644 --- a/compiler/src/errors/value/field.rs +++ b/compiler/src/errors/value/field.rs @@ -21,14 +21,14 @@ impl FieldError { } pub fn negate_operation(error: SynthesisError, span: Span) -> Self { - let message = format!("field negation failed due to synthesis error `{}`", error,); + let message = format!("field negation failed due to synthesis error `{:?}`", error,); Self::new_from_span(message, span) } pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self { let message = format!( - "the field binary operation `{}` failed due to synthesis error `{}`", + "the field binary operation `{}` failed due to synthesis error `{:?}`", operation, error, ); @@ -54,7 +54,7 @@ impl FieldError { } pub fn synthesis_error(error: SynthesisError, span: Span) -> Self { - let message = format!("compilation failed due to field synthesis error `{}`", error); + let message = format!("compilation failed due to field synthesis error `{:?}`", error); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index 5934282406..2f4086522f 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -21,14 +21,14 @@ impl GroupError { } pub fn negate_operation(error: SynthesisError, span: Span) -> Self { - let message = format!("group negation failed due to the synthesis error `{}`", error,); + let message = format!("group negation failed due to the synthesis error `{:?}`", error,); Self::new_from_span(message, span) } pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self { let message = format!( - "the group binary operation `{}` failed due to the synthesis error `{}`", + "the group binary operation `{}` failed due to the synthesis error `{:?}`", operation, error, ); @@ -48,7 +48,7 @@ impl GroupError { } pub fn synthesis_error(error: SynthesisError, span: Span) -> Self { - let message = format!("compilation failed due to group synthesis error `{}`", error); + let message = format!("compilation failed due to group synthesis error `{:?}`", error); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index 9d7f906961..c2de51c90c 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -23,7 +23,7 @@ impl IntegerError { pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { let message = format!( - "the integer operation `{}` failed due to the synthesis error `{}`", + "the integer operation `{}` failed due to the synthesis error `{:?}`", operation, error, ); diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 6f62542001..2bc42316db 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -47,7 +47,7 @@ pub fn evaluate_eq, CS: ConstraintSystem< } }; - let boolean = constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate equal"), e, span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("=="), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index a91cc8d3bc..1e8bb9c818 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -36,8 +36,7 @@ pub fn evaluate_ge, CS: ConstraintSystem< } }; - let boolean = constraint_result - .map_err(|e| ExpressionError::cannot_enforce(format!("evaluate greater than or equal"), e, span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">="), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index 4fc26cbe20..f81874b793 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -36,8 +36,7 @@ pub fn evaluate_gt, CS: ConstraintSystem< } }; - let boolean = - constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate greater than"), e, span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">"), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 06f8d47294..ccea8ecd4d 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -36,8 +36,7 @@ pub fn evaluate_le, CS: ConstraintSystem< } }; - let boolean = constraint_result - .map_err(|e| ExpressionError::cannot_enforce(format!("evaluate less than or equal"), e, span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<="), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 4c49c36bd1..ddfd432771 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -36,8 +36,7 @@ pub fn evaluate_lt, CS: ConstraintSystem< } }; - let boolean = - constraint_result.map_err(|e| ExpressionError::cannot_enforce(format!("evaluate less than"), e, span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<"), span))?; Ok(ConstrainedValue::Boolean(boolean)) }