Rename errors

This commit is contained in:
Pranav Gaddamadugu 2022-09-30 10:16:05 -07:00
parent 27494e8956
commit 508c54dd92
9 changed files with 95 additions and 139 deletions

View File

@ -1,71 +0,0 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 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::{Identifier, Type};
use leo_span::Symbol;
use serde::{Deserialize, Serialize};
use std::fmt;
#[allow(clippy::large_enum_variant)]
/// A member of a circuit definition.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum CircuitMember {
// CAUTION: circuit constants are unstable for Leo testnet3.
// /// A static constant in a circuit.
// /// For example: `const foobar: u8 = 42;`.
// CircuitConst(
// /// The identifier of the constant.
// Identifier,
// /// The type the constant has.
// Type,
// /// The expression representing the constant's value.
// /// Checked to be of the type above.
// Expression,
// ),
/// A variable definition in a circuit;
/// For example: `foobar: u8;`.
CircuitVariable(
/// The identifier of the constant.
Identifier,
/// The type the constant has.
Type,
),
// CAUTION: circuit functions are unstable for Leo testnet3.
// /// A function definition in a circuit.
// /// For example: `function bar() -> u8 { return 2u8; }`.
// CircuitFunction(
// /// The function.
// Box<Function>,
// ),
}
impl CircuitMember {
/// Returns the name of the circuit member without span.
pub fn name(&self) -> Symbol {
match self {
CircuitMember::CircuitVariable(ident, _type) => ident.name,
}
}
}
impl fmt::Display for CircuitMember {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CircuitMember::CircuitVariable(ref identifier, ref type_) => write!(f, "{}: {}", identifier, type_),
}
}
}

View File

@ -17,10 +17,10 @@
use super::*;
use leo_span::sym;
/// An initializer for a single field / variable of a circuit initializer expression.
/// An initializer for a single field / variable of a struct initializer expression.
/// That is, in `Foo { bar: 42, baz }`, this is either `bar: 42`, or `baz`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CircuitVariableInitializer {
pub struct StructVariableInitializer {
/// The name of the field / variable to be initialized.
pub identifier: Identifier,
/// The expression to initialize the field with.
@ -28,7 +28,7 @@ pub struct CircuitVariableInitializer {
pub expression: Option<Expression>,
}
impl fmt::Display for CircuitVariableInitializer {
impl fmt::Display for StructVariableInitializer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(expr) = &self.expression {
write!(f, "{}: {}", self.identifier, expr)
@ -38,21 +38,21 @@ impl fmt::Display for CircuitVariableInitializer {
}
}
/// A circuit initialization expression, e.g., `Foo { bar: 42, baz }`.
/// A struct initialization expression, e.g., `Foo { bar: 42, baz }`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CircuitExpression {
pub struct StructExpression {
/// The name of the structure type to initialize.
pub name: Identifier,
/// Initializer expressions for each of the fields in the circuit.
/// Initializer expressions for each of the fields in the struct.
///
/// N.B. Any functions or member constants in the circuit definition
/// N.B. Any functions or member constants in the struct definition
/// are excluded from this list.
pub members: Vec<CircuitVariableInitializer>,
pub members: Vec<StructVariableInitializer>,
/// A span from `name` to `}`.
pub span: Span,
}
impl CircuitExpression {
impl StructExpression {
/// Returns true if the record has all required fields and visibility.
pub fn check_record(&self) -> bool {
let has_member = |symbol| self.members.iter().any(|variable| variable.identifier.name == symbol);
@ -60,7 +60,7 @@ impl CircuitExpression {
has_member(sym::owner) && has_member(sym::gates) && has_member(sym::_nonce)
}
/// Returns the circuit as a record interface with visibility.
/// Returns the struct as a record interface with visibility.
pub fn to_record_string(&self) -> String {
format!(
"{{{}}}",
@ -80,7 +80,7 @@ impl CircuitExpression {
}
}
impl fmt::Display for CircuitExpression {
impl fmt::Display for StructExpression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
@ -94,4 +94,4 @@ impl fmt::Display for CircuitExpression {
}
}
crate::simple_node_impl!(CircuitExpression);
crate::simple_node_impl!(StructExpression);

View File

@ -0,0 +1,43 @@
// Copyright (C) 2019-2022 Aleo Systems Inc.
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 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::{Identifier, Type};
use leo_span::Symbol;
use serde::{Deserialize, Serialize};
use std::fmt;
/// A member of a struct definition, e.g `foobar: u8`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Member {
/// The identifier of the member.
pub identifier: Identifier,
/// The type of the member.
pub type_: Type,
}
impl Member {
/// Returns the name of the struct member without span.
pub fn name(&self) -> Symbol {
self.identifier.name
}
}
impl fmt::Display for Member {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}: {}", self.identifier, self.type_)
}
}

View File

@ -98,11 +98,11 @@ create_messages!(
help: None,
}
/// For when a user shadows a circuit.
/// For when a user shadows a struct.
@formatted
shadowed_circuit {
args: (circ: impl Display),
msg: format!("circuit `{circ}` shadowed by"),
shadowed_struct {
args: (struct_: impl Display),
msg: format!("struct `{struct_}` shadowed by"),
help: None,
}

View File

@ -35,7 +35,7 @@ create_messages!(
help: None,
}
/// For when a user tries to assign to a circuit static member.
/// For when a user tries to assign to a struct static member.
@formatted
illegal_static_member_assignment {
args: (member: impl Display),

View File

@ -59,11 +59,11 @@ create_messages!(
help: None,
}
/// For when reading the circuit file failed.
/// For when reading the struct file failed.
@backtraced
failed_to_read_circuit_file {
args: (path: impl Debug),
msg: format!("Cannot read circuit file from the provided file path - {:?}", path),
msg: format!("Cannot read struct file from the provided file path - {:?}", path),
help: None,
}
@ -99,11 +99,11 @@ create_messages!(
help: None,
}
/// For when the circuit file has an IO error.
/// For when the struct file has an IO error.
@backtraced
io_error_circuit_file {
args: (error: impl ErrorArg),
msg: format!("IO error circuit file from the provided file path - {}", error),
msg: format!("IO error struct file from the provided file path - {}", error),
help: None,
}
@ -123,11 +123,11 @@ create_messages!(
help: None,
}
/// For when removing the circuit file failed.
/// For when removing the struct file failed.
@backtraced
failed_to_remove_circuit_file {
args: (path: impl Debug),
msg: format!("failed removing circuit file from the provided file path - {:?}", path),
msg: format!("failed removing struct file from the provided file path - {:?}", path),
help: None,
}

View File

@ -72,11 +72,11 @@ create_messages!(
help: None,
}
/// For when the parser encountered a mix of commas and semi-colons in circuit member variables.
/// For when the parser encountered a mix of commas and semi-colons in struct member variables.
@formatted
mixed_commas_and_semicolons {
args: (),
msg: "Cannot mix use of commas and semi-colons for circuit member variable declarations.",
msg: "Cannot mix use of commas and semi-colons for struct member variable declarations.",
help: None,
}
@ -224,27 +224,11 @@ create_messages!(
help: None,
}
/// Circuit functions are unstable in testnet3.
@formatted
circuit_functions_unstable {
args: (),
msg: "Circuit functions are currently an unstable feature and are disabled in Leo for testnet3.",
help: None,
}
/// Circuit constants are unstable in testnet3.
@formatted
circuit_constants_unstable {
args: (),
msg: "Circuit constants are currently an unstable feature and are disabled in Leo for testnet3.",
help: None,
}
@formatted
invalid_associated_access {
args: (name: impl Display),
msg: format!("Invalid associated access call to circuit {name}."),
help: Some("Double colon `::` syntax is only supported for core circuits in Leo for testnet3.".to_string()),
msg: format!("Invalid associated access call to struct {name}."),
help: Some("Double colon `::` syntax is only supported for core functions in Leo for testnet3.".to_string()),
}
@formatted

View File

@ -111,17 +111,17 @@ create_messages!(
help: None,
}
/// For when an invalid core instruction is used.
/// For when an invalid core function is used.
@formatted
invalid_core_instruction {
args: (circuit: impl Display, function: impl Display),
invalid_core_function {
args: (struct_: impl Display, function: impl Display),
msg: format!(
"The instruction {circuit}::{function} is not a valid core instruction.",
"The instruction {struct_}::{function} is not a valid core function.",
),
help: None,
}
/// For when a circuit is created with the same name as a core type.
/// For when a struct is created with the same name as a core type.
@formatted
core_type_name_conflict {
args: (type_: impl Display),
@ -141,42 +141,42 @@ create_messages!(
help: None,
}
/// For when the user tries initialize a circuit with the incorrect number of args.
/// For when the user tries initialize a struct with the incorrect number of args.
@formatted
incorrect_num_circuit_members {
incorrect_num_struct_members {
args: (expected: impl Display, received: impl Display),
msg: format!(
"Circuit expected `{expected}` members, but got `{received}`",
"Struct expected `{expected}` members, but got `{received}`",
),
help: None,
}
/// For when the user is missing a circuit member during initialization.
/// For when the user is missing a struct member during initialization.
@formatted
missing_circuit_member {
args: (circuit: impl Display, member: impl Display),
missing_struct_member {
args: (struct_: impl Display, member: impl Display),
msg: format!(
"Circuit initialization expression for `{circuit}` is missing member `{member}`.",
"Struct initialization expression for `{struct_}` is missing member `{member}`.",
),
help: None,
}
/// An invalid access call is made e.g., `bool::MAX`
@formatted
invalid_core_circuit_call {
invalid_core_function_call {
args: (expr: impl Display),
msg: format!(
"{expr} is not a valid core circuit call."
"{expr} is not a valid core function call."
),
help: None,
}
/// Attempted to define more that one circuit member with the same name.
/// Attempted to define more that one struct member with the same name.
@formatted
duplicate_circuit_member {
args: (circuit: impl Display),
duplicate_struct_member {
args: (struct_: impl Display),
msg: format!(
"Circuit {circuit} defined with more than one member with the same name."
"Struct {struct_} defined with more than one member with the same name."
),
help: None,
}
@ -191,7 +191,7 @@ create_messages!(
help: None,
}
/// Attempted to access an invalid circuit.
/// Attempted to access an invalid struct.
@formatted
undefined_type {
args: (type_: impl Display),
@ -201,12 +201,12 @@ create_messages!(
help: None,
}
/// Attempted to access an invalid circuit variable.
/// Attempted to access an invalid struct variable.
@formatted
invalid_circuit_variable {
args: (variable: impl Display, circuit: impl Display),
invalid_struct_variable {
args: (variable: impl Display, struct_: impl Display),
msg: format!(
"Circuit variable {variable} is not a member of circuit {circuit}."
"Variable {variable} is not a member of struct {struct_}."
),
help: None,
}
@ -290,9 +290,9 @@ create_messages!(
}
@formatted
circuit_or_record_cannot_contain_record {
struct_or_record_cannot_contain_record {
args: (parent: impl Display, child: impl Display),
msg: format!("A circuit or record cannot contain another record."),
msg: format!("A struct or record cannot contain another record."),
help: Some(format!("Remove the record `{child}` from `{parent}`.")),
}