Skip to content

Commit

Permalink
chore(hir): hoist "main" constant for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
joss-aztec committed Apr 26, 2023
1 parent 00d4633 commit ecfe4cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions crates/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub use module_data::*;
mod namespace;
pub use namespace::*;

/// The name that is used for a non-contract program's entry-point function.
pub const MAIN_FUNCTION: &str = "main";

// XXX: Ultimately, we want to constrain an index to be of a certain type just like in RA
/// Lets first check if this is offered by any external crate
/// XXX: RA has made this a crate on crates.io
Expand Down Expand Up @@ -104,8 +107,6 @@ impl CrateDefMap {

/// Find the main function for this crate
pub fn main_function(&self) -> Option<FuncId> {
const MAIN_FUNCTION: &str = "main";

let root_module = &self.modules()[self.root.0];

// This function accepts an Ident, so we attach a dummy span to
Expand Down
6 changes: 3 additions & 3 deletions crates/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::rc::Rc;

use crate::graph::CrateId;
use crate::hir::def_map::{ModuleDefId, TryFromModuleDefId};
use crate::hir::def_map::{ModuleDefId, TryFromModuleDefId, MAIN_FUNCTION};
use crate::hir_def::stmt::{HirAssignStatement, HirLValue, HirPattern};
use crate::node_interner::{
DefinitionId, DefinitionKind, ExprId, FuncId, NodeInterner, StmtId, StructId,
Expand Down Expand Up @@ -677,7 +677,7 @@ impl<'a> Resolver<'a> {
if self.in_contract() {
!func.def.is_unconstrained && !func.def.is_open
} else {
func.name() == "main"
func.name() == MAIN_FUNCTION
}
}

Expand All @@ -688,7 +688,7 @@ impl<'a> Resolver<'a> {
// witness indices in their abis is not a concern.
!func.def.is_unconstrained && !func.def.is_open
} else {
func.name() == "main"
func.name() == MAIN_FUNCTION
}
}

Expand Down

0 comments on commit ecfe4cd

Please sign in to comment.