From 1147f326d7e0a10db3a39bd39e6efccf1eef65f3 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 28 Jul 2025 17:16:29 -0300 Subject: [PATCH 1/4] chore: try printing byte arrays as strings in the SSA interpreter --- .../src/ssa/interpreter/value.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/interpreter/value.rs b/compiler/noirc_evaluator/src/ssa/interpreter/value.rs index ee8ba30d638..ff858a60231 100644 --- a/compiler/noirc_evaluator/src/ssa/interpreter/value.rs +++ b/compiler/noirc_evaluator/src/ssa/interpreter/value.rs @@ -434,7 +434,34 @@ impl std::fmt::Display for ArrayValue { let rc = self.rc.borrow(); let is_slice = if self.is_slice { "&" } else { "" }; - write!(f, "rc{rc} {is_slice}[")?; + write!(f, "rc{rc} {is_slice}")?; + + // Check if the array could be shown as a string literal + if self.element_types.len() == 1 + && matches!(self.element_types[0], Type::Numeric(NumericType::Unsigned { bit_size: 8 })) + { + const FORM_FEED: u8 = 12; // This is the ASCII code for '\f', which isn't a valid escape sequence in strings + let printable = self.elements.borrow().iter().all(|value| { + matches!(value, Value::Numeric(NumericValue::U8(byte)) + if *byte != FORM_FEED && + (byte.is_ascii_alphanumeric() + || byte.is_ascii_punctuation() + || byte.is_ascii_whitespace())) + }); + if printable { + let bytes = self.elements.borrow().iter().map(|value| { + let Value::Numeric(NumericValue::U8(byte)) = value else { + panic!("Expected U8 value in array, found {value}"); + }; + *byte + }).collect::>(); + let string = String::from_utf8(bytes).unwrap(); + write!(f, "b{string:?}")?; + return Ok(()); + } + } + + write!(f, "[")?; let length = self.elements.borrow().len() / self.element_types.len(); if length == 0 { From 9eb2554266734bfd13187cc1651f3943503f2e94 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 28 Jul 2025 18:09:41 -0300 Subject: [PATCH 2/4] format --- .../src/ssa/interpreter/value.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/interpreter/value.rs b/compiler/noirc_evaluator/src/ssa/interpreter/value.rs index ff858a60231..927ae1364aa 100644 --- a/compiler/noirc_evaluator/src/ssa/interpreter/value.rs +++ b/compiler/noirc_evaluator/src/ssa/interpreter/value.rs @@ -442,19 +442,24 @@ impl std::fmt::Display for ArrayValue { { const FORM_FEED: u8 = 12; // This is the ASCII code for '\f', which isn't a valid escape sequence in strings let printable = self.elements.borrow().iter().all(|value| { - matches!(value, Value::Numeric(NumericValue::U8(byte)) - if *byte != FORM_FEED && - (byte.is_ascii_alphanumeric() - || byte.is_ascii_punctuation() + matches!(value, Value::Numeric(NumericValue::U8(byte)) + if *byte != FORM_FEED && + (byte.is_ascii_alphanumeric() + || byte.is_ascii_punctuation() || byte.is_ascii_whitespace())) }); if printable { - let bytes = self.elements.borrow().iter().map(|value| { - let Value::Numeric(NumericValue::U8(byte)) = value else { - panic!("Expected U8 value in array, found {value}"); - }; - *byte - }).collect::>(); + let bytes = self + .elements + .borrow() + .iter() + .map(|value| { + let Value::Numeric(NumericValue::U8(byte)) = value else { + panic!("Expected U8 value in array, found {value}"); + }; + *byte + }) + .collect::>(); let string = String::from_utf8(bytes).unwrap(); write!(f, "b{string:?}")?; return Ok(()); From ea5ce801cf8bc3b9cfb3ea924dc332fa29d4e45b Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Mon, 28 Jul 2025 18:14:13 -0300 Subject: [PATCH 3/4] Extract `is_printable_byte` --- .../noirc_evaluator/src/ssa/interpreter/value.rs | 8 ++------ compiler/noirc_evaluator/src/ssa/ir/mod.rs | 1 + compiler/noirc_evaluator/src/ssa/ir/printer.rs | 15 +++++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/interpreter/value.rs b/compiler/noirc_evaluator/src/ssa/interpreter/value.rs index 927ae1364aa..43c0e8eb990 100644 --- a/compiler/noirc_evaluator/src/ssa/interpreter/value.rs +++ b/compiler/noirc_evaluator/src/ssa/interpreter/value.rs @@ -8,6 +8,7 @@ use crate::ssa::ir::{ function::FunctionId, instruction::Intrinsic, integer::IntegerConstant, + is_printable_byte, types::{CompositeType, NumericType, Type}, value::ValueId, }; @@ -440,13 +441,8 @@ impl std::fmt::Display for ArrayValue { if self.element_types.len() == 1 && matches!(self.element_types[0], Type::Numeric(NumericType::Unsigned { bit_size: 8 })) { - const FORM_FEED: u8 = 12; // This is the ASCII code for '\f', which isn't a valid escape sequence in strings let printable = self.elements.borrow().iter().all(|value| { - matches!(value, Value::Numeric(NumericValue::U8(byte)) - if *byte != FORM_FEED && - (byte.is_ascii_alphanumeric() - || byte.is_ascii_punctuation() - || byte.is_ascii_whitespace())) + matches!(value, Value::Numeric(NumericValue::U8(byte)) if is_printable_byte(*byte)) }); if printable { let bytes = self diff --git a/compiler/noirc_evaluator/src/ssa/ir/mod.rs b/compiler/noirc_evaluator/src/ssa/ir/mod.rs index ee62a68784e..aef1ce9b0c5 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/mod.rs @@ -12,3 +12,4 @@ pub(crate) mod post_order; pub(crate) mod printer; pub mod types; pub mod value; +pub use printer::is_printable_byte; diff --git a/compiler/noirc_evaluator/src/ssa/ir/printer.rs b/compiler/noirc_evaluator/src/ssa/ir/printer.rs index d137094666d..5573a0e576d 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/printer.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/printer.rs @@ -434,12 +434,7 @@ fn try_byte_array_to_string(elements: &Vector, dfg: &DataFlowGraph) -> return None; } let byte: u8 = element as u8; - const FORM_FEED: u8 = 12; // This is the ASCII code for '\f', which isn't a valid escape sequence in strings - if byte != FORM_FEED - && (byte.is_ascii_alphanumeric() - || byte.is_ascii_punctuation() - || byte.is_ascii_whitespace()) - { + if is_printable_byte(byte) { string.push(byte as char); } else { return None; @@ -448,6 +443,14 @@ fn try_byte_array_to_string(elements: &Vector, dfg: &DataFlowGraph) -> Some(string) } +pub fn is_printable_byte(byte: u8) -> bool { + const FORM_FEED: u8 = 12; // This is the ASCII code for '\f', which isn't a valid escape sequence in strings + byte != FORM_FEED + && (byte.is_ascii_alphanumeric() + || byte.is_ascii_punctuation() + || byte.is_ascii_whitespace()) +} + fn result_types(dfg: &DataFlowGraph, results: &[ValueId]) -> String { let types = vecmap(results, |result| dfg.type_of_value(*result).to_string()); if types.is_empty() { From 1292058fa674014d5e44913fcd922b6d37efca53 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Tue, 29 Jul 2025 08:45:41 -0300 Subject: [PATCH 4/4] noir_json_parser seems to be compiling again --- .../{.failures.jsonl.does_not_compile => .failures.jsonl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/critical_libraries_status/noir-lang/noir_json_parser/{.failures.jsonl.does_not_compile => .failures.jsonl} (100%) diff --git a/.github/critical_libraries_status/noir-lang/noir_json_parser/.failures.jsonl.does_not_compile b/.github/critical_libraries_status/noir-lang/noir_json_parser/.failures.jsonl similarity index 100% rename from .github/critical_libraries_status/noir-lang/noir_json_parser/.failures.jsonl.does_not_compile rename to .github/critical_libraries_status/noir-lang/noir_json_parser/.failures.jsonl