diff --git a/compiler/ast/src/common/array_dimensions.rs b/compiler/ast/src/common/array_dimensions.rs index 4b661f703f..edb624c2d2 100644 --- a/compiler/ast/src/common/array_dimensions.rs +++ b/compiler/ast/src/common/array_dimensions.rs @@ -23,8 +23,6 @@ use std::{fmt, ops::Deref}; /// A single array dimension. #[derive(Clone, Deserialize, Debug, PartialEq, Eq, Hash)] pub enum Dimension { - /// The dimension is `_`, that is unspecified and syntactically unknown. - Unspecified, /// The dimension was specified, e.g., `5` elements. Number(PositiveNumber), } @@ -32,7 +30,6 @@ pub enum Dimension { impl fmt::Display for Dimension { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Self::Unspecified => write!(f, "_"), Self::Number(num) => write!(f, "{}", num), } } @@ -42,7 +39,6 @@ impl Dimension { /// } Returns `Some(n)` unless the dimension is [`Unspecified`]. pub fn as_specified(&self) -> Option<&PositiveNumber> { match self { - Self::Unspecified => None, Self::Number(n) => Some(n), } } @@ -71,11 +67,6 @@ impl ArrayDimensions { Self(smallvec![dim]) } - /// Returns true if the dimensions are not [`Unspecified`]. - pub fn is_specified(&self) -> bool { - !self.contains(&Dimension::Unspecified) - } - /// Returns `true` if there is an array dimension equal to zero. pub fn is_zero(&self) -> bool { self.iter().any(|d| d.is_zero()) @@ -96,7 +87,7 @@ impl ArrayDimensions { } } -/// Custom Serializer for ArrayDimensios is required to ignore internal ArrayDimension nodes in the AST. +/// Custom Serializer for ArrayDimensions is required to ignore internal ArrayDimension nodes in the AST. impl Serialize for ArrayDimensions { fn serialize(&self, serializer: S) -> Result where @@ -106,7 +97,6 @@ impl Serialize for ArrayDimensions { for dim in self.0.iter() { match dim { Dimension::Number(num) => seq.serialize_element(&num)?, - Dimension::Unspecified => seq.serialize_element(&PositiveNumber { value: "0".into() })?, } } seq.end() diff --git a/compiler/ast/src/input/input_value.rs b/compiler/ast/src/input/input_value.rs index 8007a43110..c7270eb2ee 100644 --- a/compiler/ast/src/input/input_value.rs +++ b/compiler/ast/src/input/input_value.rs @@ -132,14 +132,10 @@ impl TryFrom<(Type, Expression)> for InputValue { Self::Tuple(elements) } - (Type::Array(element_type, dimensions), Expression::ArrayInline(array_inline)) => { + (Type::Array(element_type, _dimensions), Expression::ArrayInline(array_inline)) => { let mut elements = Vec::with_capacity(array_inline.elements.len()); let span = array_inline.span().clone(); - if !dimensions.is_specified() { - return Err(InputError::array_dimensions_must_be_specified(&span).into()); - } - for element in array_inline.elements.into_iter() { if let SpreadOrExpression::Expression(value_expression) = element { elements.push(Self::try_from((*element_type.clone(), value_expression))?); diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index bb5c573984..2a24921690 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -89,11 +89,6 @@ impl Type { let mut left_dims = left_dims.to_owned(); let mut right_dims = right_dims.to_owned(); - // Unable to compare arrays with unspecified sizes. - if !left_dims.is_specified() || !right_dims.is_specified() { - return false; - } - // Remove the first element from both dimensions. let left_first = left_dims.remove_first(); let right_first = right_dims.remove_first(); diff --git a/compiler/parser/src/parser/type_.rs b/compiler/parser/src/parser/type_.rs index 37470530ce..60fd73e73a 100644 --- a/compiler/parser/src/parser/type_.rs +++ b/compiler/parser/src/parser/type_.rs @@ -84,8 +84,6 @@ impl ParserContext<'_> { fn parse_array_dimension(&mut self) -> Option { if let Some((int, _)) = self.eat_int() { Some(Dimension::Number(int)) - } else if self.eat(Token::Underscore).is_some() { - Some(Dimension::Unspecified) } else { None } diff --git a/docs/grammar/README.md b/docs/grammar/README.md index 9f10032127..26032ade6b 100644 --- a/docs/grammar/README.md +++ b/docs/grammar/README.md @@ -1013,7 +1013,7 @@ An array type consists of an element type and an indication of dimensions. There is either a single dimension, or a tuple of one or more dimensions. -Each dimension is either a natural or is unspecified. +Each dimension is natural. ```abnf diff --git a/docs/grammar/abnf-grammar.txt b/docs/grammar/abnf-grammar.txt index b5f0993019..0e75b5ef3d 100644 --- a/docs/grammar/abnf-grammar.txt +++ b/docs/grammar/abnf-grammar.txt @@ -650,7 +650,7 @@ tuple-type = "(" [ type 1*( "," type ) ] ")" ; and an indication of dimensions. ; There is either a single dimension, ; or a tuple of one or more dimensions. -; Each dimension is either a natural or is unspecified. +; Each dimension is natural. array-type = "[" type ";" array-type-dimensions "]" diff --git a/examples/hello-world/inputs/hello-world.in b/examples/hello-world/inputs/hello-world.in index 684a41fbef..b62f1de0c4 100644 --- a/examples/hello-world/inputs/hello-world.in +++ b/examples/hello-world/inputs/hello-world.in @@ -1,6 +1,5 @@ [main] -a: u32 = 1; -b: u32 = 2; +y: bool = true; [registers] -r0: u32 = 0; \ No newline at end of file +r0: bool = false; diff --git a/examples/hello-world/src/main.leo b/examples/hello-world/src/main.leo index f803309878..939345a239 100644 --- a/examples/hello-world/src/main.leo +++ b/examples/hello-world/src/main.leo @@ -1,5 +1,11 @@ // The 'hello-world' main function. -function main(a: u32, b: u32) -> u32 { - let c: u32 = a + b; - return c; +type str = [char; _]; + +function main(y: bool) -> bool { + let s = "abc"; + return (first_el(s) == 'a') == y; +} + +function first_el(s: str) -> char { + return s[0]; } diff --git a/leo/errors/src/compiler/compiler_errors.rs b/leo/errors/src/compiler/compiler_errors.rs index be14c95d06..fde3ccf4bf 100644 --- a/leo/errors/src/compiler/compiler_errors.rs +++ b/leo/errors/src/compiler/compiler_errors.rs @@ -312,12 +312,4 @@ create_errors!( msg: format!("Tried to assign to static member `{}`", member), help: None, } - - /// For when arrays with unspecified size are used in main. - @formatted - input_array_size_must_be_specified { - args: (), - msg: "arrays in main function input must have known size", - help: None, - } ); diff --git a/leo/errors/src/input/input_errors.rs b/leo/errors/src/input/input_errors.rs index c8ebb79799..1e337d264a 100644 --- a/leo/errors/src/input/input_errors.rs +++ b/leo/errors/src/input/input_errors.rs @@ -46,14 +46,6 @@ create_errors!( help: None, } - /// For when [`ArrayDimensions`] are not specified. - @formatted - array_dimensions_must_be_specified { - args: (), - msg: "array dimensions must be specified", - help: None, - } - /// For when array init is using spread. @formatted array_spread_is_not_allowed {