mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Merge remote-tracking branch 'origin/trunk' into array-wrappers
This commit is contained in:
commit
8d4331f903
41 changed files with 2057 additions and 723 deletions
|
@ -9,6 +9,14 @@ use std::{fmt, u32};
|
|||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Symbol(u64);
|
||||
|
||||
// When this is `true` (which it normally should be), Symbol's Debug::fmt implementation
|
||||
// attempts to pretty print debug symbols using interns recorded using
|
||||
// register_debug_idents calls (which should be made in debug mode).
|
||||
// Set it to false if you want to see the raw ModuleId and IdentId ints,
|
||||
// but please set it back to true before checking in the result!
|
||||
#[cfg(debug_assertions)]
|
||||
const PRETTY_PRINT_DEBUG_SYMBOLS: bool = true;
|
||||
|
||||
/// In Debug builds only, Symbol has a name() method that lets
|
||||
/// you look up its name in a global intern table. This table is
|
||||
/// behind a mutex, so it is neither populated nor available in release builds.
|
||||
|
@ -101,26 +109,30 @@ impl Symbol {
|
|||
impl fmt::Debug for Symbol {
|
||||
#[cfg(debug_assertions)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let module_id = self.module_id();
|
||||
let ident_id = self.ident_id();
|
||||
if PRETTY_PRINT_DEBUG_SYMBOLS {
|
||||
let module_id = self.module_id();
|
||||
let ident_id = self.ident_id();
|
||||
|
||||
match DEBUG_IDENT_IDS_BY_MODULE_ID.lock() {
|
||||
Ok(names) => match &names.get(&module_id.0) {
|
||||
Some(ident_ids) => match ident_ids.get_name(ident_id) {
|
||||
Some(ident_str) => write!(f, "`{:?}.{}`", module_id, ident_str),
|
||||
match DEBUG_IDENT_IDS_BY_MODULE_ID.lock() {
|
||||
Ok(names) => match &names.get(&module_id.0) {
|
||||
Some(ident_ids) => match ident_ids.get_name(ident_id) {
|
||||
Some(ident_str) => write!(f, "`{:?}.{}`", module_id, ident_str),
|
||||
None => fallback_debug_fmt(*self, f),
|
||||
},
|
||||
None => fallback_debug_fmt(*self, f),
|
||||
},
|
||||
None => fallback_debug_fmt(*self, f),
|
||||
},
|
||||
Err(err) => {
|
||||
// Print and return Err rather than panicking, because this
|
||||
// might be used in a panic error message, and if we panick
|
||||
// while we're already panicking it'll kill the process
|
||||
// without printing any of the errors!
|
||||
println!("DEBUG INFO: Failed to acquire lock for Debug reading from DEBUG_IDENT_IDS_BY_MODULE_ID, presumably because a thread panicked: {:?}", err);
|
||||
Err(err) => {
|
||||
// Print and return Err rather than panicking, because this
|
||||
// might be used in a panic error message, and if we panick
|
||||
// while we're already panicking it'll kill the process
|
||||
// without printing any of the errors!
|
||||
println!("DEBUG INFO: Failed to acquire lock for Debug reading from DEBUG_IDENT_IDS_BY_MODULE_ID, presumably because a thread panicked: {:?}", err);
|
||||
|
||||
fallback_debug_fmt(*self, f)
|
||||
fallback_debug_fmt(*self, f)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fallback_debug_fmt(*self, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -547,11 +559,13 @@ macro_rules! define_builtins {
|
|||
};
|
||||
}
|
||||
|
||||
// NOTE: Some of these builtins have a # at the beginning of their names.
|
||||
// This is because they are for compiler use only, and should not cause
|
||||
// namespace conflicts with userspace!
|
||||
define_builtins! {
|
||||
0 ATTR: "Attr" => {
|
||||
0 ATTR: "#Attr" => {
|
||||
0 UNDERSCORE: "_" // the _ used in pattern matches. This is Symbol 0.
|
||||
1 ATTR_ATTR: "Attr" // the Attr.Attr type alias, used in uniqueness types
|
||||
2 ATTR_AT_ATTR: "@Attr" // the Attr.@Attr private tag
|
||||
1 ATTR_ATTR: "Attr" // the #Attr.Attr type alias, used in uniqueness types.
|
||||
}
|
||||
1 NUM: "Num" => {
|
||||
0 NUM_NUM: "Num" imported // the Num.Num type alias
|
||||
|
@ -575,6 +589,8 @@ define_builtins! {
|
|||
4 INT_MOD: "mod"
|
||||
5 INT_HIGHEST: "highest"
|
||||
6 INT_LOWEST: "lowest"
|
||||
7 INT_ADD: "#add"
|
||||
8 INT_SUB: "#sub"
|
||||
}
|
||||
3 FLOAT: "Float" => {
|
||||
0 FLOAT_FLOAT: "Float" imported // the Float.Float type alias
|
||||
|
@ -585,6 +601,8 @@ define_builtins! {
|
|||
5 FLOAT_SQRT: "sqrt"
|
||||
6 FLOAT_HIGHEST: "highest"
|
||||
7 FLOAT_LOWEST: "lowest"
|
||||
8 FLOAT_ADD: "#add"
|
||||
9 FLOAT_SUB: "#sub"
|
||||
}
|
||||
4 BOOL: "Bool" => {
|
||||
0 BOOL_BOOL: "Bool" imported // the Bool.Bool type alias
|
||||
|
@ -606,7 +624,7 @@ define_builtins! {
|
|||
2 LIST_IS_EMPTY: "isEmpty"
|
||||
3 LIST_GET: "get"
|
||||
4 LIST_SET: "set"
|
||||
5 LIST_SET_IN_PLACE: "set_in_place"
|
||||
5 LIST_SET_IN_PLACE: "#setInPlace"
|
||||
6 LIST_PUSH: "push"
|
||||
7 LIST_MAP: "map"
|
||||
8 LIST_LEN: "len"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue