mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
refactor load/file logic
This commit is contained in:
parent
6c74d4847a
commit
e926bced10
2 changed files with 26 additions and 25 deletions
|
@ -4463,23 +4463,7 @@ fn build_header<'a>(
|
||||||
//
|
//
|
||||||
// Also build a list of imported_values_to_expose (like `bar` above.)
|
// Also build a list of imported_values_to_expose (like `bar` above.)
|
||||||
for (qualified_module_name, exposed_idents, region) in imported.into_iter() {
|
for (qualified_module_name, exposed_idents, region) in imported.into_iter() {
|
||||||
let cloned_module_name = qualified_module_name.module.clone();
|
let pq_module_name = qualified_module_name.into_pq_module_name(opt_shorthand);
|
||||||
let pq_module_name = if qualified_module_name.is_builtin() {
|
|
||||||
// If this is a builtin, it must be unqualified, and we should *never* prefix it
|
|
||||||
// with the package shorthand! The user intended to import the module as-is here.
|
|
||||||
debug_assert!(qualified_module_name.opt_package.is_none());
|
|
||||||
PQModuleName::Unqualified(qualified_module_name.module)
|
|
||||||
} else {
|
|
||||||
match qualified_module_name.opt_package {
|
|
||||||
None => match opt_shorthand {
|
|
||||||
Some(shorthand) => {
|
|
||||||
PQModuleName::Qualified(shorthand, qualified_module_name.module)
|
|
||||||
}
|
|
||||||
None => PQModuleName::Unqualified(qualified_module_name.module),
|
|
||||||
},
|
|
||||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let module_id = module_ids.get_or_insert(&pq_module_name);
|
let module_id = module_ids.get_or_insert(&pq_module_name);
|
||||||
|
|
||||||
|
@ -4492,18 +4476,14 @@ fn build_header<'a>(
|
||||||
// to the same symbols as the ones we're using here.
|
// to the same symbols as the ones we're using here.
|
||||||
let ident_ids = ident_ids_by_module.get_or_insert(module_id);
|
let ident_ids = ident_ids_by_module.get_or_insert(module_id);
|
||||||
|
|
||||||
for Loc {
|
for loc_ident in exposed_idents {
|
||||||
region,
|
let ident_id = ident_ids.get_or_insert(loc_ident.value.as_str());
|
||||||
value: ident,
|
|
||||||
} in exposed_idents
|
|
||||||
{
|
|
||||||
let ident_id = ident_ids.get_or_insert(ident.as_str());
|
|
||||||
let symbol = Symbol::new(module_id, ident_id);
|
let symbol = Symbol::new(module_id, ident_id);
|
||||||
|
|
||||||
// Since this value is exposed, add it to our module's default scope.
|
// Since this value is exposed, add it to our module's default scope.
|
||||||
debug_assert!(!scope.contains_key(&ident));
|
debug_assert!(!scope.contains_key(&loc_ident.value));
|
||||||
|
|
||||||
scope.insert(ident, (symbol, region));
|
scope.insert(loc_ident.value, (symbol, loc_ident.region));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
pub use roc_ident::IdentStr;
|
pub use roc_ident::IdentStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use crate::symbol::PQModuleName;
|
||||||
|
|
||||||
/// This could be uppercase or lowercase, qualified or unqualified.
|
/// This could be uppercase or lowercase, qualified or unqualified.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
|
||||||
pub struct Ident(pub IdentStr);
|
pub struct Ident(pub IdentStr);
|
||||||
|
@ -21,6 +23,25 @@ pub struct QualifiedModuleName<'a> {
|
||||||
pub module: ModuleName,
|
pub module: ModuleName,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> QualifiedModuleName<'a> {
|
||||||
|
pub fn into_pq_module_name(self, opt_shorthand: Option<&'a str>) -> PQModuleName<'a> {
|
||||||
|
if self.is_builtin() {
|
||||||
|
// If this is a builtin, it must be unqualified, and we should *never* prefix it
|
||||||
|
// with the package shorthand! The user intended to import the module as-is here.
|
||||||
|
debug_assert!(self.opt_package.is_none());
|
||||||
|
PQModuleName::Unqualified(self.module)
|
||||||
|
} else {
|
||||||
|
match self.opt_package {
|
||||||
|
None => match opt_shorthand {
|
||||||
|
Some(shorthand) => PQModuleName::Qualified(shorthand, self.module),
|
||||||
|
None => PQModuleName::Unqualified(self.module),
|
||||||
|
},
|
||||||
|
Some(package) => PQModuleName::Qualified(package, self.module),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct ModuleName(IdentStr);
|
pub struct ModuleName(IdentStr);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue