Skip to content

Commit

Permalink
Depreciation of . by :: in paths (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzanitti authored Aug 23, 2024
1 parent 3f3b291 commit 0dc3ae7
Show file tree
Hide file tree
Showing 36 changed files with 332 additions and 346 deletions.
6 changes: 3 additions & 3 deletions analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ pol constant _block_enforcer_last_step = [0]* + [1];
pol commit _operation_id_no_change;
_operation_id_no_change = ((1 - _block_enforcer_last_step) * (1 - instr_return));
(_operation_id_no_change * (_operation_id' - _operation_id)) = 0;
instr_identity $ [ 2, X, Y ] in main_sub.instr_return $ [ main_sub._operation_id, main_sub._input_0, main_sub._output_0 ];
instr_one $ [ 4, Y ] in main_sub.instr_return $ [ main_sub._operation_id, main_sub._output_0 ];
instr_nothing $ [ 3 ] in main_sub.instr_return $ [ main_sub._operation_id ];
instr_identity $ [ 2, X, Y ] in main_sub::instr_return $ [ main_sub::_operation_id, main_sub::_input_0, main_sub::_output_0 ];
instr_one $ [ 4, Y ] in main_sub::instr_return $ [ main_sub::_operation_id, main_sub::_output_0 ];
instr_nothing $ [ 3 ] in main_sub::instr_return $ [ main_sub::_operation_id ];
pol constant _linker_first_step = [1] + [0]*;
(_linker_first_step * (_operation_id - 2)) = 0;
namespace main_sub(16);
Expand Down
14 changes: 2 additions & 12 deletions ast/src/analyzed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,22 +452,12 @@ impl Display for AlgebraicReference {

impl Display for PolynomialReference {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", self.name)?;
if let Some(type_args) = &self.type_args {
if !type_args.is_empty() {
// We need to add a `::`-component, so the name should not contain a `.`.
// NOTE: This special handling can be removed once we remove
// the `to_dotted_string` function.
let name = if self.name.contains('.') {
// Re-format the name with ``::`-separators.
SymbolPath::from_str(&self.name).unwrap().to_string()
} else {
self.name.clone()
};
write!(f, "{name}::{}", format_type_args(type_args))?;
return Ok(());
write!(f, "::{}", format_type_args(type_args))?;
}
}
write!(f, "{}", self.name)?;

Ok(())
}
Expand Down
22 changes: 2 additions & 20 deletions ast/src/parsed/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ impl SymbolPath {
self
}

/// Formats the path and uses `.` as separator if
/// there are at most two components.
pub fn to_dotted_string(&self) -> String {
let separator = if self.parts.len() <= 2 { "." } else { "::" };
self.parts.iter().format(separator).to_string()
}

pub fn try_to_identifier(&self) -> Option<&String> {
match &self.parts[..] {
[Part::Named(name)] => Some(name),
Expand Down Expand Up @@ -207,14 +200,10 @@ impl SymbolPath {
impl FromStr for SymbolPath {
type Err = String;

/// Parses a symbol path both in the "a.b" and the "a::b" notation.
/// Parses a symbol path using the "::" notation.
fn from_str(s: &str) -> Result<Self, String> {
let (dots, double_colons) = (s.matches('.').count(), s.matches("::").count());
if dots != 0 && double_colons != 0 {
Err(format!("Path mixes \"::\" and \".\" separators: {s}"))?
}
let parts = s
.split(if double_colons > 0 { "::" } else { "." })
.split("::")
.map(|s| {
if s == "super" {
Part::Super
Expand Down Expand Up @@ -361,13 +350,6 @@ impl AbsoluteSymbolPath {
parts.push(part.to_string());
Self { parts }
}

/// Formats the path without leading `::` and uses `.` as separator if
/// there are at most two components.
pub fn to_dotted_string(&self) -> String {
let separator = if self.parts.len() <= 2 { "." } else { "::" };
self.parts.join(separator)
}
}

impl Display for AbsoluteSymbolPath {
Expand Down
10 changes: 5 additions & 5 deletions ast/src/parsed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ impl Display for NamespacedPolynomialReference {
if let Some(type_args) = &self.type_args {
write!(f, "{}::{}", self.path, format_type_args(type_args))
} else {
write!(f, "{}", self.path.to_dotted_string())
write!(f, "{}", self.path)
}
}
}
Expand Down Expand Up @@ -1216,12 +1216,12 @@ mod tests {
"a | b * (c << d + e) & (f ^ g) = h * (i + g);",
),
(
"instr_or $ [0, X, Y, Z] is (main_bin.latch * main_bin.sel[0]) $ [main_bin.operation_id, main_bin.A, main_bin.B, main_bin.C];",
"instr_or $ [0, X, Y, Z] is main_bin.latch * main_bin.sel[0] $ [main_bin.operation_id, main_bin.A, main_bin.B, main_bin.C];",
"instr_or $ [0, X, Y, Z] is (main_bin::latch * main_bin::sel[0]) $ [main_bin::operation_id, main_bin::A, main_bin::B, main_bin::C];",
"instr_or $ [0, X, Y, Z] is main_bin::latch * main_bin::sel[0] $ [main_bin::operation_id, main_bin::A, main_bin::B, main_bin::C];",
),
(
"instr_or $ [0, X, Y, Z] is main_bin.latch * main_bin.sel[0] $ [main_bin.operation_id, main_bin.A, main_bin.B, main_bin.C];",
"instr_or $ [0, X, Y, Z] is main_bin.latch * main_bin.sel[0] $ [main_bin.operation_id, main_bin.A, main_bin.B, main_bin.C];",
"instr_or $ [0, X, Y, Z] is main_bin::latch * main_bin::sel[0] $ [main_bin::operation_id, main_bin::A, main_bin::B, main_bin::C];",
"instr_or $ [0, X, Y, Z] is main_bin::latch * main_bin::sel[0] $ [main_bin::operation_id, main_bin::A, main_bin::B, main_bin::C];",
),
(
"pc' = (1 - first_step') * ((((instr__jump_to_operation * _operation_id) + (instr__loop * pc)) + (instr_return * 0)) + ((1 - ((instr__jump_to_operation + instr__loop) + instr_return)) * (pc + 1)));",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/composite/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(crate) fn machine_witness_columns<F: FieldElement>(
panic!("Machine {machine_name} has witness columns of different sizes")
}
});
let dummy_column_name = format!("{machine_name}.{DUMMY_COLUMN_NAME}");
let dummy_column_name = format!("{machine_name}::{DUMMY_COLUMN_NAME}");
let dummy_column = vec![F::zero(); size];
iter::once((dummy_column_name, dummy_column))
.chain(machine_columns.into_iter().cloned())
Expand Down
6 changes: 2 additions & 4 deletions backend/src/estark/json_exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ fn polynomial_reference_type_to_type(t: &str) -> &'static str {
/// Makes names compatible with estark, which sometimes require that
/// there is exactly one `.` in the name.
fn fixup_name(name: &str) -> String {
if name.contains('.') {
name.to_string()
} else if let Some(last) = name.rfind("::") {
format!("{}.{}", &name[..last], &name[last + 1..])
if let Some(last) = name.rfind("::") {
format!("{}.{}", &name[..last], &name[last + 2..])
} else {
panic!("Witness or intermediate column is not inside a namespace: {name}");
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/estark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type Fixed<F> = Vec<(String, Vec<F>)>;

/// eStark provers require a fixed column with the equivalent semantics to
/// Polygon zkEVM's `L1` column. Powdr generated PIL will always have
/// `main.first_step`, but directly given PIL may not have it. This is a fixup
/// `main::first_step`, but directly given PIL may not have it. This is a fixup
/// to inject such column if it doesn't exist.
///
/// TODO Improve how this is done.
Expand All @@ -86,7 +86,7 @@ fn first_step_fixup<F: FieldElement>(

let mut pil: PIL = json_exporter::export(pil);

let patched_constants = if !fixed.iter().any(|(k, _)| k == "main.first_step") {
let patched_constants = if !fixed.iter().any(|(k, _)| k == "main::first_step") {
use starky::types::Reference;
pil.nConstants += 1;
pil.references.insert(
Expand Down Expand Up @@ -125,7 +125,7 @@ struct EStarkFilesCommon<F: FieldElement> {
degree: DegreeType,
pil: PIL,
/// If this field is present, it means the constants were patched with
/// "main.first_step" column and must be written again to a file.
/// "main::first_step" column and must be written again to a file.
constants: Arc<Fixed<F>>,
output_dir: Option<PathBuf>,
proof_type: ProofType,
Expand Down
Loading

0 comments on commit 0dc3ae7

Please sign in to comment.