11use alloc:: vec:: Vec ;
2+ use core:: hash:: Hash ;
23
34use hashbrown:: HashMap ;
4- use p3_field:: PrimeCharacteristicRing ;
5+ use p3_field:: { Field , PrimeCharacteristicRing } ;
56
67use super :: compiler:: { ExpressionLowerer , NonPrimitiveLowerer , Optimizer } ;
78use super :: { BuilderConfig , ExpressionBuilder , PublicInputTracker } ;
@@ -122,6 +123,18 @@ where
122123 self . public_tracker . count ( )
123124 }
124125
126+ /// Allocates a witness hint (uninitialized witness slot set during non-primitive execution).
127+ #[ must_use]
128+ pub fn alloc_witness_hint ( & mut self , label : & ' static str ) -> ExprId {
129+ self . expr_builder . add_witness_hint ( label)
130+ }
131+
132+ /// Allocates multiple witness hints.
133+ #[ must_use]
134+ pub fn alloc_witness_hints ( & mut self , count : usize , label : & ' static str ) -> Vec < ExprId > {
135+ self . expr_builder . add_witness_hints ( count, label)
136+ }
137+
125138 /// Adds a constant to the circuit (deduplicated).
126139 ///
127140 /// If this value was previously added, returns the original ExprId.
@@ -299,7 +312,7 @@ where
299312
300313impl < F > CircuitBuilder < F >
301314where
302- F : Clone + PrimeCharacteristicRing + PartialEq + Eq + core :: hash :: Hash ,
315+ F : Field + Clone + PrimeCharacteristicRing + PartialEq + Eq + Hash ,
303316{
304317 /// Builds the circuit into a Circuit with separate lowering and IR transformation stages.
305318 /// Returns an error if lowering fails due to an internal inconsistency.
@@ -333,7 +346,7 @@ where
333346 let primitive_ops = optimizer. optimize ( primitive_ops) ;
334347
335348 // Stage 4: Generate final circuit
336- let mut circuit = Circuit :: new ( witness_count) ;
349+ let mut circuit = Circuit :: new ( witness_count, expr_to_widx ) ;
337350 circuit. primitive_ops = primitive_ops;
338351 circuit. non_primitive_ops = lowered_non_primitive_ops;
339352 circuit. public_rows = public_rows;
@@ -478,7 +491,7 @@ mod tests {
478491 assert ! ( circuit. enabled_ops. is_empty( ) ) ;
479492
480493 match & circuit. primitive_ops [ 0 ] {
481- crate :: op:: Prim :: Const { out, val } => {
494+ crate :: op:: Op :: Const { out, val } => {
482495 assert_eq ! ( * out, WitnessId ( 0 ) ) ;
483496 assert_eq ! ( * val, BabyBear :: ZERO ) ;
484497 }
@@ -501,23 +514,23 @@ mod tests {
501514 assert_eq ! ( circuit. primitive_ops. len( ) , 3 ) ;
502515
503516 match & circuit. primitive_ops [ 0 ] {
504- crate :: op:: Prim :: Const { out, val } => {
517+ crate :: op:: Op :: Const { out, val } => {
505518 assert_eq ! ( * out, WitnessId ( 0 ) ) ;
506519 assert_eq ! ( * val, BabyBear :: ZERO ) ;
507520 }
508521 _ => panic ! ( "Expected Const at index 0" ) ,
509522 }
510523
511524 match & circuit. primitive_ops [ 1 ] {
512- crate :: op:: Prim :: Public { out, public_pos } => {
525+ crate :: op:: Op :: Public { out, public_pos } => {
513526 assert_eq ! ( * out, WitnessId ( 1 ) ) ;
514527 assert_eq ! ( * public_pos, 0 ) ;
515528 }
516529 _ => panic ! ( "Expected Public at index 1" ) ,
517530 }
518531
519532 match & circuit. primitive_ops [ 2 ] {
520- crate :: op:: Prim :: Public { out, public_pos } => {
533+ crate :: op:: Op :: Public { out, public_pos } => {
521534 assert_eq ! ( * out, WitnessId ( 2 ) ) ;
522535 assert_eq ! ( * public_pos, 1 ) ;
523536 }
@@ -543,23 +556,23 @@ mod tests {
543556 assert_eq ! ( circuit. primitive_ops. len( ) , 3 ) ;
544557
545558 match & circuit. primitive_ops [ 0 ] {
546- crate :: op:: Prim :: Const { out, val } => {
559+ crate :: op:: Op :: Const { out, val } => {
547560 assert_eq ! ( * out, WitnessId ( 0 ) ) ;
548561 assert_eq ! ( * val, BabyBear :: ZERO ) ;
549562 }
550563 _ => panic ! ( "Expected Const at index 0" ) ,
551564 }
552565
553566 match & circuit. primitive_ops [ 1 ] {
554- crate :: op:: Prim :: Const { out, val } => {
567+ crate :: op:: Op :: Const { out, val } => {
555568 assert_eq ! ( * out, WitnessId ( 1 ) ) ;
556569 assert_eq ! ( * val, BabyBear :: from_u64( 1 ) ) ;
557570 }
558571 _ => panic ! ( "Expected Const at index 1" ) ,
559572 }
560573
561574 match & circuit. primitive_ops [ 2 ] {
562- crate :: op:: Prim :: Const { out, val } => {
575+ crate :: op:: Op :: Const { out, val } => {
563576 assert_eq ! ( * out, WitnessId ( 2 ) ) ;
564577 assert_eq ! ( * val, BabyBear :: from_u64( 2 ) ) ;
565578 }
@@ -581,7 +594,7 @@ mod tests {
581594 assert_eq ! ( circuit. primitive_ops. len( ) , 4 ) ;
582595
583596 match & circuit. primitive_ops [ 3 ] {
584- crate :: op:: Prim :: Add { out, a, b } => {
597+ crate :: op:: Op :: Add { out, a, b } => {
585598 assert_eq ! ( * out, WitnessId ( 3 ) ) ;
586599 assert_eq ! ( * a, WitnessId ( 1 ) ) ;
587600 assert_eq ! ( * b, WitnessId ( 2 ) ) ;
0 commit comments