Merge branch 'trunk' into add-list-dropLast

This commit is contained in:
Chelsea Troy 2021-10-25 11:49:27 -05:00 committed by GitHub
commit a4b5b81d60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 1242 additions and 693 deletions

View file

@ -1,7 +1,9 @@
use crate::ident::{Ident, ModuleName};
use crate::module_err::{IdentIdNotFound, ModuleIdNotFound, ModuleResult};
use roc_collections::all::{default_hasher, MutMap, SendMap};
use roc_ident::IdentStr;
use roc_region::all::Region;
use snafu::OptionExt;
use std::collections::HashMap;
use std::{fmt, u32};
@ -253,6 +255,30 @@ impl Interns {
}
}
pub fn get_module_ident_ids<'a>(
all_ident_ids: &'a MutMap<ModuleId, IdentIds>,
module_id: &ModuleId,
) -> ModuleResult<&'a IdentIds> {
all_ident_ids
.get(module_id)
.with_context(|| ModuleIdNotFound {
module_id: format!("{:?}", module_id),
all_ident_ids: format!("{:?}", all_ident_ids),
})
}
pub fn get_module_ident_ids_mut<'a>(
all_ident_ids: &'a mut MutMap<ModuleId, IdentIds>,
module_id: &ModuleId,
) -> ModuleResult<&'a mut IdentIds> {
all_ident_ids
.get_mut(module_id)
.with_context(|| ModuleIdNotFound {
module_id: format!("{:?}", module_id),
all_ident_ids: "I could not return all_ident_ids here because of borrowing issues.",
})
}
#[cfg(debug_assertions)]
lazy_static! {
/// This is used in Debug builds only, to let us have a Debug instance
@ -621,6 +647,17 @@ impl IdentIds {
pub fn get_name(&self, id: IdentId) -> Option<&Ident> {
self.by_id.get(id.0 as usize)
}
pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> {
Ok(self
.get_name(ident_id)
.with_context(|| IdentIdNotFound {
ident_id,
ident_ids_str: format!("{:?}", self),
})?
.as_inline_str()
.as_str())
}
}
// BUILTINS