git.delta.rocks / jrsonnet / refs/commits / 0ad724252f64

difftreelog

refactor replace serde-yaml with serde-saphyr for yaml parsing

oxsqnpvmYaroslav Bolyukin2026-02-07parent: #8a3d104.patch.diff
in: master

4 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,19 @@
 version = 4
 
 [[package]]
+name = "ahash"
+version = "0.8.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
+dependencies = [
+ "cfg-if",
+ "getrandom",
+ "once_cell",
+ "version_check",
+ "zerocopy",
+]
+
+[[package]]
 name = "aho-corasick"
 version = "1.1.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -110,6 +123,12 @@
 ]
 
 [[package]]
+name = "arraydeque"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236"
+
+[[package]]
 name = "autocfg"
 version = "1.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -303,6 +322,24 @@
 checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
 
 [[package]]
+name = "encoding_rs"
+version = "0.8.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "encoding_rs_io"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1cc3c5651fb62ab8aa3103998dade57efdd028544bd300516baa31840c252a83"
+dependencies = [
+ "encoding_rs",
+]
+
+[[package]]
 name = "equivalent"
 version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -376,9 +413,11 @@
 checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
 dependencies = [
  "cfg-if",
+ "js-sys",
  "libc",
  "r-efi",
  "wasip2",
+ "wasm-bindgen",
 ]
 
 [[package]]
@@ -434,7 +473,7 @@
  "rand",
  "random_color",
  "range-map",
- "smallvec",
+ "smallvec 1.15.1",
  "tree-sitter-highlight",
  "unicode-box-drawing",
 ]
@@ -641,8 +680,8 @@
  "regex",
  "rustc-hash 2.1.1",
  "serde",
+ "serde-saphyr",
  "serde_json",
- "serde_yaml_with_quirks",
  "sha1",
  "sha2",
  "sha3",
@@ -657,6 +696,16 @@
 ]
 
 [[package]]
+name = "js-sys"
+version = "0.3.85"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"
+dependencies = [
+ "once_cell",
+ "wasm-bindgen",
+]
+
+[[package]]
 name = "json-structural-diff"
 version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -772,6 +821,12 @@
 ]
 
 [[package]]
+name = "nohash-hasher"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
+
+[[package]]
 name = "num-bigint"
 version = "0.4.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1054,10 +1109,15 @@
 checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
 
 [[package]]
-name = "ryu"
-version = "1.0.22"
+name = "saphyr-parser-bw"
+version = "0.0.607"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"
+checksum = "2f9bae8d059bf1ca32753cf3cdafbf5d391502de2fc2ca54510811fe9c100d90"
+dependencies = [
+ "arraydeque",
+ "smallvec 2.0.0-alpha.12",
+ "thiserror",
+]
 
 [[package]]
 name = "serde"
@@ -1070,6 +1130,27 @@
 ]
 
 [[package]]
+name = "serde-saphyr"
+version = "0.0.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc14a55107113a16346915d7e3d78acc539a923458385db89670e22cac106d7a"
+dependencies = [
+ "ahash",
+ "annotate-snippets",
+ "base64",
+ "encoding_rs_io",
+ "getrandom",
+ "nohash-hasher",
+ "num-traits",
+ "regex",
+ "saphyr-parser-bw",
+ "serde",
+ "serde_json",
+ "smallvec 2.0.0-alpha.12",
+ "zmij",
+]
+
+[[package]]
 name = "serde_core"
 version = "1.0.228"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1101,19 +1182,6 @@
  "serde",
  "serde_core",
  "zmij",
-]
-
-[[package]]
-name = "serde_yaml_with_quirks"
-version = "0.9.34"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d852180e55e824bb347a8e3cdbbca1f02513ea1fa00188f1b2a8a255ac3d6cf9"
-dependencies = [
- "indexmap",
- "itoa",
- "ryu",
- "serde",
- "unsafe-libyaml",
 ]
 
 [[package]]
@@ -1167,6 +1235,12 @@
 checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
 
 [[package]]
+name = "smallvec"
+version = "2.0.0-alpha.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef784004ca8777809dcdad6ac37629f0a97caee4c685fcea805278d81dd8b857"
+
+[[package]]
 name = "stacker"
 version = "0.1.23"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1337,12 +1411,6 @@
 version = "0.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
-
-[[package]]
-name = "unsafe-libyaml"
-version = "0.2.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
 
 [[package]]
 name = "utf8parse"
@@ -1366,6 +1434,51 @@
 ]
 
 [[package]]
+name = "wasm-bindgen"
+version = "0.2.108"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+ "rustversion",
+ "wasm-bindgen-macro",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.108"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.108"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"
+dependencies = [
+ "bumpalo",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.108"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
 name = "windows-link"
 version = "0.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,11 +35,9 @@
 clap_complete = "4.5"
 
 # Parsing, manifestification is implemented manually everywhere
-# Note on serde_yaml_with_quirks: This is a fork of serde-yaml with legacy yaml 1.1 support:
-# https://github.com/dtolnay/serde-yaml/pull/225
 serde = "1.0.228"
 serde_json = "1.0.149"
-serde_yaml_with_quirks = "0.9.34"
+serde-saphyr = {version = "0.0.17", default-features = false}
 
 # Error handling
 anyhow = "1.0.101"
modifiedcrates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth
before · crates/jrsonnet-stdlib/Cargo.toml
1[package]2name = "jrsonnet-stdlib"3description = "jsonnet standard library packaged as crate"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14# Add order preservation flag to some functions15exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]16# Bigint type17exp-bigint = ["dep:num-bigint", "jrsonnet-evaluator/exp-bigint"]1819exp-null-coaelse = ["jrsonnet-parser/exp-null-coaelse", "jrsonnet-evaluator/exp-null-coaelse"]20# std.regexMatch and other helpers21exp-regex = ["dep:regex", "dep:lru", "dep:rustc-hash"]2223[dependencies]24jrsonnet-evaluator.workspace = true25jrsonnet-macros.workspace = true26jrsonnet-parser.workspace = true27jrsonnet-gcmodule.workspace = true2829# Used for std.parseJson/std.parseYaml30serde.workspace = true3132# std.md533md5.workspace = true34# std.sha135sha1.workspace = true36# std.sha256, std.sha51237sha2.workspace = true38# std.sha339sha3.workspace = true40# std.base6441base64.workspace = true42# std.parseJson43serde_json.workspace = true44# std.parseYaml, custom library fork is used for C++/golang compatibility45serde_yaml_with_quirks.workspace = true4647num-bigint = { workspace = true, optional = true }4849# regex50regex = { workspace = true, optional = true }51lru = { workspace = true, optional = true }52rustc-hash = { workspace = true, optional = true }5354[build-dependencies]55jrsonnet-parser.workspace = true
after · crates/jrsonnet-stdlib/Cargo.toml
1[package]2name = "jrsonnet-stdlib"3description = "jsonnet standard library packaged as crate"4authors.workspace = true5edition.workspace = true6license.workspace = true7repository.workspace = true8version.workspace = true910[lints]11workspace = true1213[features]14# Add order preservation flag to some functions15exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]16# Bigint type17exp-bigint = ["dep:num-bigint", "jrsonnet-evaluator/exp-bigint"]1819exp-null-coaelse = ["jrsonnet-parser/exp-null-coaelse", "jrsonnet-evaluator/exp-null-coaelse"]20# std.regexMatch and other helpers21exp-regex = ["dep:regex", "dep:lru", "dep:rustc-hash"]2223[dependencies]24jrsonnet-evaluator.workspace = true25jrsonnet-macros.workspace = true26jrsonnet-parser.workspace = true27jrsonnet-gcmodule.workspace = true2829# Used for std.parseJson/std.parseYaml30serde.workspace = true3132# std.md533md5.workspace = true34# std.sha135sha1.workspace = true36# std.sha256, std.sha51237sha2.workspace = true38# std.sha339sha3.workspace = true40# std.base6441base64.workspace = true42# std.parseJson43serde_json.workspace = true44# std.parseYaml45serde-saphyr.workspace = true4647num-bigint = { workspace = true, optional = true }4849# regex50regex = { workspace = true, optional = true }51lru = { workspace = true, optional = true }52rustc-hash = { workspace = true, optional = true }5354[build-dependencies]55jrsonnet-parser.workspace = true
modifiedcrates/jrsonnet-stdlib/src/parse.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/parse.rs
+++ b/crates/jrsonnet-stdlib/src/parse.rs
@@ -1,5 +1,4 @@
 use jrsonnet_evaluator::{function::builtin, runtime_error, IStr, Result, Val};
-use serde::Deserialize;
 
 #[builtin]
 pub fn builtin_parse_json(str: IStr) -> Result<Val> {
@@ -10,17 +9,17 @@
 
 #[builtin]
 pub fn builtin_parse_yaml(str: IStr) -> Result<Val> {
-	use serde_yaml_with_quirks::DeserializingQuirks;
-	let value = serde_yaml_with_quirks::Deserializer::from_str_with_quirks(
+	let out = serde_saphyr::from_multiple_with_options::<Val>(
 		&str,
-		DeserializingQuirks { old_octals: true },
-	);
-	let mut out = vec![];
-	for item in value {
-		let val =
-			Val::deserialize(item).map_err(|e| runtime_error!("failed to parse yaml: {e}"))?;
-		out.push(val);
-	}
+		serde_saphyr::Options {
+			// Golang/C++ compat
+			legacy_octal_numbers: true,
+			// Disable budget limits - we trust the YAML input
+			budget: None,
+			..Default::default()
+		},
+	)
+	.map_err(|e| runtime_error!("failed to parse yaml: {e}"))?;
 	Ok(if out.is_empty() {
 		Val::Null
 	} else if out.len() == 1 {