mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
refactor
This commit is contained in:
parent
08c8968236
commit
1372825ebb
2 changed files with 15 additions and 19 deletions
|
@ -12,6 +12,7 @@ use crate::scope::create_alias;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use roc_collections::VecMap;
|
use roc_collections::VecMap;
|
||||||
use roc_collections::{ImSet, MutMap, SendMap};
|
use roc_collections::{ImSet, MutMap, SendMap};
|
||||||
|
use roc_module::ident::Ident;
|
||||||
use roc_module::ident::Lowercase;
|
use roc_module::ident::Lowercase;
|
||||||
use roc_module::symbol::IdentId;
|
use roc_module::symbol::IdentId;
|
||||||
use roc_module::symbol::ModuleId;
|
use roc_module::symbol::ModuleId;
|
||||||
|
@ -1371,7 +1372,7 @@ fn to_pending_type_def<'a>(
|
||||||
let region = Region::span_across(&name.region, &ann.region);
|
let region = Region::span_across(&name.region, &ann.region);
|
||||||
|
|
||||||
match scope.introduce_without_shadow_symbol(
|
match scope.introduce_without_shadow_symbol(
|
||||||
name.value.into(),
|
&Ident::from(name.value),
|
||||||
&env.exposed_ident_ids,
|
&env.exposed_ident_ids,
|
||||||
&mut env.ident_ids,
|
&mut env.ident_ids,
|
||||||
region,
|
region,
|
||||||
|
@ -1451,7 +1452,7 @@ fn to_pending_type_def<'a>(
|
||||||
loc_has: _,
|
loc_has: _,
|
||||||
} => {
|
} => {
|
||||||
let name = match scope.introduce_without_shadow_symbol(
|
let name = match scope.introduce_without_shadow_symbol(
|
||||||
name.value.into(),
|
&Ident::from(name.value),
|
||||||
&env.exposed_ident_ids,
|
&env.exposed_ident_ids,
|
||||||
&mut env.ident_ids,
|
&mut env.ident_ids,
|
||||||
name.region,
|
name.region,
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl IdentStore {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (ident, (symbol, region)) in defaults {
|
for (ident, (symbol, region)) in defaults {
|
||||||
this.insert_unchecked(ident, symbol, region);
|
this.insert_unchecked(&ident, symbol, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
this
|
this
|
||||||
|
@ -80,7 +80,7 @@ impl IdentStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does not check that the ident is unique
|
/// Does not check that the ident is unique
|
||||||
fn insert_unchecked(&mut self, ident: Ident, symbol: Symbol, region: Region) {
|
fn insert_unchecked(&mut self, ident: &Ident, symbol: Symbol, region: Region) {
|
||||||
let ident_str = ident.as_inline_str().as_str();
|
let ident_str = ident.as_inline_str().as_str();
|
||||||
|
|
||||||
let index = self.interner.insert(ident_str);
|
let index = self.interner.insert(ident_str);
|
||||||
|
@ -279,32 +279,27 @@ impl Scope {
|
||||||
all_ident_ids: &mut IdentIds,
|
all_ident_ids: &mut IdentIds,
|
||||||
region: Region,
|
region: Region,
|
||||||
) -> Result<Symbol, (Region, Loc<Ident>, Symbol)> {
|
) -> Result<Symbol, (Region, Loc<Ident>, Symbol)> {
|
||||||
match self.idents.get_index(&ident) {
|
match self.introduce_without_shadow_symbol(&ident, exposed_ident_ids, all_ident_ids, region)
|
||||||
Some(index) => {
|
{
|
||||||
let original_region = self.idents.regions[index];
|
Ok(symbol) => Ok(symbol),
|
||||||
let shadow = Loc {
|
Err((original_region, shadow)) => {
|
||||||
value: ident.clone(),
|
|
||||||
region,
|
|
||||||
};
|
|
||||||
|
|
||||||
let ident_id = all_ident_ids.add_ident(&ident);
|
let ident_id = all_ident_ids.add_ident(&ident);
|
||||||
let symbol = Symbol::new(self.home, ident_id);
|
let symbol = Symbol::new(self.home, ident_id);
|
||||||
|
|
||||||
Err((original_region, shadow, symbol))
|
Err((original_region, shadow, symbol))
|
||||||
}
|
}
|
||||||
None => Ok(self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [Self::introduce], but does not introduce a new symbol for the shadowing symbol.
|
/// Like [Self::introduce], but does not introduce a new symbol for the shadowing symbol.
|
||||||
pub fn introduce_without_shadow_symbol(
|
pub fn introduce_without_shadow_symbol(
|
||||||
&mut self,
|
&mut self,
|
||||||
ident: Ident,
|
ident: &Ident,
|
||||||
exposed_ident_ids: &IdentIds,
|
exposed_ident_ids: &IdentIds,
|
||||||
all_ident_ids: &mut IdentIds,
|
all_ident_ids: &mut IdentIds,
|
||||||
region: Region,
|
region: Region,
|
||||||
) -> Result<Symbol, (Region, Loc<Ident>)> {
|
) -> Result<Symbol, (Region, Loc<Ident>)> {
|
||||||
match self.idents.get_symbol_and_region(&ident) {
|
match self.idents.get_symbol_and_region(ident) {
|
||||||
Some((_, original_region)) => {
|
Some((_, original_region)) => {
|
||||||
let shadow = Loc {
|
let shadow = Loc {
|
||||||
value: ident.clone(),
|
value: ident.clone(),
|
||||||
|
@ -344,7 +339,7 @@ impl Scope {
|
||||||
|
|
||||||
// Add a symbol for the shadow, but don't re-associate the member name.
|
// Add a symbol for the shadow, but don't re-associate the member name.
|
||||||
let dummy = Ident::default();
|
let dummy = Ident::default();
|
||||||
self.idents.insert_unchecked(dummy, shadow_symbol, region);
|
self.idents.insert_unchecked(&dummy, shadow_symbol, region);
|
||||||
|
|
||||||
Ok((shadow_symbol, Some(original_symbol)))
|
Ok((shadow_symbol, Some(original_symbol)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -363,7 +358,7 @@ impl Scope {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let new_symbol =
|
let new_symbol =
|
||||||
self.commit_introduction(ident, exposed_ident_ids, all_ident_ids, region);
|
self.commit_introduction(&ident, exposed_ident_ids, all_ident_ids, region);
|
||||||
Ok((new_symbol, None))
|
Ok((new_symbol, None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +366,7 @@ impl Scope {
|
||||||
|
|
||||||
fn commit_introduction(
|
fn commit_introduction(
|
||||||
&mut self,
|
&mut self,
|
||||||
ident: Ident,
|
ident: &Ident,
|
||||||
exposed_ident_ids: &IdentIds,
|
exposed_ident_ids: &IdentIds,
|
||||||
all_ident_ids: &mut IdentIds,
|
all_ident_ids: &mut IdentIds,
|
||||||
region: Region,
|
region: Region,
|
||||||
|
@ -412,7 +407,7 @@ impl Scope {
|
||||||
match self.idents.get_symbol_and_region(&ident) {
|
match self.idents.get_symbol_and_region(&ident) {
|
||||||
Some(shadowed) => Err(shadowed),
|
Some(shadowed) => Err(shadowed),
|
||||||
None => {
|
None => {
|
||||||
self.idents.insert_unchecked(ident, symbol, region);
|
self.idents.insert_unchecked(&ident, symbol, region);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue