From 1c651aaf632978cdd30bbe730330fd4af865fa7b Mon Sep 17 00:00:00 2001 From: orizi <104711814+orizi@users.noreply.github.com> Date: Sun, 29 Sep 2024 12:30:58 +0200 Subject: [PATCH] Added `NonZero()` for const value fmt. (#6424) --- .../src/optimizations/test_data/const_folding | 8 ++++---- crates/cairo-lang-semantic/src/items/fmt.rs | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/cairo-lang-lowering/src/optimizations/test_data/const_folding b/crates/cairo-lang-lowering/src/optimizations/test_data/const_folding index 33e01d5fb04..6907660a377 100644 --- a/crates/cairo-lang-lowering/src/optimizations/test_data/const_folding +++ b/crates/cairo-lang-lowering/src/optimizations/test_data/const_folding @@ -239,7 +239,7 @@ Parameters: v0: core::integer::u8 blk0 (root): Statements: (v1: core::integer::u8) <- 4 - (v2: core::zeroable::NonZero::) <- 4 + (v2: core::zeroable::NonZero::) <- NonZero(4) End: Goto(blk2, {}) @@ -477,7 +477,7 @@ Parameters: v0: core::integer::u256 blk0 (root): Statements: (v1: core::integer::u256) <- { 4: core::integer::u128, 0: core::integer::u128 } - (v2: core::zeroable::NonZero::) <- { 4: core::integer::u128, 0: core::integer::u128 } + (v2: core::zeroable::NonZero::) <- NonZero({ 4: core::integer::u128, 0: core::integer::u128 }) End: Goto(blk2, {}) @@ -719,7 +719,7 @@ blk0 (root): Statements: (v1: core::integer::u64) <- 1 (v2: core::integer::u128) <- 1 - (v3: core::zeroable::NonZero::) <- 1 + (v3: core::zeroable::NonZero::) <- NonZero(1) End: Goto(blk2, {}) @@ -3285,7 +3285,7 @@ Parameters: v0: core::integer::i8 blk0 (root): Statements: (v1: core::integer::i8) <- 4 - (v2: core::zeroable::NonZero::) <- 4 + (v2: core::zeroable::NonZero::) <- NonZero(4) End: Goto(blk2, {}) diff --git a/crates/cairo-lang-semantic/src/items/fmt.rs b/crates/cairo-lang-semantic/src/items/fmt.rs index 5e49e638a97..e25b5bfffce 100644 --- a/crates/cairo-lang-semantic/src/items/fmt.rs +++ b/crates/cairo-lang-semantic/src/items/fmt.rs @@ -33,7 +33,11 @@ impl> DebugWithDb for Const inner.fmt(f, db)?; write!(f, ")") } - ConstValue::NonZero(value) => value.fmt(f, db), + ConstValue::NonZero(value) => { + write!(f, "NonZero(")?; + value.fmt(f, db)?; + write!(f, ")") + } ConstValue::Boxed(value) => { value.fmt(f, db)?; write!(f, ".into_box()")