mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Implement derivation keys for tuple encoders
This commit is contained in:
parent
a361c4cfc1
commit
e5fcb05a2d
3 changed files with 20 additions and 3 deletions
|
@ -5,7 +5,7 @@ use roc_module::{
|
|||
use roc_types::subs::{Content, FlatType, GetSubsSlice, Subs, Variable};
|
||||
|
||||
use crate::{
|
||||
util::{check_derivable_ext_var, debug_name_record, debug_name_tag},
|
||||
util::{check_derivable_ext_var, debug_name_record, debug_name_tag, debug_name_tuple},
|
||||
DeriveError,
|
||||
};
|
||||
|
||||
|
@ -22,6 +22,7 @@ pub enum FlatEncodableKey {
|
|||
Dict(/* takes two variables */),
|
||||
// Unfortunate that we must allocate here, c'est la vie
|
||||
Record(Vec<Lowercase>),
|
||||
Tuple(u32),
|
||||
TagUnion(Vec<(TagName, u16)>),
|
||||
}
|
||||
|
||||
|
@ -32,6 +33,7 @@ impl FlatEncodableKey {
|
|||
FlatEncodableKey::Set() => "set".to_string(),
|
||||
FlatEncodableKey::Dict() => "dict".to_string(),
|
||||
FlatEncodableKey::Record(fields) => debug_name_record(fields),
|
||||
FlatEncodableKey::Tuple(arity) => debug_name_tuple(*arity),
|
||||
FlatEncodableKey::TagUnion(tags) => debug_name_tag(tags),
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +68,14 @@ impl FlatEncodable {
|
|||
|
||||
Ok(Key(FlatEncodableKey::Record(field_names)))
|
||||
}
|
||||
FlatType::Tuple(_elems, _ext) => {
|
||||
todo!()
|
||||
FlatType::Tuple(elems, ext) => {
|
||||
let (elems_iter, ext) = elems.sorted_iterator_and_ext(subs, ext);
|
||||
|
||||
check_derivable_ext_var(subs, ext, |ext| {
|
||||
matches!(ext, Content::Structure(FlatType::EmptyTuple))
|
||||
})?;
|
||||
|
||||
Ok(Key(FlatEncodableKey::Tuple(elems_iter.count() as _)))
|
||||
}
|
||||
FlatType::TagUnion(tags, ext) | FlatType::RecursiveTagUnion(_, tags, ext) => {
|
||||
// The recursion var doesn't matter, because the derived implementation will only
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue