Skip to content

Commit cda43fd

Browse files
committed
feat(strings): make strings compatible with compact list
1 parent bfd3773 commit cda43fd

File tree

13 files changed

+772
-218
lines changed

13 files changed

+772
-218
lines changed

tfhe/src/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ impl Error {
2626
}
2727
}
2828

29+
#[cfg(feature = "integer")]
30+
macro_rules! error{
31+
($($arg:tt)*) => {
32+
$crate::error::Error::new(::std::format!($($arg)*))
33+
}
34+
}
35+
36+
#[cfg(feature = "integer")]
37+
pub(crate) use error;
38+
2939
impl Display for Error {
3040
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
3141
match self.kind() {

tfhe/src/high_level_api/compact_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl crate::FheTypes {
7474
}
7575
}
7676
DataKind::Boolean => Self::Bool,
77+
DataKind::String { .. } => return None,
7778
})
7879
}
7980
}

tfhe/src/high_level_api/compressed_ciphertext_list.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -590,25 +590,29 @@ pub mod gpu {
590590
Tag::default(),
591591
))
592592
} else {
593-
Err(crate::Error::new(format!(
593+
Err(crate::error!(
594594
"Tried to expand a FheUint{} while a FheUint{} is stored in this slot",
595595
Id::num_bits(),
596596
stored_num_bits
597-
)))
597+
))
598598
}
599599
}
600600
DataKind::Signed(_) => {
601601
let stored_num_bits = cuda_num_bits_of_blocks(&blocks) as usize;
602-
Err(crate::Error::new(format!(
602+
Err(crate::error!(
603603
"Tried to expand a FheUint{} while a FheInt{} is stored in this slot",
604604
Id::num_bits(),
605605
stored_num_bits
606-
)))
606+
))
607607
}
608-
DataKind::Boolean => Err(crate::Error::new(format!(
608+
DataKind::Boolean => Err(crate::error!(
609609
"Tried to expand a FheUint{} while a FheBool is stored in this slot",
610610
Id::num_bits(),
611-
))),
611+
)),
612+
DataKind::String { .. } => Err(crate::error!(
613+
"Tried to expand a FheUint{} while a FheString is stored in this slot",
614+
Id::num_bits()
615+
)),
612616
}
613617
}
614618
}
@@ -621,11 +625,11 @@ pub mod gpu {
621625
match kind {
622626
DataKind::Unsigned(_) => {
623627
let stored_num_bits = cuda_num_bits_of_blocks(&blocks) as usize;
624-
Err(crate::Error::new(format!(
628+
Err(crate::error!(
625629
"Tried to expand a FheInt{} while a FheUint{} is stored in this slot",
626630
Id::num_bits(),
627631
stored_num_bits
628-
)))
632+
))
629633
}
630634
DataKind::Signed(_) => {
631635
let stored_num_bits = cuda_num_bits_of_blocks(&blocks) as usize;
@@ -638,17 +642,21 @@ pub mod gpu {
638642
Tag::default(),
639643
))
640644
} else {
641-
Err(crate::Error::new(format!(
645+
Err(crate::error!(
642646
"Tried to expand a FheInt{} while a FheInt{} is stored in this slot",
643647
Id::num_bits(),
644648
stored_num_bits
645-
)))
649+
))
646650
}
647651
}
648-
DataKind::Boolean => Err(crate::Error::new(format!(
649-
"Tried to expand a FheUint{} while a FheBool is stored in this slot",
652+
DataKind::Boolean => Err(crate::error!(
653+
"Tried to expand a FheInt{} while a FheBool is stored in this slot",
650654
Id::num_bits(),
651-
))),
655+
)),
656+
DataKind::String { .. } => Err(crate::error!(
657+
"Tried to expand a FheInt{} while a FheString is stored in this slot",
658+
Id::num_bits()
659+
)),
652660
}
653661
}
654662
}
@@ -661,15 +669,15 @@ pub mod gpu {
661669
match kind {
662670
DataKind::Unsigned(_) => {
663671
let stored_num_bits = cuda_num_bits_of_blocks(&blocks) as usize;
664-
Err(crate::Error::new(format!(
672+
Err(crate::error!(
665673
"Tried to expand a FheBool while a FheUint{stored_num_bits} is stored in this slot",
666-
)))
674+
))
667675
}
668676
DataKind::Signed(_) => {
669677
let stored_num_bits = cuda_num_bits_of_blocks(&blocks) as usize;
670-
Err(crate::Error::new(format!(
678+
Err(crate::error!(
671679
"Tried to expand a FheBool while a FheInt{stored_num_bits} is stored in this slot",
672-
)))
680+
))
673681
}
674682
DataKind::Boolean => {
675683
let mut boolean_block = CudaBooleanBlock::from_cuda_radix_ciphertext(blocks);
@@ -680,6 +688,9 @@ pub mod gpu {
680688
// The expander will be responsible for setting the correct tag
681689
Ok(Self::new(boolean_block, Tag::default()))
682690
}
691+
DataKind::String { .. } => Err(crate::error!(
692+
"Tried to expand a FheBool while a FheString is stored in this slot"
693+
)),
683694
}
684695
}
685696
}

tfhe/src/high_level_api/utils.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@ impl<Id: FheUintId> Expandable for FheUint<Id> {
2424
Tag::default(),
2525
))
2626
} else {
27-
Err(crate::Error::new(format!(
27+
Err(crate::error!(
2828
"Tried to expand a FheUint{} while a FheUint{} is stored in this slot",
2929
Id::num_bits(),
3030
stored_num_bits
31-
)))
31+
))
3232
}
3333
}
3434
DataKind::Signed(_) => {
3535
let stored_num_bits = num_bits_of_blocks(&blocks) as usize;
36-
Err(crate::Error::new(format!(
36+
Err(crate::error!(
3737
"Tried to expand a FheUint{} while a FheInt{} is stored in this slot",
3838
Id::num_bits(),
3939
stored_num_bits
40-
)))
40+
))
4141
}
42-
DataKind::Boolean => Err(crate::Error::new(format!(
42+
DataKind::Boolean => Err(crate::error!(
4343
"Tried to expand a FheUint{} while a FheBool is stored in this slot",
4444
Id::num_bits(),
45-
))),
45+
)),
46+
DataKind::String { .. } => Err(crate::error!(
47+
"Tried to expand a FheUint{} while a string is stored in this slot",
48+
Id::num_bits()
49+
)),
4650
}
4751
}
4852
}
@@ -52,11 +56,11 @@ impl<Id: FheIntId> Expandable for FheInt<Id> {
5256
match kind {
5357
DataKind::Unsigned(_) => {
5458
let stored_num_bits = num_bits_of_blocks(&blocks) as usize;
55-
Err(crate::Error::new(format!(
59+
Err(crate::error!(
5660
"Tried to expand a FheInt{} while a FheUint{} is stored in this slot",
5761
Id::num_bits(),
5862
stored_num_bits
59-
)))
63+
))
6064
}
6165
DataKind::Signed(_) => {
6266
let stored_num_bits = num_bits_of_blocks(&blocks) as usize;
@@ -67,17 +71,21 @@ impl<Id: FheIntId> Expandable for FheInt<Id> {
6771
Tag::default(),
6872
))
6973
} else {
70-
Err(crate::Error::new(format!(
74+
Err(crate::error!(
7175
"Tried to expand a FheInt{} while a FheInt{} is stored in this slot",
7276
Id::num_bits(),
7377
stored_num_bits
74-
)))
78+
))
7579
}
7680
}
77-
DataKind::Boolean => Err(crate::Error::new(format!(
78-
"Tried to expand a FheUint{} while a FheBool is stored in this slot",
81+
DataKind::Boolean => Err(crate::error!(
82+
"Tried to expand a FheInt{} while a FheBool is stored in this slot",
7983
Id::num_bits(),
80-
))),
84+
)),
85+
DataKind::String { .. } => Err(crate::error!(
86+
"Tried to expand a FheInt{} while a string is stored in this slot",
87+
Id::num_bits()
88+
)),
8189
}
8290
}
8391
}
@@ -87,15 +95,15 @@ impl Expandable for FheBool {
8795
match kind {
8896
DataKind::Unsigned(_) => {
8997
let stored_num_bits = num_bits_of_blocks(&blocks) as usize;
90-
Err(crate::Error::new(format!(
98+
Err(crate::error!(
9199
"Tried to expand a FheBool while a FheUint{stored_num_bits} is stored in this slot",
92-
)))
100+
))
93101
}
94102
DataKind::Signed(_) => {
95103
let stored_num_bits = num_bits_of_blocks(&blocks) as usize;
96-
Err(crate::Error::new(format!(
104+
Err(crate::error!(
97105
"Tried to expand a FheBool while a FheInt{stored_num_bits} is stored in this slot",
98-
)))
106+
))
99107
}
100108
DataKind::Boolean => {
101109
let mut boolean_block = BooleanBlock::new_unchecked(blocks[0].clone());
@@ -105,6 +113,9 @@ impl Expandable for FheBool {
105113
// The expander will be responsible for setting the correct tag
106114
Ok(Self::new(boolean_block, Tag::default()))
107115
}
116+
DataKind::String { .. } => Err(crate::Error::new(
117+
"Tried to expand a FheBool while a string is stored in this slot".to_string(),
118+
)),
108119
}
109120
}
110121
}

0 commit comments

Comments
 (0)