Skip to content

Commit 605a393

Browse files
String -> Arc<str>
1 parent 9d78e7e commit 605a393

7 files changed

Lines changed: 33 additions & 26 deletions

File tree

src/aiur/bytecode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use rustc_hash::FxHashMap;
24

35
use crate::FxIndexMap;
@@ -7,7 +9,7 @@ use super::G;
79
pub struct Toplevel {
810
pub(crate) functions: Vec<Function>,
911
#[allow(dead_code)]
10-
pub(crate) filtered_functions: Vec<FxHashMap<String, Function>>,
12+
pub(crate) filtered_functions: Vec<FxHashMap<Arc<str>, Function>>,
1113
pub(crate) memory_sizes: Vec<usize>,
1214
}
1315

@@ -70,7 +72,7 @@ pub enum Op {
7072
#[derive(Clone)]
7173
pub enum Ctrl {
7274
Match(ValIdx, FxIndexMap<G, Block>, Option<Box<Block>>),
73-
Return(SelIdx, String, Vec<ValIdx>),
75+
Return(SelIdx, Arc<str>, Vec<ValIdx>),
7476
Yield(SelIdx, Vec<ValIdx>),
7577
MatchContinue(
7678
ValIdx,

src/aiur/execute.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use multi_stark::p3_field::{PrimeCharacteristicRing, PrimeField64};
22
use rustc_hash::FxHashMap;
33
use std::collections::hash_map::Entry;
4+
use std::sync::Arc;
45

56
use crate::{
67
FxIndexMap,
@@ -18,7 +19,7 @@ use crate::{
1819
pub struct QueryResult {
1920
pub(crate) output: Vec<G>,
2021
pub(crate) multiplicity: G,
21-
pub(crate) return_group: String,
22+
pub(crate) return_group: Arc<str>,
2223
}
2324

2425
pub type QueryMap = FxIndexMap<Vec<G>, QueryResult>;
@@ -257,7 +258,7 @@ impl Function {
257258
let result = QueryResult {
258259
output: vec![ptr],
259260
multiplicity: G::from_bool(!unconstrained),
260-
return_group: String::new(),
261+
return_group: Arc::from(""),
261262
};
262263
memory_queries.insert(values, result);
263264
map.push(ptr);

src/aiur/split.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use rustc_hash::{FxHashMap, FxHashSet};
24

35
use crate::FxIndexMap;
@@ -6,7 +8,7 @@ use super::bytecode::{Block, Ctrl, Function};
68
use super::layout::compute_layout;
79

810
impl Function {
9-
pub fn return_groups(&self) -> FxHashSet<String> {
11+
pub fn return_groups(&self) -> FxHashSet<Arc<str>> {
1012
let mut groups = FxHashSet::default();
1113
collect_block(&self.body, &mut groups);
1214
groups
@@ -36,7 +38,7 @@ impl Function {
3638
self
3739
}
3840

39-
pub fn split(&self) -> FxHashMap<String, Function> {
41+
pub fn split(&self) -> FxHashMap<Arc<str>, Function> {
4042
self
4143
.return_groups()
4244
.into_iter()
@@ -58,7 +60,7 @@ fn filter_block(block: &Block, target: &str) -> Option<Block> {
5860
fn filter_ctrl(ctrl: &Ctrl, target: &str) -> Option<Ctrl> {
5961
match ctrl {
6062
Ctrl::Return(sel, group, vs) => {
61-
if group == target {
63+
if group.as_ref() == target {
6264
Some(Ctrl::Return(*sel, group.clone(), vs.clone()))
6365
} else {
6466
None
@@ -148,11 +150,11 @@ fn filter_cases(
148150
new_cases
149151
}
150152

151-
fn collect_block(block: &Block, groups: &mut FxHashSet<String>) {
153+
fn collect_block(block: &Block, groups: &mut FxHashSet<Arc<str>>) {
152154
collect_ctrl(&block.ctrl, groups);
153155
}
154156

155-
fn collect_ctrl(ctrl: &Ctrl, groups: &mut FxHashSet<String>) {
157+
fn collect_ctrl(ctrl: &Ctrl, groups: &mut FxHashSet<Arc<str>>) {
156158
match ctrl {
157159
Ctrl::Return(_, group, _) => {
158160
groups.insert(group.clone());

src/aiur/synthesis.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use multi_stark::{
24
lookup::LookupAir,
35
p3_air::{Air, AirBuilder, BaseAir},
@@ -71,7 +73,7 @@ where
7173
}
7274

7375
enum CircuitType {
74-
Function { idx: usize, group: String },
76+
Function { idx: usize, group: Arc<str> },
7577
Memory { width: usize },
7678
Bytes1,
7779
Bytes2,
@@ -85,8 +87,8 @@ impl AiurSystem {
8587
let toplevel_ref = &toplevel;
8688
let function_circuits =
8789
(0..toplevel_ref.functions.len()).flat_map(move |i| {
88-
let groups: Vec<String> = if toplevel_ref.functions[i].constrained {
89-
let mut gs: Vec<String> =
90+
let groups: Vec<Arc<str>> = if toplevel_ref.functions[i].constrained {
91+
let mut gs: Vec<Arc<str>> =
9092
toplevel_ref.filtered_functions[i].keys().cloned().collect();
9193
gs.sort();
9294
gs
@@ -142,8 +144,9 @@ impl AiurSystem {
142144
let _g = tracing::info_span!("aiur/witness").entered();
143145
let functions: Vec<CircuitType> = (0..self.toplevel.functions.len())
144146
.flat_map(|idx| {
145-
let groups: Vec<String> = if self.toplevel.functions[idx].constrained {
146-
let mut gs: Vec<String> =
147+
let groups: Vec<Arc<str>> = if self.toplevel.functions[idx].constrained
148+
{
149+
let mut gs: Vec<Arc<str>> =
147150
self.toplevel.filtered_functions[idx].keys().cloned().collect();
148151
gs.sort();
149152
gs

src/aiur/trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Toplevel {
8989
let queries = unfiltered_queries
9090
.iter()
9191
.filter(|(_, res)| {
92-
!res.multiplicity.is_zero() && res.return_group == group
92+
!res.multiplicity.is_zero() && res.return_group.as_ref() == group
9393
})
9494
.collect::<Vec<_>>();
9595
let height_no_padding = queries.len();

src/ffi/aiur/protocol.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,25 @@ extern "C" fn rs_aiur_toplevel_execute(
136136

137137
// Per-function array of `(group, width, unique_rows, total_hits)` quadruples,
138138
// one per split. Queries within a function are partitioned by return group.
139-
let function_stats: Vec<Vec<(String, usize, usize, usize)>> = (0..toplevel
140-
.functions
141-
.len())
139+
let function_stats: Vec<Vec<(std::sync::Arc<str>, usize, usize, usize)>> = (0
140+
..toplevel.functions.len())
142141
.map(|i| {
143142
let queries = &query_record.function_queries[i];
144-
let mut stats: Vec<(String, usize, usize, usize)> = toplevel
143+
let mut stats: Vec<(std::sync::Arc<str>, usize, usize, usize)> = toplevel
145144
.filtered_functions[i]
146145
.iter()
147146
.map(|(group, func)| {
148147
let (rows, hits) = queries
149148
.iter()
150-
.filter(|(_, res)| res.return_group == *group)
149+
.filter(|(_, res)| res.return_group.as_ref() == group.as_ref())
151150
.fold((0usize, 0usize), |(r, h), (_, res)| {
152151
let m = usize::try_from(res.multiplicity.as_canonical_u64())
153152
.expect("multiplicity exceeds usize");
154153
if m != 0 { (r + 1, h + m) } else { (r, h) }
155154
});
156155
let l = func.layout;
157-
let width = l.input_size
158-
+ l.selectors
159-
+ l.auxiliaries
160-
+ 4 * (1 + l.lookups);
156+
let width =
157+
l.input_size + l.selectors + l.auxiliaries + 4 * (1 + l.lookups);
161158
(group.clone(), width, rows, hits)
162159
})
163160
.collect();
@@ -181,7 +178,7 @@ extern "C" fn rs_aiur_toplevel_execute(
181178
for (j, (group, width, rows, hits)) in per_fn.iter().enumerate() {
182179
// (String × Nat × Nat × Nat) — right-nested pair encoding
183180
let quad = LeanProd::new(
184-
LeanString::new(group),
181+
LeanString::new(group.as_ref()),
185182
LeanProd::new(
186183
LeanOwned::box_usize(*width),
187184
LeanProd::new(

src/ffi/aiur/toplevel.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ fn decode_ctrl(ctor: LeanCtor<LeanBorrowed<'_>>) -> Ctrl {
171171
1 => {
172172
let [sel_idx_obj, group_obj, val_idxs_obj] = ctor.objs::<3>();
173173
let sel_idx = lean_unbox_nat_as_usize(&sel_idx_obj);
174-
let group = group_obj.as_string().to_string();
174+
let group_lean = group_obj.as_string();
175+
let group: std::sync::Arc<str> =
176+
std::sync::Arc::from(group_lean.as_str());
175177
let val_idxs = decode_vec_val_idx(val_idxs_obj);
176178
Ctrl::Return(sel_idx, group, val_idxs)
177179
},

0 commit comments

Comments
 (0)