mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
Merge branch 'trunk' into add-list-dropLast
This commit is contained in:
commit
a4b5b81d60
48 changed files with 1242 additions and 693 deletions
|
@ -4,7 +4,7 @@ use std::fmt;
|
|||
|
||||
/// This could be uppercase or lowercase, qualified or unqualified.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Ident(IdentStr);
|
||||
pub struct Ident(pub IdentStr); // Is IdentStr allowed to be pub?
|
||||
|
||||
impl Ident {
|
||||
pub fn as_inline_str(&self) -> &IdentStr {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
pub mod ident;
|
||||
pub mod low_level;
|
||||
pub mod module_err;
|
||||
pub mod operator;
|
||||
pub mod symbol;
|
||||
|
||||
|
|
30
compiler/module/src/module_err.rs
Normal file
30
compiler/module/src/module_err.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use snafu::{Backtrace, Snafu};
|
||||
|
||||
use crate::symbol::IdentId;
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
#[snafu(visibility(pub))]
|
||||
pub enum ModuleError {
|
||||
#[snafu(display(
|
||||
"ModuleIdNotFound: I could not find the ModuleId {} in Interns.all_ident_ids: {}.",
|
||||
module_id,
|
||||
all_ident_ids
|
||||
))]
|
||||
ModuleIdNotFound {
|
||||
module_id: String,
|
||||
all_ident_ids: String,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
#[snafu(display(
|
||||
"IdentIdNotFound: I could not find IdentId {:?} in ident_ids {:?}.",
|
||||
ident_id,
|
||||
ident_ids_str
|
||||
))]
|
||||
IdentIdNotFound {
|
||||
ident_id: IdentId,
|
||||
ident_ids_str: String,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
}
|
||||
|
||||
pub type ModuleResult<T, E = ModuleError> = std::result::Result<T, E>;
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue