allow expression in degree statement

This commit is contained in:
schaeff
2024-03-14 22:11:35 +01:00
parent b2e9861a13
commit 8065794633
9 changed files with 24 additions and 18 deletions

View File

@@ -182,7 +182,7 @@ impl<'a> ASMPILConverter<'a> {
panic!();
};
let degree = input.degree.map(|s| s.degree.try_into().unwrap());
let degree = input.degree.map(|s| s.degree);
self.submachines = input.submachines;

View File

@@ -10,7 +10,6 @@ use std::{
};
use itertools::Either;
use powdr_number::BigUint;
use crate::parsed::{
asm::{
@@ -529,7 +528,7 @@ pub struct OperationSymbol {
#[derive(Clone, Debug)]
pub struct DegreeStatement {
pub degree: BigUint,
pub degree: Expression,
}
#[derive(Clone, Debug)]

View File

@@ -40,7 +40,7 @@ impl Display for PILGraph {
impl Display for Object {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
if let Some(degree) = self.degree {
if let Some(degree) = self.degree.as_ref() {
writeln!(f, "// Degree {}", degree)?;
}
for s in &self.pil {

View File

@@ -43,7 +43,7 @@ pub enum TypeOrExpression {
#[derive(Default, Clone)]
pub struct Object {
pub degree: Option<u64>,
pub degree: Option<Expression>,
/// the pil identities for this machine
pub pil: Vec<PilStatement>,
/// the links from this machine to its children
@@ -57,8 +57,8 @@ pub struct Object {
}
impl Object {
pub fn with_degree(mut self, degree: Option<u64>) -> Self {
self.degree = degree;
pub fn with_degree<D: Into<Expression>>(mut self, degree: Option<D>) -> Self {
self.degree = degree.map(Into::into);
self
}
}

View File

@@ -475,8 +475,8 @@ pub struct Instruction {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum MachineStatement {
Degree(SourceRef, BigUint),
CallSelectors(SourceRef, String),
Degree(SourceRef, Expression),
Pil(SourceRef, PilStatement),
Submachine(SourceRef, SymbolPath, String),
RegisterDeclaration(SourceRef, String, Option<RegisterFlag>),

View File

@@ -15,7 +15,7 @@ use powdr_ast::{
use itertools::Itertools;
const DEFAULT_DEGREE: u64 = 1024;
const DEFAULT_DEGREE: u32 = 1024;
const MAIN_OPERATION_NAME: &str = "main";
/// a monolithic linker which outputs a single AIR
@@ -27,11 +27,12 @@ pub fn link(graph: PILGraph) -> Result<PILFile, Vec<String>> {
.get(&main_machine.location)
.unwrap()
.degree
.unwrap_or(DEFAULT_DEGREE);
.clone()
.unwrap_or_else(|| DEFAULT_DEGREE.into());
let mut errors = vec![];
let mut pil = process_definitions(main_degree, graph.definitions);
let mut pil = process_definitions(&main_degree, graph.definitions);
for (location, object) in graph.objects.into_iter() {
if let Some(degree) = object.degree {
@@ -47,7 +48,7 @@ pub fn link(graph: PILGraph) -> Result<PILFile, Vec<String>> {
pil.push(PilStatement::Namespace(
SourceRef::unknown(),
SymbolPath::from_identifier(location.to_string()),
Expression::Number(main_degree.into(), None),
main_degree.clone(),
));
pil.extend(object.pil);
@@ -90,7 +91,7 @@ pub fn link(graph: PILGraph) -> Result<PILFile, Vec<String>> {
// Extract the utilities and sort them into namespaces where possible.
fn process_definitions(
main_degree: u64,
main_degree: &Expression,
definitions: BTreeMap<AbsoluteSymbolPath, TypeOrExpression>,
) -> Vec<PilStatement> {
let mut current_namespace = Default::default();
@@ -125,7 +126,7 @@ fn process_definitions(
PilStatement::Namespace(
SourceRef::unknown(),
namespace.relative_to(&AbsoluteSymbolPath::default()),
Expression::Number(main_degree.into(), None),
main_degree.clone(),
),
statement,
]
@@ -306,7 +307,7 @@ mod test {
#[test]
fn compile_empty_vm() {
let expectation = r#"namespace main(8);
let expectation = r#"namespace main((4 + 4));
pol commit _operation_id(i) query std::prover::Query::Hint(2);
pol constant _block_enforcer_last_step = [0]* + [1];
let _operation_id_no_change = ((1 - _block_enforcer_last_step) * (1 - instr_return));

View File

@@ -270,7 +270,7 @@ PilStatementInMachine: MachineStatement = {
}
Degree: MachineStatement = {
<start:@L> "degree" <deg:UnsignedInteger> ";" => MachineStatement::Degree(ctx.source_ref(start), deg)
<start:@L> "degree" <deg:Expression> ";" => MachineStatement::Degree(ctx.source_ref(start), deg)
}
CallSelectors: MachineStatement = {

View File

@@ -235,7 +235,13 @@ pub fn rust_continuations_dry_run<F: FieldElement>(
.fold(None, |acc, (_, m)| acc.or(m.degree.clone()))
.unwrap()
.degree;
let length = F::from(length).to_degree() as usize;
let length: usize = match length {
Expression::Number(length, None) => length.try_into().unwrap(),
e => unimplemented!(
"degree {e} is not supported in continuations as we don't have an evaluator yet"
),
};
loop {
log::info!("\nRunning chunk {}...", chunk_index);

View File

@@ -1,5 +1,5 @@
machine VM {
degree 8;
degree 4 + 4;
reg pc[@pc];
}