build(ariadne): vendor serde crates

This commit was merged in pull request #15.
This commit is contained in:
alexion committed 2026-09-05 20:21:54 -04:00
1 parent 90f46026f0
commit 64773e0948
490 files changed
+175103

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;
use std::thread;
#[test]
#[cfg_attr(not(exhaustive), ignore = "requires cfg(exhaustive)")]
fn test_exhaustive() {
const BATCH_SIZE: u32 = 1_000_000;
let counter = Arc::new(AtomicU32::new(0));
let finished = Arc::new(AtomicU32::new(0));
let mut workers = Vec::new();
for _ in 0..num_cpus::get() {
let counter = counter.clone();
let finished = finished.clone();
workers.push(thread::spawn(move || loop {
let batch = counter.fetch_add(1, Ordering::Relaxed);
if batch > u32::MAX / BATCH_SIZE {
return;
}
let min = batch * BATCH_SIZE;
let max = if batch == u32::MAX / BATCH_SIZE {
u32::MAX
} else {
min + BATCH_SIZE - 1
};
let mut zmij_buffer = zmij::Buffer::new();
let mut ryu_buffer = ryu::Buffer::new();
for u in min..=max {
let f = f32::from_bits(u);
if !f.is_finite() {
continue;
}
let zmij = zmij_buffer.format_finite(f);
assert_eq!(Ok(f), zmij.parse(), "{zmij:?}");
let ryu = ryu_buffer.format_finite(f);
let matches = if ryu.contains('e') && !ryu.contains("e-") {
ryu.split_once('e') == zmij.split_once("e+")
} else {
ryu == zmij
};
assert!(matches, "{ryu} != {zmij}");
}
let increment = max - min + 1;
let update = finished.fetch_add(increment, Ordering::Relaxed);
println!("{}", u64::from(update) + u64::from(increment));
}));
}
for w in workers {
w.join().unwrap();
}
}
+36
View File
@@ -0,0 +1,36 @@
use rand::rngs::{SmallRng, SysRng};
use rand::{Rng as _, SeedableRng as _};
const N: usize = if cfg!(miri) {
500
} else if let b"0" = opt_level::OPT_LEVEL.as_bytes() {
1_000_000
} else {
100_000_000
};
#[test]
fn ryu_comparison() {
let mut ryu_buffer = ryu::Buffer::new();
let mut zmij_buffer = zmij::Buffer::new();
let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
let mut fail = 0;
for _ in 0..N {
let bits = rng.next_u64();
let float = f64::from_bits(bits);
let ryu = ryu_buffer.format(float);
let zmij = zmij_buffer.format(float);
let matches = if ryu.contains('e') && !ryu.contains("e-") {
ryu.split_once('e') == zmij.split_once("e+")
} else {
ryu == zmij
};
if !matches {
eprintln!("RYU={ryu} ZMIJ={zmij}");
fail += 1;
}
}
assert!(fail == 0, "{fail} mismatches");
}
+144
View File
@@ -0,0 +1,144 @@
#![allow(clippy::float_cmp, clippy::unreadable_literal)]
fn dtoa(value: f64) -> String {
zmij::Buffer::new().format(value).to_owned()
}
fn ftoa(value: f32) -> String {
zmij::Buffer::new().format(value).to_owned()
}
mod dtoa_test {
use super::dtoa;
#[test]
fn normal() {
assert_eq!(dtoa(6.62607015e-34), "6.62607015e-34");
// Exact half-ulp tie when rounding to nearest integer.
assert_eq!(dtoa(5.444310685350916e+14), "544431068535091.6");
}
#[test]
fn subnormal() {
assert_eq!(dtoa(0.0f64.next_up()), "5e-324");
assert_eq!(dtoa(1e-323), "1e-323");
assert_eq!(dtoa(1.2e-322), "1.2e-322");
assert_eq!(dtoa(1.24e-322), "1.24e-322");
assert_eq!(dtoa(1.234e-320), "1.234e-320");
assert_eq!(dtoa(2.2250738585072004e-308), "2.2250738585072004e-308");
}
#[test]
fn all_irregular() {
for exp in 1..0x3ff {
let bits = exp << 52;
let value = f64::from_bits(bits);
assert_eq!(dtoa(value), ryu::Buffer::new().format(value));
}
}
#[test]
fn all_exponents() {
for exp in 0..=0x3ff {
let bits = (exp << 52) | 1;
let value = f64::from_bits(bits);
assert_eq!(dtoa(value), ryu::Buffer::new().format(value));
}
}
#[test]
fn small_int() {
assert_eq!(dtoa(1.0), "1.0");
}
#[test]
fn zero() {
assert_eq!(dtoa(0.0), "0.0");
assert_eq!(dtoa(-0.0), "-0.0");
}
#[test]
fn inf() {
assert_eq!(dtoa(f64::INFINITY), "inf");
}
#[test]
fn nan() {
assert_eq!(dtoa(f64::NAN.copysign(-1.0)), "NaN");
}
#[test]
fn shorter() {
// A possibly shorter underestimate is picked (u' in Schubfach).
assert_eq!(dtoa(-4.932096661796888e-226), "-4.932096661796888e-226");
// A possibly shorter overestimate is picked (w' in Schubfach).
assert_eq!(dtoa(3.439070283483335e+35), "3.439070283483335e+35");
}
#[test]
fn single_candidate() {
// Only an underestimate is in the rounding region (u in Schubfach).
assert_eq!(dtoa(6.606854224493745e-17), "6.606854224493745e-17");
// Only an overestimate is in the rounding region (w in Schubfach).
assert_eq!(dtoa(6.079537928711555e+61), "6.079537928711555e+61");
}
#[test]
fn boundary_cases() {
assert_eq!(dtoa(1.3588129002659584e-245), "1.3588129002659584e-245");
assert_eq!(dtoa(2.9802322387695312e-08), "2.9802322387695312e-8");
assert_eq!(dtoa(5.960464477539063e-08), "5.960464477539063e-8");
assert_eq!(dtoa(1.3076622631878654e+65), "1.3076622631878654e+65");
assert_eq!(dtoa(9.03725590277404e+159), "9.03725590277404e+159");
assert_eq!(dtoa(9.03725590277404e+160), "9.03725590277404e+160");
assert_eq!(dtoa(9.03725590277404e+161), "9.03725590277404e+161");
assert_eq!(dtoa(9.03725590277404e+162), "9.03725590277404e+162");
assert_eq!(dtoa(5.960464477539062e-07), "5.960464477539062e-7");
}
#[test]
fn fixed_with_zeros() {
assert_eq!(dtoa(43210.0), "43210.0");
assert_eq!(dtoa(43210.1), "43210.1");
assert_eq!(dtoa(10000.0), "10000.0");
assert_eq!(dtoa(-5942736479622170.0), "-5942736479622170.0");
}
#[test]
fn no_buffer() {
assert_eq!(dtoa(6.62607015e-34), "6.62607015e-34");
}
}
mod ftoa_test {
use super::ftoa;
#[test]
fn fixed_with_zeros() {
assert_eq!(ftoa(43210.0), "43210.0");
assert_eq!(ftoa(43210.1), "43210.1");
assert_eq!(ftoa(10000.0), "10000.0");
}
#[test]
fn normal() {
assert_eq!(ftoa(6.62607e-34), "6.62607e-34");
assert_eq!(ftoa(1.342178e+08), "134217800.0");
assert_eq!(ftoa(1.3421781e+08), "134217810.0");
}
#[test]
fn subnormal() {
assert_eq!(ftoa(0.0f32.next_up()), "1e-45");
}
#[test]
fn no_buffer() {
assert_eq!(ftoa(6.62607e-34), "6.62607e-34");
}
}