git.delta.rocks / jrsonnet / refs/commits / a8de1ded43ea

difftreelog

build use `workspace.dependencies`

Yaroslav Bolyukin2022-10-26parent: #fe52b32.patch.diff
in: master

16 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -25,9 +25,9 @@
 
 [[package]]
 name = "anyhow"
-version = "1.0.57"
+version = "1.0.66"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
+checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
 
 [[package]]
 name = "atty"
@@ -48,9 +48,9 @@
 
 [[package]]
 name = "base64"
-version = "0.13.0"
+version = "0.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
+checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
 
 [[package]]
 name = "bincode"
@@ -87,35 +87,33 @@
 
 [[package]]
 name = "clap"
-version = "3.2.8"
+version = "4.0.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83"
+checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"
 dependencies = [
  "atty",
  "bitflags",
  "clap_derive",
  "clap_lex",
- "indexmap",
  "once_cell",
  "strsim",
  "termcolor",
- "textwrap",
 ]
 
 [[package]]
 name = "clap_complete"
-version = "3.2.3"
+version = "4.0.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ead064480dfc4880a10764488415a97fdd36a4cf1bb022d372f02e8faf8386e1"
+checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3"
 dependencies = [
  "clap",
 ]
 
 [[package]]
 name = "clap_derive"
