mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
Merge pull request #1225 from AleoHQ/fix-1217-self-not-canonicalized
[Fix] Adds Self canonicalization for static calls
This commit is contained in:
commit
bfc995be34
@ -315,16 +315,16 @@ impl ConstInt {
|
|||||||
|
|
||||||
pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result<ConstInt, AsgConvertError> {
|
pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result<ConstInt, AsgConvertError> {
|
||||||
Ok(match int_type {
|
Ok(match int_type {
|
||||||
IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
value: ConstValue::Boolean(
|
value: ConstValue::Boolean(
|
||||||
value
|
value
|
||||||
.parse::<bool>()
|
.parse::<bool>()
|
||||||
.map_err(|_| AsgConvertError::invalid_boolean(&value, span))?,
|
.map_err(|_| AsgConvertError::invalid_boolean(value, span))?,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
Constant {
|
Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
span: Some(span.clone()),
|
span: Some(span.clone()),
|
||||||
value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Group(value) => {
|
Group(value) => {
|
||||||
@ -188,7 +188,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> {
|
|||||||
Some(PartialType::Type(Type::Field)) => Constant {
|
Some(PartialType::Type(Type::Field)) => Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
span: Some(span.clone()),
|
span: Some(span.clone()),
|
||||||
value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?),
|
value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?),
|
||||||
},
|
},
|
||||||
Some(PartialType::Type(Type::Group)) => Constant {
|
Some(PartialType::Type(Type::Group)) => Constant {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
|
@ -341,7 +341,7 @@ impl<'a> FromAst<'a, leo_ast::Expression> for &'a Expression<'a> {
|
|||||||
.context
|
.context
|
||||||
.alloc_expression(CallExpression::from_ast(scope, call, expected_type).map(Expression::Call)?),
|
.alloc_expression(CallExpression::from_ast(scope, call, expected_type).map(Expression::Call)?),
|
||||||
};
|
};
|
||||||
expression.enforce_parents(&expression);
|
expression.enforce_parents(expression);
|
||||||
Ok(expression)
|
Ok(expression)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ impl<'a> Function<'a> {
|
|||||||
let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable {
|
||||||
id: scope.context.get_id(),
|
id: scope.context.get_id(),
|
||||||
name: identifier.clone(),
|
name: identifier.clone(),
|
||||||
type_: scope.resolve_ast_type(&type_)?,
|
type_: scope.resolve_ast_type(type_)?,
|
||||||
mutable: *mutable,
|
mutable: *mutable,
|
||||||
const_: *const_,
|
const_: *const_,
|
||||||
declaration: crate::VariableDeclaration::Parameter,
|
declaration: crate::VariableDeclaration::Parameter,
|
||||||
|
@ -127,7 +127,7 @@ fn resolve_import_package_access(
|
|||||||
PackageAccess::Multiple(packages) => {
|
PackageAccess::Multiple(packages) => {
|
||||||
package_segments.push(packages.name.name.to_string());
|
package_segments.push(packages.name.name.to_string());
|
||||||
for subaccess in packages.accesses.iter() {
|
for subaccess in packages.accesses.iter() {
|
||||||
resolve_import_package_access(output, package_segments.clone(), &subaccess);
|
resolve_import_package_access(output, package_segments.clone(), subaccess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,6 +308,6 @@ impl<'a, T: Monoid, R: MonoidalReducerProgram<'a, T>> MonoidalDirector<'a, T, R>
|
|||||||
let circuits = input.circuits.iter().map(|(_, c)| self.reduce_circuit(c)).collect();
|
let circuits = input.circuits.iter().map(|(_, c)| self.reduce_circuit(c)).collect();
|
||||||
|
|
||||||
self.reducer
|
self.reducer
|
||||||
.reduce_program(&input, imported_modules, functions, circuits)
|
.reduce_program(input, imported_modules, functions, circuits)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,12 +79,12 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scope
|
scope
|
||||||
.resolve_variable(&name)
|
.resolve_variable(name)
|
||||||
.ok_or_else(|| AsgConvertError::unresolved_reference(name, &span))?
|
.ok_or_else(|| AsgConvertError::unresolved_reference(name, span))?
|
||||||
};
|
};
|
||||||
|
|
||||||
if !variable.borrow().mutable {
|
if !variable.borrow().mutable {
|
||||||
return Err(AsgConvertError::immutable_assignment(&name, &statement.span));
|
return Err(AsgConvertError::immutable_assignment(name, &statement.span));
|
||||||
}
|
}
|
||||||
let mut target_type: Option<PartialType> = Some(variable.borrow().type_.clone().into());
|
let mut target_type: Option<PartialType> = Some(variable.borrow().type_.clone().into());
|
||||||
|
|
||||||
@ -123,13 +123,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
) {
|
) {
|
||||||
let left = match left {
|
let left = match left {
|
||||||
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
||||||
AsgConvertError::invalid_assign_index(&name, &x.to_string(), &statement.span)
|
AsgConvertError::invalid_assign_index(name, &x.to_string(), &statement.span)
|
||||||
})?,
|
})?,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
let right = match right {
|
let right = match right {
|
||||||
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
ConstValue::Int(x) => x.to_usize().ok_or_else(|| {
|
||||||
AsgConvertError::invalid_assign_index(&name, &x.to_string(), &statement.span)
|
AsgConvertError::invalid_assign_index(name, &x.to_string(), &statement.span)
|
||||||
})?,
|
})?,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
@ -137,7 +137,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
target_type = Some(PartialType::Array(item.clone(), Some((right - left) as usize)))
|
target_type = Some(PartialType::Array(item.clone(), Some((right - left) as usize)))
|
||||||
} else {
|
} else {
|
||||||
return Err(AsgConvertError::invalid_backwards_assignment(
|
return Err(AsgConvertError::invalid_backwards_assignment(
|
||||||
&name,
|
name,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
&statement.span,
|
&statement.span,
|
||||||
@ -145,7 +145,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(AsgConvertError::index_into_non_array(&name, &statement.span)),
|
_ => return Err(AsgConvertError::index_into_non_array(name, &statement.span)),
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignAccess::ArrayRange(Cell::new(left), Cell::new(right))
|
AssignAccess::ArrayRange(Cell::new(left), Cell::new(right))
|
||||||
@ -153,7 +153,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
AstAssigneeAccess::ArrayIndex(index) => {
|
AstAssigneeAccess::ArrayIndex(index) => {
|
||||||
target_type = match target_type.clone() {
|
target_type = match target_type.clone() {
|
||||||
Some(PartialType::Array(item, _)) => item.map(|x| *x),
|
Some(PartialType::Array(item, _)) => item.map(|x| *x),
|
||||||
_ => return Err(AsgConvertError::index_into_non_array(&name, &statement.span)),
|
_ => return Err(AsgConvertError::index_into_non_array(name, &statement.span)),
|
||||||
};
|
};
|
||||||
AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast(
|
AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast(
|
||||||
scope,
|
scope,
|
||||||
@ -171,7 +171,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> {
|
|||||||
.get(index)
|
.get(index)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or_else(|| AsgConvertError::tuple_index_out_of_bounds(index, &statement.span))?,
|
.ok_or_else(|| AsgConvertError::tuple_index_out_of_bounds(index, &statement.span))?,
|
||||||
_ => return Err(AsgConvertError::index_into_non_tuple(&name, &statement.span)),
|
_ => return Err(AsgConvertError::index_into_non_tuple(name, &statement.span)),
|
||||||
};
|
};
|
||||||
AssignAccess::Tuple(index)
|
AssignAccess::Tuple(index)
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ impl<'a> FromAst<'a, leo_ast::Block> for BlockStatement<'a> {
|
|||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for item in statement.statements.iter() {
|
for item in statement.statements.iter() {
|
||||||
output.push(Cell::new(<&'a Statement<'a>>::from_ast(&new_scope, item, None)?));
|
output.push(Cell::new(<&'a Statement<'a>>::from_ast(new_scope, item, None)?));
|
||||||
}
|
}
|
||||||
Ok(BlockStatement {
|
Ok(BlockStatement {
|
||||||
parent: Cell::new(None),
|
parent: Cell::new(None),
|
||||||
|
@ -70,7 +70,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> {
|
|||||||
let type_ = statement
|
let type_ = statement
|
||||||
.type_
|
.type_
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|x| scope.resolve_ast_type(&x))
|
.map(|x| scope.resolve_ast_type(x))
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?;
|
let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?;
|
||||||
|
@ -47,7 +47,7 @@ impl Canonicalizer {
|
|||||||
let mut left = Box::new(start);
|
let mut left = Box::new(start);
|
||||||
|
|
||||||
for access in accesses.iter() {
|
for access in accesses.iter() {
|
||||||
match self.canonicalize_assignee_access(&access) {
|
match self.canonicalize_assignee_access(access) {
|
||||||
AssigneeAccess::ArrayIndex(index) => {
|
AssigneeAccess::ArrayIndex(index) => {
|
||||||
left = Box::new(Expression::ArrayAccess(ArrayAccessExpression {
|
left = Box::new(Expression::ArrayAccess(ArrayAccessExpression {
|
||||||
array: left,
|
array: left,
|
||||||
@ -276,6 +276,11 @@ impl Canonicalizer {
|
|||||||
span: call.span.clone(),
|
span: call.span.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Expression::Identifier(identifier) => {
|
||||||
|
if identifier.name.as_ref() == "Self" && self.circuit_name.is_some() {
|
||||||
|
return Expression::Identifier(self.circuit_name.as_ref().unwrap().clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +295,7 @@ impl Canonicalizer {
|
|||||||
|
|
||||||
AssigneeAccess::ArrayRange(left, right)
|
AssigneeAccess::ArrayRange(left, right)
|
||||||
}
|
}
|
||||||
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(&index)),
|
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(index)),
|
||||||
_ => access.clone(),
|
_ => access.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +318,7 @@ impl Canonicalizer {
|
|||||||
let statements = block
|
let statements = block
|
||||||
.statements
|
.statements
|
||||||
.iter()
|
.iter()
|
||||||
.map(|block_statement| self.canonicalize_statement(&block_statement))
|
.map(|block_statement| self.canonicalize_statement(block_statement))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Block {
|
Block {
|
||||||
|
@ -50,34 +50,32 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
// Expressions
|
// Expressions
|
||||||
pub fn reduce_expression(&mut self, expression: &Expression) -> Result<Expression, ReducerError> {
|
pub fn reduce_expression(&mut self, expression: &Expression) -> Result<Expression, ReducerError> {
|
||||||
let new = match expression {
|
let new = match expression {
|
||||||
Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?),
|
Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)?),
|
||||||
Expression::Value(value) => self.reduce_value(&value)?,
|
Expression::Value(value) => self.reduce_value(value)?,
|
||||||
Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary)?),
|
Expression::Binary(binary) => Expression::Binary(self.reduce_binary(binary)?),
|
||||||
Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary)?),
|
Expression::Unary(unary) => Expression::Unary(self.reduce_unary(unary)?),
|
||||||
Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary)?),
|
Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(ternary)?),
|
||||||
Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast)?),
|
Expression::Cast(cast) => Expression::Cast(self.reduce_cast(cast)?),
|
||||||
|
|
||||||
Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(&array_inline)?),
|
Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(array_inline)?),
|
||||||
Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(&array_init)?),
|
Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(array_init)?),
|
||||||
Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(&array_access)?),
|
Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(array_access)?),
|
||||||
Expression::ArrayRangeAccess(array_range_access) => {
|
Expression::ArrayRangeAccess(array_range_access) => {
|
||||||
Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access)?)
|
Expression::ArrayRangeAccess(self.reduce_array_range_access(array_range_access)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(&tuple_init)?),
|
Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(tuple_init)?),
|
||||||
Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(&tuple_access)?),
|
Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(tuple_access)?),
|
||||||
|
|
||||||
Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(&circuit_init)?),
|
Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(circuit_init)?),
|
||||||
Expression::CircuitMemberAccess(circuit_member_access) => {
|
Expression::CircuitMemberAccess(circuit_member_access) => {
|
||||||
Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access)?)
|
Expression::CircuitMemberAccess(self.reduce_circuit_member_access(circuit_member_access)?)
|
||||||
}
|
}
|
||||||
Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => {
|
Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => {
|
||||||
Expression::CircuitStaticFunctionAccess(
|
Expression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(circuit_static_fn_access)?)
|
||||||
self.reduce_circuit_static_fn_access(&circuit_static_fn_access)?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression::Call(call) => Expression::Call(self.reduce_call(&call)?),
|
Expression::Call(call) => Expression::Call(self.reduce_call(call)?),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.reducer.reduce_expression(expression, new)
|
self.reducer.reduce_expression(expression, new)
|
||||||
@ -93,7 +91,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
|
|
||||||
pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result<GroupValue, ReducerError> {
|
pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result<GroupValue, ReducerError> {
|
||||||
let new = match group_value {
|
let new = match group_value {
|
||||||
GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?),
|
GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(group_tuple)?),
|
||||||
_ => group_value.clone(),
|
_ => group_value.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -107,9 +105,9 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_value(&mut self, value: &ValueExpression) -> Result<Expression, ReducerError> {
|
pub fn reduce_value(&mut self, value: &ValueExpression) -> Result<Expression, ReducerError> {
|
||||||
let new = match value {
|
let new = match value {
|
||||||
ValueExpression::Group(group_value) => {
|
ValueExpression::Group(group_value) => {
|
||||||
Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)))
|
Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(group_value)?)))
|
||||||
}
|
}
|
||||||
ValueExpression::String(string, span) => self.reduce_string(string, &span)?,
|
ValueExpression::String(string, span) => self.reduce_string(string, span)?,
|
||||||
_ => Expression::Value(value.clone()),
|
_ => Expression::Value(value.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -284,14 +282,14 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
// Statements
|
// Statements
|
||||||
pub fn reduce_statement(&mut self, statement: &Statement) -> Result<Statement, ReducerError> {
|
pub fn reduce_statement(&mut self, statement: &Statement) -> Result<Statement, ReducerError> {
|
||||||
let new = match statement {
|
let new = match statement {
|
||||||
Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)?),
|
Statement::Return(return_statement) => Statement::Return(self.reduce_return(return_statement)?),
|
||||||
Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)?),
|
Statement::Definition(definition) => Statement::Definition(self.reduce_definition(definition)?),
|
||||||
Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)?),
|
Statement::Assign(assign) => Statement::Assign(self.reduce_assign(assign)?),
|
||||||
Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(&conditional)?),
|
Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(conditional)?),
|
||||||
Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration)?),
|
Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(iteration)?),
|
||||||
Statement::Console(console) => Statement::Console(self.reduce_console(&console)?),
|
Statement::Console(console) => Statement::Console(self.reduce_console(console)?),
|
||||||
Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)?),
|
Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(expression)?),
|
||||||
Statement::Block(block) => Statement::Block(self.reduce_block(&block)?),
|
Statement::Block(block) => Statement::Block(self.reduce_block(block)?),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.reducer.reduce_statement(statement, new)
|
self.reducer.reduce_statement(statement, new)
|
||||||
@ -334,8 +332,8 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
|
|
||||||
AssigneeAccess::ArrayRange(left, right)
|
AssigneeAccess::ArrayRange(left, right)
|
||||||
}
|
}
|
||||||
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(&index)?),
|
AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(index)?),
|
||||||
AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)?),
|
AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(identifier)?),
|
||||||
_ => access.clone(),
|
_ => access.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -456,7 +454,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
|
|
||||||
let mut global_consts = IndexMap::new();
|
let mut global_consts = IndexMap::new();
|
||||||
for (name, definition) in program.global_consts.iter() {
|
for (name, definition) in program.global_consts.iter() {
|
||||||
global_consts.insert(name.clone(), self.reduce_definition(&definition)?);
|
global_consts.insert(name.clone(), self.reduce_definition(definition)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.reducer
|
self.reducer
|
||||||
@ -513,12 +511,10 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
|
|||||||
pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result<CircuitMember, ReducerError> {
|
pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result<CircuitMember, ReducerError> {
|
||||||
let new = match circuit_member {
|
let new = match circuit_member {
|
||||||
CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable(
|
CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable(
|
||||||
self.reduce_identifier(&identifier)?,
|
self.reduce_identifier(identifier)?,
|
||||||
self.reduce_type(&type_, &identifier.span)?,
|
self.reduce_type(type_, &identifier.span)?,
|
||||||
),
|
),
|
||||||
CircuitMember::CircuitFunction(function) => {
|
CircuitMember::CircuitFunction(function) => CircuitMember::CircuitFunction(self.reduce_function(function)?),
|
||||||
CircuitMember::CircuitFunction(self.reduce_function(&function)?)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.reducer.reduce_circuit_member(circuit_member, new)
|
self.reducer.reduce_circuit_member(circuit_member, new)
|
||||||
|
@ -70,8 +70,8 @@ impl Type {
|
|||||||
(Type::Char, Type::Char) => true,
|
(Type::Char, Type::Char) => true,
|
||||||
(Type::Field, Type::Field) => true,
|
(Type::Field, Type::Field) => true,
|
||||||
(Type::Group, Type::Group) => true,
|
(Type::Group, Type::Group) => true,
|
||||||
(Type::IntegerType(left), Type::IntegerType(right)) => left.eq(&right),
|
(Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right),
|
||||||
(Type::Circuit(left), Type::Circuit(right)) => left.eq(&right),
|
(Type::Circuit(left), Type::Circuit(right)) => left.eq(right),
|
||||||
(Type::SelfType, Type::SelfType) => true,
|
(Type::SelfType, Type::SelfType) => true,
|
||||||
(Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => {
|
(Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => {
|
||||||
// Convert array dimensions to owned.
|
// Convert array dimensions to owned.
|
||||||
|
@ -181,7 +181,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
|||||||
state_string: &str,
|
state_string: &str,
|
||||||
state_path: &Path,
|
state_path: &Path,
|
||||||
) -> Result<(), CompilerError> {
|
) -> Result<(), CompilerError> {
|
||||||
let input_syntax_tree = LeoInputParser::parse_file(&input_string).map_err(|mut e| {
|
let input_syntax_tree = LeoInputParser::parse_file(input_string).map_err(|mut e| {
|
||||||
e.set_path(
|
e.set_path(
|
||||||
input_path.to_str().unwrap_or_default(),
|
input_path.to_str().unwrap_or_default(),
|
||||||
&input_string.lines().map(|x| x.to_string()).collect::<Vec<String>>()[..],
|
&input_string.lines().map(|x| x.to_string()).collect::<Vec<String>>()[..],
|
||||||
@ -189,7 +189,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
|||||||
|
|
||||||
e
|
e
|
||||||
})?;
|
})?;
|
||||||
let state_syntax_tree = LeoInputParser::parse_file(&state_string).map_err(|mut e| {
|
let state_syntax_tree = LeoInputParser::parse_file(state_string).map_err(|mut e| {
|
||||||
e.set_path(
|
e.set_path(
|
||||||
state_path.to_str().unwrap_or_default(),
|
state_path.to_str().unwrap_or_default(),
|
||||||
&state_string.lines().map(|x| x.to_string()).collect::<Vec<String>>()[..],
|
&state_string.lines().map(|x| x.to_string()).collect::<Vec<String>>()[..],
|
||||||
@ -308,14 +308,14 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
|||||||
/// Synthesizes the circuit with program input to verify correctness.
|
/// Synthesizes the circuit with program input to verify correctness.
|
||||||
///
|
///
|
||||||
pub fn compile_constraints<CS: ConstraintSystem<F>>(&self, cs: &mut CS) -> Result<Output, CompilerError> {
|
pub fn compile_constraints<CS: ConstraintSystem<F>>(&self, cs: &mut CS) -> Result<Output, CompilerError> {
|
||||||
generate_constraints::<F, G, CS>(cs, &self.asg.as_ref().unwrap(), &self.program_input)
|
generate_constraints::<F, G, CS>(cs, self.asg.as_ref().unwrap(), &self.program_input)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Synthesizes the circuit for test functions with program input.
|
/// Synthesizes the circuit for test functions with program input.
|
||||||
///
|
///
|
||||||
pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), CompilerError> {
|
pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), CompilerError> {
|
||||||
generate_test_constraints::<F, G>(&self.asg.as_ref().unwrap(), input_pairs, &self.output_directory)
|
generate_test_constraints::<F, G>(self.asg.as_ref().unwrap(), input_pairs, &self.output_directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -44,7 +44,7 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSy
|
|||||||
|
|
||||||
match main {
|
match main {
|
||||||
Some(function) => {
|
Some(function) => {
|
||||||
let result = resolved_program.enforce_main_function(cs, &function, input)?;
|
let result = resolved_program.enforce_main_function(cs, function, input)?;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
_ => Err(CompilerError::NoMainFunction),
|
_ => Err(CompilerError::NoMainFunction),
|
||||||
|
@ -94,7 +94,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
.len()
|
.len()
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| ExpressionError::array_length_out_of_bounds(span))?;
|
.map_err(|_| ExpressionError::array_length_out_of_bounds(span))?;
|
||||||
self.array_bounds_check(cs, &&index_resolved, array_len, span)?;
|
self.array_bounds_check(cs, &index_resolved, array_len, span)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut current_value = array.pop().unwrap();
|
let mut current_value = array.pop().unwrap();
|
||||||
|
@ -44,7 +44,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let return_value = self
|
let return_value = self
|
||||||
.enforce_function(&mut cs.ns(name_unique), &function, target, arguments)
|
.enforce_function(&mut cs.ns(name_unique), function, target, arguments)
|
||||||
.map_err(|error| ExpressionError::from(Box::new(error)))?;
|
.map_err(|error| ExpressionError::from(Box::new(error)))?;
|
||||||
|
|
||||||
Ok(return_value)
|
Ok(return_value)
|
||||||
|
@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
span,
|
span,
|
||||||
)?)),
|
)?)),
|
||||||
Type::Array(type_, len) => self.allocate_array(cs, name, &*type_, *len, input_option, span),
|
Type::Array(type_, len) => self.allocate_array(cs, name, &*type_, *len, input_option, span),
|
||||||
Type::Tuple(types) => self.allocate_tuple(cs, &name, types, input_option, span),
|
Type::Tuple(types) => self.allocate_tuple(cs, name, types, input_option, span),
|
||||||
_ => unimplemented!("main function input not implemented for type {}", type_), // Should not happen.
|
_ => unimplemented!("main function input not implemented for type {}", type_), // Should not happen.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
|
|
||||||
if let Some(asg_input) = asg_input {
|
if let Some(asg_input) = asg_input {
|
||||||
let value =
|
let value =
|
||||||
self.allocate_input_keyword(cs, &function.name.borrow().span, &asg_input.container_circuit, input)?;
|
self.allocate_input_keyword(cs, &function.name.borrow().span, asg_input.container_circuit, input)?;
|
||||||
|
|
||||||
self.store(asg_input.container.borrow().id, value);
|
self.store(asg_input.container.borrow().id, value);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
cs.ns(|| format!("select result {} {}:{}", i, span.line_start, span.col_start)),
|
cs.ns(|| format!("select result {} {}:{}", i, span.line_start, span.col_start)),
|
||||||
&indicator,
|
&indicator,
|
||||||
&result,
|
&result,
|
||||||
&value,
|
value,
|
||||||
)
|
)
|
||||||
.map_err(|_| StatementError::select_fail(result.to_string(), value.to_string(), span))?,
|
.map_err(|_| StatementError::select_fail(result.to_string(), value.to_string(), span))?,
|
||||||
);
|
);
|
||||||
@ -94,7 +94,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
if expected_return.is_unit() {
|
if expected_return.is_unit() {
|
||||||
Ok(ConstrainedValue::Tuple(vec![]))
|
Ok(ConstrainedValue::Tuple(vec![]))
|
||||||
} else {
|
} else {
|
||||||
return_value.ok_or_else(|| StatementError::no_returns(&expected_return, span))
|
return_value.ok_or_else(|| StatementError::no_returns(expected_return, span))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,49 +155,49 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
asg: &AsgExpression,
|
asg: &AsgExpression,
|
||||||
) -> Result<AstExpression, ReducerError> {
|
) -> Result<AstExpression, ReducerError> {
|
||||||
let new = match (ast, asg) {
|
let new = match (ast, asg) {
|
||||||
(AstExpression::Value(value), AsgExpression::Constant(const_)) => self.reduce_value(&value, &const_)?,
|
(AstExpression::Value(value), AsgExpression::Constant(const_)) => self.reduce_value(value, const_)?,
|
||||||
(AstExpression::Binary(ast), AsgExpression::Binary(asg)) => {
|
(AstExpression::Binary(ast), AsgExpression::Binary(asg)) => {
|
||||||
AstExpression::Binary(self.reduce_binary(&ast, &asg)?)
|
AstExpression::Binary(self.reduce_binary(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::Unary(ast), AsgExpression::Unary(asg)) => {
|
(AstExpression::Unary(ast), AsgExpression::Unary(asg)) => {
|
||||||
AstExpression::Unary(self.reduce_unary(&ast, &asg)?)
|
AstExpression::Unary(self.reduce_unary(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::Ternary(ast), AsgExpression::Ternary(asg)) => {
|
(AstExpression::Ternary(ast), AsgExpression::Ternary(asg)) => {
|
||||||
AstExpression::Ternary(self.reduce_ternary(&ast, &asg)?)
|
AstExpression::Ternary(self.reduce_ternary(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::Cast(ast), AsgExpression::Cast(asg)) => AstExpression::Cast(self.reduce_cast(&ast, &asg)?),
|
(AstExpression::Cast(ast), AsgExpression::Cast(asg)) => AstExpression::Cast(self.reduce_cast(ast, asg)?),
|
||||||
|
|
||||||
(AstExpression::ArrayInline(ast), AsgExpression::ArrayInline(asg)) => {
|
(AstExpression::ArrayInline(ast), AsgExpression::ArrayInline(asg)) => {
|
||||||
AstExpression::ArrayInline(self.reduce_array_inline(&ast, &asg)?)
|
AstExpression::ArrayInline(self.reduce_array_inline(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::ArrayInit(ast), AsgExpression::ArrayInit(asg)) => {
|
(AstExpression::ArrayInit(ast), AsgExpression::ArrayInit(asg)) => {
|
||||||
AstExpression::ArrayInit(self.reduce_array_init(&ast, &asg)?)
|
AstExpression::ArrayInit(self.reduce_array_init(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::ArrayAccess(ast), AsgExpression::ArrayAccess(asg)) => {
|
(AstExpression::ArrayAccess(ast), AsgExpression::ArrayAccess(asg)) => {
|
||||||
AstExpression::ArrayAccess(self.reduce_array_access(&ast, &asg)?)
|
AstExpression::ArrayAccess(self.reduce_array_access(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::ArrayRangeAccess(ast), AsgExpression::ArrayRangeAccess(asg)) => {
|
(AstExpression::ArrayRangeAccess(ast), AsgExpression::ArrayRangeAccess(asg)) => {
|
||||||
AstExpression::ArrayRangeAccess(self.reduce_array_range_access(&ast, &asg)?)
|
AstExpression::ArrayRangeAccess(self.reduce_array_range_access(ast, asg)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
(AstExpression::TupleInit(ast), AsgExpression::TupleInit(asg)) => {
|
(AstExpression::TupleInit(ast), AsgExpression::TupleInit(asg)) => {
|
||||||
AstExpression::TupleInit(self.reduce_tuple_init(&ast, &asg)?)
|
AstExpression::TupleInit(self.reduce_tuple_init(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::TupleAccess(ast), AsgExpression::TupleAccess(asg)) => {
|
(AstExpression::TupleAccess(ast), AsgExpression::TupleAccess(asg)) => {
|
||||||
AstExpression::TupleAccess(self.reduce_tuple_access(&ast, &asg)?)
|
AstExpression::TupleAccess(self.reduce_tuple_access(ast, asg)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
(AstExpression::CircuitInit(ast), AsgExpression::CircuitInit(asg)) => {
|
(AstExpression::CircuitInit(ast), AsgExpression::CircuitInit(asg)) => {
|
||||||
AstExpression::CircuitInit(self.reduce_circuit_init(&ast, &asg)?)
|
AstExpression::CircuitInit(self.reduce_circuit_init(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::CircuitMemberAccess(ast), AsgExpression::CircuitAccess(asg)) => {
|
(AstExpression::CircuitMemberAccess(ast), AsgExpression::CircuitAccess(asg)) => {
|
||||||
AstExpression::CircuitMemberAccess(self.reduce_circuit_member_access(&ast, &asg)?)
|
AstExpression::CircuitMemberAccess(self.reduce_circuit_member_access(ast, asg)?)
|
||||||
}
|
}
|
||||||
(AstExpression::CircuitStaticFunctionAccess(ast), AsgExpression::CircuitAccess(asg)) => {
|
(AstExpression::CircuitStaticFunctionAccess(ast), AsgExpression::CircuitAccess(asg)) => {
|
||||||
AstExpression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(&ast, &asg)?)
|
AstExpression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(ast, asg)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
(AstExpression::Call(ast), AsgExpression::Call(asg)) => AstExpression::Call(self.reduce_call(&ast, &asg)?),
|
(AstExpression::Call(ast), AsgExpression::Call(asg)) => AstExpression::Call(self.reduce_call(ast, asg)?),
|
||||||
_ => ast.clone(),
|
_ => ast.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
ast: &AstCastExpression,
|
ast: &AstCastExpression,
|
||||||
asg: &AsgCastExpression,
|
asg: &AsgCastExpression,
|
||||||
) -> Result<AstCastExpression, ReducerError> {
|
) -> Result<AstCastExpression, ReducerError> {
|
||||||
let inner = self.reduce_expression(&ast.inner, &asg.inner.get())?;
|
let inner = self.reduce_expression(&ast.inner, asg.inner.get())?;
|
||||||
let target_type = self.reduce_type(&ast.target_type, &asg.target_type, &ast.span)?;
|
let target_type = self.reduce_type(&ast.target_type, &asg.target_type, &ast.span)?;
|
||||||
|
|
||||||
self.ast_reducer.reduce_cast(ast, inner, target_type)
|
self.ast_reducer.reduce_cast(ast, inner, target_type)
|
||||||
@ -524,7 +524,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
AstAssignAccess::ArrayRange(left, right)
|
AstAssignAccess::ArrayRange(left, right)
|
||||||
}
|
}
|
||||||
(AstAssignAccess::ArrayIndex(ast_index), AsgAssignAccess::ArrayIndex(asg_index)) => {
|
(AstAssignAccess::ArrayIndex(ast_index), AsgAssignAccess::ArrayIndex(asg_index)) => {
|
||||||
let index = self.reduce_expression(&ast_index, asg_index.get())?;
|
let index = self.reduce_expression(ast_index, asg_index.get())?;
|
||||||
AstAssignAccess::ArrayIndex(index)
|
AstAssignAccess::ArrayIndex(index)
|
||||||
}
|
}
|
||||||
_ => ast.clone(),
|
_ => ast.clone(),
|
||||||
@ -577,7 +577,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
block = self.reduce_block(&ast.block, asg_block)?;
|
block = self.reduce_block(&ast.block, asg_block)?;
|
||||||
} else {
|
} else {
|
||||||
return Err(ReducerError::from(CombinerError::asg_statement_not_block(
|
return Err(ReducerError::from(CombinerError::asg_statement_not_block(
|
||||||
&asg.span.as_ref().unwrap(),
|
asg.span.as_ref().unwrap(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let next = match (ast.next.as_ref(), asg.next.get()) {
|
let next = match (ast.next.as_ref(), asg.next.get()) {
|
||||||
@ -595,7 +595,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
) -> Result<AstConsoleStatement, ReducerError> {
|
) -> Result<AstConsoleStatement, ReducerError> {
|
||||||
let function = match (&ast.function, &asg.function) {
|
let function = match (&ast.function, &asg.function) {
|
||||||
(AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => {
|
(AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => {
|
||||||
AstConsoleFunction::Assert(self.reduce_expression(&ast_expression, asg_expression.get())?)
|
AstConsoleFunction::Assert(self.reduce_expression(ast_expression, asg_expression.get())?)
|
||||||
}
|
}
|
||||||
(AstConsoleFunction::Error(ast_console_args), AsgConsoleFunction::Error(asg_format))
|
(AstConsoleFunction::Error(ast_console_args), AsgConsoleFunction::Error(asg_format))
|
||||||
| (AstConsoleFunction::Log(ast_console_args), AsgConsoleFunction::Log(asg_format)) => {
|
| (AstConsoleFunction::Log(ast_console_args), AsgConsoleFunction::Log(asg_format)) => {
|
||||||
@ -603,7 +603,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
for (ast_parameter, asg_parameter) in
|
for (ast_parameter, asg_parameter) in
|
||||||
ast_console_args.parameters.iter().zip(asg_format.parameters.iter())
|
ast_console_args.parameters.iter().zip(asg_format.parameters.iter())
|
||||||
{
|
{
|
||||||
parameters.push(self.reduce_expression(&ast_parameter, asg_parameter.get())?);
|
parameters.push(self.reduce_expression(ast_parameter, asg_parameter.get())?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let args = AstConsoleArgs {
|
let args = AstConsoleArgs {
|
||||||
@ -640,14 +640,14 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
let asg_type = AsgType::Tuple(types);
|
let asg_type = AsgType::Tuple(types);
|
||||||
|
|
||||||
type_ = match &ast.type_ {
|
type_ = match &ast.type_ {
|
||||||
Some(ast_type) => Some(self.reduce_type(&ast_type, &asg_type, &ast.span)?),
|
Some(ast_type) => Some(self.reduce_type(ast_type, &asg_type, &ast.span)?),
|
||||||
None if self.options.type_inference_enabled() => Some((&asg_type).into()),
|
None if self.options.type_inference_enabled() => Some((&asg_type).into()),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
type_ = match &ast.type_ {
|
type_ = match &ast.type_ {
|
||||||
Some(ast_type) => {
|
Some(ast_type) => {
|
||||||
Some(self.reduce_type(&ast_type, &asg.variables.first().unwrap().borrow().type_, &ast.span)?)
|
Some(self.reduce_type(ast_type, &asg.variables.first().unwrap().borrow().type_, &ast.span)?)
|
||||||
}
|
}
|
||||||
None if self.options.type_inference_enabled() => {
|
None if self.options.type_inference_enabled() => {
|
||||||
Some((&asg.variables.first().unwrap().borrow().type_).into())
|
Some((&asg.variables.first().unwrap().borrow().type_).into())
|
||||||
@ -683,7 +683,7 @@ impl<R: ReconstructingReducer, O: CombinerOptions> CombineAstAsgDirector<R, O> {
|
|||||||
block = self.reduce_block(&ast.block, asg_block)?;
|
block = self.reduce_block(&ast.block, asg_block)?;
|
||||||
} else {
|
} else {
|
||||||
return Err(ReducerError::from(CombinerError::asg_statement_not_block(
|
return Err(ReducerError::from(CombinerError::asg_statement_not_block(
|
||||||
&asg.span.as_ref().unwrap(),
|
asg.span.as_ref().unwrap(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
.len()
|
.len()
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?;
|
.map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?;
|
||||||
self.array_bounds_check(cs, &&index_resolved, array_len, &span)?;
|
self.array_bounds_check(cs, &index_resolved, array_len, &span)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, item) in input.iter_mut().enumerate() {
|
for (i, item) in input.iter_mut().enumerate() {
|
||||||
@ -116,7 +116,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
unique_namespace,
|
unique_namespace,
|
||||||
&index_comparison,
|
&index_comparison,
|
||||||
&temp_item,
|
&temp_item,
|
||||||
&item,
|
item,
|
||||||
)
|
)
|
||||||
.map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?;
|
.map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?;
|
||||||
*item = value;
|
*item = value;
|
||||||
@ -153,7 +153,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
.len()
|
.len()
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?;
|
.map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?;
|
||||||
self.array_bounds_check(cs, &&index_resolved, array_len, &span)?;
|
self.array_bounds_check(cs, &index_resolved, array_len, &span)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, item) in context.input.iter_mut().enumerate() {
|
for (i, item) in context.input.iter_mut().enumerate() {
|
||||||
@ -197,7 +197,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
item
|
item
|
||||||
};
|
};
|
||||||
let value =
|
let value =
|
||||||
ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, &item)
|
ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, item)
|
||||||
.map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?;
|
.map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?;
|
||||||
**item = value;
|
**item = value;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
|||||||
);
|
);
|
||||||
let branch_2_indicator = Boolean::and(
|
let branch_2_indicator = Boolean::and(
|
||||||
&mut cs.ns(|| format!("branch 2 {}:{}", &span.line_start, &span.col_start)),
|
&mut cs.ns(|| format!("branch 2 {}:{}", &span.line_start, &span.col_start)),
|
||||||
&outer_indicator,
|
outer_indicator,
|
||||||
&inner_indicator,
|
&inner_indicator,
|
||||||
)
|
)
|
||||||
.map_err(|_| StatementError::indicator_calculation(branch_2_name, &span))?;
|
.map_err(|_| StatementError::indicator_calculation(branch_2_name, &span))?;
|
||||||
|
@ -124,7 +124,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<'a, F
|
|||||||
|
|
||||||
write!(f, "({})", values)
|
write!(f, "({})", values)
|
||||||
}
|
}
|
||||||
ConstrainedValue::CircuitExpression(ref circuit, ref members) => {
|
ConstrainedValue::CircuitExpression(circuit, ref members) => {
|
||||||
write!(f, "{} {{", circuit.name.borrow())?;
|
write!(f, "{} {{", circuit.name.borrow())?;
|
||||||
for (i, member) in members.iter().enumerate() {
|
for (i, member) in members.iter().enumerate() {
|
||||||
write!(f, "{}: {}", member.0, member.1)?;
|
write!(f, "{}: {}", member.0, member.1)?;
|
||||||
|
@ -54,7 +54,7 @@ impl<'a> ImportParser<'a> {
|
|||||||
// Build the package abstract syntax tree.
|
// Build the package abstract syntax tree.
|
||||||
let program_string =
|
let program_string =
|
||||||
&std::fs::read_to_string(&file_path).map_err(|x| ImportParserError::io_error(span, file_path_str, x))?;
|
&std::fs::read_to_string(&file_path).map_err(|x| ImportParserError::io_error(span, file_path_str, x))?;
|
||||||
let mut program = leo_parser::parse(&file_path_str, &program_string)?;
|
let mut program = leo_parser::parse(file_path_str, program_string)?;
|
||||||
program.name = file_name;
|
program.name = file_name;
|
||||||
let mut ast = leo_ast::Ast::new(program);
|
let mut ast = leo_ast::Ast::new(program);
|
||||||
ast.canonicalize()?;
|
ast.canonicalize()?;
|
||||||
|
@ -191,7 +191,7 @@ impl InputParserError {
|
|||||||
expected, actual
|
expected, actual
|
||||||
);
|
);
|
||||||
|
|
||||||
Self::new_from_span(message, &span)
|
Self::new_from_span(message, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn section(header: Header) -> Self {
|
pub fn section(header: Header) -> Self {
|
||||||
|
@ -32,7 +32,7 @@ pub enum GroupCoordinate<'ast> {
|
|||||||
impl<'ast> GroupCoordinate<'ast> {
|
impl<'ast> GroupCoordinate<'ast> {
|
||||||
pub fn span(&self) -> &Span<'ast> {
|
pub fn span(&self) -> &Span<'ast> {
|
||||||
match self {
|
match self {
|
||||||
GroupCoordinate::Number(number) => &number.span(),
|
GroupCoordinate::Number(number) => number.span(),
|
||||||
GroupCoordinate::SignHigh(sign_high) => &sign_high.span,
|
GroupCoordinate::SignHigh(sign_high) => &sign_high.span,
|
||||||
GroupCoordinate::SignLow(sign_low) => &sign_low.span,
|
GroupCoordinate::SignLow(sign_low) => &sign_low.span,
|
||||||
GroupCoordinate::Inferred(inferred) => &inferred.span,
|
GroupCoordinate::Inferred(inferred) => &inferred.span,
|
||||||
|
@ -39,13 +39,13 @@ pub enum Value<'ast> {
|
|||||||
impl<'ast> Value<'ast> {
|
impl<'ast> Value<'ast> {
|
||||||
pub fn span(&self) -> &Span<'ast> {
|
pub fn span(&self) -> &Span<'ast> {
|
||||||
match self {
|
match self {
|
||||||
Value::Address(value) => &value.span(),
|
Value::Address(value) => value.span(),
|
||||||
Value::Boolean(value) => &value.span,
|
Value::Boolean(value) => &value.span,
|
||||||
Value::Char(value) => &value.span,
|
Value::Char(value) => &value.span,
|
||||||
Value::Field(value) => &value.span,
|
Value::Field(value) => &value.span,
|
||||||
Value::Group(value) => &value.span,
|
Value::Group(value) => &value.span,
|
||||||
Value::Implicit(value) => &value.span(),
|
Value::Implicit(value) => value.span(),
|
||||||
Value::Integer(value) => &value.span(),
|
Value::Integer(value) => value.span(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,10 @@ pub fn write_token_and_username(token: &str, username: &str) -> Result<(), io::E
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf())?;
|
||||||
credentials.write_all(&token.as_bytes())?;
|
credentials.write_all(token.as_bytes())?;
|
||||||
|
|
||||||
let mut username_file = File::create(&LEO_USERNAME_PATH.to_path_buf())?;
|
let mut username_file = File::create(&LEO_USERNAME_PATH.to_path_buf())?;
|
||||||
username_file.write_all(&username.as_bytes())?;
|
username_file.write_all(username.as_bytes())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ impl Updater {
|
|||||||
.repo_owner(Self::LEO_REPO_OWNER)
|
.repo_owner(Self::LEO_REPO_OWNER)
|
||||||
.repo_name(Self::LEO_REPO_NAME)
|
.repo_name(Self::LEO_REPO_NAME)
|
||||||
.bin_name(Self::LEO_BIN_NAME)
|
.bin_name(Self::LEO_BIN_NAME)
|
||||||
.current_version(&env!("CARGO_PKG_VERSION"))
|
.current_version(env!("CARGO_PKG_VERSION"))
|
||||||
.show_download_progress(show_output)
|
.show_download_progress(show_output)
|
||||||
.no_confirm(true)
|
.no_confirm(true)
|
||||||
.show_output(show_output)
|
.show_output(show_output)
|
||||||
@ -69,7 +69,7 @@ impl Updater {
|
|||||||
.repo_owner(Self::LEO_REPO_OWNER)
|
.repo_owner(Self::LEO_REPO_OWNER)
|
||||||
.repo_name(Self::LEO_REPO_NAME)
|
.repo_name(Self::LEO_REPO_NAME)
|
||||||
.bin_name(Self::LEO_BIN_NAME)
|
.bin_name(Self::LEO_BIN_NAME)
|
||||||
.current_version(&env!("CARGO_PKG_VERSION"))
|
.current_version(env!("CARGO_PKG_VERSION"))
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let current_version = updater.current_version();
|
let current_version = updater.current_version();
|
||||||
|
@ -123,14 +123,14 @@ impl Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the input file already exists.
|
// Check if the input file already exists.
|
||||||
let input_file = InputFile::new(&package_name);
|
let input_file = InputFile::new(package_name);
|
||||||
if input_file.exists_at(path) {
|
if input_file.exists_at(path) {
|
||||||
existing_files.push(input_file.filename());
|
existing_files.push(input_file.filename());
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the state file already exists.
|
// Check if the state file already exists.
|
||||||
let state_file = StateFile::new(&package_name);
|
let state_file = StateFile::new(package_name);
|
||||||
if state_file.exists_at(path) {
|
if state_file.exists_at(path) {
|
||||||
existing_files.push(state_file.filename());
|
existing_files.push(state_file.filename());
|
||||||
result = false;
|
result = false;
|
||||||
@ -157,24 +157,24 @@ impl Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the manifest file exists.
|
// Check if the manifest file exists.
|
||||||
if !Manifest::exists_at(&path) {
|
if !Manifest::exists_at(path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the input file exists.
|
// Check if the input file exists.
|
||||||
let input_file = InputFile::new(&package_name);
|
let input_file = InputFile::new(package_name);
|
||||||
if !input_file.exists_at(&path) {
|
if !input_file.exists_at(path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the state file exists.
|
// Check if the state file exists.
|
||||||
let state_file = StateFile::new(&package_name);
|
let state_file = StateFile::new(package_name);
|
||||||
if !state_file.exists_at(&path) {
|
if !state_file.exists_at(path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the main file exists.
|
// Check if the main file exists.
|
||||||
if !MainFile::exists_at(&path) {
|
if !MainFile::exists_at(path) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,34 +195,34 @@ impl Package {
|
|||||||
// Next, initialize this directory as a Leo package.
|
// Next, initialize this directory as a Leo package.
|
||||||
{
|
{
|
||||||
// Create the manifest file.
|
// Create the manifest file.
|
||||||
Manifest::new(&package_name, author)?.write_to(&path)?;
|
Manifest::new(package_name, author)?.write_to(path)?;
|
||||||
|
|
||||||
// Verify that the .gitignore file does not exist.
|
// Verify that the .gitignore file does not exist.
|
||||||
if !Gitignore::exists_at(&path) {
|
if !Gitignore::exists_at(path) {
|
||||||
// Create the .gitignore file.
|
// Create the .gitignore file.
|
||||||
Gitignore::new().write_to(&path)?;
|
Gitignore::new().write_to(path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the README.md file does not exist.
|
// Verify that the README.md file does not exist.
|
||||||
if !README::exists_at(&path) {
|
if !README::exists_at(path) {
|
||||||
// Create the README.md file.
|
// Create the README.md file.
|
||||||
README::new(package_name).write_to(&path)?;
|
README::new(package_name).write_to(path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the source directory.
|
// Create the source directory.
|
||||||
SourceDirectory::create(&path)?;
|
SourceDirectory::create(path)?;
|
||||||
|
|
||||||
// Create the input directory.
|
// Create the input directory.
|
||||||
InputsDirectory::create(&path)?;
|
InputsDirectory::create(path)?;
|
||||||
|
|
||||||
// Create the input file in the inputs directory.
|
// Create the input file in the inputs directory.
|
||||||
InputFile::new(&package_name).write_to(&path)?;
|
InputFile::new(package_name).write_to(path)?;
|
||||||
|
|
||||||
// Create the state file in the inputs directory.
|
// Create the state file in the inputs directory.
|
||||||
StateFile::new(&package_name).write_to(&path)?;
|
StateFile::new(package_name).write_to(path)?;
|
||||||
|
|
||||||
// Create the main file in the source directory.
|
// Create the main file in the source directory.
|
||||||
MainFile::new(&package_name).write_to(&path)?;
|
MainFile::new(package_name).write_to(path)?;
|
||||||
}
|
}
|
||||||
// Next, verify that a valid Leo package has been initialized in this directory
|
// Next, verify that a valid Leo package has been initialized in this directory
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ fn main() -> Result<(), SyntaxError> {
|
|||||||
let input_filepath = Path::new(&cli_arguments[1]);
|
let input_filepath = Path::new(&cli_arguments[1]);
|
||||||
|
|
||||||
// Construct the serialized syntax tree.
|
// Construct the serialized syntax tree.
|
||||||
let serialized_leo_tree = to_leo_tree(&input_filepath)?;
|
let serialized_leo_tree = to_leo_tree(input_filepath)?;
|
||||||
println!("{}", serialized_leo_tree);
|
println!("{}", serialized_leo_tree);
|
||||||
|
|
||||||
// Determine the output directory.
|
// Determine the output directory.
|
||||||
|
@ -227,7 +227,7 @@ impl ParserContext {
|
|||||||
base.name = format_tendril!("{}{}", base.name, next.name);
|
base.name = format_tendril!("{}{}", base.name, next.name);
|
||||||
base.span = base.span + next.span;
|
base.span = base.span + next.span;
|
||||||
}
|
}
|
||||||
x if KEYWORD_TOKENS.contains(&x) => {
|
x if KEYWORD_TOKENS.contains(x) => {
|
||||||
let next = self.expect_loose_identifier()?;
|
let next = self.expect_loose_identifier()?;
|
||||||
base.name = format_tendril!("{}{}", base.name, next.name);
|
base.name = format_tendril!("{}{}", base.name, next.name);
|
||||||
base.span = base.span + next.span;
|
base.span = base.span + next.span;
|
||||||
|
@ -281,7 +281,7 @@ impl ParserContext {
|
|||||||
"log" => ConsoleFunction::Log(self.parse_console_args()?),
|
"log" => ConsoleFunction::Log(self.parse_console_args()?),
|
||||||
x => {
|
x => {
|
||||||
return Err(SyntaxError::unexpected_ident(
|
return Err(SyntaxError::unexpected_ident(
|
||||||
&x,
|
x,
|
||||||
&["assert", "error", "log"],
|
&["assert", "error", "log"],
|
||||||
&function.span,
|
&function.span,
|
||||||
));
|
));
|
||||||
|
@ -101,7 +101,7 @@ impl Token {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(ascii_number) = u8::from_str_radix(&hex_string, 16) {
|
if let Ok(ascii_number) = u8::from_str_radix(hex_string, 16) {
|
||||||
// According to RFC, we allow only values less than 128.
|
// According to RFC, we allow only values less than 128.
|
||||||
if ascii_number > 127 {
|
if ascii_number > 127 {
|
||||||
return None;
|
return None;
|
||||||
@ -123,7 +123,7 @@ impl Token {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(hex) = u32::from_str_radix(&unicode_number, 16) {
|
if let Ok(hex) = u32::from_str_radix(unicode_number, 16) {
|
||||||
if let Some(character) = std::char::from_u32(hex) {
|
if let Some(character) = std::char::from_u32(hex) {
|
||||||
// scalar
|
// scalar
|
||||||
return Some(Char::Scalar(character));
|
return Some(Char::Scalar(character));
|
||||||
|
@ -17,5 +17,5 @@ outputs:
|
|||||||
type: bool
|
type: bool
|
||||||
value: "true"
|
value: "true"
|
||||||
initial_ast: 4c74b65863cddde8ce523495358ab619ec48645dcb8409658a3fb3d7a3821d6d
|
initial_ast: 4c74b65863cddde8ce523495358ab619ec48645dcb8409658a3fb3d7a3821d6d
|
||||||
canonicalized_ast: b5697d5884139da5a68861213ff3c7660f694e682078e1bd350856206e0289b8
|
canonicalized_ast: 45dc35a683e14503f8a1fc40280f05e7d096b49896f115ffa649e76b9cd80941
|
||||||
type_inferenced_ast: ff4b8f91f014277d6bb2d8d82c31361e5a5c5a46ed87a1e61f0c2e2e8d5fd254
|
type_inferenced_ast: 11af72cfc90adc12c3412e3067ad285a2279de0f4f12af5081dbe27c58b5a3bf
|
||||||
|
Loading…
Reference in New Issue
Block a user