mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Fast-path for determining ability member impls for builtin opaques
This commit is contained in:
parent
297a571b34
commit
e6094df69b
8 changed files with 182 additions and 60 deletions
|
@ -52,7 +52,7 @@ impl DeriveKey {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq, Eq, Debug)]
|
||||
#[derive(Hash, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum Derived {
|
||||
/// If a derived implementation name is well-known ahead-of-time, we can inline the symbol
|
||||
/// directly rather than associating a key for an implementation to be made later on.
|
||||
|
@ -123,4 +123,34 @@ impl Derived {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn builtin_with_builtin_symbol(
|
||||
builtin: DeriveBuiltin,
|
||||
symbol: Symbol,
|
||||
) -> Result<Self, DeriveError> {
|
||||
match builtin {
|
||||
DeriveBuiltin::ToEncoder => match encoding::FlatEncodable::from_builtin_symbol(symbol)?
|
||||
{
|
||||
FlatEncodable::Immediate(imm) => Ok(Derived::Immediate(imm)),
|
||||
FlatEncodable::Key(repr) => Ok(Derived::Key(DeriveKey::ToEncoder(repr))),
|
||||
},
|
||||
DeriveBuiltin::Decoder => match decoding::FlatDecodable::from_builtin_symbol(symbol)? {
|
||||
FlatDecodable::Immediate(imm) => Ok(Derived::Immediate(imm)),
|
||||
FlatDecodable::Key(repr) => Ok(Derived::Key(DeriveKey::Decoder(repr))),
|
||||
},
|
||||
DeriveBuiltin::Hash => match hash::FlatHash::from_builtin_symbol(symbol)? {
|
||||
FlatHash::SingleLambdaSetImmediate(imm) => {
|
||||
Ok(Derived::SingleLambdaSetImmediate(imm))
|
||||
}
|
||||
FlatHash::Key(repr) => Ok(Derived::Key(DeriveKey::Hash(repr))),
|
||||
},
|
||||
DeriveBuiltin::IsEq => {
|
||||
// If obligation checking passes, we always lower derived implementations of `isEq`
|
||||
// to the `Eq` low-level, to be fulfilled by the backends.
|
||||
Ok(Derived::SingleLambdaSetImmediate(
|
||||
Symbol::BOOL_STRUCTURAL_EQ,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue