Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) printing integers as integers instead of fields #2625

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/hir/def_collector/dc_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
hir::def_collector::dc_crate::{UnresolvedStruct, UnresolvedTrait},
node_interner::TraitId,
parser::SubModule,
FunctionDefinition, Ident, LetStatement, NoirFunction, NoirStruct,
NoirTrait, NoirTypeAlias, ParsedModule, TraitImpl, TraitImplItem, TraitItem, TypeImpl,
FunctionDefinition, Ident, LetStatement, NoirFunction, NoirStruct, NoirTrait, NoirTypeAlias,
ParsedModule, TraitImpl, TraitImplItem, TraitItem, TypeImpl,
};

use super::{
Expand Down
30 changes: 18 additions & 12 deletions crates/noirc_printable_type/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ fn fetch_printable_type(
fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
let mut output = String::new();
match (value, typ) {
(
PrintableValue::Field(f),
PrintableType::Field
// TODO(#2401): We should print the sign for these and probably print normal integers instead of field strings
| PrintableType::SignedInteger { .. }
| PrintableType::UnsignedInteger { .. },
) => {
(PrintableValue::Field(f), PrintableType::Field) => {
output.push_str(&format_field_string(*f));
}
(PrintableValue::Field(f), PrintableType::UnsignedInteger { .. }) => {
output.push_str(&format!("{}", f.to_u128()));
}
(PrintableValue::Field(_f), PrintableType::SignedInteger { .. }) => {
// TODO: I am not sure how to convert an element to a signed integer in this case
}
(PrintableValue::Field(f), PrintableType::Boolean) => {
if f.is_one() {
output.push_str("true");
Expand All @@ -176,8 +176,11 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
(PrintableValue::Vec(vector), PrintableType::Array { typ, .. }) => {
output.push('[');
let mut values = vector.iter().peekable();
while let Some(value) = values.next() {
output.push_str(&format!("{}", PrintableValueDisplay::Plain(value.clone(), *typ.clone())));
while let Some(value) = values.next() {
output.push_str(&format!(
"{}",
PrintableValueDisplay::Plain(value.clone(), *typ.clone())
));
if values.peek().is_some() {
output.push_str(", ");
}
Expand All @@ -193,9 +196,12 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
output.push_str(&format!("{name} {{ "));

let mut fields = fields.iter().peekable();
while let Some((key, field_type)) = fields.next() {
while let Some((key, field_type)) = fields.next() {
let value = &map[key];
output.push_str(&format!("{key}: {}", PrintableValueDisplay::Plain(value.clone(), field_type.clone())));
output.push_str(&format!(
"{key}: {}",
PrintableValueDisplay::Plain(value.clone(), field_type.clone())
));
if fields.peek().is_some() {
output.push_str(", ");
}
Expand All @@ -204,7 +210,7 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option<String> {
output.push_str(" }");
}

_ => return None
_ => return None,
};

Some(output)
Expand Down