Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Sep 19, 2023
1 parent 1364a38 commit 970cab1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions compiler/noirc_frontend/src/ast/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ impl NoirFunction {
&self.def.attributes
}
pub fn function_attribute(&self) -> Option<&FunctionAttribute> {
self.def.attributes.function_attribute.as_ref()
self.def.attributes.function.as_ref()
}
pub fn other_attributes(&self) -> &Vec<SecondaryAttribute> {
self.def.attributes.secondary_attributes.as_ref()
pub fn secondary_attributes(&self) -> &Vec<SecondaryAttribute> {
self.def.attributes.secondary.as_ref()
}
pub fn def(&self) -> &FunctionDefinition {
&self.def
Expand Down Expand Up @@ -97,7 +97,7 @@ impl NoirFunction {
impl From<FunctionDefinition> for NoirFunction {
fn from(fd: FunctionDefinition) -> Self {
// The function type is determined by the existence of a function attribute
let kind = match fd.attributes.function_attribute {
let kind = match fd.attributes.function {
Some(FunctionAttribute::Builtin(_)) => FunctionKind::Builtin,
Some(FunctionAttribute::Foreign(_)) => FunctionKind::LowLevel,
Some(FunctionAttribute::Test { .. }) => FunctionKind::Normal,
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl CrateDefMap {
module.value_definitions().filter_map(|id| {
if let Some(func_id) = id.as_function() {
let func_meta = interner.function_meta(&func_id);
match func_meta.attributes.function_attribute {
match func_meta.attributes.function {
Some(FunctionAttribute::Test(scope)) => {
Some(TestFunction::new(func_id, scope, func_meta.name.location))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ impl<'a> Resolver<'a> {
self.push_err(ResolverError::DistinctNotAllowed { ident: func.name_ident().clone() });
}

if matches!(attributes.function_attribute, Some(FunctionAttribute::Test { .. }))
if matches!(attributes.function, Some(FunctionAttribute::Test { .. }))
&& !parameters.is_empty()
{
self.push_err(ResolverError::TestFunctionHasParameters {
Expand Down
10 changes: 5 additions & 5 deletions compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,29 +364,29 @@ impl fmt::Display for TestScope {
// Calls to functions which have the foreign attribute are executed in the host language
pub struct Attributes {
// Each function can have a single Primary Attribute
pub function_attribute: Option<FunctionAttribute>,
pub function: Option<FunctionAttribute>,
// Each function can have many Secondary Attributes
pub secondary_attributes: Vec<SecondaryAttribute>,
pub secondary: Vec<SecondaryAttribute>,
}

impl Attributes {
pub fn empty() -> Self {
Self { function_attribute: None, secondary_attributes: Vec::new() }
Self { function: None, secondary: Vec::new() }
}

/// Returns true if one of the secondary attributes is `contract_library_method`
///
/// This is useful for finding out if we should compile a contract method
/// as an entry point or not.
pub fn has_contract_library_method(&self) -> bool {
self.secondary_attributes
self.secondary
.iter()
.any(|attribute| attribute == &SecondaryAttribute::ContractLibraryMethod)
}

/// Returns note if a deprecated secondary attribute is found
pub fn get_deprecated_note(&self) -> Option<Option<String>> {
self.secondary_attributes.iter().find_map(|attr| match attr {
self.secondary.iter().find_map(|attr| match attr {
SecondaryAttribute::Deprecated(note) => Some(note.clone()),
_ => None,
})
Expand Down
6 changes: 3 additions & 3 deletions compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ impl<'interner> Monomorphizer<'interner> {
let meta = self.interner.function_meta(&id);
match meta.kind {
FunctionKind::LowLevel => {
let attribute = meta.attributes.function_attribute.expect("all low level functions must contain a function attribute which contains the opcode which it links to");
let attribute = meta.attributes.function.expect("all low level functions must contain a function attribute which contains the opcode which it links to");
let opcode = attribute.foreign().expect(
"ice: function marked as foreign, but attribute kind does not match this",
);
Definition::LowLevel(opcode)
}
FunctionKind::Builtin => {
let attribute = meta.attributes.function_attribute.expect("all low level functions must contain a primary attribute which contains the opcode which it links to");
let attribute = meta.attributes.function.expect("all low level functions must contain a primary attribute which contains the opcode which it links to");
let opcode = attribute.builtin().expect(
"ice: function marked as builtin, but attribute kind does not match this",
);
Expand All @@ -165,7 +165,7 @@ impl<'interner> Monomorphizer<'interner> {
FunctionKind::Oracle => {
let attr = meta
.attributes
.function_attribute
.function
.expect("Oracle function must have an oracle attribute");

match attr {
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn validate_attributes(
}
}

Attributes { function_attribute: primary, secondary_attributes: secondary }
Attributes { function: primary, secondary }
}

fn validate_struct_attributes(
Expand Down

0 comments on commit 970cab1

Please sign in to comment.