diff --git a/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs index cc3a7c02a75..1367b1753af 100644 --- a/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/crates/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -130,7 +130,10 @@ impl<'a> FunctionContext<'a> { let slice_contents = self.codegen_array(elements, typ[1].clone()); Tree::Branch(vec![slice_length.into(), slice_contents]) } - _ => unreachable!("ICE: array literal type must be an array or a slice, but got {}", array.typ), + _ => unreachable!( + "ICE: array literal type must be an array or a slice, but got {}", + array.typ + ), } } ast::Literal::Integer(value, typ) => { diff --git a/crates/noirc_frontend/src/ast/function.rs b/crates/noirc_frontend/src/ast/function.rs index 2c418dbefd7..377e6aa77ad 100644 --- a/crates/noirc_frontend/src/ast/function.rs +++ b/crates/noirc_frontend/src/ast/function.rs @@ -86,6 +86,7 @@ impl From for NoirFunction { Some(Attribute::Test) => FunctionKind::Normal, Some(Attribute::Oracle(_)) => FunctionKind::Oracle, Some(Attribute::Deprecated(_)) | None => FunctionKind::Normal, + Some(Attribute::Custom(_)) => FunctionKind::Normal, }; NoirFunction { def: fd, kind } diff --git a/crates/noirc_frontend/src/lexer/lexer.rs b/crates/noirc_frontend/src/lexer/lexer.rs index 8a98d5bfa3c..d0fa475426a 100644 --- a/crates/noirc_frontend/src/lexer/lexer.rs +++ b/crates/noirc_frontend/src/lexer/lexer.rs @@ -453,6 +453,18 @@ fn deprecated_attribute_with_note() { assert_eq!(token.token(), &Token::Attribute(Attribute::Deprecated("hello".to_string().into()))); } +#[test] +fn custom_attribute() { + let input = r#"#[custom(hello)]"#; + let mut lexer = Lexer::new(input); + + let token = lexer.next().unwrap().unwrap(); + assert_eq!( + token.token(), + &Token::Attribute(Attribute::Custom("custom(hello)".to_string().into())) + ); +} + #[test] fn test_custom_gate_syntax() { let input = "#[foreign(sha256)]#[foreign(blake2s)]#[builtin(sum)]"; diff --git a/crates/noirc_frontend/src/lexer/token.rs b/crates/noirc_frontend/src/lexer/token.rs index 3ef1d2a5dde..6291ac4de12 100644 --- a/crates/noirc_frontend/src/lexer/token.rs +++ b/crates/noirc_frontend/src/lexer/token.rs @@ -326,6 +326,7 @@ pub enum Attribute { Oracle(String), Deprecated(Option), Test, + Custom(String), } impl fmt::Display for Attribute { @@ -337,6 +338,7 @@ impl fmt::Display for Attribute { Attribute::Test => write!(f, "#[test]"), Attribute::Deprecated(None) => write!(f, "#[deprecated]"), Attribute::Deprecated(Some(ref note)) => write!(f, r#"#[deprecated("{note}")]"#), + Attribute::Custom(ref k) => write!(f, "#[{k}]"), } } } @@ -390,8 +392,9 @@ impl Attribute { Attribute::Deprecated(name.trim_matches('"').to_string().into()) } ["test"] => Attribute::Test, - _ => { - return Err(LexerErrorKind::MalformedFuncAttribute { span, found: word.to_owned() }) + tokens => { + tokens.iter().try_for_each(|token| validate(token))?; + Attribute::Custom(word.to_owned()) } }; @@ -429,6 +432,7 @@ impl AsRef for Attribute { Attribute::Oracle(string) => string, Attribute::Deprecated(Some(string)) => string, Attribute::Test | Attribute::Deprecated(None) => "", + Attribute::Custom(string) => string, } } }