Runtime logging. (#3821)

* Implement Printable for tuples.

* Add debugging function.

* Add debug 1.

* Implement  for everything.

* RuntimeDebug derive.

* Introduce RuntimeDebug.

* Add some dummy logging.

* Replace RuntimeDebug with Debug.

* Revert "Replace RuntimeDebug with Debug."

This reverts commit bc47070a8cb30241b2b590b2fa29fd195088162f.

* Working on Debug for all.

* Fix bounds.

* Add debug utils.

* Implement runtime logging.

* Add some docs and clean up.

* Clean up derives.

* Fix custom derive impl.

* Bump runtime.

* Fix long lines.

* Fix doc test.

* Use CARGO_CFG_STD.

* Revert "Use CARGO_CFG_STD."

This reverts commit ea429566de18ed0fa052571b359eb9826a64a9f4.

* Use parse_macro_input

* Update lockfile.

* Apply review suggestions.

* Remove stray re-export.

* Add no-std impl.

* Update lockfile.
This commit is contained in:
Tomasz Drwięga
2019-10-22 14:13:44 +02:00
committed by Bastian Köcher
parent 934d7aac1c
commit 20a3989785
86 changed files with 1266 additions and 469 deletions
+7 -5
View File
@@ -5,11 +5,12 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
num-traits = { version = "0.2.8", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
integer-sqrt = "0.1.2"
num-traits = { version = "0.2.8", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
substrate-debug-derive = { path = "../primitives/debug-derive", default-features = false }
[dev-dependencies]
primitive-types = "0.6.0"
@@ -19,8 +20,9 @@ rand = "0.7.2"
bench = []
default = ["std"]
std = [
"serde",
"codec/std",
"num-traits/std",
"rstd/std",
"codec/std",
"serde",
"substrate-debug-derive/std",
]
+7 -1
View File
@@ -427,8 +427,8 @@ impl BigUint {
}
}
#[cfg(feature = "std")]
impl rstd::fmt::Debug for BigUint {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut rstd::fmt::Formatter<'_>) -> rstd::fmt::Result {
write!(
f,
@@ -437,6 +437,12 @@ impl rstd::fmt::Debug for BigUint {
u128::try_from(self.clone()).unwrap_or(0),
)
}
#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut rstd::fmt::Formatter<'_>) -> rstd::fmt::Result {
Ok(())
}
}
impl PartialEq for BigUint {
+7 -2
View File
@@ -144,11 +144,16 @@ impl CheckedAdd for Fixed64 {
}
}
#[cfg(feature = "std")]
impl rstd::fmt::Debug for Fixed64 {
fn fmt(&self, f: &mut rstd::fmt::Formatter<'_>) -> rstd::fmt::Result {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
write!(f, "Fixed64({},{})", self.0 / DIV, (self.0 % DIV) / 1000)
}
#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut rstd::fmt::Formatter) -> rstd::fmt::Result {
Ok(())
}
}
#[cfg(test)]
@@ -20,14 +20,15 @@ use serde::{Serialize, Deserialize};
use rstd::{ops, prelude::*, convert::TryInto};
use codec::{Encode, Decode, CompactAs};
use crate::traits::{SaturatedConversion, UniqueSaturatedInto, Saturating};
use substrate_debug_derive::RuntimeDebug;
macro_rules! implement_per_thing {
($name:ident, $test_mod:ident, [$($test_units:tt),+], $max:tt, $type:ty, $upper_type:ty, $title:expr $(,)?) => {
/// A fixed point representation of a number between in the range [0, 1].
///
#[doc = $title]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Ord, PartialOrd))]
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, CompactAs)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Ord, PartialOrd))]
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, RuntimeDebug, CompactAs)]
pub struct $name($type);
impl $name {
@@ -189,7 +190,7 @@ macro_rules! implement_per_thing {
#[cfg(test)]
mod $test_mod {
use codec::{Encode, Decode};
use super::{$name, Saturating};
use super::{$name, Saturating, RuntimeDebug};
use crate::traits::Zero;
@@ -208,7 +209,7 @@ macro_rules! implement_per_thing {
assert!(<$upper_type>::from($max).checked_mul($max.into()).is_some());
}
#[derive(Encode, Decode, PartialEq, Eq, Debug)]
#[derive(Encode, Decode, PartialEq, Eq, RuntimeDebug)]
struct WithCompact<T: codec::HasCompact> {
data: T,
}
@@ -17,10 +17,10 @@
use rstd::{cmp::Ordering, prelude::*};
use crate::helpers_128bit;
use num_traits::Zero;
use substrate_debug_derive::RuntimeDebug;
/// A wrapper for any rational number with a 128 bit numerator and denominator.
#[derive(Clone, Copy, Default, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Clone, Copy, Default, Eq, RuntimeDebug)]
pub struct Rational128(u128, u128);
impl Rational128 {