Skip to content

Commit

Permalink
chore: Remove concept of storage slot from the compiler (#3582)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored Nov 27, 2023
1 parent 90a6304 commit 9f1382f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 34 deletions.
3 changes: 1 addition & 2 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ fn resolve_globals(
let globals = vecmap(globals, |global| {
let module_id = ModuleId { local_id: global.module_id, krate: crate_id };
let path_resolver = StandardPathResolver::new(module_id);
let storage_slot = context.next_storage_slot(module_id);

let mut resolver = Resolver::new(
&mut context.def_interner,
Expand All @@ -662,7 +661,7 @@ fn resolve_globals(

context.def_interner.update_global(global.stmt_id, hir_stmt);

context.def_interner.push_global(global.stmt_id, name, global.module_id, storage_slot);
context.def_interner.push_global(global.stmt_id, name, global.module_id);

(global.file_id, global.stmt_id)
});
Expand Down
19 changes: 0 additions & 19 deletions compiler/noirc_frontend/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ pub struct Context {
/// A map of each file that already has been visited from a prior `mod foo;` declaration.
/// This is used to issue an error if a second `mod foo;` is declared to the same file.
pub visited_files: BTreeMap<fm::FileId, Location>,

/// Maps a given (contract) module id to the next available storage slot
/// for that contract.
pub storage_slots: BTreeMap<def_map::ModuleId, StorageSlot>,
}

#[derive(Debug, Copy, Clone)]
Expand All @@ -42,8 +38,6 @@ pub enum FunctionNameMatch<'a> {
Contains(&'a str),
}

pub type StorageSlot = u32;

impl Context {
pub fn new(file_manager: FileManager, crate_graph: CrateGraph) -> Context {
Context {
Expand All @@ -52,7 +46,6 @@ impl Context {
visited_files: BTreeMap::new(),
crate_graph,
file_manager,
storage_slots: BTreeMap::new(),
}
}

Expand Down Expand Up @@ -200,16 +193,4 @@ impl Context {
fn module(&self, module_id: def_map::ModuleId) -> &def_map::ModuleData {
module_id.module(&self.def_maps)
}

/// Returns the next available storage slot in the given module.
/// Returns None if the given module is not a contract module.
fn next_storage_slot(&mut self, module_id: def_map::ModuleId) -> Option<StorageSlot> {
let module = self.module(module_id);

module.is_contract.then(|| {
let next_slot = self.storage_slots.entry(module_id).or_insert(0);
*next_slot += 1;
*next_slot
})
}
}
15 changes: 2 additions & 13 deletions compiler/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::ast::Ident;
use crate::graph::CrateId;
use crate::hir::def_collector::dc_crate::{UnresolvedStruct, UnresolvedTrait, UnresolvedTypeAlias};
use crate::hir::def_map::{LocalModuleId, ModuleId};
use crate::hir::StorageSlot;
use crate::hir_def::stmt::HirLetStatement;
use crate::hir_def::traits::TraitImpl;
use crate::hir_def::traits::{Trait, TraitConstraint};
Expand Down Expand Up @@ -399,10 +398,6 @@ impl DefinitionKind {
pub struct GlobalInfo {
pub ident: Ident,
pub local_id: LocalModuleId,

/// Global definitions have an associated storage slot if they are defined within
/// a contract. If they're defined elsewhere, this value is None.
pub storage_slot: Option<StorageSlot>,
}

impl Default for NodeInterner {
Expand Down Expand Up @@ -578,14 +573,8 @@ impl NodeInterner {
self.id_to_type.insert(definition_id.into(), typ);
}

pub fn push_global(
&mut self,
stmt_id: StmtId,
ident: Ident,
local_id: LocalModuleId,
storage_slot: Option<StorageSlot>,
) {
self.globals.insert(stmt_id, GlobalInfo { ident, local_id, storage_slot });
pub fn push_global(&mut self, stmt_id: StmtId, ident: Ident, local_id: LocalModuleId) {
self.globals.insert(stmt_id, GlobalInfo { ident, local_id });
}

/// Intern an empty global stmt. Used for collecting globals
Expand Down

0 comments on commit 9f1382f

Please sign in to comment.