-version = "3.2.7"
+version = "4.0.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902"
+checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3"
 dependencies = [
  "heck",
  "proc-macro-error",
@@ -126,9 +124,9 @@
 
 [[package]]
 name = "clap_lex"
-version = "0.2.4"
+version = "0.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
+checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
 dependencies = [
  "os_str_bytes",
 ]
@@ -144,9 +142,9 @@
 
 [[package]]
 name = "getrandom"
-version = "0.2.6"
+version = "0.2.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
+checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
 dependencies = [
  "cfg-if 1.0.0",
  "libc",
@@ -155,15 +153,9 @@
 
 [[package]]
 name = "hashbrown"
-version = "0.11.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
-
-[[package]]
-name = "hashbrown"
-version = "0.12.1"
+version = "0.12.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
+checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
 dependencies = [
  "ahash",
 ]
@@ -185,23 +177,23 @@
 
 [[package]]
 name = "indexmap"
-version = "1.8.2"
+version = "1.9.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a"
+checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
 dependencies = [
  "autocfg",
- "hashbrown 0.11.2",
+ "hashbrown",
 ]
 
 [[package]]
 name = "itoa"
-version = "1.0.2"
+version = "1.0.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
+checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
 
 [[package]]
 name = "jrsonnet"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "clap",
  "clap_complete",
@@ -215,7 +207,7 @@
 
 [[package]]
 name = "jrsonnet-cli"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "clap",
  "jrsonnet-evaluator",
@@ -226,12 +218,12 @@
 
 [[package]]
 name = "jrsonnet-evaluator"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "annotate-snippets",
  "anyhow",
  "bincode",
- "hashbrown 0.12.1",
+ "hashbrown",
  "jrsonnet-gcmodule",
  "jrsonnet-interner",
  "jrsonnet-macros",
@@ -268,9 +260,9 @@
 
 [[package]]
 name = "jrsonnet-interner"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
- "hashbrown 0.12.1",
+ "hashbrown",
  "jrsonnet-gcmodule",
  "rustc-hash",
  "serde",
@@ -279,7 +271,7 @@
 
 [[package]]
 name = "jrsonnet-macros"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -288,7 +280,7 @@
 
 [[package]]
 name = "jrsonnet-parser"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "jrsonnet-gcmodule",
  "jrsonnet-interner",
@@ -300,7 +292,7 @@
 
 [[package]]
 name = "jrsonnet-stdlib"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "base64",
  "bincode",
@@ -317,7 +309,7 @@
 
 [[package]]
 name = "jrsonnet-types"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "jrsonnet-gcmodule",
  "peg",
@@ -325,13 +317,13 @@
 
 [[package]]
 name = "libc"
-version = "0.2.126"
+version = "0.2.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
+checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
 
 [[package]]
 name = "libjsonnet"
-version = "0.4.2"
+version = "0.5.0"
 dependencies = [
  "jrsonnet-evaluator",
  "jrsonnet-gcmodule",
@@ -381,15 +373,15 @@
 
 [[package]]
 name = "once_cell"
-version = "1.12.0"
+version = "1.15.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
+checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
 
 [[package]]
 name = "os_str_bytes"
-version = "6.1.0"
+version = "6.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
+checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
 
 [[package]]
 name = "parking_lot"
@@ -423,9 +415,9 @@
 
 [[package]]
 name = "peg"
-version = "0.8.0"
+version = "0.8.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af728fe826811af3b38c37e93de6d104485953ea373d656eebae53d6987fcd2c"
+checksum = "a07f2cafdc3babeebc087e499118343442b742cc7c31b4d054682cc598508554"
 dependencies = [
  "peg-macros",
  "peg-runtime",
@@ -433,9 +425,9 @@
 
 [[package]]
 name = "peg-macros"
-version = "0.8.0"
+version = "0.8.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4536be147b770b824895cbad934fccce8e49f14b4c4946eaa46a6e4a12fcdc16"
+checksum = "4a90084dc05cf0428428e3d12399f39faad19b0909f64fb9170c9fdd6d9cd49b"
 dependencies = [
  "peg-runtime",
  "proc-macro2",
@@ -444,9 +436,9 @@
 
 [[package]]
 name = "peg-runtime"
-version = "0.8.0"
+version = "0.8.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f9b0efd3ba03c3a409d44d60425f279ec442bcf0b9e63ff4e410da31c8b0f69f"
+checksum = "9fa00462b37ead6d11a82c9d568b26682d78e0477dc02d1966c013af80969739"
 
 [[package]]
 name = "proc-macro-error"
@@ -474,18 +466,18 @@
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.39"
+version = "1.0.47"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
+checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
 dependencies = [
  "unicode-ident",
 ]
 
 [[package]]
 name = "quote"
-version = "1.0.18"
+version = "1.0.21"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
+checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
 dependencies = [
  "proc-macro2",
 ]
@@ -504,9 +496,9 @@
 
 [[package]]
 name = "ryu"
-version = "1.0.10"
+version = "1.0.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
+checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
 
 [[package]]
 name = "scopeguard"
@@ -516,18 +508,18 @@
 
 [[package]]
 name = "serde"
-version = "1.0.142"
+version = "1.0.147"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2"
+checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
 dependencies = [
  "serde_derive",
 ]
 
 [[package]]
 name = "serde_derive"
-version = "1.0.142"
+version = "1.0.147"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "34b5b8d809babe02f538c2cfec6f2c1ed10804c0e5a6a041a049a4f5588ccc2e"
+checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -536,9 +528,9 @@
 
 [[package]]
 name = "serde_json"
-version = "1.0.82"
+version = "1.0.87"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7"
+checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"
 dependencies = [
  "itoa",
  "ryu",
@@ -559,9 +551,9 @@
 
 [[package]]
 name = "smallvec"
-version = "1.8.0"
+version = "1.10.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
+checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
 
 [[package]]
 name = "static_assertions"
@@ -599,9 +591,9 @@
 
 [[package]]
 name = "syn"
-version = "1.0.96"
+version = "1.0.103"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
+checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -628,25 +620,19 @@
 ]
 
 [[package]]
-name = "textwrap"
-version = "0.15.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
-
-[[package]]
 name = "thiserror"
-version = "1.0.31"
+version = "1.0.37"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
+checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
 dependencies = [
  "thiserror-impl",
 ]
 
 [[package]]
 name = "thiserror-impl"
-version = "1.0.31"
+version = "1.0.37"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
+checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -655,15 +641,15 @@
 
 [[package]]
 name = "unicode-ident"
-version = "1.0.0"
+version = "1.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
+checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
 
 [[package]]
 name = "unicode-width"
-version = "0.1.9"
+version = "0.1.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
+checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
 
 [[package]]
 name = "version_check"
@@ -673,9 +659,9 @@
 
 [[package]]
 name = "wasi"
-version = "0.10.2+wasi-snapshot-preview1"
+version = "0.11.0+wasi-snapshot-preview1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
 
 [[package]]
 name = "winapi"
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,16 @@
 [workspace]
+package.version = "0.5.0"
 members = ["crates/*", "bindings/jsonnet", "cmds/jrsonnet", "tests"]
 
+[workspace.dependencies]
+jrsonnet-evaluator = { path = "./crates/jrsonnet-evaluator", version = "0.5.0" }
+jrsonnet-macros = { path = "./crates/jrsonnet-macros", version = "0.5.0" }
+jrsonnet-parser = { path = "./crates/jrsonnet-parser", version = "0.5.0" }
+jrsonnet-interner = { path = "./crates/jrsonnet-interner", version = "0.5.0" }
+jrsonnet-stdlib = { path = "./crates/jrsonnet-stdlib", version = "0.5.0" }
+jrsonnet-cli = { path = "./crates/jrsonnet-cli", version = "0.5.0" }
+jrsonnet-types = { path = "./crates/jrsonnet-types", version = "0.5.0" }
+
 [profile.test]
 opt-level = 1
 
modifiedbindings/jsonnet/Cargo.tomldiffbeforeafterboth
--- a/bindings/jsonnet/Cargo.toml
+++ b/bindings/jsonnet/Cargo.toml
@@ -1,16 +1,16 @@
 [package]
 name = "libjsonnet"
 description = "Rust implementation of libjsonnet.so"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
 publish = false
 
 [dependencies]
-jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2" }
-jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
-jrsonnet-stdlib = { path = "../../crates/jrsonnet-stdlib", version = "0.4.2" }
+jrsonnet-evaluator.workspace = true
+jrsonnet-parser.workspace = true
+jrsonnet-stdlib.workspace = true
 jrsonnet-gcmodule = { version = "0.3.4" }
 
 [lib]
modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet"
 description = "Rust jsonnet implementation"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
@@ -21,9 +21,9 @@
 legacy-this-file = ["jrsonnet-cli/legacy-this-file"]
 
 [dependencies]
-jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2" }
-jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
-jrsonnet-cli = { path = "../../crates/jrsonnet-cli", version = "0.4.2" }
+jrsonnet-evaluator.workspace = true
+jrsonnet-parser.workspace = true
+jrsonnet-cli.workspace = true
 jrsonnet-gcmodule = { version = "0.3.4" }
 
 mimallocator = { version = "0.1.3", optional = true }
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet-cli"
 description = "Utilities for building jrsonnet CLIs"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
@@ -14,11 +14,9 @@
 legacy-this-file = ["jrsonnet-stdlib/legacy-this-file"]
 
 [dependencies]
-jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "0.4.2", features = [
-    "explaining-traces",
-] }
-jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
+jrsonnet-evaluator = { workspace = true, features = ["explaining-traces"] }
+jrsonnet-parser.workspace = true
+jrsonnet-stdlib.workspace = true
 jrsonnet-gcmodule = { version = "0.3.4" }
-jrsonnet-stdlib = { path = "../../crates/jrsonnet-stdlib", version = "0.4.2" }
 
 clap = { version = "4.0", features = ["derive"] }
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet-evaluator"
 description = "jsonnet interpreter"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
@@ -24,10 +24,10 @@
 nightly = []
 
 [dependencies]
-jrsonnet-interner = { path = "../jrsonnet-interner", version = "0.4.2" }
-jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.4.2" }
-jrsonnet-types = { path = "../jrsonnet-types", version = "0.4.2" }
-jrsonnet-macros = { path = "../jrsonnet-macros", version = "0.4.2" }
+jrsonnet-interner.workspace = true
+jrsonnet-parser.workspace = true
+jrsonnet-types.workspace = true
+jrsonnet-macros.workspace = true
 jrsonnet-gcmodule = { version = "0.3.4" }
 
 pathdiff = "0.2.1"
modifiedcrates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -32,7 +32,7 @@
 		Destruct::Array { start, rest, end } => {
 			use jrsonnet_parser::DestructRest;
 
-			use crate::{throw, val::ArrValue};
+			use crate::val::ArrValue;
 
 			#[derive(Trace)]
 			struct DataThunk {
@@ -43,8 +43,8 @@
 			impl ThunkValue for DataThunk {
 				type Output = ArrValue;
 
-				fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
-					let v = self.parent.evaluate(s)?;
+				fn get(self: Box<Self>) -> Result<Self::Output> {
+					let v = self.parent.evaluate()?;
 					let arr = match v {
 						Val::Arr(a) => a,
 						_ => throw!("expected array"),
@@ -79,9 +79,9 @@
 				impl ThunkValue for BaseThunk {
 					type Output = Val;
 
-					fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
-						let full = self.full.evaluate(s.clone())?;
-						Ok(full.get(s, self.index)?.expect("length is checked"))
+					fn get(self: Box<Self>) -> Result<Self::Output> {
+						let full = self.full.evaluate()?;
+						Ok(full.get(self.index)?.expect("length is checked"))
 					}
 				}
 				for (i, d) in start.iter().enumerate() {
@@ -108,8 +108,8 @@
 					impl ThunkValue for RestThunk {
 						type Output = Val;
 
-						fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
-							let full = self.full.evaluate(s)?;
+						fn get(self: Box<Self>) -> Result<Self::Output> {
+							let full = self.full.evaluate()?;
 							let to = full.len() - self.end;
 							Ok(Val::Arr(full.slice(Some(self.start), Some(to), None)))
 						}
@@ -140,10 +140,10 @@
 				impl ThunkValue for EndThunk {
 					type Output = Val;
 
-					fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
-						let full = self.full.evaluate(s.clone())?;
+					fn get(self: Box<Self>) -> Result<Self::Output> {
+						let full = self.full.evaluate()?;
 						Ok(full
-							.get(s, full.len() - self.end + self.index)?
+							.get(full.len() - self.end + self.index)?
 							.expect("length is checked"))
 					}
 				}
@@ -163,7 +163,7 @@
 		}
 		#[cfg(feature = "exp-destruct")]
 		Destruct::Object { fields, rest } => {
-			use crate::{obj::ObjValue, throw};
+			use crate::obj::ObjValue;
 
 			#[derive(Trace)]
 			struct DataThunk {
@@ -174,8 +174,8 @@
 			impl ThunkValue for DataThunk {
 				type Output = ObjValue;
 
-				fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
-					let v = self.parent.evaluate(s)?;
+				fn get(self: Box<Self>) -> Result<Self::Output> {
+					let v = self.parent.evaluate()?;
 					let obj = match v {
 						Val::Obj(o) => o,
 						_ => throw!("expected object"),
@@ -215,13 +215,13 @@
 				impl ThunkValue for FieldThunk {
 					type Output = Val;
 
-					fn get(self: Box<Self>, s: State) -> Result<Self::Output> {
-						let full = self.full.evaluate(s.clone())?;
-						if let Some(field) = full.get(s.clone(), self.field)? {
+					fn get(self: Box<Self>) -> Result<Self::Output> {
+						let full = self.full.evaluate()?;
+						if let Some(field) = full.get(self.field)? {
 							Ok(field)
 						} else {
 							let (fctx, expr) = self.default.as_ref().expect("shape is checked");
-							Ok(evaluate(s, fctx.clone().unwrap(), &expr)?)
+							Ok(evaluate(fctx.clone().unwrap(), &expr)?)
 						}
 					}
 				}
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -178,7 +178,10 @@
 			}
 			Val::Obj(obj) => {
 				let mut map = serializer.serialize_map(Some(obj.len()))?;
-				for (field, value) in obj.iter() {
+				for (field, value) in obj.iter(
+					#[cfg(feature = "exp-preserve-order")]
+					true,
+				) {
 					let mut serde_error = None;
 					// TODO: rewrite using try{} after stabilization
 					State::push_description(
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/obj.rs
1use std::{2	cell::RefCell,3	fmt::Debug,4	hash::{Hash, Hasher},5	ptr::addr_of,6};78use jrsonnet_gcmodule::{Cc, Trace, Weak};9use jrsonnet_interner::IStr;10use jrsonnet_parser::{ExprLocation, Visibility};11use rustc_hash::FxHashMap;1213use crate::{14	error::{Error::*, LocError},15	function::CallLocation,16	gc::{GcHashMap, GcHashSet, TraceBox},17	operator::evaluate_add_op,18	throw, MaybeUnbound, Result, State, Thunk, Unbound, Val,19};2021#[cfg(not(feature = "exp-preserve-order"))]22mod ordering {23	#![allow(24		// This module works as stub for preserve-order feature25		clippy::unused_self,26	)]2728	use jrsonnet_gcmodule::Trace;2930	#[derive(Clone, Copy, Default, Debug, Trace)]31	pub struct FieldIndex;32	impl FieldIndex {33		pub const fn next(self) -> Self {34			Self35		}36	}3738	#[derive(Clone, Copy, Default, Debug, Trace)]39	pub struct SuperDepth;40	impl SuperDepth {41		pub const fn deeper(self) -> Self {42			Self43		}44	}4546	#[derive(Clone, Copy)]47	pub struct FieldSortKey;48	impl FieldSortKey {49		pub const fn new(_: SuperDepth, _: FieldIndex) -> Self {50			Self51		}52	}53}5455#[cfg(feature = "exp-preserve-order")]56mod ordering {57	use std::cmp::Reverse;5859	use jrsonnet_gcmodule::Trace;6061	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]62	pub struct FieldIndex(u32);63	impl FieldIndex {64		pub fn next(self) -> Self {65			Self(self.0 + 1)66		}67	}6869	#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]70	pub struct SuperDepth(u32);71	impl SuperDepth {72		pub fn deeper(self) -> Self {73			Self(self.0 + 1)74		}75	}7677	#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]78	pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);79	impl FieldSortKey {80		pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {81			Self(Reverse(depth), index)82		}83		pub fn collide(self, other: Self) -> Self {84			if self.0 .0 > other.0 .0 {85				self86			} else if self.0 .0 < other.0 .0 {87				other88			} else {89				unreachable!("object can't have two fields with same name")90			}91		}92	}93}9495use ordering::*;9697#[allow(clippy::module_name_repetitions)]98#[derive(Debug, Trace)]99pub struct ObjMember {100	pub add: bool,101	pub visibility: Visibility,102	original_index: FieldIndex,103	pub invoke: MaybeUnbound,104	pub location: Option<ExprLocation>,105}106107pub trait ObjectAssertion: Trace {108	fn run(&self, super_obj: Option<ObjValue>, this: Option<ObjValue>) -> Result<()>;109}110111// Field => This112113#[derive(Trace)]114enum CacheValue {115	Cached(Val),116	NotFound,117	Pending,118	Errored(LocError),119}120121#[allow(clippy::module_name_repetitions)]122#[derive(Trace)]123#[trace(tracking(force))]124pub struct ObjValueInternals {125	sup: Option<ObjValue>,126	this: Option<ObjValue>,127128	assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,129	assertions_ran: RefCell<GcHashSet<ObjValue>>,130	this_entries: Cc<GcHashMap<IStr, ObjMember>>,131	value_cache: RefCell<GcHashMap<IStr, CacheValue>>,132}133134#[derive(Clone, Trace)]135pub struct WeakObjValue(#[trace(skip)] pub(crate) Weak<ObjValueInternals>);136137impl PartialEq for WeakObjValue {138	fn eq(&self, other: &Self) -> bool {139		Weak::ptr_eq(&self.0, &other.0)140	}141}142143impl Eq for WeakObjValue {}144impl Hash for WeakObjValue {145	fn hash<H: Hasher>(&self, hasher: &mut H) {146		// Safety: usize is POD147		let addr = unsafe { *std::ptr::addr_of!(self.0).cast() };148		hasher.write_usize(addr);149	}150}151152#[allow(clippy::module_name_repetitions)]153#[derive(Clone, Trace)]154pub struct ObjValue(pub(crate) Cc<ObjValueInternals>);155impl Debug for ObjValue {156	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {157		if let Some(super_obj) = self.0.sup.as_ref() {158			if f.alternate() {159				write!(f, "{super_obj:#?}")?;160			} else {161				write!(f, "{super_obj:?}")?;162			}163			write!(f, " + ")?;164		}165		let mut debug = f.debug_struct("ObjValue");166		for (name, member) in self.0.this_entries.iter() {167			debug.field(name, member);168		}169		debug.finish_non_exhaustive()170	}171}172173impl ObjValue {174	pub fn new(175		sup: Option<Self>,176		this_entries: Cc<GcHashMap<IStr, ObjMember>>,177		assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,178	) -> Self {179		Self(Cc::new(ObjValueInternals {180			sup,181			this: None,182			assertions,183			assertions_ran: RefCell::new(GcHashSet::new()),184			this_entries,185			value_cache: RefCell::new(GcHashMap::new()),186		}))187	}188	pub fn new_empty() -> Self {189		Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))190	}191	#[must_use]192	pub fn extend_from(&self, sup: Self) -> Self {193		match &self.0.sup {194			None => Self::new(195				Some(sup),196				self.0.this_entries.clone(),197				self.0.assertions.clone(),198			),199			Some(v) => Self::new(200				Some(v.extend_from(sup)),201				self.0.this_entries.clone(),202				self.0.assertions.clone(),203			),204		}205	}206	pub(crate) fn extend_with_raw_member(self, key: IStr, value: ObjMember) -> Self {207		let mut new = GcHashMap::with_capacity(1);208		new.insert(key, value);209		Self::new(Some(self), Cc::new(new), Cc::new(Vec::new()))210	}211	pub fn extend_field(&mut self, name: IStr) -> ObjMemberBuilder<ExtendBuilder<'_>> {212		ObjMemberBuilder::new(ExtendBuilder(self), name, FieldIndex::default())213	}214215	#[must_use]216	pub fn with_this(&self, this: Self) -> Self {217		Self(Cc::new(ObjValueInternals {218			sup: self.0.sup.clone(),219			assertions: self.0.assertions.clone(),220			assertions_ran: RefCell::new(GcHashSet::new()),221			this: Some(this),222			this_entries: self.0.this_entries.clone(),223			value_cache: RefCell::new(GcHashMap::new()),224		}))225	}226227	pub fn len(&self) -> usize {228		self.fields_visibility()229			.into_iter()230			.filter(|(_, (visible, _))| *visible)231			.count()232	}233234	pub fn is_empty(&self) -> bool {235		if !self.0.this_entries.is_empty() {236			return false;237		}238		self.0.sup.as_ref().map_or(true, Self::is_empty)239	}240241	/// Run callback for every field found in object242	///243	/// Returns true if ended prematurely244	pub(crate) fn enum_fields(245		&self,246		depth: SuperDepth,247		handler: &mut impl FnMut(SuperDepth, &IStr, &ObjMember) -> bool,248	) -> bool {249		if let Some(s) = &self.0.sup {250			if s.enum_fields(depth.deeper(), handler) {251				return true;252			}253		}254		for (name, member) in self.0.this_entries.iter() {255			if handler(depth, name, member) {256				return true;257			}258		}259		false260	}261262	pub fn fields_visibility(&self) -> FxHashMap<IStr, (bool, FieldSortKey)> {263		let mut out = FxHashMap::default();264		self.enum_fields(SuperDepth::default(), &mut |depth, name, member| {265			let new_sort_key = FieldSortKey::new(depth, member.original_index);266			let entry = out.entry(name.clone());267			let (visible, _) = entry.or_insert((true, new_sort_key));268			match member.visibility {269				Visibility::Normal => {}270				Visibility::Hidden => {271					*visible = false;272				}273				Visibility::Unhide => {274					*visible = true;275				}276			};277			false278		});279		out280	}281	pub fn fields_ex(282		&self,283		include_hidden: bool,284		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,285	) -> Vec<IStr> {286		#[cfg(feature = "exp-preserve-order")]287		if preserve_order {288			let (mut fields, mut keys): (Vec<_>, Vec<_>) = self289				.fields_visibility()290				.into_iter()291				.filter(|(_, (visible, _))| include_hidden || *visible)292				.enumerate()293				.map(|(idx, (k, (_, sk)))| (k, (sk, idx)))294				.unzip();295			keys.sort_unstable_by_key(|v| v.0);296			// Reorder in-place by resulting indexes297			for i in 0..fields.len() {298				let x = fields[i].clone();299				let mut j = i;300				loop {301					let k = keys[j].1;302					keys[j].1 = j;303					if k == i {304						break;305					}306					fields[j] = fields[k].clone();307					j = k308				}309				fields[j] = x;310			}311			return fields;312		}313314		let mut fields: Vec<_> = self315			.fields_visibility()316			.into_iter()317			.filter(|(_, (visible, _))| include_hidden || *visible)318			.map(|(k, _)| k)319			.collect();320		fields.sort_unstable();321		fields322	}323	pub fn fields(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Vec<IStr> {324		self.fields_ex(325			false,326			#[cfg(feature = "exp-preserve-order")]327			preserve_order,328		)329	}330331	pub fn field_visibility(&self, name: IStr) -> Option<Visibility> {332		if let Some(m) = self.0.this_entries.get(&name) {333			Some(match &m.visibility {334				Visibility::Normal => self335					.0336					.sup337					.as_ref()338					.and_then(|super_obj| super_obj.field_visibility(name))339					.unwrap_or(Visibility::Normal),340				v => *v,341			})342		} else if let Some(super_obj) = &self.0.sup {343			super_obj.field_visibility(name)344		} else {345			None346		}347	}348349	fn has_field_include_hidden(&self, name: IStr) -> bool {350		if self.0.this_entries.contains_key(&name) {351			true352		} else if let Some(super_obj) = &self.0.sup {353			super_obj.has_field_include_hidden(name)354		} else {355			false356		}357	}358359	pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {360		if include_hidden {361			self.has_field_include_hidden(name)362		} else {363			self.has_field(name)364		}365	}366	pub fn has_field(&self, name: IStr) -> bool {367		self.field_visibility(name)368			.map_or(false, |v| v.is_visible())369	}370371	pub fn iter(&self) -> impl Iterator<Item = (IStr, Result<Val>)> + '_ {372		let fields = self.fields();373		fields.into_iter().map(|field| {374			(375				field.clone(),376				self.get(field)377					.map(|opt| opt.expect("iterating over keys, field exists")),378			)379		})380	}381382	pub fn get(&self, key: IStr) -> Result<Option<Val>> {383		self.run_assertions()?;384		if let Some(v) = self.0.value_cache.borrow().get(&key) {385			return Ok(match v {386				CacheValue::Cached(v) => Some(v.clone()),387				CacheValue::NotFound => None,388				CacheValue::Pending => throw!(InfiniteRecursionDetected),389				CacheValue::Errored(e) => return Err(e.clone()),390			});391		}392		self.0393			.value_cache394			.borrow_mut()395			.insert(key.clone(), CacheValue::Pending);396		let value = self397			.get_raw(398				key.clone(),399				self.0.this.clone().unwrap_or_else(|| self.clone()),400			)401			.map_err(|e| {402				self.0403					.value_cache404					.borrow_mut()405					.insert(key.clone(), CacheValue::Errored(e.clone()));406				e407			})?;408		self.0.value_cache.borrow_mut().insert(409			key,410			value411				.as_ref()412				.map_or(CacheValue::NotFound, |v| CacheValue::Cached(v.clone())),413		);414		Ok(value)415	}416417	fn get_raw(&self, key: IStr, real_this: Self) -> Result<Option<Val>> {418		match (self.0.this_entries.get(&key), &self.0.sup) {419			(Some(k), None) => Ok(Some(self.evaluate_this(k, real_this)?)),420			(Some(k), Some(super_obj)) => {421				let our = self.evaluate_this(k, real_this.clone())?;422				if k.add {423					super_obj424						.get_raw(key, real_this)?425						.map_or(Ok(Some(our.clone())), |v| {426							Ok(Some(evaluate_add_op(&v, &our)?))427						})428				} else {429					Ok(Some(our))430				}431			}432			(None, Some(super_obj)) => super_obj.get_raw(key, real_this),433			(None, None) => Ok(None),434		}435	}436	fn evaluate_this(&self, v: &ObjMember, real_this: Self) -> Result<Val> {437		v.invoke438			.evaluate(self.0.sup.clone(), Some(real_this))?439			.evaluate()440	}441442	fn run_assertions_raw(&self, real_this: &Self) -> Result<()> {443		if self.0.assertions_ran.borrow_mut().insert(real_this.clone()) {444			for assertion in self.0.assertions.iter() {445				if let Err(e) = assertion.run(self.0.sup.clone(), Some(real_this.clone())) {446					self.0.assertions_ran.borrow_mut().remove(real_this);447					return Err(e);448				}449			}450			if let Some(super_obj) = &self.0.sup {451				super_obj.run_assertions_raw(real_this)?;452			}453		}454		Ok(())455	}456	pub fn run_assertions(&self) -> Result<()> {457		self.run_assertions_raw(self)458	}459460	pub fn ptr_eq(a: &Self, b: &Self) -> bool {461		Cc::ptr_eq(&a.0, &b.0)462	}463	pub fn downgrade(self) -> WeakObjValue {464		WeakObjValue(self.0.downgrade())465	}466}467468impl PartialEq for ObjValue {469	fn eq(&self, other: &Self) -> bool {470		Cc::ptr_eq(&self.0, &other.0)471	}472}473474impl Eq for ObjValue {}475impl Hash for ObjValue {476	fn hash<H: Hasher>(&self, hasher: &mut H) {477		hasher.write_usize(addr_of!(*self.0) as usize);478	}479}480481#[allow(clippy::module_name_repetitions)]482pub struct ObjValueBuilder {483	sup: Option<ObjValue>,484	map: GcHashMap<IStr, ObjMember>,485	assertions: Vec<TraceBox<dyn ObjectAssertion>>,486	next_field_index: FieldIndex,487}488impl ObjValueBuilder {489	pub fn new() -> Self {490		Self::with_capacity(0)491	}492	pub fn with_capacity(capacity: usize) -> Self {493		Self {494			sup: None,495			map: GcHashMap::with_capacity(capacity),496			assertions: Vec::new(),497			next_field_index: FieldIndex::default(),498		}499	}500	pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {501		self.assertions.reserve_exact(capacity);502		self503	}504	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {505		self.sup = Some(super_obj);506		self507	}508509	pub fn assert(&mut self, assertion: TraceBox<dyn ObjectAssertion>) -> &mut Self {510		self.assertions.push(assertion);511		self512	}513	pub fn member(&mut self, name: IStr) -> ObjMemberBuilder<ValueBuilder<'_>> {514		let field_index = self.next_field_index;515		self.next_field_index = self.next_field_index.next();516		ObjMemberBuilder::new(ValueBuilder(self), name, field_index)517	}518519	pub fn build(self) -> ObjValue {520		ObjValue::new(self.sup, Cc::new(self.map), Cc::new(self.assertions))521	}522}523impl Default for ObjValueBuilder {524	fn default() -> Self {525		Self::with_capacity(0)526	}527}528529#[allow(clippy::module_name_repetitions)]530#[must_use = "value not added unless binding() was called"]531pub struct ObjMemberBuilder<Kind> {532	kind: Kind,533	name: IStr,534	add: bool,535	visibility: Visibility,536	original_index: FieldIndex,537	location: Option<ExprLocation>,538}539540#[allow(clippy::missing_const_for_fn)]541impl<Kind> ObjMemberBuilder<Kind> {542	pub(crate) fn new(kind: Kind, name: IStr, original_index: FieldIndex) -> Self {543		Self {544			kind,545			name,546			original_index,547			add: false,548			visibility: Visibility::Normal,549			location: None,550		}551	}552553	pub const fn with_add(mut self, add: bool) -> Self {554		self.add = add;555		self556	}557	pub fn add(self) -> Self {558		self.with_add(true)559	}560	pub fn with_visibility(mut self, visibility: Visibility) -> Self {561		self.visibility = visibility;562		self563	}564	pub fn hide(self) -> Self {565		self.with_visibility(Visibility::Hidden)566	}567	pub fn with_location(mut self, location: ExprLocation) -> Self {568		self.location = Some(location);569		self570	}571	fn build_member(self, binding: MaybeUnbound) -> (Kind, IStr, ObjMember) {572		(573			self.kind,574			self.name,575			ObjMember {576				add: self.add,577				visibility: self.visibility,578				original_index: self.original_index,579				invoke: binding,580				location: self.location,581			},582		)583	}584}585586pub struct ValueBuilder<'v>(&'v mut ObjValueBuilder);587impl ObjMemberBuilder<ValueBuilder<'_>> {588	/// Inserts value, replacing if it is already defined589	pub fn value_unchecked(self, value: Val) {590		let (receiver, name, member) =591			self.build_member(MaybeUnbound::Bound(Thunk::evaluated(value)));592		let entry = receiver.0.map.entry(name);593		entry.insert(member);594	}595596	pub fn value(self, value: Val) -> Result<()> {597		self.thunk(Thunk::evaluated(value))598	}599	pub fn thunk(self, value: Thunk<Val>) -> Result<()> {600		self.binding(MaybeUnbound::Bound(value))601	}602	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) -> Result<()> {603		self.binding(MaybeUnbound::Unbound(Cc::new(bindable)))604	}605	pub fn binding(self, binding: MaybeUnbound) -> Result<()> {606		let (receiver, name, member) = self.build_member(binding);607		let location = member.location.clone();608		let old = receiver.0.map.insert(name.clone(), member);609		if old.is_some() {610			State::push(611				CallLocation(location.as_ref()),612				|| format!("field <{}> initializtion", name.clone()),613				|| throw!(DuplicateFieldName(name.clone())),614			)?;615		}616		Ok(())617	}618}619620pub struct ExtendBuilder<'v>(&'v mut ObjValue);621impl ObjMemberBuilder<ExtendBuilder<'_>> {622	pub fn value(self, value: Val) {623		self.binding(MaybeUnbound::Bound(Thunk::evaluated(value)));624	}625	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {626		self.binding(MaybeUnbound::Unbound(Cc::new(bindable)));627	}628	pub fn binding(self, binding: MaybeUnbound) {629		let (receiver, name, member) = self.build_member(binding);630		let new = receiver.0.clone();631		*receiver.0 = new.extend_with_raw_member(name, member);632	}633}
after · crates/jrsonnet-evaluator/src/obj.rs
1use std::{2	cell::RefCell,3	fmt::Debug,4	hash::{Hash, Hasher},5	ptr::addr_of,6};78use jrsonnet_gcmodule::{Cc, Trace, Weak};9use jrsonnet_interner::IStr;10use jrsonnet_parser::{ExprLocation, Visibility};11use rustc_hash::FxHashMap;1213use crate::{14	error::{Error::*, LocError},15	function::CallLocation,16	gc::{GcHashMap, GcHashSet, TraceBox},17	operator::evaluate_add_op,18	throw, MaybeUnbound, Result, State, Thunk, Unbound, Val,19};2021#[cfg(not(feature = "exp-preserve-order"))]22mod ordering {23	#![allow(24		// This module works as stub for preserve-order feature25		clippy::unused_self,26	)]2728	use jrsonnet_gcmodule::Trace;2930	#[derive(Clone, Copy, Default, Debug, Trace)]31	pub struct FieldIndex;32	impl FieldIndex {33		pub const fn next(self) -> Self {34			Self35		}36	}3738	#[derive(Clone, Copy, Default, Debug, Trace)]39	pub struct SuperDepth;40	impl SuperDepth {41		pub const fn deeper(self) -> Self {42			Self43		}44	}4546	#[derive(Clone, Copy)]47	pub struct FieldSortKey;48	impl FieldSortKey {49		pub const fn new(_: SuperDepth, _: FieldIndex) -> Self {50			Self51		}52	}53}5455#[cfg(feature = "exp-preserve-order")]56mod ordering {57	use std::cmp::Reverse;5859	use jrsonnet_gcmodule::Trace;6061	#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]62	pub struct FieldIndex(u32);63	impl FieldIndex {64		pub fn next(self) -> Self {65			Self(self.0 + 1)66		}67	}6869	#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]70	pub struct SuperDepth(u32);71	impl SuperDepth {72		pub fn deeper(self) -> Self {73			Self(self.0 + 1)74		}75	}7677	#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]78	pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);79	impl FieldSortKey {80		pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {81			Self(Reverse(depth), index)82		}83		pub fn collide(self, other: Self) -> Self {84			if self.0 .0 > other.0 .0 {85				self86			} else if self.0 .0 < other.0 .0 {87				other88			} else {89				unreachable!("object can't have two fields with same name")90			}91		}92	}93}9495use ordering::*;9697#[allow(clippy::module_name_repetitions)]98#[derive(Debug, Trace)]99pub struct ObjMember {100	pub add: bool,101	pub visibility: Visibility,102	original_index: FieldIndex,103	pub invoke: MaybeUnbound,104	pub location: Option<ExprLocation>,105}106107pub trait ObjectAssertion: Trace {108	fn run(&self, super_obj: Option<ObjValue>, this: Option<ObjValue>) -> Result<()>;109}110111// Field => This112113#[derive(Trace)]114enum CacheValue {115	Cached(Val),116	NotFound,117	Pending,118	Errored(LocError),119}120121#[allow(clippy::module_name_repetitions)]122#[derive(Trace)]123#[trace(tracking(force))]124pub struct ObjValueInternals {125	sup: Option<ObjValue>,126	this: Option<ObjValue>,127128	assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,129	assertions_ran: RefCell<GcHashSet<ObjValue>>,130	this_entries: Cc<GcHashMap<IStr, ObjMember>>,131	value_cache: RefCell<GcHashMap<IStr, CacheValue>>,132}133134#[derive(Clone, Trace)]135pub struct WeakObjValue(#[trace(skip)] pub(crate) Weak<ObjValueInternals>);136137impl PartialEq for WeakObjValue {138	fn eq(&self, other: &Self) -> bool {139		Weak::ptr_eq(&self.0, &other.0)140	}141}142143impl Eq for WeakObjValue {}144impl Hash for WeakObjValue {145	fn hash<H: Hasher>(&self, hasher: &mut H) {146		// Safety: usize is POD147		let addr = unsafe { *std::ptr::addr_of!(self.0).cast() };148		hasher.write_usize(addr);149	}150}151152#[allow(clippy::module_name_repetitions)]153#[derive(Clone, Trace)]154pub struct ObjValue(pub(crate) Cc<ObjValueInternals>);155impl Debug for ObjValue {156	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {157		if let Some(super_obj) = self.0.sup.as_ref() {158			if f.alternate() {159				write!(f, "{super_obj:#?}")?;160			} else {161				write!(f, "{super_obj:?}")?;162			}163			write!(f, " + ")?;164		}165		let mut debug = f.debug_struct("ObjValue");166		for (name, member) in self.0.this_entries.iter() {167			debug.field(name, member);168		}169		debug.finish_non_exhaustive()170	}171}172173impl ObjValue {174	pub fn new(175		sup: Option<Self>,176		this_entries: Cc<GcHashMap<IStr, ObjMember>>,177		assertions: Cc<Vec<TraceBox<dyn ObjectAssertion>>>,178	) -> Self {179		Self(Cc::new(ObjValueInternals {180			sup,181			this: None,182			assertions,183			assertions_ran: RefCell::new(GcHashSet::new()),184			this_entries,185			value_cache: RefCell::new(GcHashMap::new()),186		}))187	}188	pub fn new_empty() -> Self {189		Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))190	}191	#[must_use]192	pub fn extend_from(&self, sup: Self) -> Self {193		match &self.0.sup {194			None => Self::new(195				Some(sup),196				self.0.this_entries.clone(),197				self.0.assertions.clone(),198			),199			Some(v) => Self::new(200				Some(v.extend_from(sup)),201				self.0.this_entries.clone(),202				self.0.assertions.clone(),203			),204		}205	}206	pub(crate) fn extend_with_raw_member(self, key: IStr, value: ObjMember) -> Self {207		let mut new = GcHashMap::with_capacity(1);208		new.insert(key, value);209		Self::new(Some(self), Cc::new(new), Cc::new(Vec::new()))210	}211	pub fn extend_field(&mut self, name: IStr) -> ObjMemberBuilder<ExtendBuilder<'_>> {212		ObjMemberBuilder::new(ExtendBuilder(self), name, FieldIndex::default())213	}214215	#[must_use]216	pub fn with_this(&self, this: Self) -> Self {217		Self(Cc::new(ObjValueInternals {218			sup: self.0.sup.clone(),219			assertions: self.0.assertions.clone(),220			assertions_ran: RefCell::new(GcHashSet::new()),221			this: Some(this),222			this_entries: self.0.this_entries.clone(),223			value_cache: RefCell::new(GcHashMap::new()),224		}))225	}226227	pub fn len(&self) -> usize {228		self.fields_visibility()229			.into_iter()230			.filter(|(_, (visible, _))| *visible)231			.count()232	}233234	pub fn is_empty(&self) -> bool {235		if !self.0.this_entries.is_empty() {236			return false;237		}238		self.0.sup.as_ref().map_or(true, Self::is_empty)239	}240241	/// Run callback for every field found in object242	///243	/// Returns true if ended prematurely244	pub(crate) fn enum_fields(245		&self,246		depth: SuperDepth,247		handler: &mut impl FnMut(SuperDepth, &IStr, &ObjMember) -> bool,248	) -> bool {249		if let Some(s) = &self.0.sup {250			if s.enum_fields(depth.deeper(), handler) {251				return true;252			}253		}254		for (name, member) in self.0.this_entries.iter() {255			if handler(depth, name, member) {256				return true;257			}258		}259		false260	}261262	pub fn fields_visibility(&self) -> FxHashMap<IStr, (bool, FieldSortKey)> {263		let mut out = FxHashMap::default();264		self.enum_fields(SuperDepth::default(), &mut |depth, name, member| {265			let new_sort_key = FieldSortKey::new(depth, member.original_index);266			let entry = out.entry(name.clone());267			let (visible, _) = entry.or_insert((true, new_sort_key));268			match member.visibility {269				Visibility::Normal => {}270				Visibility::Hidden => {271					*visible = false;272				}273				Visibility::Unhide => {274					*visible = true;275				}276			};277			false278		});279		out280	}281	pub fn fields_ex(282		&self,283		include_hidden: bool,284		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,285	) -> Vec<IStr> {286		#[cfg(feature = "exp-preserve-order")]287		if preserve_order {288			let (mut fields, mut keys): (Vec<_>, Vec<_>) = self289				.fields_visibility()290				.into_iter()291				.filter(|(_, (visible, _))| include_hidden || *visible)292				.enumerate()293				.map(|(idx, (k, (_, sk)))| (k, (sk, idx)))294				.unzip();295			keys.sort_unstable_by_key(|v| v.0);296			// Reorder in-place by resulting indexes297			for i in 0..fields.len() {298				let x = fields[i].clone();299				let mut j = i;300				loop {301					let k = keys[j].1;302					keys[j].1 = j;303					if k == i {304						break;305					}306					fields[j] = fields[k].clone();307					j = k308				}309				fields[j] = x;310			}311			return fields;312		}313314		let mut fields: Vec<_> = self315			.fields_visibility()316			.into_iter()317			.filter(|(_, (visible, _))| include_hidden || *visible)318			.map(|(k, _)| k)319			.collect();320		fields.sort_unstable();321		fields322	}323	pub fn fields(&self, #[cfg(feature = "exp-preserve-order")] preserve_order: bool) -> Vec<IStr> {324		self.fields_ex(325			false,326			#[cfg(feature = "exp-preserve-order")]327			preserve_order,328		)329	}330331	pub fn field_visibility(&self, name: IStr) -> Option<Visibility> {332		if let Some(m) = self.0.this_entries.get(&name) {333			Some(match &m.visibility {334				Visibility::Normal => self335					.0336					.sup337					.as_ref()338					.and_then(|super_obj| super_obj.field_visibility(name))339					.unwrap_or(Visibility::Normal),340				v => *v,341			})342		} else if let Some(super_obj) = &self.0.sup {343			super_obj.field_visibility(name)344		} else {345			None346		}347	}348349	fn has_field_include_hidden(&self, name: IStr) -> bool {350		if self.0.this_entries.contains_key(&name) {351			true352		} else if let Some(super_obj) = &self.0.sup {353			super_obj.has_field_include_hidden(name)354		} else {355			false356		}357	}358359	pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {360		if include_hidden {361			self.has_field_include_hidden(name)362		} else {363			self.has_field(name)364		}365	}366	pub fn has_field(&self, name: IStr) -> bool {367		self.field_visibility(name)368			.map_or(false, |v| v.is_visible())369	}370371	pub fn iter(372		&self,373		#[cfg(feature = "exp-preserve-order")] preserve_order: bool,374	) -> impl Iterator<Item = (IStr, Result<Val>)> + '_ {375		let fields = self.fields(376			#[cfg(feature = "exp-preserve-order")]377			preserve_order,378		);379		fields.into_iter().map(|field| {380			(381				field.clone(),382				self.get(field)383					.map(|opt| opt.expect("iterating over keys, field exists")),384			)385		})386	}387388	pub fn get(&self, key: IStr) -> Result<Option<Val>> {389		self.run_assertions()?;390		if let Some(v) = self.0.value_cache.borrow().get(&key) {391			return Ok(match v {392				CacheValue::Cached(v) => Some(v.clone()),393				CacheValue::NotFound => None,394				CacheValue::Pending => throw!(InfiniteRecursionDetected),395				CacheValue::Errored(e) => return Err(e.clone()),396			});397		}398		self.0399			.value_cache400			.borrow_mut()401			.insert(key.clone(), CacheValue::Pending);402		let value = self403			.get_raw(404				key.clone(),405				self.0.this.clone().unwrap_or_else(|| self.clone()),406			)407			.map_err(|e| {408				self.0409					.value_cache410					.borrow_mut()411					.insert(key.clone(), CacheValue::Errored(e.clone()));412				e413			})?;414		self.0.value_cache.borrow_mut().insert(415			key,416			value417				.as_ref()418				.map_or(CacheValue::NotFound, |v| CacheValue::Cached(v.clone())),419		);420		Ok(value)421	}422423	fn get_raw(&self, key: IStr, real_this: Self) -> Result<Option<Val>> {424		match (self.0.this_entries.get(&key), &self.0.sup) {425			(Some(k), None) => Ok(Some(self.evaluate_this(k, real_this)?)),426			(Some(k), Some(super_obj)) => {427				let our = self.evaluate_this(k, real_this.clone())?;428				if k.add {429					super_obj430						.get_raw(key, real_this)?431						.map_or(Ok(Some(our.clone())), |v| {432							Ok(Some(evaluate_add_op(&v, &our)?))433						})434				} else {435					Ok(Some(our))436				}437			}438			(None, Some(super_obj)) => super_obj.get_raw(key, real_this),439			(None, None) => Ok(None),440		}441	}442	fn evaluate_this(&self, v: &ObjMember, real_this: Self) -> Result<Val> {443		v.invoke444			.evaluate(self.0.sup.clone(), Some(real_this))?445			.evaluate()446	}447448	fn run_assertions_raw(&self, real_this: &Self) -> Result<()> {449		if self.0.assertions_ran.borrow_mut().insert(real_this.clone()) {450			for assertion in self.0.assertions.iter() {451				if let Err(e) = assertion.run(self.0.sup.clone(), Some(real_this.clone())) {452					self.0.assertions_ran.borrow_mut().remove(real_this);453					return Err(e);454				}455			}456			if let Some(super_obj) = &self.0.sup {457				super_obj.run_assertions_raw(real_this)?;458			}459		}460		Ok(())461	}462	pub fn run_assertions(&self) -> Result<()> {463		self.run_assertions_raw(self)464	}465466	pub fn ptr_eq(a: &Self, b: &Self) -> bool {467		Cc::ptr_eq(&a.0, &b.0)468	}469	pub fn downgrade(self) -> WeakObjValue {470		WeakObjValue(self.0.downgrade())471	}472}473474impl PartialEq for ObjValue {475	fn eq(&self, other: &Self) -> bool {476		Cc::ptr_eq(&self.0, &other.0)477	}478}479480impl Eq for ObjValue {}481impl Hash for ObjValue {482	fn hash<H: Hasher>(&self, hasher: &mut H) {483		hasher.write_usize(addr_of!(*self.0) as usize);484	}485}486487#[allow(clippy::module_name_repetitions)]488pub struct ObjValueBuilder {489	sup: Option<ObjValue>,490	map: GcHashMap<IStr, ObjMember>,491	assertions: Vec<TraceBox<dyn ObjectAssertion>>,492	next_field_index: FieldIndex,493}494impl ObjValueBuilder {495	pub fn new() -> Self {496		Self::with_capacity(0)497	}498	pub fn with_capacity(capacity: usize) -> Self {499		Self {500			sup: None,501			map: GcHashMap::with_capacity(capacity),502			assertions: Vec::new(),503			next_field_index: FieldIndex::default(),504		}505	}506	pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {507		self.assertions.reserve_exact(capacity);508		self509	}510	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {511		self.sup = Some(super_obj);512		self513	}514515	pub fn assert(&mut self, assertion: TraceBox<dyn ObjectAssertion>) -> &mut Self {516		self.assertions.push(assertion);517		self518	}519	pub fn member(&mut self, name: IStr) -> ObjMemberBuilder<ValueBuilder<'_>> {520		let field_index = self.next_field_index;521		self.next_field_index = self.next_field_index.next();522		ObjMemberBuilder::new(ValueBuilder(self), name, field_index)523	}524525	pub fn build(self) -> ObjValue {526		ObjValue::new(self.sup, Cc::new(self.map), Cc::new(self.assertions))527	}528}529impl Default for ObjValueBuilder {530	fn default() -> Self {531		Self::with_capacity(0)532	}533}534535#[allow(clippy::module_name_repetitions)]536#[must_use = "value not added unless binding() was called"]537pub struct ObjMemberBuilder<Kind> {538	kind: Kind,539	name: IStr,540	add: bool,541	visibility: Visibility,542	original_index: FieldIndex,543	location: Option<ExprLocation>,544}545546#[allow(clippy::missing_const_for_fn)]547impl<Kind> ObjMemberBuilder<Kind> {548	pub(crate) fn new(kind: Kind, name: IStr, original_index: FieldIndex) -> Self {549		Self {550			kind,551			name,552			original_index,553			add: false,554			visibility: Visibility::Normal,555			location: None,556		}557	}558559	pub const fn with_add(mut self, add: bool) -> Self {560		self.add = add;561		self562	}563	pub fn add(self) -> Self {564		self.with_add(true)565	}566	pub fn with_visibility(mut self, visibility: Visibility) -> Self {567		self.visibility = visibility;568		self569	}570	pub fn hide(self) -> Self {571		self.with_visibility(Visibility::Hidden)572	}573	pub fn with_location(mut self, location: ExprLocation) -> Self {574		self.location = Some(location);575		self576	}577	fn build_member(self, binding: MaybeUnbound) -> (Kind, IStr, ObjMember) {578		(579			self.kind,580			self.name,581			ObjMember {582				add: self.add,583				visibility: self.visibility,584				original_index: self.original_index,585				invoke: binding,586				location: self.location,587			},588		)589	}590}591592pub struct ValueBuilder<'v>(&'v mut ObjValueBuilder);593impl ObjMemberBuilder<ValueBuilder<'_>> {594	/// Inserts value, replacing if it is already defined595	pub fn value_unchecked(self, value: Val) {596		let (receiver, name, member) =597			self.build_member(MaybeUnbound::Bound(Thunk::evaluated(value)));598		let entry = receiver.0.map.entry(name);599		entry.insert(member);600	}601602	pub fn value(self, value: Val) -> Result<()> {603		self.thunk(Thunk::evaluated(value))604	}605	pub fn thunk(self, value: Thunk<Val>) -> Result<()> {606		self.binding(MaybeUnbound::Bound(value))607	}608	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) -> Result<()> {609		self.binding(MaybeUnbound::Unbound(Cc::new(bindable)))610	}611	pub fn binding(self, binding: MaybeUnbound) -> Result<()> {612		let (receiver, name, member) = self.build_member(binding);613		let location = member.location.clone();614		let old = receiver.0.map.insert(name.clone(), member);615		if old.is_some() {616			State::push(617				CallLocation(location.as_ref()),618				|| format!("field <{}> initializtion", name.clone()),619				|| throw!(DuplicateFieldName(name.clone())),620			)?;621		}622		Ok(())623	}624}625626pub struct ExtendBuilder<'v>(&'v mut ObjValue);627impl ObjMemberBuilder<ExtendBuilder<'_>> {628	pub fn value(self, value: Val) {629		self.binding(MaybeUnbound::Bound(Thunk::evaluated(value)));630	}631	pub fn bindable(self, bindable: TraceBox<dyn Unbound<Bound = Thunk<Val>>>) {632		self.binding(MaybeUnbound::Unbound(Cc::new(bindable)));633	}634	pub fn binding(self, binding: MaybeUnbound) {635		let (receiver, name, member) = self.build_member(binding);636		let new = receiver.0.clone();637		*receiver.0 = new.extend_with_raw_member(name, member);638	}639}
modifiedcrates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -625,6 +625,7 @@
 pub fn format_arr(str: &str, mut values: &[Val]) -> Result<String> {
 	let codes = parse_codes(str)?;
 	let mut out = String::new();
+	let value_count = values.len();
 
 	for code in codes {
 		match code {
@@ -673,6 +674,13 @@
 		}
 	}
 
+	if !values.is_empty() {
+		throw!(
+			"too many values to format, expected {value_count}, got {}",
+			value_count + values.len()
+		)
+	}
+
 	Ok(out)
 }
 
modifiedcrates/jrsonnet-interner/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-interner/Cargo.toml
+++ b/crates/jrsonnet-interner/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet-interner"
 description = "Jrsonnet string interning"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -255,9 +255,7 @@
 		let mut pool = pool.borrow_mut();
 		let entry = pool.raw_entry_mut().from_key(bytes);
 		match entry {
-			hashbrown::hash_map::RawEntryMut::Occupied(mut i) => {
-				IBytes(i.get_key_value().0.clone())
-			}
+			hashbrown::hash_map::RawEntryMut::Occupied(i) => IBytes(i.get_key_value().0.clone()),
 			hashbrown::hash_map::RawEntryMut::Vacant(e) => {
 				let (k, _) = e.insert(Inner::new_bytes(bytes), ());
 				IBytes(k.clone())
modifiedcrates/jrsonnet-macros/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-macros/Cargo.toml
+++ b/crates/jrsonnet-macros/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "jrsonnet-macros"
-version = "0.4.2"
+version.workspace = true
 edition = "2021"
 
 [lib]
modifiedcrates/jrsonnet-parser/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-parser/Cargo.toml
+++ b/crates/jrsonnet-parser/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet-parser"
 description = "jsonnet language parser and AST"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
@@ -26,7 +26,7 @@
 serde = ["dep:serde"]
 
 [dependencies]
-jrsonnet-interner = { path = "../jrsonnet-interner", version = "0.4.2" }
+jrsonnet-interner.workspace = true
 jrsonnet-gcmodule = { version = "0.3.4" }
 
 static_assertions = "1.1"
modifiedcrates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet-stdlib"
 description = "jsonnet standard library packaged as crate"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"
@@ -17,9 +17,9 @@
 exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]
 
 [dependencies]
-jrsonnet-evaluator = { path = "../jrsonnet-evaluator", version = "0.4.2" }
-jrsonnet-macros = { path = "../jrsonnet-macros", version = "0.4.2" }
-jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.4.2" }
+jrsonnet-evaluator.workspace = true
+jrsonnet-macros.workspace = true
+jrsonnet-parser.workspace = true
 jrsonnet-gcmodule = "0.3.4"
 
 # Used for stdlib AST serialization
@@ -37,5 +37,5 @@
 serde_yaml_with_quirks = "0.8.24"
 
 [build-dependencies]
-jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.4.2" }
+jrsonnet-parser.workspace = true
 structdump = { version = "0.2.0", features = ["derive"] }
modifiedcrates/jrsonnet-types/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "jrsonnet-types"
 description = "Jrsonnet type system definition"
-version = "0.4.2"
+version.workspace = true
 authors = ["Yaroslav Bolyukin <iam@lach.pw>"]
 license = "MIT"
 edition = "2021"