Skip to content

Commit

Permalink
chore!: remove distinct keyword (#5219)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

This PR removes the `distinct` keyword and any traces of distinctiveness
from the codebase as they have been deprecated for a couple of releases.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jun 11, 2024
1 parent ff67e14 commit 1d62c59
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 78 deletions.
23 changes: 0 additions & 23 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,26 +390,3 @@ impl std::fmt::Display for Visibility {
}
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// Represents whether the return value should compromise of unique witness indices such that no
/// index occurs within the program's abi more than once.
///
/// This is useful for application stacks that require an uniform abi across across multiple
/// circuits. When index duplication is allowed, the compiler may identify that a public input
/// reaches the output unaltered and is thus referenced directly, causing the input and output
/// witness indices to overlap. Similarly, repetitions of copied values in the output may be
/// optimized away.
pub enum Distinctness {
Distinct,
DuplicationAllowed,
}

impl std::fmt::Display for Distinctness {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Distinct => write!(f, "distinct"),
Self::DuplicationAllowed => write!(f, "duplication-allowed"),
}
}
}
14 changes: 0 additions & 14 deletions compiler/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ pub enum ResolverError {
UnnecessaryPub { ident: Ident, position: PubPosition },
#[error("Required 'pub', main function must return public value")]
NecessaryPub { ident: Ident },
#[error("'distinct' keyword can only be used with main method")]
DistinctNotAllowed { ident: Ident },
#[error("Missing expression for declared constant")]
MissingRhsExpr { name: String, span: Span },
#[error("Expression invalid in an array length context")]
Expand Down Expand Up @@ -220,18 +218,6 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
diag.add_note("The `pub` keyword is mandatory for the entry-point function return type because the verifier cannot retrieve private witness and thus the function will not be able to return a 'priv' value".to_owned());
diag
}
ResolverError::DistinctNotAllowed { ident } => {
let name = &ident.0.contents;

let mut diag = Diagnostic::simple_error(
format!("Invalid `distinct` keyword on return type of function {name}"),
"Invalid distinct on return type".to_string(),
ident.0.span(),
);

diag.add_note("The `distinct` keyword is only valid when used on the main function of a program, as its only purpose is to ensure that all witness indices that occur in the abi are unique".to_owned());
diag
}
ResolverError::MissingRhsExpr { name, span } => Diagnostic::simple_error(
format!(
"no expression specifying the value stored by the constant variable {name}"
Expand Down
3 changes: 0 additions & 3 deletions compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ pub enum Keyword {
Contract,
Crate,
Dep,
Distinct,
Else,
Field,
Fn,
Expand Down Expand Up @@ -884,7 +883,6 @@ impl fmt::Display for Keyword {
Keyword::Contract => write!(f, "contract"),
Keyword::Crate => write!(f, "crate"),
Keyword::Dep => write!(f, "dep"),
Keyword::Distinct => write!(f, "distinct"),
Keyword::Else => write!(f, "else"),
Keyword::Field => write!(f, "Field"),
Keyword::Fn => write!(f, "fn"),
Expand Down Expand Up @@ -932,7 +930,6 @@ impl Keyword {
"contract" => Keyword::Contract,
"crate" => Keyword::Crate,
"dep" => Keyword::Dep,
"distinct" => Keyword::Distinct,
"else" => Keyword::Else,
"Field" => Keyword::Field,
"fn" => Keyword::Fn,
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_frontend/src/noir_parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ extern {
"contract" => BorrowedToken::Keyword(noir_token::Keyword::Contract),
"crate" => BorrowedToken::Keyword(noir_token::Keyword::Crate),
"dep" => BorrowedToken::Keyword(noir_token::Keyword::Dep),
"distinct" => BorrowedToken::Keyword(noir_token::Keyword::Distinct),
"else" => BorrowedToken::Keyword(noir_token::Keyword::Else),
"Field" => BorrowedToken::Keyword(noir_token::Keyword::Field),
"fn" => BorrowedToken::Keyword(noir_token::Keyword::Fn),
Expand Down
2 changes: 0 additions & 2 deletions compiler/noirc_frontend/src/parser/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ pub enum ParserErrorReason {
TraitImplFunctionModifiers,
#[error("comptime keyword is deprecated")]
ComptimeDeprecated,
#[error("distinct keyword is deprecated. The `distinct` behavior is now the default.")]
DistinctDeprecated,
#[error("{0} are experimental and aren't fully supported yet")]
ExperimentalFeature(&'static str),
#[error(
Expand Down
23 changes: 3 additions & 20 deletions compiler/noirc_frontend/src/parser/parser/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ use super::{
parameter_name_recovery, parameter_recovery, parenthesized, parse_type, pattern,
self_parameter, where_clause, NoirParser,
};
use crate::ast::{
FunctionDefinition, FunctionReturnType, Ident, ItemVisibility, NoirFunction, Param, Visibility,
};
use crate::parser::labels::ParsingRuleLabel;
use crate::parser::spanned;
use crate::token::{Keyword, Token};
use crate::{
ast::{
FunctionDefinition, FunctionReturnType, Ident, ItemVisibility, NoirFunction, Param,
Visibility,
},
parser::{ParserError, ParserErrorReason},
};

use chumsky::prelude::*;

Expand Down Expand Up @@ -95,20 +91,9 @@ pub(super) fn generics() -> impl NoirParser<Vec<Ident>> {
.map(|opt| opt.unwrap_or_default())
}

#[deprecated = "Distinct keyword is now deprecated. Remove this function after the 0.30.0 release"]
fn optional_distinctness() -> impl NoirParser<bool> {
keyword(Keyword::Distinct).or_not().validate(|opt, span, emit| {
if opt.is_some() {
emit(ParserError::with_reason(ParserErrorReason::DistinctDeprecated, span));
}
opt.is_some()
})
}

pub(super) fn function_return_type() -> impl NoirParser<(Visibility, FunctionReturnType)> {
#[allow(deprecated)]
just(Token::Arrow)
.ignore_then(optional_distinctness())
.ignore_then(optional_visibility())
.then(spanned(parse_type()))
.or_not()
Expand Down Expand Up @@ -224,8 +209,6 @@ mod test {
// A leading plus is not allowed.
"fn func_name<T>(f: Field, y : T) where T: + SomeTrait {}",
"fn func_name<T>(f: Field, y : T) where T: TraitX + <Y> {}",
// `distinct` is deprecated
"fn main(x: pub u8, y: pub u8) -> distinct pub [u8; 2] { [x, y] }",
],
);
}
Expand Down
15 changes: 0 additions & 15 deletions tooling/noirc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,6 @@ impl From<&Visibility> for AbiVisibility {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
/// Represents whether the return value should compromise of unique witness indices such that no
/// index occurs within the program's abi more than once.
///
/// This is useful for application stacks that require an uniform abi across across multiple
/// circuits. When index duplication is allowed, the compiler may identify that a public input
/// reaches the output unaltered and is thus referenced directly, causing the input and output
/// witness indices to overlap. Similarly, repetitions of copied values in the output may be
/// optimized away.
pub enum AbiDistinctness {
Distinct,
DuplicationAllowed,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Sign {
Expand Down

0 comments on commit 1d62c59

Please sign in to comment.