mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
use IdentStr
This commit is contained in:
parent
bd35770e9a
commit
ceb5cc66fa
30 changed files with 241 additions and 219 deletions
|
@ -348,11 +348,11 @@ fn tag_name_to_expr<'a>(env: &Env<'a, '_>, tag_name: &TagName) -> Expr<'a> {
|
|||
match tag_name {
|
||||
TagName::Global(_) => Expr::GlobalTag(
|
||||
env.arena
|
||||
.alloc_str(&tag_name.as_string(env.interns, env.home)),
|
||||
.alloc_str(&tag_name.as_ident_str(env.interns, env.home)),
|
||||
),
|
||||
TagName::Private(_) => Expr::PrivateTag(
|
||||
env.arena
|
||||
.alloc_str(&tag_name.as_string(env.interns, env.home)),
|
||||
.alloc_str(&tag_name.as_ident_str(env.interns, env.home)),
|
||||
),
|
||||
TagName::Closure(_) => unreachable!("User cannot type this"),
|
||||
}
|
||||
|
@ -672,7 +672,7 @@ fn bool_to_ast<'a>(env: &Env<'a, '_>, value: bool, content: &Content) -> Expr<'a
|
|||
let (tag_name, payload_vars) = tags.iter().next().unwrap();
|
||||
|
||||
let loc_tag_expr = {
|
||||
let tag_name = &tag_name.as_string(env.interns, env.home);
|
||||
let tag_name = &tag_name.as_ident_str(env.interns, env.home);
|
||||
let tag_expr = if tag_name.starts_with('@') {
|
||||
Expr::PrivateTag(arena.alloc_str(tag_name))
|
||||
} else {
|
||||
|
@ -713,11 +713,11 @@ fn bool_to_ast<'a>(env: &Env<'a, '_>, value: bool, content: &Content) -> Expr<'a
|
|||
|
||||
let tag_name = if value {
|
||||
max_by_key(tag_name_1, tag_name_2, |n| {
|
||||
n.as_string(env.interns, env.home)
|
||||
n.as_ident_str(env.interns, env.home)
|
||||
})
|
||||
} else {
|
||||
min_by_key(tag_name_1, tag_name_2, |n| {
|
||||
n.as_string(env.interns, env.home)
|
||||
n.as_ident_str(env.interns, env.home)
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -784,7 +784,7 @@ fn byte_to_ast<'a>(env: &Env<'a, '_>, value: u8, content: &Content) -> Expr<'a>
|
|||
let (tag_name, payload_vars) = tags.iter().next().unwrap();
|
||||
|
||||
let loc_tag_expr = {
|
||||
let tag_name = &tag_name.as_string(env.interns, env.home);
|
||||
let tag_name = &tag_name.as_ident_str(env.interns, env.home);
|
||||
let tag_expr = if tag_name.starts_with('@') {
|
||||
Expr::PrivateTag(arena.alloc_str(tag_name))
|
||||
} else {
|
||||
|
@ -908,7 +908,7 @@ fn num_to_ast<'a>(env: &Env<'a, '_>, num_expr: Expr<'a>, content: &Content) -> E
|
|||
}
|
||||
|
||||
let loc_tag_expr = {
|
||||
let tag_name = &tag_name.as_string(env.interns, env.home);
|
||||
let tag_name = &tag_name.as_ident_str(env.interns, env.home);
|
||||
let tag_expr = if tag_name.starts_with('@') {
|
||||
Expr::PrivateTag(arena.alloc_str(tag_name))
|
||||
} else {
|
||||
|
|
|
@ -159,7 +159,7 @@ fn can_annotation_help(
|
|||
Err(problem) => {
|
||||
env.problem(roc_problem::can::Problem::RuntimeError(problem));
|
||||
|
||||
return Type::Erroneous(Problem::UnrecognizedIdent(ident.into()));
|
||||
return Type::Erroneous(Problem::UnrecognizedIdent(ident));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::procedure::References;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::ident::ModuleName;
|
||||
use roc_module::ident::{Ident, ModuleName};
|
||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||
use roc_problem::can::{Problem, RuntimeError};
|
||||
use roc_region::all::{Located, Region};
|
||||
|
@ -62,22 +61,21 @@ impl<'a> Env<'a> {
|
|||
/// Returns Err if the symbol resolved, but it was not exposed by the given module
|
||||
pub fn qualified_lookup(
|
||||
&mut self,
|
||||
module_name: &str,
|
||||
module_name_str: &str,
|
||||
ident: &str,
|
||||
region: Region,
|
||||
) -> Result<Symbol, RuntimeError> {
|
||||
debug_assert!(
|
||||
!module_name.is_empty(),
|
||||
!module_name_str.is_empty(),
|
||||
"Called env.qualified_lookup with an unqualified ident: {:?}",
|
||||
ident
|
||||
);
|
||||
|
||||
let module_name: InlinableString = module_name.into();
|
||||
let module_name = ModuleName::from(module_name_str);
|
||||
let ident = Ident::from(ident);
|
||||
|
||||
match self.module_ids.get_id(&module_name) {
|
||||
Some(&module_id) => {
|
||||
let ident: InlinableString = ident.into();
|
||||
|
||||
// You can do qualified lookups on your own module, e.g.
|
||||
// if I'm in the Foo module, I can do a `Foo.bar` lookup.
|
||||
if module_id == self.home {
|
||||
|
@ -114,7 +112,7 @@ impl<'a> Env<'a> {
|
|||
Ok(symbol)
|
||||
}
|
||||
None => Err(RuntimeError::ValueNotExposed {
|
||||
module_name: ModuleName::from(module_name),
|
||||
module_name,
|
||||
ident,
|
||||
region,
|
||||
}),
|
||||
|
|
|
@ -98,7 +98,7 @@ where
|
|||
// Here we essentially add those "defs" to "the beginning of the module"
|
||||
// by canonicalizing them right before we canonicalize the actual ast::Def nodes.
|
||||
for (ident, (symbol, region)) in exposed_imports {
|
||||
let first_char = ident.as_inline_str().chars().next().unwrap();
|
||||
let first_char = ident.as_inline_str().as_str().chars().next().unwrap();
|
||||
|
||||
if first_char.is_lowercase() {
|
||||
// this is a value definition
|
||||
|
|
|
@ -89,7 +89,7 @@ impl Scope {
|
|||
None => Err(RuntimeError::LookupNotInScope(
|
||||
Located {
|
||||
region,
|
||||
value: ident.clone().into(),
|
||||
value: ident.clone(),
|
||||
},
|
||||
self.idents.keys().map(|v| v.as_ref().into()).collect(),
|
||||
)),
|
||||
|
@ -124,9 +124,9 @@ impl Scope {
|
|||
// If this IdentId was already added previously
|
||||
// when the value was exposed in the module header,
|
||||
// use that existing IdentId. Otherwise, create a fresh one.
|
||||
let ident_id = match exposed_ident_ids.get_id(ident.as_inline_str()) {
|
||||
let ident_id = match exposed_ident_ids.get_id(&ident) {
|
||||
Some(ident_id) => *ident_id,
|
||||
None => all_ident_ids.add(ident.clone().into()),
|
||||
None => all_ident_ids.add(ident.clone()),
|
||||
};
|
||||
|
||||
let symbol = Symbol::new(self.home, ident_id);
|
||||
|
@ -143,7 +143,7 @@ impl Scope {
|
|||
///
|
||||
/// Used for record guards like { x: Just _ }
|
||||
pub fn ignore(&mut self, ident: Ident, all_ident_ids: &mut IdentIds) -> Symbol {
|
||||
let ident_id = all_ident_ids.add(ident.into());
|
||||
let ident_id = all_ident_ids.add(ident);
|
||||
Symbol::new(self.home, ident_id)
|
||||
}
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
|
|||
bumpalo::collections::Vec::from_iter_in(it.take(argument_types.len()), env.arena);
|
||||
|
||||
for (argument, name) in arguments.iter().zip(ARGUMENT_SYMBOLS.iter()) {
|
||||
argument.set_name(name.ident_string(&env.interns));
|
||||
argument.set_name(name.as_str(&env.interns));
|
||||
}
|
||||
|
||||
match arguments.as_slice() {
|
||||
|
@ -245,13 +245,13 @@ fn build_transform_caller_help<'a, 'ctx, 'env>(
|
|||
|
||||
let mut it = function_value.get_param_iter();
|
||||
let closure_ptr = it.next().unwrap().into_pointer_value();
|
||||
closure_ptr.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
closure_ptr.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
|
||||
let arguments =
|
||||
bumpalo::collections::Vec::from_iter_in(it.take(argument_layouts.len()), env.arena);
|
||||
|
||||
for (argument, name) in arguments.iter().zip(ARGUMENT_SYMBOLS[1..].iter()) {
|
||||
argument.set_name(name.ident_string(&env.interns));
|
||||
argument.set_name(name.as_str(&env.interns));
|
||||
}
|
||||
|
||||
let mut arguments_cast =
|
||||
|
@ -439,7 +439,7 @@ fn build_rc_wrapper<'a, 'ctx, 'env>(
|
|||
let mut it = function_value.get_param_iter();
|
||||
let value_ptr = it.next().unwrap().into_pointer_value();
|
||||
|
||||
value_ptr.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value_ptr.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
|
||||
let value_type = basic_type_from_layout(env, layout).ptr_type(AddressSpace::Generic);
|
||||
|
||||
|
@ -457,7 +457,7 @@ fn build_rc_wrapper<'a, 'ctx, 'env>(
|
|||
}
|
||||
Mode::IncN => {
|
||||
let n = it.next().unwrap().into_int_value();
|
||||
n.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
n.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
increment_n_refcount_layout(env, function_value, layout_ids, n, value, layout);
|
||||
}
|
||||
|
@ -521,8 +521,8 @@ pub fn build_eq_wrapper<'a, 'ctx, 'env>(
|
|||
let value_ptr1 = it.next().unwrap().into_pointer_value();
|
||||
let value_ptr2 = it.next().unwrap().into_pointer_value();
|
||||
|
||||
value_ptr1.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value_ptr2.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
value_ptr1.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
value_ptr2.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let value_type = basic_type_from_layout(env, layout).ptr_type(AddressSpace::Generic);
|
||||
|
||||
|
@ -602,9 +602,9 @@ pub fn build_compare_wrapper<'a, 'ctx, 'env>(
|
|||
let value_ptr1 = it.next().unwrap().into_pointer_value();
|
||||
let value_ptr2 = it.next().unwrap().into_pointer_value();
|
||||
|
||||
closure_ptr.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value_ptr1.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
value_ptr2.set_name(Symbol::ARG_3.ident_string(&env.interns));
|
||||
closure_ptr.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
value_ptr1.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
value_ptr2.set_name(Symbol::ARG_3.as_str(&env.interns));
|
||||
|
||||
let value_type = basic_type_from_layout(env, layout);
|
||||
let value_ptr_type = value_type.ptr_type(AddressSpace::Generic);
|
||||
|
|
|
@ -2997,7 +2997,7 @@ fn expose_function_to_host<'a, 'ctx, 'env>(
|
|||
roc_function: FunctionValue<'ctx>,
|
||||
) {
|
||||
// Assumption: there is only one specialization of a host-exposed function
|
||||
let ident_string = symbol.ident_string(&env.interns);
|
||||
let ident_string = symbol.as_str(&env.interns);
|
||||
let c_function_name: String = format!("roc__{}_1_exposed", ident_string);
|
||||
|
||||
expose_function_to_host_help(env, ident_string, roc_function, &c_function_name);
|
||||
|
@ -3005,7 +3005,7 @@ fn expose_function_to_host<'a, 'ctx, 'env>(
|
|||
|
||||
fn expose_function_to_host_help<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
ident_string: &inlinable_string::InlinableString,
|
||||
ident_string: &str,
|
||||
roc_function: FunctionValue<'ctx>,
|
||||
c_function_name: &str,
|
||||
) -> FunctionValue<'ctx> {
|
||||
|
@ -3485,7 +3485,7 @@ fn func_spec_name<'a>(
|
|||
|
||||
let mut buf = bumpalo::collections::String::with_capacity_in(1, arena);
|
||||
|
||||
let ident_string = symbol.ident_string(interns);
|
||||
let ident_string = symbol.as_str(interns);
|
||||
let module_string = interns.module_ids.get_name(symbol.module_id()).unwrap();
|
||||
write!(buf, "{}_{}_", module_string, ident_string).unwrap();
|
||||
|
||||
|
@ -3554,7 +3554,7 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
let function_name = format!(
|
||||
"roc__{}_{}_caller",
|
||||
def_name,
|
||||
alias_symbol.ident_string(&env.interns)
|
||||
alias_symbol.as_str(&env.interns)
|
||||
);
|
||||
|
||||
let mut argument_types = Vec::with_capacity_in(arguments.len() + 3, env.arena);
|
||||
|
@ -3667,14 +3667,14 @@ fn build_host_exposed_alias_size_help<'a, 'ctx, 'env>(
|
|||
format!(
|
||||
"roc__{}_{}_{}_size",
|
||||
def_name,
|
||||
alias_symbol.ident_string(&env.interns),
|
||||
alias_symbol.as_str(&env.interns),
|
||||
label
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"roc__{}_{}_size",
|
||||
def_name,
|
||||
alias_symbol.ident_string(&env.interns)
|
||||
alias_symbol.as_str(&env.interns)
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -3741,7 +3741,7 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
|||
&top_level.result,
|
||||
);
|
||||
|
||||
let ident_string = proc.name.ident_string(&env.interns);
|
||||
let ident_string = proc.name.as_str(&env.interns);
|
||||
let fn_name: String = format!("{}_1", ident_string);
|
||||
|
||||
build_closure_caller(
|
||||
|
@ -3770,7 +3770,7 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
|||
|
||||
// Add args to scope
|
||||
for (arg_val, (layout, arg_symbol)) in fn_val.get_param_iter().zip(args) {
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
scope.insert(*arg_symbol, (*layout, arg_val));
|
||||
}
|
||||
|
||||
|
|
|
@ -830,8 +830,8 @@ fn build_hash_wrapper<'a, 'ctx, 'env>(
|
|||
let seed_arg = it.next().unwrap().into_int_value();
|
||||
let value_ptr = it.next().unwrap().into_pointer_value();
|
||||
|
||||
seed_arg.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value_ptr.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
seed_arg.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
value_ptr.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let value_type = basic_type_from_layout(env, layout).ptr_type(AddressSpace::Generic);
|
||||
|
||||
|
|
|
@ -236,8 +236,8 @@ fn build_hash_struct_help<'a, 'ctx, 'env>(
|
|||
let seed = it.next().unwrap().into_int_value();
|
||||
let value = it.next().unwrap().into_struct_value();
|
||||
|
||||
seed.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
seed.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
value.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let entry = ctx.append_basic_block(parent, "entry");
|
||||
env.builder.position_at_end(entry);
|
||||
|
@ -377,8 +377,8 @@ fn build_hash_tag_help<'a, 'ctx, 'env>(
|
|||
let seed = it.next().unwrap().into_int_value();
|
||||
let value = it.next().unwrap();
|
||||
|
||||
seed.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
seed.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
value.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let entry = ctx.append_basic_block(parent, "entry");
|
||||
env.builder.position_at_end(entry);
|
||||
|
@ -716,8 +716,8 @@ fn build_hash_list_help<'a, 'ctx, 'env>(
|
|||
let seed = it.next().unwrap().into_int_value();
|
||||
let value = it.next().unwrap().into_struct_value();
|
||||
|
||||
seed.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
value.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
seed.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
value.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let entry = ctx.append_basic_block(parent, "entry");
|
||||
env.builder.position_at_end(entry);
|
||||
|
|
|
@ -436,8 +436,8 @@ fn build_list_eq_help<'a, 'ctx, 'env>(
|
|||
let list1 = it.next().unwrap().into_struct_value();
|
||||
let list2 = it.next().unwrap().into_struct_value();
|
||||
|
||||
list1.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
list2.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
list1.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
list2.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let entry = ctx.append_basic_block(parent, "entry");
|
||||
env.builder.position_at_end(entry);
|
||||
|
@ -644,8 +644,8 @@ fn build_struct_eq_help<'a, 'ctx, 'env>(
|
|||
let struct1 = it.next().unwrap().into_struct_value();
|
||||
let struct2 = it.next().unwrap().into_struct_value();
|
||||
|
||||
struct1.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
struct2.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
struct1.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
struct2.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let entry = ctx.append_basic_block(parent, "entry");
|
||||
let start = ctx.append_basic_block(parent, "start");
|
||||
|
@ -825,8 +825,8 @@ fn build_tag_eq_help<'a, 'ctx, 'env>(
|
|||
let tag1 = it.next().unwrap();
|
||||
let tag2 = it.next().unwrap();
|
||||
|
||||
tag1.set_name(Symbol::ARG_1.ident_string(&env.interns));
|
||||
tag2.set_name(Symbol::ARG_2.ident_string(&env.interns));
|
||||
tag1.set_name(Symbol::ARG_1.as_str(&env.interns));
|
||||
tag2.set_name(Symbol::ARG_2.as_str(&env.interns));
|
||||
|
||||
let entry = ctx.append_basic_block(parent, "entry");
|
||||
|
||||
|
|
|
@ -399,7 +399,7 @@ fn modify_refcount_struct_help<'a, 'ctx, 'env>(
|
|||
let arg_symbol = Symbol::ARG_1;
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
|
||||
|
@ -781,7 +781,7 @@ fn modify_refcount_list_help<'a, 'ctx, 'env>(
|
|||
let arg_symbol = Symbol::ARG_1;
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
let original_wrapper = arg_val.into_struct_value();
|
||||
|
@ -900,7 +900,7 @@ fn modify_refcount_str_help<'a, 'ctx, 'env>(
|
|||
let arg_symbol = Symbol::ARG_1;
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
|
||||
|
@ -1019,7 +1019,7 @@ fn modify_refcount_dict_help<'a, 'ctx, 'env>(
|
|||
let arg_symbol = Symbol::ARG_1;
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
|
||||
|
@ -1226,7 +1226,7 @@ fn build_rec_union_help<'a, 'ctx, 'env>(
|
|||
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
|
||||
|
@ -1574,7 +1574,7 @@ fn build_reuse_rec_union_help<'a, 'ctx, 'env>(
|
|||
|
||||
let arg_val = reset_function.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = reset_function;
|
||||
|
||||
|
@ -1732,7 +1732,7 @@ fn modify_refcount_union_help<'a, 'ctx, 'env>(
|
|||
let arg_symbol = Symbol::ARG_1;
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.ident_string(&env.interns));
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
|
||||
|
|
|
@ -207,6 +207,14 @@ impl Default for IdentStr {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for IdentStr {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for IdentStr {
|
||||
fn from(str: &str) -> Self {
|
||||
Self::from_slice(str.as_bytes())
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::docs::TypeAnnotation::{
|
|||
Apply, BoundVariable, Function, NoTypeAnn, ObscuredRecord, ObscuredTagUnion, Record, TagUnion,
|
||||
};
|
||||
use crate::file::LoadedModule;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_can::scope::Scope;
|
||||
use roc_module::ident::ModuleName;
|
||||
use roc_module::symbol::IdentIds;
|
||||
|
@ -169,10 +168,7 @@ fn generate_entry_doc<'a>(
|
|||
Def::Annotation(loc_pattern, _loc_ann) => match loc_pattern.value {
|
||||
Pattern::Identifier(identifier) => {
|
||||
// Check if the definition is exposed
|
||||
if ident_ids
|
||||
.get_id(&InlinableString::from(identifier))
|
||||
.is_some()
|
||||
{
|
||||
if ident_ids.get_id(&identifier.into()).is_some() {
|
||||
let doc_def = DocDef {
|
||||
name: identifier.to_string(),
|
||||
type_annotation: NoTypeAnn,
|
||||
|
@ -193,10 +189,7 @@ fn generate_entry_doc<'a>(
|
|||
} => match ann_pattern.value {
|
||||
Pattern::Identifier(identifier) => {
|
||||
// Check if the definition is exposed
|
||||
if ident_ids
|
||||
.get_id(&InlinableString::from(identifier))
|
||||
.is_some()
|
||||
{
|
||||
if ident_ids.get_id(&identifier.into()).is_some() {
|
||||
let doc_def = DocDef {
|
||||
name: identifier.to_string(),
|
||||
type_annotation: type_to_docs(false, ann_type.value),
|
||||
|
|
|
@ -2837,10 +2837,8 @@ fn send_header<'a>(
|
|||
let mut ident_ids_by_module = (*ident_ids_by_module).lock();
|
||||
|
||||
let name = match opt_shorthand {
|
||||
Some(shorthand) => {
|
||||
PQModuleName::Qualified(shorthand, declared_name.as_inline_str().clone())
|
||||
}
|
||||
None => PQModuleName::Unqualified(declared_name.as_inline_str().clone()),
|
||||
Some(shorthand) => PQModuleName::Qualified(shorthand, declared_name),
|
||||
None => PQModuleName::Unqualified(declared_name),
|
||||
};
|
||||
home = module_ids.get_or_insert(&name);
|
||||
|
||||
|
@ -2859,13 +2857,11 @@ fn send_header<'a>(
|
|||
let pq_module_name = match qualified_module_name.opt_package {
|
||||
None => match opt_shorthand {
|
||||
Some(shorthand) => {
|
||||
PQModuleName::Qualified(shorthand, qualified_module_name.module.into())
|
||||
PQModuleName::Qualified(shorthand, qualified_module_name.module)
|
||||
}
|
||||
None => PQModuleName::Unqualified(qualified_module_name.module.into()),
|
||||
None => PQModuleName::Unqualified(qualified_module_name.module),
|
||||
},
|
||||
Some(package) => {
|
||||
PQModuleName::Qualified(package, cloned_module_name.clone().into())
|
||||
}
|
||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name),
|
||||
};
|
||||
|
||||
let module_id = module_ids.get_or_insert(&pq_module_name);
|
||||
|
@ -2881,7 +2877,7 @@ fn send_header<'a>(
|
|||
.or_insert_with(IdentIds::default);
|
||||
|
||||
for ident in exposed_idents {
|
||||
let ident_id = ident_ids.get_or_insert(ident.as_inline_str());
|
||||
let ident_id = ident_ids.get_or_insert(&ident);
|
||||
let symbol = Symbol::new(module_id, ident_id);
|
||||
|
||||
// Since this value is exposed, add it to our module's default scope.
|
||||
|
@ -3011,8 +3007,6 @@ fn send_header_two<'a>(
|
|||
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
|
||||
module_timing: ModuleTiming,
|
||||
) -> (ModuleId, Msg<'a>) {
|
||||
use inlinable_string::InlinableString;
|
||||
|
||||
let PlatformHeaderInfo {
|
||||
filename,
|
||||
shorthand,
|
||||
|
@ -3025,7 +3019,7 @@ fn send_header_two<'a>(
|
|||
imports,
|
||||
} = info;
|
||||
|
||||
let declared_name: InlinableString = "".into();
|
||||
let declared_name: ModuleName = "".into();
|
||||
|
||||
let mut imported: Vec<(QualifiedModuleName, Vec<Ident>, Region)> =
|
||||
Vec::with_capacity(imports.len());
|
||||
|
@ -3082,10 +3076,8 @@ fn send_header_two<'a>(
|
|||
for (qualified_module_name, exposed_idents, region) in imported.into_iter() {
|
||||
let cloned_module_name = qualified_module_name.module.clone();
|
||||
let pq_module_name = match qualified_module_name.opt_package {
|
||||
None => PQModuleName::Qualified(shorthand, qualified_module_name.module.into()),
|
||||
Some(package) => {
|
||||
PQModuleName::Qualified(package, cloned_module_name.clone().into())
|
||||
}
|
||||
None => PQModuleName::Qualified(shorthand, qualified_module_name.module),
|
||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name.clone()),
|
||||
};
|
||||
|
||||
let module_id = module_ids.get_or_insert(&pq_module_name);
|
||||
|
@ -3101,7 +3093,7 @@ fn send_header_two<'a>(
|
|||
.or_insert_with(IdentIds::default);
|
||||
|
||||
for ident in exposed_idents {
|
||||
let ident_id = ident_ids.get_or_insert(ident.as_inline_str());
|
||||
let ident_id = ident_ids.get_or_insert(&ident);
|
||||
let symbol = Symbol::new(module_id, ident_id);
|
||||
|
||||
// Since this value is exposed, add it to our module's default scope.
|
||||
|
@ -3118,7 +3110,7 @@ fn send_header_two<'a>(
|
|||
|
||||
for (loc_ident, _) in unpack_exposes_entries(arena, requires) {
|
||||
let ident: Ident = loc_ident.value.into();
|
||||
let ident_id = ident_ids.get_or_insert(ident.as_inline_str());
|
||||
let ident_id = ident_ids.get_or_insert(&ident);
|
||||
let symbol = Symbol::new(app_module_id, ident_id);
|
||||
|
||||
// Since this value is exposed, add it to our module's default scope.
|
||||
|
@ -3185,7 +3177,7 @@ fn send_header_two<'a>(
|
|||
let module_name = ModuleNameEnum::PkgConfig;
|
||||
|
||||
let main_for_host = {
|
||||
let ident_str: InlinableString = provides[0].value.as_str().into();
|
||||
let ident_str: Ident = provides[0].value.as_str().into();
|
||||
let ident_id = ident_ids.get_or_insert(&ident_str);
|
||||
|
||||
Symbol::new(home, ident_id)
|
||||
|
@ -3426,7 +3418,10 @@ fn fabricate_effects_module<'a>(
|
|||
|
||||
for exposed in header.exposes {
|
||||
if let ExposesEntry::Exposed(module_name) = exposed.value {
|
||||
module_ids.get_or_insert(&PQModuleName::Qualified(shorthand, module_name.into()));
|
||||
module_ids.get_or_insert(&PQModuleName::Qualified(
|
||||
shorthand,
|
||||
module_name.as_str().into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3436,7 +3431,7 @@ fn fabricate_effects_module<'a>(
|
|||
let mut module_ids = (*module_ids).lock();
|
||||
let mut ident_ids_by_module = (*ident_ids_by_module).lock();
|
||||
|
||||
let name = PQModuleName::Qualified(shorthand, declared_name.as_inline_str().clone());
|
||||
let name = PQModuleName::Qualified(shorthand, declared_name);
|
||||
module_id = module_ids.get_or_insert(&name);
|
||||
|
||||
// Ensure this module has an entry in the exposed_ident_ids map.
|
||||
|
|
|
@ -17,7 +17,6 @@ mod helpers;
|
|||
mod test_load {
|
||||
use crate::helpers::fixtures_dir;
|
||||
use bumpalo::Bump;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_can::builtins::builtin_defs_map;
|
||||
use roc_can::def::Declaration::*;
|
||||
use roc_can::def::Def;
|
||||
|
@ -169,8 +168,8 @@ mod test_load {
|
|||
.expect("Test ModuleID not found in module_ids");
|
||||
|
||||
// App module names are hardcoded and not based on anything user-specified
|
||||
if expected_name != ModuleName::APP {
|
||||
assert_eq!(expected_name, &InlinableString::from(module_name));
|
||||
if expected_name.as_str() != ModuleName::APP {
|
||||
assert_eq!(&expected_name.as_str(), &module_name);
|
||||
}
|
||||
|
||||
loaded_module
|
||||
|
@ -340,7 +339,7 @@ mod test_load {
|
|||
.get_name(loaded_module.module_id)
|
||||
.expect("Test ModuleID not found in module_ids");
|
||||
|
||||
assert_eq!(expected_name, &InlinableString::from("Primary"));
|
||||
assert_eq!(expected_name.as_str(), "Primary");
|
||||
assert_eq!(def_count, 10);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use crate::symbol::{Interns, ModuleId, Symbol};
|
||||
use inlinable_string::InlinableString;
|
||||
pub use roc_ident::IdentStr;
|
||||
use std::fmt;
|
||||
|
||||
/// This could be uppercase or lowercase, qualified or unqualified.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Ident(InlinableString);
|
||||
pub struct Ident(IdentStr);
|
||||
|
||||
impl Ident {
|
||||
pub fn as_inline_str(&self) -> &InlinableString {
|
||||
pub fn as_inline_str(&self) -> &IdentStr {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
@ -18,19 +19,27 @@ pub struct QualifiedModuleName<'a> {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ModuleName(InlinableString);
|
||||
pub struct ModuleName(IdentStr);
|
||||
|
||||
impl std::ops::Deref for ModuleName {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
/// An uncapitalized identifier, such as a field name or local variable
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Lowercase(roc_ident::IdentStr);
|
||||
pub struct Lowercase(IdentStr);
|
||||
|
||||
/// A capitalized identifier, such as a tag name or module name
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Uppercase(roc_ident::IdentStr);
|
||||
pub struct Uppercase(IdentStr);
|
||||
|
||||
/// A string representing a foreign (linked-in) symbol
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
pub struct ForeignSymbol(InlinableString);
|
||||
pub struct ForeignSymbol(IdentStr);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum TagName {
|
||||
|
@ -52,11 +61,15 @@ pub enum TagName {
|
|||
}
|
||||
|
||||
impl TagName {
|
||||
pub fn as_string(&self, interns: &Interns, home: ModuleId) -> InlinableString {
|
||||
pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr {
|
||||
match self {
|
||||
TagName::Global(uppercase) => uppercase.as_inline_str().as_str().clone().into(),
|
||||
TagName::Private(symbol) => symbol.fully_qualified(interns, home),
|
||||
TagName::Closure(symbol) => symbol.fully_qualified(interns, home),
|
||||
TagName::Global(uppercase) => uppercase.as_ident_str().clone(),
|
||||
TagName::Private(symbol) => {
|
||||
symbol.fully_qualified(interns, home).as_ident_str().clone()
|
||||
}
|
||||
TagName::Closure(symbol) => {
|
||||
symbol.fully_qualified(interns, home).as_ident_str().clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +87,10 @@ impl ModuleName {
|
|||
pub const RESULT: &'static str = "Result";
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&*self.0
|
||||
self.0.as_str()
|
||||
}
|
||||
|
||||
pub fn as_inline_str(&self) -> &InlinableString {
|
||||
pub fn as_ident_str(&self) -> &IdentStr {
|
||||
&self.0
|
||||
}
|
||||
|
||||
|
@ -99,6 +112,12 @@ impl<'a> From<&'a str> for ModuleName {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<IdentStr> for ModuleName {
|
||||
fn from(string: IdentStr) -> Self {
|
||||
Self(string.as_str().into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<str>> for ModuleName {
|
||||
fn from(string: Box<str>) -> Self {
|
||||
Self((string.as_ref()).into())
|
||||
|
@ -111,36 +130,24 @@ impl From<String> for ModuleName {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<InlinableString> for ModuleName {
|
||||
fn from(string: InlinableString) -> Self {
|
||||
Self(string)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ModuleName> for InlinableString {
|
||||
fn from(name: ModuleName) -> Self {
|
||||
name.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ModuleName> for &'a InlinableString {
|
||||
fn from(name: &'a ModuleName) -> Self {
|
||||
&name.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ModuleName> for Box<str> {
|
||||
fn from(name: ModuleName) -> Self {
|
||||
name.0.to_string().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ForeignSymbol {
|
||||
pub fn as_str(&self) -> &str {
|
||||
&*self.0
|
||||
impl fmt::Display for ModuleName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_inline_str(&self) -> &InlinableString {
|
||||
impl ForeignSymbol {
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.0.as_str()
|
||||
}
|
||||
|
||||
pub fn as_inline_str(&self) -> &IdentStr {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +169,7 @@ impl Uppercase {
|
|||
self.0.as_str()
|
||||
}
|
||||
|
||||
pub fn as_inline_str(&self) -> &roc_ident::IdentStr {
|
||||
pub fn as_ident_str(&self) -> &IdentStr {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +213,7 @@ impl From<Lowercase> for InlinableString {
|
|||
impl AsRef<str> for Ident {
|
||||
#[inline(always)]
|
||||
fn as_ref(&self) -> &str {
|
||||
self.0.as_ref()
|
||||
self.0.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,19 +235,19 @@ impl From<String> for Ident {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<InlinableString> for Ident {
|
||||
fn from(string: InlinableString) -> Self {
|
||||
impl From<IdentStr> for Ident {
|
||||
fn from(string: IdentStr) -> Self {
|
||||
Self(string)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ident> for InlinableString {
|
||||
impl From<Ident> for IdentStr {
|
||||
fn from(ident: Ident) -> Self {
|
||||
ident.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Ident> for &'a InlinableString {
|
||||
impl<'a> From<&'a Ident> for &'a IdentStr {
|
||||
fn from(ident: &'a Ident) -> Self {
|
||||
&ident.0
|
||||
}
|
||||
|
@ -252,6 +259,12 @@ impl From<Ident> for Box<str> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Ident {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// Rather than displaying as this:
|
||||
///
|
||||
/// Lowercase("foo")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::ident::Ident;
|
||||
use inlinable_string::InlinableString;
|
||||
use crate::ident::{Ident, ModuleName};
|
||||
use roc_collections::all::{default_hasher, MutMap, SendMap};
|
||||
use roc_ident::IdentStr;
|
||||
use roc_region::all::Region;
|
||||
use std::collections::HashMap;
|
||||
use std::{fmt, u32};
|
||||
|
@ -52,7 +52,7 @@ impl Symbol {
|
|||
self.module_id().is_builtin()
|
||||
}
|
||||
|
||||
pub fn module_string<'a>(&self, interns: &'a Interns) -> &'a InlinableString {
|
||||
pub fn module_string<'a>(&self, interns: &'a Interns) -> &'a ModuleName {
|
||||
interns
|
||||
.module_ids
|
||||
.get_name(self.module_id())
|
||||
|
@ -65,7 +65,11 @@ impl Symbol {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn ident_string(self, interns: &Interns) -> &InlinableString {
|
||||
pub fn as_str(self, interns: &Interns) -> &str {
|
||||
self.ident_str(interns).as_str()
|
||||
}
|
||||
|
||||
pub fn ident_str(self, interns: &Interns) -> &IdentStr {
|
||||
let ident_ids = interns
|
||||
.all_ident_ids
|
||||
.get(&self.module_id())
|
||||
|
@ -77,30 +81,33 @@ impl Symbol {
|
|||
)
|
||||
});
|
||||
|
||||
ident_ids.get_name(self.ident_id()).unwrap_or_else(|| {
|
||||
ident_ids
|
||||
.get_name(self.ident_id())
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"ident_string's IdentIds did not contain an entry for {} in module {:?}",
|
||||
self.ident_id().0,
|
||||
self.module_id()
|
||||
)
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn as_u64(self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn fully_qualified(self, interns: &Interns, home: ModuleId) -> InlinableString {
|
||||
pub fn fully_qualified(self, interns: &Interns, home: ModuleId) -> ModuleName {
|
||||
let module_id = self.module_id();
|
||||
|
||||
if module_id == home {
|
||||
self.ident_string(interns).clone()
|
||||
self.ident_str(interns).clone().into()
|
||||
} else {
|
||||
// TODO do this without format! to avoid allocation for short strings
|
||||
format!(
|
||||
"{}.{}",
|
||||
self.module_string(interns),
|
||||
self.ident_string(interns)
|
||||
self.module_string(interns).as_str(),
|
||||
self.ident_str(interns)
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
@ -209,11 +216,11 @@ pub struct Interns {
|
|||
}
|
||||
|
||||
impl Interns {
|
||||
pub fn module_id(&mut self, name: &InlinableString) -> ModuleId {
|
||||
pub fn module_id(&mut self, name: &ModuleName) -> ModuleId {
|
||||
self.module_ids.get_or_insert(name)
|
||||
}
|
||||
|
||||
pub fn module_name(&self, module_id: ModuleId) -> &InlinableString {
|
||||
pub fn module_name(&self, module_id: ModuleId) -> &ModuleName {
|
||||
self.module_ids.get_name(module_id).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Unable to find interns entry for module_id {:?} in Interns {:?}",
|
||||
|
@ -222,7 +229,9 @@ impl Interns {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn symbol(&self, module_id: ModuleId, ident: InlinableString) -> Symbol {
|
||||
pub fn symbol(&self, module_id: ModuleId, ident: IdentStr) -> Symbol {
|
||||
let ident: Ident = ident.into();
|
||||
|
||||
match self.all_ident_ids.get(&module_id) {
|
||||
Some(ident_ids) => match ident_ids.get_id(&ident) {
|
||||
Some(ident_id) => Symbol::new(module_id, *ident_id),
|
||||
|
@ -278,7 +287,7 @@ impl ModuleId {
|
|||
// This is a no-op that should get DCE'd
|
||||
}
|
||||
|
||||
pub fn to_string(self, interns: &Interns) -> &InlinableString {
|
||||
pub fn to_ident_str(self, interns: &Interns) -> &ModuleName {
|
||||
interns
|
||||
.module_ids
|
||||
.get_name(self)
|
||||
|
@ -338,7 +347,7 @@ pub enum PackageQualified<'a, T> {
|
|||
}
|
||||
|
||||
/// Package-qualified module name
|
||||
pub type PQModuleName<'a> = PackageQualified<'a, InlinableString>;
|
||||
pub type PQModuleName<'a> = PackageQualified<'a, ModuleName>;
|
||||
|
||||
impl<'a, T> PackageQualified<'a, T> {
|
||||
pub fn as_inner(&self) -> &T {
|
||||
|
@ -377,13 +386,13 @@ impl<'a> PackageModuleIds<'a> {
|
|||
}
|
||||
|
||||
pub fn into_module_ids(self) -> ModuleIds {
|
||||
let by_name: MutMap<InlinableString, ModuleId> = self
|
||||
let by_name: MutMap<ModuleName, ModuleId> = self
|
||||
.by_name
|
||||
.into_iter()
|
||||
.map(|(pqname, module_id)| (pqname.as_inner().clone(), module_id))
|
||||
.collect();
|
||||
|
||||
let by_id: Vec<InlinableString> = self
|
||||
let by_id: Vec<ModuleName> = self
|
||||
.by_id
|
||||
.into_iter()
|
||||
.map(|pqname| pqname.as_inner().clone())
|
||||
|
@ -399,9 +408,9 @@ impl<'a> PackageModuleIds<'a> {
|
|||
names
|
||||
.entry(module_id.0)
|
||||
.or_insert_with(|| match module_name {
|
||||
PQModuleName::Unqualified(module) => module.to_string().into(),
|
||||
PQModuleName::Unqualified(module) => module.as_str().into(),
|
||||
PQModuleName::Qualified(package, module) => {
|
||||
let name = format!("{}.{}", package, module).into();
|
||||
let name = format!("{}.{}", package, module.as_str()).into();
|
||||
name
|
||||
}
|
||||
});
|
||||
|
@ -431,13 +440,13 @@ impl<'a> PackageModuleIds<'a> {
|
|||
/// Since these are interned strings, this shouldn't result in many total allocations in practice.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ModuleIds {
|
||||
by_name: MutMap<InlinableString, ModuleId>,
|
||||
by_name: MutMap<ModuleName, ModuleId>,
|
||||
/// Each ModuleId is an index into this Vec
|
||||
by_id: Vec<InlinableString>,
|
||||
by_id: Vec<ModuleName>,
|
||||
}
|
||||
|
||||
impl ModuleIds {
|
||||
pub fn get_or_insert(&mut self, module_name: &InlinableString) -> ModuleId {
|
||||
pub fn get_or_insert(&mut self, module_name: &ModuleName) -> ModuleId {
|
||||
match self.by_name.get(module_name) {
|
||||
Some(id) => *id,
|
||||
None => {
|
||||
|
@ -458,29 +467,29 @@ impl ModuleIds {
|
|||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn insert_debug_name(module_id: ModuleId, module_name: &InlinableString) {
|
||||
fn insert_debug_name(module_id: ModuleId, module_name: &ModuleName) {
|
||||
let mut names = DEBUG_MODULE_ID_NAMES.lock().expect("Failed to acquire lock for Debug interning into DEBUG_MODULE_ID_NAMES, presumably because a thread panicked.");
|
||||
|
||||
// TODO make sure modules are never added more than once!
|
||||
names
|
||||
.entry(module_id.0)
|
||||
.or_insert_with(|| module_name.to_string().into());
|
||||
.or_insert_with(|| module_name.as_str().to_string().into());
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn insert_debug_name(_module_id: ModuleId, _module_name: &InlinableString) {
|
||||
fn insert_debug_name(_module_id: ModuleId, _module_name: &ModuleName) {
|
||||
// By design, this is a no-op in release builds!
|
||||
}
|
||||
|
||||
pub fn get_id(&self, module_name: &InlinableString) -> Option<&ModuleId> {
|
||||
pub fn get_id(&self, module_name: &ModuleName) -> Option<&ModuleId> {
|
||||
self.by_name.get(module_name)
|
||||
}
|
||||
|
||||
pub fn get_name(&self, id: ModuleId) -> Option<&InlinableString> {
|
||||
pub fn get_name(&self, id: ModuleId) -> Option<&ModuleName> {
|
||||
self.by_id.get(id.0 as usize)
|
||||
}
|
||||
|
||||
pub fn available_modules(&self) -> impl Iterator<Item = &InlinableString> {
|
||||
pub fn available_modules(&self) -> impl Iterator<Item = &ModuleName> {
|
||||
self.by_id.iter()
|
||||
}
|
||||
}
|
||||
|
@ -500,23 +509,23 @@ pub struct IdentId(u32);
|
|||
/// Since these are interned strings, this shouldn't result in many total allocations in practice.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct IdentIds {
|
||||
by_ident: MutMap<InlinableString, IdentId>,
|
||||
by_ident: MutMap<Ident, IdentId>,
|
||||
|
||||
/// Each IdentId is an index into this Vec
|
||||
by_id: Vec<InlinableString>,
|
||||
by_id: Vec<Ident>,
|
||||
|
||||
next_generated_name: u32,
|
||||
}
|
||||
|
||||
impl IdentIds {
|
||||
pub fn idents(&self) -> impl Iterator<Item = (IdentId, &InlinableString)> {
|
||||
pub fn idents(&self) -> impl Iterator<Item = (IdentId, &Ident)> {
|
||||
self.by_id
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, ident)| (IdentId(index as u32), ident))
|
||||
}
|
||||
|
||||
pub fn add(&mut self, ident_name: InlinableString) -> IdentId {
|
||||
pub fn add(&mut self, ident_name: Ident) -> IdentId {
|
||||
let by_id = &mut self.by_id;
|
||||
let ident_id = IdentId(by_id.len() as u32);
|
||||
|
||||
|
@ -526,7 +535,7 @@ impl IdentIds {
|
|||
ident_id
|
||||
}
|
||||
|
||||
pub fn get_or_insert(&mut self, name: &InlinableString) -> IdentId {
|
||||
pub fn get_or_insert(&mut self, name: &Ident) -> IdentId {
|
||||
match self.by_ident.get(name) {
|
||||
Some(id) => *id,
|
||||
None => {
|
||||
|
@ -542,7 +551,7 @@ impl IdentIds {
|
|||
}
|
||||
}
|
||||
|
||||
/// Generates a unique, new name that's just a strigified integer
|
||||
/// Generates a unique, new name that's just a stringified integer
|
||||
/// (e.g. "1" or "5"), using an internal counter. Since valid Roc variable
|
||||
/// names cannot begin with a number, this has no chance of colliding
|
||||
/// with actual user-defined variables.
|
||||
|
@ -550,7 +559,7 @@ impl IdentIds {
|
|||
/// This is used, for example, during canonicalization of an Expr::Closure
|
||||
/// to generate a unique symbol to refer to that closure.
|
||||
pub fn gen_unique(&mut self) -> IdentId {
|
||||
// TODO convert this directly from u32 into InlinableString,
|
||||
// TODO convert this directly from u32 into IdentStr,
|
||||
// without allocating an extra string along the way like this.
|
||||
let ident = self.next_generated_name.to_string().into();
|
||||
|
||||
|
@ -559,11 +568,11 @@ impl IdentIds {
|
|||
self.add(ident)
|
||||
}
|
||||
|
||||
pub fn get_id(&self, ident_name: &InlinableString) -> Option<&IdentId> {
|
||||
pub fn get_id(&self, ident_name: &Ident) -> Option<&IdentId> {
|
||||
self.by_ident.get(ident_name)
|
||||
}
|
||||
|
||||
pub fn get_name(&self, id: IdentId) -> Option<&InlinableString> {
|
||||
pub fn get_name(&self, id: IdentId) -> Option<&Ident> {
|
||||
self.by_id.get(id.0 as usize)
|
||||
}
|
||||
}
|
||||
|
@ -655,7 +664,7 @@ macro_rules! define_builtins {
|
|||
let mut by_id = Vec::with_capacity(capacity);
|
||||
|
||||
let mut insert_both = |id: ModuleId, name_str: &'static str| {
|
||||
let name: InlinableString = name_str.into();
|
||||
let name: ModuleName = name_str.into();
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
Self::insert_debug_name(id, &name);
|
||||
|
@ -682,8 +691,8 @@ macro_rules! define_builtins {
|
|||
let mut by_id = Vec::with_capacity(capacity);
|
||||
|
||||
let mut insert_both = |id: ModuleId, name_str: &'static str| {
|
||||
let raw_name: InlinableString = name_str.into();
|
||||
let name = PQModuleName::Unqualified(raw_name);
|
||||
let raw_name: IdentStr = name_str.into();
|
||||
let name = PQModuleName::Unqualified(raw_name.into());
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
Self::insert_debug_name(id, &name);
|
||||
|
|
|
@ -2084,7 +2084,7 @@ impl LayoutId {
|
|||
// Returns something like "foo#1" when given a symbol that interns to "foo"
|
||||
// and a LayoutId of 1.
|
||||
pub fn to_symbol_string(self, symbol: Symbol, interns: &Interns) -> String {
|
||||
let ident_string = symbol.ident_string(interns);
|
||||
let ident_string = symbol.ident_str(interns);
|
||||
let module_string = interns.module_ids.get_name(symbol.module_id()).unwrap();
|
||||
format!("{}_{}_{}", module_string, ident_string, self.0)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use inlinable_string::InlinableString;
|
||||
use roc_collections::all::MutSet;
|
||||
use roc_module::ident::{Ident, Lowercase, ModuleName, TagName};
|
||||
use roc_module::operator::BinOp;
|
||||
|
@ -135,14 +134,14 @@ pub enum RuntimeError {
|
|||
UnresolvedTypeVar,
|
||||
ErroneousType,
|
||||
|
||||
LookupNotInScope(Located<InlinableString>, MutSet<Box<str>>),
|
||||
LookupNotInScope(Located<Ident>, MutSet<Box<str>>),
|
||||
ValueNotExposed {
|
||||
module_name: ModuleName,
|
||||
ident: InlinableString,
|
||||
ident: Ident,
|
||||
region: Region,
|
||||
},
|
||||
ModuleNotImported {
|
||||
module_name: InlinableString,
|
||||
module_name: ModuleName,
|
||||
imported_modules: MutSet<Box<str>>,
|
||||
region: Region,
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use roc_collections::all::MutSet;
|
||||
use roc_module::ident::Lowercase;
|
||||
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
||||
use roc_parse::parser::{Col, Row};
|
||||
use roc_problem::can::PrecedenceProblem::BothNonAssociative;
|
||||
use roc_problem::can::{BadPattern, FloatErrorKind, IntErrorKind, Problem, RuntimeError};
|
||||
|
@ -1002,13 +1002,16 @@ fn to_circular_def_doc<'b>(
|
|||
fn not_found<'b>(
|
||||
alloc: &'b RocDocAllocator<'b>,
|
||||
region: roc_region::all::Region,
|
||||
name: &str,
|
||||
name: &Ident,
|
||||
thing: &'b str,
|
||||
options: MutSet<Box<str>>,
|
||||
) -> RocDocBuilder<'b> {
|
||||
use crate::error::r#type::suggest;
|
||||
|
||||
let mut suggestions = suggest::sort(name, options.iter().map(|v| v.as_ref()).collect());
|
||||
let mut suggestions = suggest::sort(
|
||||
name.as_inline_str().as_str(),
|
||||
options.iter().map(|v| v.as_ref()).collect(),
|
||||
);
|
||||
suggestions.truncate(4);
|
||||
|
||||
let default_no = alloc.concat(vec![
|
||||
|
@ -1049,12 +1052,13 @@ fn not_found<'b>(
|
|||
fn module_not_found<'b>(
|
||||
alloc: &'b RocDocAllocator<'b>,
|
||||
region: roc_region::all::Region,
|
||||
name: &str,
|
||||
name: &ModuleName,
|
||||
options: MutSet<Box<str>>,
|
||||
) -> RocDocBuilder<'b> {
|
||||
use crate::error::r#type::suggest;
|
||||
|
||||
let mut suggestions = suggest::sort(name, options.iter().map(|v| v.as_ref()).collect());
|
||||
let mut suggestions =
|
||||
suggest::sort(name.as_str(), options.iter().map(|v| v.as_ref()).collect());
|
||||
suggestions.truncate(4);
|
||||
|
||||
let default_no = alloc.concat(vec![
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use roc_can::expected::{Expected, PExpected};
|
||||
use roc_collections::all::{Index, MutSet, SendMap};
|
||||
use roc_module::ident::{Lowercase, TagName};
|
||||
use roc_module::ident::{IdentStr, Lowercase, TagName};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_solve::solve;
|
||||
use roc_types::pretty_print::Parens;
|
||||
|
@ -1312,6 +1312,12 @@ pub mod suggest {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToStr for super::IdentStr {
|
||||
fn to_str(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, B> ToStr for (A, B)
|
||||
where
|
||||
A: ToStr,
|
||||
|
@ -2426,11 +2432,11 @@ fn type_problem_to_pretty<'b>(
|
|||
}
|
||||
},
|
||||
TagTypo(typo, possibilities_tn) => {
|
||||
let possibilities = possibilities_tn
|
||||
let possibilities: Vec<IdentStr> = possibilities_tn
|
||||
.into_iter()
|
||||
.map(|tag_name| tag_name.as_string(alloc.interns, alloc.home))
|
||||
.map(|tag_name| tag_name.as_ident_str(alloc.interns, alloc.home))
|
||||
.collect();
|
||||
let typo_str = format!("{}", typo.as_string(alloc.interns, alloc.home));
|
||||
let typo_str = format!("{}", typo.as_ident_str(alloc.interns, alloc.home));
|
||||
let suggestions = suggest::sort(&typo_str, possibilities);
|
||||
|
||||
match suggestions.get(0) {
|
||||
|
|
|
@ -259,19 +259,19 @@ impl<'a> RocDocAllocator<'a> {
|
|||
}
|
||||
|
||||
pub fn symbol_unqualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
|
||||
self.text(format!("{}", symbol.ident_string(self.interns)))
|
||||
self.text(format!("{}", symbol.ident_str(self.interns)))
|
||||
.annotate(Annotation::Symbol)
|
||||
}
|
||||
pub fn symbol_foreign_qualified(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
|
||||
if symbol.module_id() == self.home || symbol.module_id().is_builtin() {
|
||||
// Render it unqualified if it's in the current module or a builtin
|
||||
self.text(format!("{}", symbol.ident_string(self.interns)))
|
||||
self.text(format!("{}", symbol.ident_str(self.interns)))
|
||||
.annotate(Annotation::Symbol)
|
||||
} else {
|
||||
self.text(format!(
|
||||
"{}.{}",
|
||||
symbol.module_string(self.interns),
|
||||
symbol.ident_string(self.interns),
|
||||
symbol.ident_str(self.interns),
|
||||
))
|
||||
.annotate(Annotation::Symbol)
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ impl<'a> RocDocAllocator<'a> {
|
|||
self.text(format!(
|
||||
"{}.{}",
|
||||
symbol.module_string(self.interns),
|
||||
symbol.ident_string(self.interns),
|
||||
symbol.ident_str(self.interns),
|
||||
))
|
||||
.annotate(Annotation::Symbol)
|
||||
}
|
||||
|
@ -288,13 +288,13 @@ impl<'a> RocDocAllocator<'a> {
|
|||
pub fn private_tag_name(&'a self, symbol: Symbol) -> DocBuilder<'a, Self, Annotation> {
|
||||
if symbol.module_id() == self.home {
|
||||
// Render it unqualified if it's in the current module.
|
||||
self.text(format!("{}", symbol.ident_string(self.interns)))
|
||||
self.text(format!("{}", symbol.ident_str(self.interns)))
|
||||
.annotate(Annotation::PrivateTag)
|
||||
} else {
|
||||
self.text(format!(
|
||||
"{}.{}",
|
||||
symbol.module_string(self.interns),
|
||||
symbol.ident_string(self.interns),
|
||||
symbol.ident_str(self.interns),
|
||||
))
|
||||
.annotate(Annotation::PrivateTag)
|
||||
}
|
||||
|
|
|
@ -4500,6 +4500,6 @@ mod solve_expr {
|
|||
);
|
||||
|
||||
// without RecordFields in FlatType assert_eq!((40, 72, 56, 48, 64), query)
|
||||
assert_eq!((24, 104, 88, 80, 64), query)
|
||||
assert_eq!((24, 104, 88, 80, 48), query)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1882,7 +1882,7 @@ fn hof_conditional() {
|
|||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Roc failed with message: \"Shadowing { original_region: |L 3-3, C 4-5|, shadow: |L 6-6, C 8-9| Ident(\\\"x\\\") }\""
|
||||
expected = "Roc failed with message: \"Shadowing { original_region: |L 3-3, C 4-5|, shadow: |L 6-6, C 8-9| Ident"
|
||||
)]
|
||||
fn pattern_shadowing() {
|
||||
assert_evals_to!(
|
||||
|
@ -2361,7 +2361,7 @@ fn backpassing_result() {
|
|||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Shadowing { original_region: |L 3-3, C 4-5|, shadow: |L 5-5, C 6-7| Ident(\\\"x\\\") }"
|
||||
expected = "Shadowing { original_region: |L 3-3, C 4-5|, shadow: |L 5-5, C 6-7| Ident"
|
||||
)]
|
||||
fn function_malformed_pattern() {
|
||||
assert_evals_to!(
|
||||
|
|
|
@ -369,8 +369,10 @@ fn write_sorted_tags<'a>(
|
|||
let interns = &env.interns;
|
||||
let home = env.home;
|
||||
|
||||
sorted_fields
|
||||
.sort_by(|(a, _), (b, _)| a.as_string(interns, home).cmp(&b.as_string(interns, home)));
|
||||
sorted_fields.sort_by(|(a, _), (b, _)| {
|
||||
a.as_ident_str(interns, home)
|
||||
.cmp(&b.as_ident_str(interns, home))
|
||||
});
|
||||
|
||||
let mut any_written_yet = false;
|
||||
|
||||
|
@ -381,7 +383,7 @@ fn write_sorted_tags<'a>(
|
|||
any_written_yet = true;
|
||||
}
|
||||
|
||||
buf.push_str(&label.as_string(interns, home));
|
||||
buf.push_str(label.as_ident_str(interns, home).as_str());
|
||||
|
||||
for var in vars {
|
||||
buf.push(' ');
|
||||
|
@ -715,15 +717,15 @@ fn write_fn(
|
|||
|
||||
fn write_symbol(env: &Env, symbol: Symbol, buf: &mut String) {
|
||||
let interns = &env.interns;
|
||||
let ident = symbol.ident_string(interns);
|
||||
let ident = symbol.ident_str(interns);
|
||||
let module_id = symbol.module_id();
|
||||
|
||||
// Don't qualify the symbol if it's in our home module,
|
||||
// or if it's a builtin (since all their types are always in scope)
|
||||
if module_id != env.home && !module_id.is_builtin() {
|
||||
buf.push_str(module_id.to_string(interns));
|
||||
buf.push_str(module_id.to_ident_str(interns).as_str());
|
||||
buf.push('.');
|
||||
}
|
||||
|
||||
buf.push_str(ident);
|
||||
buf.push_str(ident.as_str());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::pretty_print::Parens;
|
||||
use crate::subs::{LambdaSet, RecordFields, Subs, VarStore, Variable};
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_collections::all::{ImMap, ImSet, Index, MutSet, SendMap};
|
||||
use roc_module::ident::{ForeignSymbol, Ident, Lowercase, TagName};
|
||||
use roc_module::low_level::LowLevel;
|
||||
|
@ -1118,7 +1117,7 @@ pub enum Problem {
|
|||
CanonicalizationProblem,
|
||||
CircularType(Symbol, Box<ErrorType>, Region),
|
||||
CyclicAlias(Symbol, Region, Vec<Symbol>),
|
||||
UnrecognizedIdent(InlinableString),
|
||||
UnrecognizedIdent(Ident),
|
||||
Shadowed(Region, Located<Ident>),
|
||||
BadTypeArguments {
|
||||
symbol: Symbol,
|
||||
|
@ -1196,7 +1195,7 @@ fn write_error_type_help(
|
|||
if write_parens {
|
||||
buf.push('(');
|
||||
}
|
||||
buf.push_str(symbol.ident_string(interns));
|
||||
buf.push_str(symbol.ident_str(interns).as_str());
|
||||
|
||||
for arg in arguments {
|
||||
buf.push(' ');
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
|
|||
let exposed_values = loaded_module
|
||||
.exposed_values
|
||||
.iter()
|
||||
.map(|symbol| symbol.ident_string(&loaded_module.interns).to_string())
|
||||
.map(|symbol| symbol.ident_str(&loaded_module.interns).to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
(exposed_values, d)
|
||||
|
@ -77,7 +77,7 @@ pub fn generate(filenames: Vec<PathBuf>, std_lib: StdLib, build_dir: &Path) {
|
|||
|
||||
// TODO should this also include exposed_aliases?
|
||||
for symbol in loaded_module.exposed_values.iter() {
|
||||
exports.push(symbol.ident_string(&loaded_module.interns));
|
||||
exports.push(symbol.ident_str(&loaded_module.interns));
|
||||
}
|
||||
|
||||
let exports = exports.into_bump_slice();
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
use bumpalo::{collections::Vec as BumpVec, Bump};
|
||||
use inlinable_string::InlinableString;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::lang::ast::{
|
||||
|
@ -22,8 +21,7 @@ use roc_can::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int
|
|||
use roc_can::operator::desugar_expr;
|
||||
use roc_collections::all::default_hasher;
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::ident::Lowercase;
|
||||
use roc_module::ident::ModuleName;
|
||||
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::operator::CalledVia;
|
||||
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
|
||||
|
@ -200,11 +198,11 @@ impl<'a> Env<'a> {
|
|||
ident
|
||||
);
|
||||
|
||||
let module_name: InlinableString = module_name.into();
|
||||
let module_name: ModuleName = module_name.into();
|
||||
|
||||
match self.module_ids.get_id(&module_name) {
|
||||
Some(&module_id) => {
|
||||
let ident: InlinableString = ident.into();
|
||||
let ident: Ident = ident.into();
|
||||
|
||||
// You can do qualified lookups on your own module, e.g.
|
||||
// if I'm in the Foo module, I can do a `Foo.bar` lookup.
|
||||
|
|
|
@ -232,7 +232,7 @@ impl Scope {
|
|||
// If this IdentId was already added previously
|
||||
// when the value was exposed in the module header,
|
||||
// use that existing IdentId. Otherwise, create a fresh one.
|
||||
let ident_id = match exposed_ident_ids.get_id(&ident.as_inline_str()) {
|
||||
let ident_id = match exposed_ident_ids.get_id(&ident) {
|
||||
Some(ident_id) => *ident_id,
|
||||
None => all_ident_ids.add(ident.clone().into()),
|
||||
};
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
use crate::lang::expr::Env;
|
||||
use crate::lang::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
|
||||
use crate::lang::scope::Scope;
|
||||
use inlinable_string::InlinableString;
|
||||
// use roc_can::expr::Output;
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_module::ident::{Ident, TagName};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue