mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Add derive key for Inspect
This commit is contained in:
parent
fb9e0fc777
commit
d0841fb018
6 changed files with 259 additions and 1 deletions
|
@ -16,12 +16,14 @@
|
|||
pub mod decoding;
|
||||
pub mod encoding;
|
||||
pub mod hash;
|
||||
pub mod inspect;
|
||||
mod util;
|
||||
|
||||
use decoding::{FlatDecodable, FlatDecodableKey};
|
||||
use encoding::{FlatEncodable, FlatEncodableKey};
|
||||
use hash::{FlatHash, FlatHashKey};
|
||||
|
||||
use inspect::{FlatInspectable, FlatInspectableKey};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_types::subs::{Subs, Variable};
|
||||
|
||||
|
@ -40,6 +42,7 @@ pub enum DeriveKey {
|
|||
ToEncoder(FlatEncodableKey),
|
||||
Decoder(FlatDecodableKey),
|
||||
Hash(FlatHashKey),
|
||||
ToInspector(FlatInspectableKey),
|
||||
}
|
||||
|
||||
impl DeriveKey {
|
||||
|
@ -48,6 +51,7 @@ impl DeriveKey {
|
|||
DeriveKey::ToEncoder(key) => format!("toEncoder_{}", key.debug_name()),
|
||||
DeriveKey::Decoder(key) => format!("decoder_{}", key.debug_name()),
|
||||
DeriveKey::Hash(key) => format!("hash_{}", key.debug_name()),
|
||||
DeriveKey::ToInspector(key) => format!("toInspector_{}", key.debug_name()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +81,7 @@ pub enum DeriveBuiltin {
|
|||
Decoder,
|
||||
Hash,
|
||||
IsEq,
|
||||
ToInspector,
|
||||
}
|
||||
|
||||
impl TryFrom<Symbol> for DeriveBuiltin {
|
||||
|
@ -88,6 +93,7 @@ impl TryFrom<Symbol> for DeriveBuiltin {
|
|||
Symbol::DECODE_DECODER => Ok(DeriveBuiltin::Decoder),
|
||||
Symbol::HASH_HASH => Ok(DeriveBuiltin::Hash),
|
||||
Symbol::BOOL_IS_EQ => Ok(DeriveBuiltin::IsEq),
|
||||
Symbol::INSPECT_TO_INSPECTOR => Ok(DeriveBuiltin::ToInspector),
|
||||
_ => Err(value),
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +127,10 @@ impl Derived {
|
|||
Symbol::BOOL_STRUCTURAL_EQ,
|
||||
))
|
||||
}
|
||||
DeriveBuiltin::ToInspector => match FlatInspectable::from_var(subs, var) {
|
||||
FlatInspectable::Immediate(imm) => Ok(Derived::Immediate(imm)),
|
||||
FlatInspectable::Key(repr) => Ok(Derived::Key(DeriveKey::ToInspector(repr))),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +161,12 @@ impl Derived {
|
|||
Symbol::BOOL_STRUCTURAL_EQ,
|
||||
))
|
||||
}
|
||||
DeriveBuiltin::ToInspector => {
|
||||
match inspect::FlatInspectable::from_builtin_alias(symbol).unwrap() {
|
||||
FlatInspectable::Immediate(imm) => Ok(Derived::Immediate(imm)),
|
||||
FlatInspectable::Key(repr) => Ok(Derived::Key(DeriveKey::ToInspector(repr))),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue