Merge pull request #1524 from rtfeldman/use-ident-str

Use ident str
This commit is contained in:
Richard Feldman 2021-08-03 23:46:35 -04:00 committed by GitHub
commit 3576224f75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 304 additions and 308 deletions

17
Cargo.lock generated
View File

@ -3037,7 +3037,6 @@ dependencies = [
"im 14.3.0",
"im-rc 14.3.0",
"indoc 0.3.6",
"inlinable_string",
"maplit",
"pretty_assertions 0.5.1",
"quickcheck 0.8.5",
@ -3065,7 +3064,6 @@ dependencies = [
"im-rc 14.3.0",
"indoc 0.3.6",
"inkwell 0.1.0",
"inlinable_string",
"libc",
"libloading 0.6.7",
"maplit",
@ -3162,7 +3160,6 @@ dependencies = [
"im 15.0.0",
"im-rc 15.0.0",
"indoc 1.0.3",
"inlinable_string",
"libc",
"log",
"maplit",
@ -3204,7 +3201,6 @@ dependencies = [
"im 14.3.0",
"im-rc 14.3.0",
"indoc 0.3.6",
"inlinable_string",
"maplit",
"pretty_assertions 0.5.1",
"quickcheck 0.8.5",
@ -3223,7 +3219,6 @@ dependencies = [
"im 14.3.0",
"im-rc 14.3.0",
"indoc 0.3.6",
"inlinable_string",
"itertools 0.9.0",
"libc",
"libloading 0.6.7",
@ -3262,7 +3257,6 @@ dependencies = [
"im-rc 14.3.0",
"indoc 0.3.6",
"inkwell 0.1.0",
"inlinable_string",
"libc",
"maplit",
"morphic_lib",
@ -3299,7 +3293,6 @@ dependencies = [
"bumpalo",
"crossbeam",
"indoc 0.3.6",
"inlinable_string",
"maplit",
"morphic_lib",
"num_cpus",
@ -3330,12 +3323,13 @@ version = "0.1.0"
dependencies = [
"bumpalo",
"indoc 0.3.6",
"inlinable_string",
"lazy_static",
"maplit",
"pretty_assertions 0.5.1",
"roc_collections",
"roc_ident",
"roc_region",
"static_assertions",
]
[[package]]
@ -3374,7 +3368,6 @@ dependencies = [
"bumpalo",
"encode_unicode",
"indoc 0.3.6",
"inlinable_string",
"pretty_assertions 0.5.1",
"quickcheck 0.8.5",
"quickcheck_macros 0.8.0",
@ -3388,7 +3381,6 @@ name = "roc_problem"
version = "0.1.0"
dependencies = [
"indoc 0.3.6",
"inlinable_string",
"maplit",
"pretty_assertions 0.5.1",
"quickcheck 0.8.5",
@ -3412,7 +3404,6 @@ dependencies = [
"im 14.3.0",
"im-rc 14.3.0",
"indoc 0.3.6",
"inlinable_string",
"maplit",
"pretty_assertions 0.5.1",
"quickcheck 0.8.5",
@ -3464,7 +3455,6 @@ name = "roc_types"
version = "0.1.0"
dependencies = [
"indoc 0.3.6",
"inlinable_string",
"maplit",
"pretty_assertions 0.5.1",
"quickcheck 0.8.5",
@ -3472,6 +3462,7 @@ dependencies = [
"roc_collections",
"roc_module",
"roc_region",
"static_assertions",
"ven_ena",
]
@ -3952,7 +3943,6 @@ dependencies = [
"im-rc 14.3.0",
"indoc 0.3.6",
"inkwell 0.1.0",
"inlinable_string",
"libc",
"libloading 0.6.7",
"maplit",
@ -3988,7 +3978,6 @@ dependencies = [
"im 14.3.0",
"im-rc 14.3.0",
"indoc 0.3.6",
"inlinable_string",
"libc",
"libloading 0.6.7",
"pretty_assertions 0.5.1",

View File

@ -63,7 +63,6 @@ rustyline-derive = { git = "https://github.com/rtfeldman/rustyline", tag = "prom
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.2", features = ["collections"] }
inlinable_string = "0.1"
libc = "0.2"
libloading = "0.6"

View File

@ -1,5 +1,4 @@
extern crate bumpalo;
extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;

View File

@ -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 {

View File

@ -2,7 +2,6 @@
extern crate pretty_assertions;
extern crate bumpalo;
extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;

View File

@ -17,7 +17,6 @@ ven_graph = { path = "../../vendor/pathfinding" }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -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 {

View File

@ -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,
}),

View File

@ -9,7 +9,6 @@ use crate::num::{
use crate::pattern::{canonicalize_pattern, Pattern};
use crate::procedure::References;
use crate::scope::Scope;
use inlinable_string::InlinableString;
use roc_collections::all::{ImSet, MutMap, MutSet, SendMap};
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel;
@ -58,7 +57,7 @@ pub enum Expr {
// Int and Float store a variable to generate better error messages
Int(Variable, Variable, i128),
Float(Variable, Variable, f64),
Str(InlinableString),
Str(Box<str>),
List {
elem_var: Variable,
loc_elems: Vec<Located<Expr>>,
@ -1574,7 +1573,7 @@ pub fn is_valid_interpolation(expr: &ast::Expr<'_>) -> bool {
enum StrSegment {
Interpolation(Located<Expr>),
Plaintext(InlinableString),
Plaintext(Box<str>),
}
fn flatten_str_lines<'a>(

View File

@ -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

View File

@ -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)
}

View File

@ -13,7 +13,6 @@ roc_parse = { path = "../parse" }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -21,7 +21,6 @@ roc_mono = { path = "../mono" }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
target-lexicon = "0.10"
libloading = "0.6"
object = { version = "0.24", features = ["write"] }

View File

@ -20,7 +20,6 @@ morphic_lib = { path = "../../vendor/morphic_lib" }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
inkwell = { path = "../../vendor/inkwell" }
target-lexicon = "0.10"

View File

@ -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);

View File

@ -596,12 +596,7 @@ fn promote_to_main_function<'a, 'ctx, 'env>(
let main_fn_name = "$Test.main";
// Add main to the module.
let main_fn = expose_function_to_host_help(
env,
&inlinable_string::InlinableString::from(main_fn_name),
roc_main_fn,
main_fn_name,
);
let main_fn = expose_function_to_host_help(env, main_fn_name, roc_main_fn, main_fn_name);
(main_fn_name, main_fn)
}
@ -2997,7 +2992,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 +3000,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 +3480,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 +3549,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 +3662,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 +3736,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 +3765,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));
}

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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;

View File

@ -24,7 +24,7 @@ use std::alloc::{GlobalAlloc, Layout, System};
#[cfg(target_endian = "little")]
#[repr(C)]
pub struct IdentStr {
elements: *mut u8,
elements: *const u8,
length: usize,
}
@ -207,12 +207,26 @@ 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())
}
}
impl From<String> for IdentStr {
fn from(str: String) -> Self {
Self::from_slice(str.as_bytes())
}
}
impl fmt::Debug for IdentStr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// IdentStr { is_small_str: false, storage: Refcounted(3), elements: [ 1,2,3,4] }
@ -223,6 +237,16 @@ impl fmt::Debug for IdentStr {
}
}
impl fmt::Display for IdentStr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// IdentStr { is_small_str: false, storage: Refcounted(3), elements: [ 1,2,3,4] }
f.write_str(self.as_str())
}
}
unsafe impl std::marker::Sync for IdentStr {}
unsafe impl std::marker::Send for IdentStr {}
impl PartialEq for IdentStr {
fn eq(&self, other: &Self) -> bool {
self.as_slice() == other.as_slice()
@ -231,6 +255,27 @@ impl PartialEq for IdentStr {
impl Eq for IdentStr {}
impl PartialOrd for IdentStr {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.as_str().partial_cmp(other.as_str())
}
}
impl Ord for IdentStr {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.as_str().cmp(other.as_str())
}
}
impl std::hash::Hash for IdentStr {
fn hash<H>(&self, hasher: &mut H)
where
H: std::hash::Hasher,
{
self.as_str().hash(hasher)
}
}
impl Clone for IdentStr {
fn clone(&self) -> Self {
if self.is_small_str() || self.is_empty() {
@ -270,7 +315,7 @@ impl Drop for IdentStr {
let align = mem::align_of::<u8>();
let layout = Layout::from_size_align_unchecked(self.length, align);
System.dealloc(self.elements, layout);
System.dealloc(self.elements as *mut _, layout);
}
}
}

View File

@ -22,7 +22,6 @@ roc_reporting = { path = "../reporting" }
morphic_lib = { path = "../../vendor/morphic_lib" }
ven_pretty = { path = "../../vendor/pretty" }
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
parking_lot = { version = "0.11", features = ["deadlock_detection"] }
crossbeam = "0.7"
num_cpus = "1"

View File

@ -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),

View File

@ -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.

View File

@ -6,7 +6,6 @@ extern crate pretty_assertions;
extern crate maplit;
extern crate bumpalo;
extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;
@ -17,7 +16,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 +167,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 +338,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);
}

View File

@ -7,10 +7,11 @@ license = "UPL-1.0"
[dependencies]
roc_region = { path = "../region" }
roc_ident = { path = "../ident" }
roc_collections = { path = "../collections" }
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
lazy_static = "1.4"
static_assertions = "1.1.0"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -1,13 +1,13 @@
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,24 +18,32 @@ 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(InlinableString);
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(InlinableString);
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 {
/// Global tags have no module, but tend to be short strings (since they're
/// never qualified), so we store them as inlinable strings.
/// never qualified), so we store them as ident strings.
///
/// This is allows canonicalization to happen in parallel without locks.
/// If global tags had a Symbol representation, then each module would have to
@ -51,12 +59,18 @@ pub enum TagName {
Closure(Symbol),
}
static_assertions::assert_eq_size!([u8; 24], 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().clone(),
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 +88,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 +113,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 +131,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 fmt::Display for ModuleName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl ForeignSymbol {
pub fn as_str(&self) -> &str {
&*self.0
self.0.as_str()
}
pub fn as_inline_str(&self) -> &InlinableString {
pub fn as_inline_str(&self) -> &IdentStr {
&self.0
}
}
@ -159,10 +167,10 @@ impl<'a> From<String> for ForeignSymbol {
impl Uppercase {
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
}
}
@ -181,7 +189,7 @@ impl<'a> From<String> for Uppercase {
impl Lowercase {
pub fn as_str(&self) -> &str {
&*self.0
self.0.as_str()
}
}
@ -197,16 +205,10 @@ impl<'a> From<String> for Lowercase {
}
}
impl From<Lowercase> for InlinableString {
fn from(lowercase: Lowercase) -> Self {
lowercase.0
}
}
impl AsRef<str> for Ident {
#[inline(always)]
fn as_ref(&self) -> &str {
self.0.as_ref()
self.0.as_str()
}
}
@ -228,19 +230,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 +254,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")

View File

@ -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(|| {
panic!(
"ident_string's IdentIds did not contain an entry for {} in module {:?}",
self.ident_id().0,
self.module_id()
)
})
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);

View File

@ -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)
}

View File

@ -10,7 +10,6 @@ roc_collections = { path = "../collections" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
encode_unicode = "0.3"
[dev-dependencies]

View File

@ -7,7 +7,6 @@ use crate::parser::{
};
use crate::string_literal;
use bumpalo::collections::Vec;
use inlinable_string::InlinableString;
use roc_region::all::Loc;
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@ -48,12 +47,6 @@ impl<'a> From<ModuleName<'a>> for &'a str {
}
}
impl<'a> From<ModuleName<'a>> for InlinableString {
fn from(name: ModuleName<'a>) -> InlinableString {
name.0.into()
}
}
impl<'a> ModuleName<'a> {
pub fn new(name: &'a str) -> Self {
ModuleName(name)

View File

@ -10,7 +10,6 @@ roc_collections = { path = "../collections" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
roc_parse = { path = "../parse" }
inlinable_string = "0.1"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -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,
},

View File

@ -16,7 +16,6 @@ roc_can = { path = "../can" }
roc_solve = { path = "../solve" }
roc_mono = { path = "../mono" }
ven_pretty = { path = "../../vendor/pretty" }
inlinable_string = "0.1"
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
distance = "0.4.0"

View File

@ -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![

View File

@ -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;
@ -1280,8 +1280,6 @@ fn problems_to_tip<'b>(
}
pub mod suggest {
use core::convert::AsRef;
use inlinable_string::InlinableString;
use roc_module::ident::Lowercase;
pub trait ToStr {
@ -1300,18 +1298,18 @@ pub mod suggest {
}
}
impl ToStr for InlinableString {
fn to_str(&self) -> &str {
self.as_ref()
}
}
impl ToStr for &str {
fn to_str(&self) -> &str {
self
}
}
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 +2424,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) {

View File

@ -1,4 +1,3 @@
use inlinable_string::InlinableString;
use roc_module::ident::Ident;
use roc_module::ident::{Lowercase, ModuleName, TagName, Uppercase};
use roc_module::symbol::{Interns, ModuleId, Symbol};
@ -259,19 +258,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 +279,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 +287,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)
}
@ -333,10 +332,6 @@ impl<'a> RocDocAllocator<'a> {
self.text(name).annotate(Annotation::Module)
}
pub fn inlinable_string(&'a self, s: InlinableString) -> DocBuilder<'a, Self, Annotation> {
self.text(format!("{}", s)).annotate(Annotation::Module)
}
pub fn binop(
&'a self,
content: roc_module::operator::BinOp,

View File

@ -4488,18 +4488,4 @@ mod solve_expr {
"RBTree {}",
);
}
#[test]
fn sizes() {
let query = (
std::mem::size_of::<roc_module::ident::TagName>(),
std::mem::size_of::<roc_types::subs::Descriptor>(),
std::mem::size_of::<roc_types::subs::Content>(),
std::mem::size_of::<roc_types::subs::FlatType>(),
std::mem::size_of::<roc_types::types::Problem>(),
);
// without RecordFields in FlatType assert_eq!((40, 72, 56, 48, 64), query)
assert_eq!((40, 104, 88, 80, 64), query)
}
}

View File

@ -26,7 +26,6 @@ roc_std = { path = "../../roc_std" }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
either = "1.6.1"
indoc = "0.3.3"
libc = "0.2"

View File

@ -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!(

View File

@ -25,7 +25,6 @@ test_mono_macros = { path = "../test_mono_macros" }
im = "14" # im and im-rc should always have the same version!
im-rc = "14" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
either = "1.6.1"
indoc = "0.3.3"
libc = "0.2"

View File

@ -10,7 +10,7 @@ roc_collections = { path = "../collections" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
ven_ena = { path = "../../vendor/ena" }
inlinable_string = "0.1"
static_assertions = "1.1.0"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -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());
}

View File

@ -7,6 +7,13 @@ use std::fmt;
use std::iter::{once, Extend, FromIterator, Iterator, Map, Zip};
use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey};
// if your changes cause this number to go down, great!
// please change it to the lower number.
// if it went up, maybe check that the change is really required
static_assertions::assert_eq_size!([u8; 104], Descriptor);
static_assertions::assert_eq_size!([u8; 88], Content);
static_assertions::assert_eq_size!([u8; 80], FlatType);
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct Mark(i32);
@ -494,7 +501,7 @@ fn unnamed_flex_var() -> Content {
}
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Rank(usize);
pub struct Rank(u32);
impl Rank {
pub const NONE: Rank = Rank(0);
@ -508,7 +515,7 @@ impl Rank {
}
pub fn into_usize(self) -> usize {
self.0
self.0 as usize
}
}
@ -526,13 +533,13 @@ impl fmt::Debug for Rank {
impl From<Rank> for usize {
fn from(rank: Rank) -> Self {
rank.0
rank.0 as usize
}
}
impl From<usize> for Rank {
fn from(index: usize) -> Self {
Rank(index)
Rank(index as u32)
}
}

View File

@ -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(' ');

View File

@ -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();

View File

@ -23,7 +23,6 @@ ven_graph = { path = "../vendor/pathfinding" }
im = "15" # im and im-rc should always have the same version!
im-rc = "15" # im and im-rc should always have the same version!
bumpalo = { version = "3.6.1", features = ["collections"] }
inlinable_string = "0.1"
arraystring = "0.3.0"
libc = "0.2"
page_size = "0.4"

View File

@ -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.

View File

@ -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()),
};

View File

@ -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};