Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove experimental feature warning for traits #3783

Merged
merged 9 commits into from
Dec 13, 2023
41 changes: 27 additions & 14 deletions compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,12 @@ fn trait_definition() -> impl NoirParser<TopLevelStatement> {
.then(trait_body())
.then_ignore(just(Token::RightBrace))
.validate(|(((name, generics), where_clause), items), span, emit| {
emit(ParserError::with_reason(ParserErrorReason::ExperimentalFeature("Traits"), span));
if !generics.is_empty() {
emit(ParserError::with_reason(
ParserErrorReason::ExperimentalFeature("Generic traits"),
span,
));
}
TopLevelStatement::Trait(NoirTrait { name, generics, where_clause, span, items })
})
}
Expand All @@ -437,7 +442,13 @@ fn trait_constant_declaration() -> impl NoirParser<TraitItem> {
.then(parse_type())
.then(optional_default_value())
.then_ignore(just(Token::Semicolon))
.map(|((name, typ), default_value)| TraitItem::Constant { name, typ, default_value })
.validate(|((name, typ), default_value), span, emit| {
emit(ParserError::with_reason(
ParserErrorReason::ExperimentalFeature("Associated constants"),
span,
));
TraitItem::Constant { name, typ, default_value }
})
}

/// trait_function_declaration: 'fn' ident generics '(' declaration_parameters ')' function_return_type
Expand Down Expand Up @@ -544,10 +555,15 @@ fn function_declaration_parameters() -> impl NoirParser<Vec<(Ident, UnresolvedTy

/// trait_type_declaration: 'type' ident generics
fn trait_type_declaration() -> impl NoirParser<TraitItem> {
keyword(Keyword::Type)
.ignore_then(ident())
.then_ignore(just(Token::Semicolon))
.map(|name| TraitItem::Type { name })
keyword(Keyword::Type).ignore_then(ident()).then_ignore(just(Token::Semicolon)).validate(
|name, span, emit| {
emit(ParserError::with_reason(
ParserErrorReason::ExperimentalFeature("Associated types"),
span,
));
TraitItem::Type { name }
},
)
}

/// Parses a non-trait implementation, adding a set of methods to a type.
Expand Down Expand Up @@ -581,11 +597,10 @@ fn trait_implementation() -> impl NoirParser<TopLevelStatement> {
.then_ignore(just(Token::LeftBrace))
.then(trait_implementation_body())
.then_ignore(just(Token::RightBrace))
.validate(|args, span, emit| {
.map(|args| {
let ((other_args, where_clause), items) = args;
let (((impl_generics, trait_name), trait_generics), object_type) = other_args;

emit(ParserError::with_reason(ParserErrorReason::ExperimentalFeature("Traits"), span));
TopLevelStatement::TraitImpl(NoirTraitImpl {
impl_generics,
trait_name,
Expand Down Expand Up @@ -616,12 +631,10 @@ fn where_clause() -> impl NoirParser<Vec<UnresolvedTraitConstraint>> {
trait_bounds: Vec<TraitBound>,
}

let constraints = parse_type().then_ignore(just(Token::Colon)).then(trait_bounds()).validate(
|(typ, trait_bounds), span, emit| {
emit(ParserError::with_reason(ParserErrorReason::ExperimentalFeature("Traits"), span));
MultiTraitConstraint { typ, trait_bounds }
},
);
let constraints = parse_type()
.then_ignore(just(Token::Colon))
.then(trait_bounds())
.map(|(typ, trait_bounds)| MultiTraitConstraint { typ, trait_bounds });

keyword(Keyword::Where)
.ignore_then(constraints.separated_by(just(Token::Comma)))
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"monomorphizes",
"nand",
"nargo",
"newtype",
"nixpkgs",
"noirc",
"noirup",
Expand All @@ -89,6 +90,7 @@
"pprof",
"preprocess",
"prettytable",
"println",
"printstd",
"pseudocode",
"quantile",
Expand Down
Loading
Loading