mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
remove exosed_ident_ids
This commit is contained in:
parent
b1fe5659a4
commit
572bd66fb7
4 changed files with 34 additions and 14 deletions
|
@ -2,7 +2,7 @@ use crate::procedure::References;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use roc_collections::{MutMap, VecSet};
|
use roc_collections::{MutMap, VecSet};
|
||||||
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
||||||
use roc_module::symbol::{ IdentIdsByModule, ModuleId, ModuleIds, Symbol};
|
use roc_module::symbol::{IdentIdsByModule, ModuleId, ModuleIds, Symbol};
|
||||||
use roc_problem::can::{Problem, RuntimeError};
|
use roc_problem::can::{Problem, RuntimeError};
|
||||||
use roc_region::all::{Loc, Region};
|
use roc_region::all::{Loc, Region};
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,10 @@ pub struct Scope {
|
||||||
/// unqualified idents into Symbols.
|
/// unqualified idents into Symbols.
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
|
|
||||||
exposed_ident_ids: IdentIds,
|
|
||||||
pub ident_ids: IdentIds,
|
pub ident_ids: IdentIds,
|
||||||
|
|
||||||
|
/// The first `exposed_ident_count` identifiers are exposed
|
||||||
|
exposed_ident_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_aliases(var_store: &mut VarStore) -> SendMap<Symbol, Alias> {
|
fn add_aliases(var_store: &mut VarStore) -> SendMap<Symbol, Alias> {
|
||||||
|
@ -71,8 +73,8 @@ impl Scope {
|
||||||
pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope {
|
pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope {
|
||||||
Scope {
|
Scope {
|
||||||
home,
|
home,
|
||||||
ident_ids: initial_ident_ids.clone(),
|
exposed_ident_count: initial_ident_ids.len(),
|
||||||
exposed_ident_ids: initial_ident_ids,
|
ident_ids: initial_ident_ids,
|
||||||
idents: IdentStore::new(),
|
idents: IdentStore::new(),
|
||||||
aliases: SendMap::default(),
|
aliases: SendMap::default(),
|
||||||
// TODO(abilities): default abilities in scope
|
// TODO(abilities): default abilities in scope
|
||||||
|
@ -87,8 +89,8 @@ impl Scope {
|
||||||
) -> Scope {
|
) -> Scope {
|
||||||
Scope {
|
Scope {
|
||||||
home,
|
home,
|
||||||
ident_ids: initial_ident_ids.clone(),
|
exposed_ident_count: initial_ident_ids.len(),
|
||||||
exposed_ident_ids: initial_ident_ids,
|
ident_ids: initial_ident_ids,
|
||||||
idents: IdentStore::new(),
|
idents: IdentStore::new(),
|
||||||
aliases: add_aliases(var_store),
|
aliases: add_aliases(var_store),
|
||||||
// TODO(abilities): default abilities in scope
|
// TODO(abilities): default abilities in scope
|
||||||
|
@ -280,12 +282,10 @@ impl Scope {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol {
|
fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol {
|
||||||
// If this IdentId was already added previously
|
// if the identifier is exposed, use the IdentId we already have for it
|
||||||
// when the value was exposed in the module header,
|
let ident_id = match self.ident_ids.get_id(ident) {
|
||||||
// use that existing IdentId. Otherwise, create a fresh one.
|
Some(ident_id) if ident_id.index() < self.exposed_ident_count => ident_id,
|
||||||
let ident_id = match self.exposed_ident_ids.get_id(ident) {
|
_ => self.ident_ids.add_ident(ident),
|
||||||
Some(ident_id) => ident_id,
|
|
||||||
None => self.ident_ids.add_ident(ident),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let symbol = Symbol::new(self.home, ident_id);
|
let symbol = Symbol::new(self.home, ident_id);
|
||||||
|
@ -344,14 +344,12 @@ impl Scope {
|
||||||
F: FnOnce(&mut Scope) -> T,
|
F: FnOnce(&mut Scope) -> T,
|
||||||
{
|
{
|
||||||
let idents = self.idents.clone();
|
let idents = self.idents.clone();
|
||||||
let exposed_ident_ids = self.exposed_ident_ids.clone();
|
|
||||||
let aliases = self.aliases.clone();
|
let aliases = self.aliases.clone();
|
||||||
let abilities_store = self.abilities_store.clone();
|
let abilities_store = self.abilities_store.clone();
|
||||||
|
|
||||||
let result = f(self);
|
let result = f(self);
|
||||||
|
|
||||||
self.idents = idents;
|
self.idents = idents;
|
||||||
self.exposed_ident_ids = exposed_ident_ids;
|
|
||||||
self.aliases = aliases;
|
self.aliases = aliases;
|
||||||
self.abilities_store = abilities_store;
|
self.abilities_store = abilities_store;
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,14 @@ impl SmallStringInterner {
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.lengths.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.lengths.is_empty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -522,6 +522,12 @@ impl ModuleIds {
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct IdentId(u32);
|
pub struct IdentId(u32);
|
||||||
|
|
||||||
|
impl IdentId {
|
||||||
|
pub const fn index(self) -> usize {
|
||||||
|
self.0 as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Stores a mapping between Ident and IdentId.
|
/// Stores a mapping between Ident and IdentId.
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
pub struct IdentIds {
|
pub struct IdentIds {
|
||||||
|
@ -584,6 +590,14 @@ impl IdentIds {
|
||||||
ident_ids_str: format!("{:?}", self),
|
ident_ids_str: format!("{:?}", self),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.interner.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.interner.is_empty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue