Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Separate Call statement type, parse HyperTransition variant with …
Browse files Browse the repository at this point in the history
…curly braces
  • Loading branch information
alxkzmn committed Aug 26, 2024
1 parent 7d8a13b commit eef6836
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
8 changes: 3 additions & 5 deletions src/compiler/abepi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl<F: From<u64> + TryInto<u32> + Clone + Debug, V: Clone + Debug> CompilationU
Statement::Transition(dsym, id, stmt) => {
self.compiler_statement_transition(dsym, id, *stmt)
}
Statement::HyperTransition(dsym, ids, machine, exprs, state) => {
self.compiler_statement_hyper_transition(dsym, ids, machine, exprs, state)
Statement::HyperTransition(dsym, state, call) => {
self.compiler_statement_hyper_transition(dsym, state, *call)
}
_ => vec![],
}
Expand Down Expand Up @@ -427,10 +427,8 @@ impl<F: From<u64> + TryInto<u32> + Clone + Debug, V: Clone + Debug> CompilationU
fn compiler_statement_hyper_transition(
&self,
_dsym: DebugSymRef,
_ids: Vec<V>,
_machine: V,
_exprs: Vec<Expression<F, V>>,
_state: V,
_call: Statement<F, V>,
) -> Vec<CompilationResult<F, V>> {
todo!("Compile expressions?")
}
Expand Down
18 changes: 7 additions & 11 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,27 +818,23 @@ mod test {

assert!(result.is_ok());

// Wrong transition operator
let circuit = "
machine caller (signal n) (signal b: field) {
a', b, c' <== fibo(d, e, f + g) --> final;
-> final {
a', b, c' <== fibo(d, e, f + g);
}
}
";

let debug_sym_ref_factory = DebugSymRefFactory::new("", circuit);
let result = TLDeclsParser::new().parse(&debug_sym_ref_factory, circuit);

assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(
err.to_string(),
"Unrecognized token `-` found at 99:100\nExpected one of \"->\""
);
assert!(result.is_ok());

// No transition
// Wrong transition operator
let circuit = "
machine caller (signal n) (signal b: field) {
a', b, c' <== fibo(d, e, f + g);
a', b, c' <== fibo(d, e, f + g) --> final;
}
";

Expand All @@ -849,7 +845,7 @@ mod test {
let err = result.err().unwrap();
assert_eq!(
err.to_string(),
"Unrecognized token `;` found at 98:99\nExpected one of \"->\""
"Unrecognized token `-` found at 99:100\nExpected one of \"->\" or \";\""
);
}
}
12 changes: 8 additions & 4 deletions src/compiler/semantic/analyser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,16 @@ impl Analyser {

Statement::SignalDecl(_, _) => {}
Statement::WGVarDecl(_, _) => {}
Statement::HyperTransition(_, ids, _machine, exprs, _state) => {
// TODO analyze machine? analyze state?
Statement::HyperTransition(_, state, call) => {
self.analyse_statement(*call);
self.collect_id_usages(&[state]);
}
Statement::Call(_, ids, _machine, exprs) => {
// TODO analyze machine?
self.collect_id_usages(&ids);
exprs
.into_iter()
.for_each(|expr| self.analyse_expression(expr));
self.collect_id_usages(&ids);
.for_each(|expr| self.analyse_expression(expr))
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/setup_inter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ impl SetupInterpreter {

SignalAssignment(_, _, _) | WGAssignment(_, _, _) => vec![],
SignalDecl(_, _) | WGVarDecl(_, _) => vec![],
HyperTransition(_, _, _, _, _) => todo!(),
Call(_, _, _, _) => todo!(),
HyperTransition(_, _, _) => todo!(),
};

self.add_poly_constraints(result.into_iter().map(|cr| cr.anti_booly).collect());
Expand Down
3 changes: 2 additions & 1 deletion src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ impl<'a, F: Field + Hash> Interpreter<'a, F> {
Block(_, stmts) => self.exec_step_block(stmts),
Assert(_, _) => Ok(None),
StateDecl(_, _, _) => Ok(None),
HyperTransition(_, _, _, _, _) => Ok(None), // TODO execute transition?
Call(_, _, _, _) => todo!("execute call?"),
HyperTransition(_, _, _) => todo!("execute hypertransition?"),
}
}

Expand Down
30 changes: 16 additions & 14 deletions src/parser/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ pub enum Statement<F, V> {
Transition(DebugSymRef, V, Box<Statement<F, V>>), // -> x { y }

Block(DebugSymRef, Vec<Statement<F, V>>), // { x }
/// Call into another machine with assertion and subsequent transition to another
/// state.
/// Call into another machine with assertion.
/// Tuple values:
/// - debug symbol reference;
/// - assigned/asserted ids vector;
/// - machine ID;
/// - call argument expressions vector;
/// - call argument expressions vector.
Call(DebugSymRef, Vec<V>, V, Vec<Expression<F, V>>),
/// Call into another machine with assertion and subsequent transition to another
/// state.
/// Tuple values:
/// - debug symbol reference;
/// - next state ID.
HyperTransition(DebugSymRef, Vec<V>, V, Vec<Expression<F, V>>, V),
/// - machine call;
HyperTransition(DebugSymRef, V, Box<Statement<F, V>>),
}

impl<F: Debug> Debug for Statement<F, Identifier> {
Expand Down Expand Up @@ -93,15 +98,11 @@ impl<F: Debug> Debug for Statement<F, Identifier> {
.join(" ")
)
}
Statement::HyperTransition(_, ids, machine, exprs, state) => {
write!(
f,
"{:?} <== {} ({:?}) --> {:?};",
ids,
machine.name(),
exprs,
state
)
Statement::Call(_, ids, machine, exprs) => {
write!(f, "{:?} <== {} ({:?});", ids, machine.name(), exprs)
}
Statement::HyperTransition(_, state, call) => {
write!(f, "{:?} -> {:?};", call, state)
}
}
}
Expand All @@ -121,7 +122,8 @@ impl<F, V> Statement<F, V> {
Statement::StateDecl(dsym, _, _) => dsym.clone(),
Statement::Transition(dsym, _, _) => dsym.clone(),
Statement::Block(dsym, _) => dsym.clone(),
Statement::HyperTransition(dsym, _, _, _, _) => dsym.clone(),
Statement::Call(dsym, _, _, _) => dsym.clone(),
Statement::HyperTransition(dsym, _, _) => dsym.clone(),
}
}
}
8 changes: 8 additions & 0 deletions src/parser/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ pub fn build_transition<F>(
) -> Statement<F, Identifier> {
Statement::Transition(dsym, id, Box::new(block))
}

pub fn build_hyper_transition<F>(
dsym: DebugSymRef,
state: Identifier,
call: Statement<F, Identifier>,
) -> Statement<F, Identifier> {
Statement::HyperTransition(dsym, state, Box::new(call))
}
9 changes: 7 additions & 2 deletions src/parser/chiquito.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ StatementType: Statement<BigInt, Identifier> = {
ParseWGVarDecl,
ParseTransitionSimple,
ParseTransition,
HyperTransition
HyperTransition,
Call,
}

AssertEq: Statement<BigInt, Identifier> = {
Expand Down Expand Up @@ -113,7 +114,11 @@ ParseTransition: Statement<BigInt, Identifier> = {
}

HyperTransition: Statement<BigInt, Identifier> = {
<l: @L> <ids: ParseIdsList> "<==" <machine: Identifier> "(" <es:ParseExpressionList> ")" "->" <st: Identifier> <r: @R> => Statement::HyperTransition(dsym_factory.create(l,r), ids, machine, es, st),
<l: @L> <call: Call> "->" <st: Identifier> <r: @R> => build_hyper_transition(dsym_factory.create(l,r), st, call),
}

Call: Statement<BigInt, Identifier> = {
<l: @L> <ids: ParseIdsList> "<==" <machine: Identifier> "(" <es:ParseExpressionList> ")" <r: @R> => Statement::Call(dsym_factory.create(l,r), ids, machine, es),
}

ParseSignalDecl: Statement<BigInt, Identifier> = {
Expand Down

0 comments on commit eef6836

Please sign in to comment.