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: Allow secret functions to use public parameters #1051

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions crates/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl<'a> Resolver<'a> {
let mut parameter_types = vec![];

for (pattern, typ, visibility) in func.parameters().iter().cloned() {
if func.name() != "main" && visibility == noirc_abi::AbiVisibility::Public {
if visibility == noirc_abi::AbiVisibility::Public && !self.pub_allowed(func) {
self.push_err(ResolverError::UnnecessaryPub { ident: func.name_ident().clone() })
}

Expand All @@ -610,8 +610,9 @@ impl<'a> Resolver<'a> {

self.declare_numeric_generics(&parameter_types, &return_type);

if func.name() == "main"
&& *return_type != Type::Unit
// 'pub_allowed' also implies 'pub' is required on return types
if self.pub_allowed(func)
&& return_type.as_ref() != &Type::Unit
&& func.def.return_visibility != noirc_abi::AbiVisibility::Public
{
self.push_err(ResolverError::NecessaryPub { ident: func.name_ident().clone() })
Expand Down Expand Up @@ -645,6 +646,15 @@ impl<'a> Resolver<'a> {
}
}

/// True if the 'pub' keyword is allowed on parameters in this function
fn pub_allowed(&self, func: &NoirFunction) -> bool {
if self.in_contract() {
!func.def.is_unconstrained && !func.def.is_open
} else {
func.name() == "main"
}
}

fn handle_function_type(&mut self, func: &NoirFunction) -> Option<ContractFunctionType> {
if func.def.is_open {
if self.in_contract() {
Expand Down