difftreelog
refactor greately simplify object self/super implementation
in: master
18 files changed
Cargo.lockdiffbeforeafterboth180 packageslockfile v4
Might be heavy and slow!
ahash
0.8.12crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75used byaho-corasick
1.1.4crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301depends onaliasable
0.1.3crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fdused byallocator-api2
0.2.21crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923annotate-snippets
0.12.11crates.io↘ 2↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum16e4850548ff4a25a77ce3bda7241874e17fb702ea551f0cc62a2dbe052f1272depends onannotated-string
0.3.0crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum298ed730801db3c02f2edba003c9420a0f57ea48d37fdc5601c536113668c059used byanstream
0.6.21crates.io↘ 7↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4adepends onused byanstyle
1.0.13crates.io↘ 0↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78anstyle-parse
0.2.7crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2depends onused byanstyle-query
1.1.5crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadcdepends onused byanstyle-wincon
3.0.11crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747dused byanyhow
1.0.101crates.io↘ 0↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75eaar_archive_writer
0.5.1crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7eb93bbb63b9c227414f6eb3a0adfddca591a8ce1e9b60661bb08969b87e340bdepends onused byarraydeque
0.5.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236used byautocfg
1.5.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8used bybase64
0.22.1crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6bitflags
2.10.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3used byblock-buffer
0.10.4crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71depends onused bybumpalo
3.19.1crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510depends oncc
1.2.55crates.io↘ 2↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum47b26a0954ae34af09b50f0de26458fa95369a0d478d8236d3f93082b219bd29depends oncfg-if
1.0.4crates.io↘ 0↖ 7sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801clap
4.5.57crates.io↘ 2↖ 5sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum6899ea499e3fb9305a65d5ebf6e3d2248c5fab291f300ad0a704fbe142eae31adepends onclap_builder
4.5.57crates.io↘ 4↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7b12c8b680195a62a8364d16b8447b01b6c2c8f9aaf68bee653be34d4245e238used byclap_complete
4.5.65crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum430b4dc2b5e3861848de79627b2bedc9f3342c7da5173a14eaa5d0f8dc18ae5ddepends onused byclap_derive
4.5.55crates.io↘ 4↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5used byclap_lex
0.7.7crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumc3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32used bycolorchoice
1.0.4crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumb05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75used byconsole
0.15.11crates.io↘ 4↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8used bycountme
3.0.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636used bycpufeatures
0.2.17crates.io↘ 1↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280depends oncrypto-common
0.1.7crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60adepends onused bydifflib
0.4.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8used bydigest
0.10.7crates.io↘ 2↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292depends ondprint-core
0.67.4crates.io↘ 7↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2c1d827947704a9495f705d6aeed270fa21a67f825f22902c28f38dc3af7a9aedepends onused bydrop_bomb
0.1.5crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9bda8e21c04aca2ae33ffc2fd8c23134f3cac46db123ba97bd9d3f3b8a4a85e1either
1.15.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719used byencode_unicode
1.0.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0used byencoding_rs
0.8.35crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3depends onused byencoding_rs_io
0.1.7crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum1cc3c5651fb62ab8aa3103998dade57efdd028544bd300516baa31840c252a83depends onused byequivalent
1.0.2crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0ferrno
0.3.14crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efebdepends onused byextension-trait
1.0.2crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumdd65f1b59dd22d680c7a626cc4a000c1e03d241c51c3e034d2bc9f1e90734f9bdepends onused byfastrand
2.3.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411beused byfind-msvc-tools
0.1.9crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582used byfnv
1.0.7crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1used byfoldhash
0.1.5crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2used byfoldhash
0.2.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdbused bygeneric-array
0.14.7crates.io↘ 2↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9adepends ongetrandom
0.3.4crates.io↘ 6↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fdhashbrown
0.14.5crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1used byhashbrown
0.15.5crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1used byhashbrown
0.16.1crates.io↘ 3↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100heck
0.4.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8used byheck
0.5.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55eaused byhi-doc
0.3.0crates.io↘ 10↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf70fb920ba34768415fb239d7d607486083bfc38ad35e3f1d558697f9f646f11depends onhi-doc-jumprope
1.2.1crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum236c25809a9c0a0249b3488feb57744e12aa64e4f3db851980eab303719c7bdddepends onused byindexmap
2.13.0crates.io↘ 4↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017indoc
2.0.7crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706depends oninsta
1.46.3crates.io↘ 4↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume82db8c87c7f1ccecb34ce0c24399b8a73081427f3c7c50a5d597925356115e4is_terminal_polyfill
1.70.2crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695used byitertools
0.14.0crates.io↘ 1↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285depends onitoa
1.0.17crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2used byjrsonnet-cli
0.5.0-pre97workspace↘ 5↖ 1jrsonnet-evaluator
0.5.0-pre97workspace↘ 17↖ 5depends on- annotate-snippets
0.12.11 - anyhow
1.0.101 - hi-doc
0.3.0 - jrsonnet-gcmodule
0.4.0 - jrsonnet-interner
0.5.0-pre97 - jrsonnet-macros
0.5.0-pre97 - jrsonnet-parser
0.5.0-pre97 - jrsonnet-types
0.5.0-pre97 - num-bigint
0.4.6 - pathdiff
0.2.3 - rustc-hash
2.1.1 - rustversion
1.0.22 - serde
1.0.228 - stacker
0.1.23 - static_assertions
1.1.0 - strsim
0.11.1 - thiserror
2.0.18
- annotate-snippets
jrsonnet-fmt
0.5.0-pre97workspace↘ 8↖ 0jrsonnet-gcmodule-derive
0.4.0workspace↘ 3↖ 1depends onused byjrsonnet-interner
0.5.0-pre97workspace↘ 3↖ 3jrsonnet-macros
0.5.0-pre97workspace↘ 4↖ 2jrsonnet-parser
0.5.0-pre97workspace↘ 4↖ 5jrsonnet-rowan-parser
0.5.0-pre97workspace↘ 7↖ 1jrsonnet-stdlib
0.5.0-pre97workspace↘ 16↖ 3depends onjrsonnet-types
0.5.0-pre97workspace↘ 2↖ 1depends onjs-sys
0.3.85crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3depends onused byjson-structural-diff
0.2.0crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume878e36a8a44c158505c2c818abdc1350413ad83dcb774a0459f6a7ef2b65cbfdepends onused bykeccak
0.1.5crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654depends onused bylibc
0.2.180crates.io↘ 0↖ 7sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fclibjsonnet
0.5.0-pre97workspace↘ 5↖ 0linux-raw-sys
0.11.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumdf1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039used bylogos
0.16.1crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumeb2c55a318a87600ea870ff8c2012148b44bf18b74fad48d0f835c38c7d07c5fdepends onlogos-codegen
0.16.1crates.io↘ 6↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum58b3ffaa284e1350d017a57d04ada118c4583cf260c8fb01e0fe28a2e9cf8970used bylogos-derive
0.16.1crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum52d3a9855747c17eaf4383823f135220716ab49bea5fbea7dd42cc9a92f8aa31depends onused bylru
0.16.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593depends onused bymd5
0.8.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumae960838283323069879657ca3de837e9f7bbb4c7bf6ea7f1b290d5e9476d2e0used bymemchr
2.8.0crates.io↘ 0↖ 5sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79mimalloc-sys
0.1.6crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4aa3cefb626f6ae3d0b2f71c5378c89d2b1d4d7bc246b0ca9a7ee61a4daad291depends onused bymimallocator
0.1.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2d44fe4ebf6b538fcf39d9975c2b90bb3232d1ba8e8bffeacd004f27b20c577adepends onused bynohash-hasher
0.2.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451used bynum-bigint
0.4.6crates.io↘ 3↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9num-integer
0.1.46crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858fdepends onused bynum-traits
0.2.19crates.io↘ 1↖ 5sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841depends onobject
0.37.3crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fedepends onused byonce_cell
1.21.3crates.io↘ 0↖ 6sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2donce_cell_polyfill
1.70.2crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4feused byouroboros
0.18.5crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum1e0f050db9c44b97a94723127e6be766ac5c340c48f2c4bb3ffa11713744be59used byouroboros_macro
0.18.5crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum3c7028bdd3d43083f6d8d4d5187680d0d3560d54df4cc9d752005268b41e64d0used bypathdiff
0.2.3crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumdf94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3peg
0.8.5crates.io↘ 2↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9928cfca101b36ec5163e70049ee5368a8a1c3c6efc9ca9c5f9cc2f816152477depends onpeg-macros
0.8.5crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum6298ab04c202fa5b5d52ba03269fb7b74550b150323038878fe6c372d8280f71used bypeg-runtime
0.8.5crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum132dca9b868d927b35b5dd728167b2dee150eb1ad686008fc71ccb298b776fcaused byppv-lite86
0.2.21crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9depends onused byproc-macro2
1.0.106crates.io↘ 1↖ 16sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934depends onused by- clap_derive
4.5.55 - extension-trait
1.0.2 - jrsonnet-gcmodule-derive
0.4.0 - jrsonnet-macros
0.5.0-pre97 - logos-codegen
0.16.1 - ouroboros_macro
0.18.5 - peg-macros
0.8.5 - proc-macro2-diagnostics
0.10.1 - quote
1.0.44 - serde_derive
1.0.228 - syn
2.0.114 - syn-dissect-closure
0.1.0 - thiserror-impl
2.0.18 - wasm-bindgen-macro-support
0.2.108 - xtask
0.1.0 - zerocopy-derive
0.8.39
- clap_derive
proc-macro2-diagnostics
0.10.1crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumaf066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8used bypsm
0.1.30crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum3852766467df634d74f0b2d7819bf8dc483a0eb2e3b0f50f756f9cfe8b0d18d8depends onused byquote
1.0.44crates.io↘ 1↖ 16sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4depends onused by- clap_derive
4.5.55 - extension-trait
1.0.2 - jrsonnet-gcmodule-derive
0.4.0 - jrsonnet-macros
0.5.0-pre97 - logos-codegen
0.16.1 - ouroboros_macro
0.18.5 - peg-macros
0.8.5 - proc-macro2-diagnostics
0.10.1 - serde_derive
1.0.228 - syn
2.0.114 - syn-dissect-closure
0.1.0 - thiserror-impl
2.0.18 - wasm-bindgen-macro
0.2.108 - wasm-bindgen-macro-support
0.2.108 - xtask
0.1.0 - zerocopy-derive
0.8.39
- clap_derive
r-efi
5.3.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0fused byrand
0.9.2crates.io↘ 2↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1depends onrand_chacha
0.9.0crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cbdepends onused byrand_core
0.9.5crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83cdepends onused byrandom_color
1.1.0crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd635c5e80ae160390ac62ca027d2d06c94c1dc69e5c0a12f1e3a53664dc84966depends onused byrange-map
0.2.0crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum12a5a2d6c7039059af621472a4389be1215a816df61aa4d531cfe85264aee95fdepends onused byregex
1.12.3crates.io↘ 4↖ 5sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276regex-automata
0.4.14crates.io↘ 3↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8fregex-syntax
0.8.9crates.io↘ 0↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4crowan
0.16.1crates.io↘ 4↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum417a3a9f582e349834051b8a10c8d71ca88da4211e4093528e36b9845f6b5f21rustc-hash
1.1.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2used byrustc-hash
2.1.1crates.io↘ 0↖ 4sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0drustix
1.1.3crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34used byrustversion
1.0.22crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumb39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46dsaphyr-parser-bw
0.0.607crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2f9bae8d059bf1ca32753cf3cdafbf5d391502de2fc2ca54510811fe9c100d90used byserde
1.0.228crates.io↘ 2↖ 9sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9edepends onserde_core
1.0.228crates.io↘ 1↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67addepends onserde_derive
1.0.228crates.io↘ 3↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79depends onserde_json
1.0.149crates.io↘ 6↖ 6sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86serde-saphyr
0.0.17crates.io↘ 13↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbc14a55107113a16346915d7e3d78acc539a923458385db89670e22cac106d7adepends onused bysha1
0.10.6crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksume3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6badepends onused bysha2
0.10.9crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283depends onused bysha3
0.10.8crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60depends onused bysimilar
2.7.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumbbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daaused bysmallvec
1.15.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03used bysmallvec
2.0.0-alpha.12crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumef784004ca8777809dcdad6ac37629f0a97caee4c685fcea805278d81dd8b857stacker
0.1.23crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum08d74a23609d509411d10e2176dc2a4346e3b4aea2e7b1869f19fdedbc71c013static_assertions
1.1.0crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543fstr_indices
0.4.4crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6used bystreaming-iterator
0.1.9crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520strsim
0.11.1crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4fsyn
2.0.114crates.io↘ 3↖ 12sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2asyn-dissect-closure
0.1.0crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum343bae741672e4b94421cbe93f9794ba9a061434272f7e3a29ff43be26be3ac9depends onused bytempfile
3.24.0crates.io↘ 5↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9ctests
0.1.0workspace↘ 6↖ 0text-size
1.1.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233used bythiserror
2.0.18crates.io↘ 1↖ 6sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4depends onthiserror-impl
2.0.18crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5depends onused bytree-sitter
0.26.5crates.io↘ 6↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum12987371f54efc9b9306a20dc87ed5aaee9f320c8a8b115e28515c412b2efe39depends onused bytree-sitter-highlight
0.26.5crates.io↘ 4↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2b688407049ea1b55a7e872f138947d22389118b9c4d09b459cb34ca205e41c0used bytree-sitter-language
0.1.7crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum009994f150cc0cd50ff54917d5bc8bffe8cad10ca10d81c34da2ec421ae61782used bytypenum
1.19.0crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bbungrammar
1.16.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksuma3e5df347f0bf3ec1d670aad6ca5c6a1859cd9ea61d2113125794654ccced68fused byunicode-box-drawing
0.3.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum2a1f97719cf40224391201fc11e7f5b0cc0ba21416367cfc914e2d45af4e42efused byunicode-ident
1.0.22crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5unicode-width
0.2.2crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumb4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254utf8parse
0.2.2crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821version_check
0.9.5crates.io↘ 0↖ 3sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105awasip2
1.0.2+wasi-0.2.9crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5depends onused bywasm-bindgen
0.2.108crates.io↘ 5↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566depends onused bywasm-bindgen-macro
0.2.108crates.io↘ 2↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608used bywasm-bindgen-macro-support
0.2.108crates.io↘ 5↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55used bywindows_aarch64_gnullvm
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3used bywindows_aarch64_msvc
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469used bywindows_i686_gnu
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0bused bywindows_i686_gnullvm
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66used bywindows_i686_msvc
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66used bywindows_x86_64_gnu
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78used bywindows_x86_64_gnullvm
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0dused bywindows_x86_64_msvc
0.52.6crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ecused bywindows-link
0.2.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumf0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5used bywindows-sys
0.59.0crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853bdepends onused bywindows-sys
0.61.2crates.io↘ 1↖ 5sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fcdepends onwindows-targets
0.52.6crates.io↘ 8↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973depends onused bywit-bindgen
0.51.0crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumd7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5used byxshell
0.2.7crates.io↘ 1↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373ddepends onused byxshell-macros
0.2.7crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547used byxtask
0.1.0workspace↘ 8↖ 0yansi
1.0.1crates.io↘ 0↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumcfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049zerocopy
0.8.39crates.io↘ 1↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksumdb6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4adepends onused byzerocopy-derive
0.8.39crates.io↘ 3↖ 1sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517depends onused byzmij
1.0.19crates.io↘ 0↖ 2sourceregistry+https://github.com/rust-lang/crates.io-indexchecksum3ff05f8caa9038894637571ae6b9e29466c1f4f829d26c9b28f869a29cbe3445
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -57,6 +57,7 @@
num-bigint = { workspace = true, features = ["serde"], optional = true }
stacker = "0.1.23"
+educe = { version = "0.6.0", default-features = false, features = ["Clone", "Debug", "Eq", "Hash", "PartialEq"] }
[build-dependencies]
rustversion = "1.0.22"
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -1,32 +1,27 @@
use std::fmt::Debug;
+use educe::Educe;
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;
use rustc_hash::FxHashMap;
use crate::{
error::ErrorKind::*, gc::WithCapacityExt as _, map::LayeredHashMap, ObjValue, Pending, Result,
- Thunk, Val,
+ SupThis, Thunk, Val,
};
+/// Context keeps information about current lexical code location
+///
+/// This information includes local variables, top-level object (`$`), current object (`this`), and super object (`super`)
+#[derive(Debug, Trace, Clone, Educe)]
+#[educe(PartialEq)]
+pub struct Context(#[educe(PartialEq(method = Cc::ptr_eq))] Cc<ContextInternal>);
-#[derive(Trace)]
-struct ContextInternals {
+#[derive(Debug, Trace)]
+struct ContextInternal {
dollar: Option<ObjValue>,
- sup: Option<ObjValue>,
- this: Option<ObjValue>,
+ sup_this: Option<SupThis>,
bindings: LayeredHashMap,
-}
-impl Debug for ContextInternals {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("Context").finish()
- }
}
-
-/// Context keeps information about current lexical code location
-///
-/// This information includes local variables, top-level object (`$`), current object (`this`), and super object (`super`)
-#[derive(Debug, Clone, Trace)]
-pub struct Context(Cc<ContextInternals>);
impl Context {
pub fn new_future() -> Pending<Self> {
Pending::new()
@@ -36,12 +31,35 @@
self.0.dollar.as_ref()
}
+ pub fn try_dollar(&self) -> Result<ObjValue> {
+ self.0
+ .dollar
+ .clone()
+ .ok_or_else(|| CantUseSelfSupOutsideOfObject.into())
+ }
+
pub fn this(&self) -> Option<&ObjValue> {
- self.0.this.as_ref()
+ self.0.sup_this.as_ref().map(SupThis::this)
+ }
+
+ pub fn try_this(&self) -> Result<ObjValue> {
+ self.0
+ .sup_this
+ .as_ref()
+ .ok_or_else(|| CantUseSelfSupOutsideOfObject.into())
+ .map(SupThis::this)
+ .cloned()
+ }
+
+ pub fn sup_this(&self) -> Option<&SupThis> {
+ self.0.sup_this.as_ref()
}
- pub fn super_obj(&self) -> Option<&ObjValue> {
- self.0.sup.as_ref()
+ pub fn try_sup_this(&self) -> Result<SupThis> {
+ self.0
+ .sup_this
+ .clone()
+ .ok_or_else(|| CantUseSelfSupOutsideOfObject.into())
}
pub fn binding(&self, name: IStr) -> Result<Thunk<Val>> {
@@ -83,41 +101,52 @@
pub fn with_var(self, name: impl Into<IStr>, value: Val) -> Self {
let mut new_bindings = FxHashMap::with_capacity(1);
new_bindings.insert(name.into(), Thunk::evaluated(value));
- self.extend(new_bindings, None, None, None)
+ self.extend_bindings(new_bindings)
}
#[must_use]
- pub fn extend(
+ pub fn extend_bindings_sup_this(
self,
new_bindings: FxHashMap<IStr, Thunk<Val>>,
- new_dollar: Option<ObjValue>,
- new_sup: Option<ObjValue>,
- new_this: Option<ObjValue>,
+ sup_this: SupThis,
) -> Self {
- let ctx = &self.0;
- let dollar = new_dollar.or_else(|| ctx.dollar.clone());
- let this = new_this.or_else(|| ctx.this.clone());
- let sup = new_sup.or_else(|| ctx.sup.clone());
+ let ctx = &self;
+ let dollar = ctx
+ .0
+ .dollar
+ .clone()
+ .or_else(|| Some(sup_this.this().clone()));
let bindings = if new_bindings.is_empty() {
- ctx.bindings.clone()
+ ctx.0.bindings.clone()
} else {
- ctx.bindings.clone().extend(new_bindings)
+ ctx.0.bindings.clone().extend(new_bindings)
};
- Self(Cc::new(ContextInternals {
+ Self(Cc::new(ContextInternal {
dollar,
- sup,
- this,
+ sup_this: Some(sup_this),
bindings,
}))
}
-}
-
-impl PartialEq for Context {
- fn eq(&self, other: &Self) -> bool {
- Cc::ptr_eq(&self.0, &other.0)
+ #[must_use]
+ pub fn extend_bindings(self, new_bindings: FxHashMap<IStr, Thunk<Val>>) -> Self {
+ if new_bindings.is_empty() {
+ return self;
+ }
+ let ctx = &self;
+ let bindings = if new_bindings.is_empty() {
+ ctx.0.bindings.clone()
+ } else {
+ ctx.0.bindings.clone().extend(new_bindings)
+ };
+ Self(Cc::new(ContextInternal {
+ dollar: ctx.0.dollar.clone(),
+ sup_this: ctx.0.sup_this.clone(),
+ bindings,
+ }))
}
}
+#[derive(Default)]
pub struct ContextBuilder {
bindings: FxHashMap<IStr, Thunk<Val>>,
extend: Option<Context>,
@@ -127,20 +156,25 @@
pub fn new() -> Self {
Self::with_capacity(0)
}
+
pub fn with_capacity(capacity: usize) -> Self {
Self {
bindings: FxHashMap::with_capacity(capacity),
extend: None,
}
}
+
pub fn extend(parent: Context) -> Self {
Self {
bindings: FxHashMap::new(),
extend: Some(parent),
}
}
+
/// # Panics
- /// If `name` is already bound
+ ///
+ /// If `name` is already bound. Makes no sense to bind same local multiple times,
+ /// unless it is separate context layers.
pub fn bind(&mut self, name: impl Into<IStr>, value: Thunk<Val>) -> &mut Self {
let old = self.bindings.insert(name.into(), value);
assert!(old.is_none(), "variable bound twice in single context call");
@@ -148,14 +182,12 @@
}
pub fn build(self) -> Context {
if let Some(parent) = self.extend {
- // TODO: replace self.extend with Result<Context, State>, and remove `state` field
- parent.extend(self.bindings, None, None, None)
+ parent.extend_bindings(self.bindings)
} else {
- Context(Cc::new(ContextInternals {
+ Context(Cc::new(ContextInternal {
bindings: LayeredHashMap::new(self.bindings),
dollar: None,
- sup: None,
- this: None,
+ sup_this: None,
}))
}
}
crates/jrsonnet-evaluator/src/dynamic.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/dynamic.rs
+++ b/crates/jrsonnet-evaluator/src/dynamic.rs
@@ -1,11 +1,13 @@
-use std::cell::OnceCell;
+use std::ptr::addr_of;
+use std::{cell::OnceCell, hash::Hasher};
+use educe::Educe;
use jrsonnet_gcmodule::{Cc, Trace};
use crate::{bail, error::ErrorKind::InfiniteRecursionDetected, val::ThunkValue, Result};
-// TODO: Replace with OnceCell once in std
-#[derive(Clone, Trace)]
+#[derive(Trace, Educe)]
+#[educe(Clone)]
pub struct Pending<V: Trace + 'static>(pub Cc<OnceCell<V>>);
impl<T: Trace + 'static> Pending<T> {
pub fn new() -> Self {
@@ -25,7 +27,7 @@
.expect("wrapper is filled already");
}
}
-impl<T: Clone + Trace + 'static> Pending<T> {
+impl<T: Trace + 'static + Clone> Pending<T> {
/// # Panics
/// If wrapper is not yet filled
pub fn unwrap(&self) -> T {
@@ -52,3 +54,7 @@
Self::new()
}
}
+
+pub fn identity_hash<T, H: Hasher>(v: &Cc<T>, hasher: &mut H) {
+ hasher.write_usize(addr_of!(**v) as usize);
+}
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -119,10 +119,8 @@
#[error("binary operation {1} {0} {2} is not implemented")]
BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),
- #[error("no top level object in this context")]
- NoTopLevelObjectFound,
- #[error("self is only usable inside objects")]
- CantUseSelfOutsideOfObject,
+ #[error("self/super/$ are only usable inside objects")]
+ CantUseSelfSupOutsideOfObject,
#[error("no super found")]
NoSuperFound,
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -11,18 +11,7 @@
use self::destructure::destruct;
use crate::{
- arr::ArrValue,
- bail,
- destructure::evaluate_dest,
- error::{suggest_object_fields, ErrorKind::*},
- evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},
- function::{CallLocation, FuncDesc, FuncVal},
- gc::WithCapacityExt as _,
- in_frame,
- typed::Typed,
- val::{CachedUnbound, IndexableVal, NumValue, StrValue, Thunk},
- Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, ResultExt,
- Unbound, Val,
+ Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result, ResultExt, SupThis, Unbound, Val, arr::ArrValue, bail, destructure::evaluate_dest, error::{ErrorKind::*, suggest_object_fields}, evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op}, function::{CallLocation, FuncDesc, FuncVal}, gc::WithCapacityExt as _, in_frame, typed::Typed, val::{CachedUnbound, IndexableVal, NumValue, StrValue, Thunk}, with_state
};
pub mod destructure;
pub mod operator;
@@ -126,10 +115,7 @@
let fctx = Pending::new();
let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());
destruct(var, item, fctx.clone(), &mut new_bindings)?;
- let ctx = ctx
- .clone()
- .extend(new_bindings, None, None, None)
- .into_future(fctx);
+ let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);
evaluate_comp(ctx, &specs[1..], callback)?;
}
@@ -169,18 +155,18 @@
impl<V, T> CloneableUnbound<T> for V where V: Unbound<Bound = T> + Clone {}
fn evaluate_object_locals(
- fctx: Pending<Context>,
+ fctx: Context,
locals: Rc<Vec<BindSpec>>,
) -> impl CloneableUnbound<Context> {
#[derive(Trace, Clone)]
struct UnboundLocals {
- fctx: Pending<Context>,
+ fctx: Context,
locals: Rc<Vec<BindSpec>>,
}
impl Unbound for UnboundLocals {
type Bound = Context;
- fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Context> {
+ fn bind(&self, sup_this: SupThis) -> Result<Context> {
let fctx = Context::new_future();
let mut new_bindings =
FxHashMap::with_capacity(self.locals.iter().map(BindSpec::capacity_hint).sum());
@@ -188,11 +174,10 @@
evaluate_dest(b, fctx.clone(), &mut new_bindings)?;
}
- let ctx = self.fctx.unwrap();
- let new_dollar = ctx.dollar().cloned().or_else(|| this.clone());
+ let ctx = self.fctx.clone();
let ctx = ctx
- .extend(new_bindings, new_dollar, sup, this)
+ .extend_bindings_sup_this(new_bindings, sup_this)
.into_future(fctx);
Ok(ctx)
@@ -229,8 +214,8 @@
}
impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {
type Bound = Val;
- fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {
- evaluate_named(self.uctx.bind(sup, this)?, &self.value, self.name.clone())
+ fn bind(&self, sup_this: SupThis) -> Result<Val> {
+ evaluate_named(self.uctx.bind(sup_this)?, &self.value, self.name.clone())
}
}
@@ -260,9 +245,9 @@
}
impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {
type Bound = Val;
- fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {
+ fn bind(&self, sup_this: SupThis) -> Result<Val> {
Ok(evaluate_method(
- self.uctx.bind(sup, this)?,
+ self.uctx.bind(sup_this)?,
self.name.clone(),
self.params.clone(),
self.value.clone(),
@@ -298,10 +283,8 @@
.collect::<Vec<_>>(),
);
- let fctx = Context::new_future();
-
// We have single context for all fields, so we can cache binds
- let uctx = CachedUnbound::new(evaluate_object_locals(fctx.clone(), locals));
+ let uctx = CachedUnbound::new(evaluate_object_locals(ctx.clone(), locals));
for member in members {
match member {
@@ -315,8 +298,8 @@
assert: AssertStmt,
}
impl<B: Unbound<Bound = Context>> ObjectAssertion for ObjectAssert<B> {
- fn run(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<()> {
- let ctx = self.uctx.bind(sup, this)?;
+ fn run(&self, sup_this: SupThis) -> Result<()> {
+ let ctx = self.uctx.bind(sup_this)?;
evaluate_assert(ctx, &self.assert)
}
}
@@ -330,9 +313,7 @@
}
}
}
- let this = builder.build();
- fctx.fill(ctx.extend(FxHashMap::new(), None, None, Some(this.clone())));
- Ok(this)
+ Ok(builder.build())
}
pub fn evaluate_object(ctx: Context, object: &ObjBody) -> Result<ObjValue> {
@@ -347,22 +328,13 @@
.cloned()
.collect::<Vec<_>>(),
);
- let mut ctxs = vec![];
evaluate_comp(ctx, &obj.compspecs, &mut |ctx| {
- let fctx = Context::new_future();
- ctxs.push((ctx.clone(), fctx.clone()));
- let uctx = evaluate_object_locals(fctx, locals.clone());
+ let uctx = evaluate_object_locals(ctx.clone(), locals.clone());
evaluate_field_member(&mut builder, ctx, uctx, &obj.field)
})?;
- let this = builder.build();
- for (ctx, fctx) in ctxs {
- let _ctx = ctx
- .extend(FxHashMap::new(), None, None, Some(this.clone()))
- .into_future(fctx);
- }
- this
+ builder.build()
}
})
}
@@ -428,19 +400,9 @@
}
let loc = expr.span();
Ok(match expr.expr() {
- Literal(LiteralType::This) => {
- Val::Obj(ctx.this().ok_or(CantUseSelfOutsideOfObject)?.clone())
- }
- Literal(LiteralType::Super) => Val::Obj(
- ctx.super_obj().ok_or(NoSuperFound)?.with_this(
- ctx.this()
- .expect("if super exists - then this should too")
- .clone(),
- ),
- ),
- Literal(LiteralType::Dollar) => {
- Val::Obj(ctx.dollar().ok_or(NoTopLevelObjectFound)?.clone())
- }
+ Literal(LiteralType::This) => Val::Obj(ctx.try_this()?),
+ Literal(LiteralType::Super) => Val::Obj(ctx.try_sup_this()?.standalone_super()?),
+ Literal(LiteralType::Dollar) => Val::Obj(ctx.try_dollar()?),
Literal(LiteralType::True) => Val::Bool(true),
Literal(LiteralType::False) => Val::Bool(false),
Literal(LiteralType::Null) => Val::Null,
@@ -452,15 +414,18 @@
//
// Note that other jsonnet implementations will fail on `if value in (super)` expression,
// because the standalone super literal is not supported, that is because in other
- // implementations `in super` treated differently from in `smth_else`.
+ // implementations `in super` treated differently from `in smth_else`.
BinaryOp(field, BinaryOpType::In, e)
if matches!(e.expr(), Expr::Literal(LiteralType::Super)) =>
{
- let Some(super_obj) = ctx.super_obj() else {
+ let sup_this = ctx.try_sup_this()?;
+ // In jsonnet, "field" in e is eager, LHS expression is always executed regardless of super existence.
+ // In jrsonnet, however, this wasn't true, this was kept here for compatibility.
+ if !sup_this.has_super() {
return Ok(Val::Bool(false));
- };
- let field = evaluate(ctx.clone(), field)?;
- Val::Bool(super_obj.has_field_ex(field.to_string()?, true))
+ }
+ let field = evaluate(ctx, field)?;
+ Val::Bool(sup_this.field_in_super(field.to_string()?))
}
BinaryOp(v1, o, v2) => evaluate_binary_op_special(ctx, v1, *o, v2)?,
UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(ctx, v)?)?,
@@ -473,13 +438,16 @@
let mut parts = parts.iter();
let mut indexable = if matches!(indexable.expr(), Expr::Literal(LiteralType::Super)) {
let part = parts.next().expect("at least part should exist");
- let Some(super_obj) = ctx.super_obj() else {
+ // sup_this existence check might also be skipped here for null-coalesce...
+ // But I believe this might cause errors.
+ let sup_this = ctx.try_sup_this()?;
+ if !sup_this.has_super() {
#[cfg(feature = "exp-null-coaelse")]
if part.null_coaelse {
return Ok(Val::Null);
}
bail!(NoSuperFound)
- };
+ }
let name = evaluate(ctx.clone(), &part.value)?;
let Val::Str(name) = name else {
@@ -490,19 +458,19 @@
))
};
- let this = ctx
- .this()
- .expect("no this found, while super present, should not happen");
let name = name.into_flat();
- match super_obj
- .get_for(name.clone(), this.clone())
+ match sup_this
+ .get_super(name.clone())
.with_description_src(&part.value, || format!("field <{name}> access"))?
{
Some(v) => v,
#[cfg(feature = "exp-null-coaelse")]
None if part.null_coaelse => return Ok(Val::Null),
None => {
- let suggestions = suggest_object_fields(super_obj, name.clone());
+ let suggestions = suggest_object_fields(
+ &sup_this.standalone_super().expect("super exists"),
+ name.clone(),
+ );
bail!(NoSuchField(name, suggestions))
}
@@ -589,7 +557,7 @@
for b in bindings {
evaluate_dest(b, fctx.clone(), &mut new_bindings)?;
}
- let ctx = ctx.extend(new_bindings, None, None, None).into_future(fctx);
+ let ctx = ctx.extend_bindings(new_bindings).into_future(fctx);
evaluate(ctx, &returned.clone())?
}
Arr(items) => {
@@ -652,7 +620,7 @@
Slice(value, desc) => {
fn parse_idx<T: Typed>(
loc: CallLocation<'_>,
- ctx: &Context,
+ ctx: Context,
expr: Option<&LocExpr>,
desc: &'static str,
) -> Result<Option<T>> {
@@ -660,7 +628,7 @@
Ok(in_frame(
loc,
|| format!("slice {desc}"),
- || <Option<T>>::from_untyped(evaluate(ctx.clone(), value)?),
+ || <Option<T>>::from_untyped(evaluate(ctx, value)?),
)?)
} else {
Ok(None)
@@ -670,9 +638,9 @@
let indexable = evaluate(ctx.clone(), value)?;
let loc = CallLocation::new(&loc);
- let start = parse_idx(loc, &ctx, desc.start.as_ref(), "start")?;
- let end = parse_idx(loc, &ctx, desc.end.as_ref(), "end")?;
- let step = parse_idx(loc, &ctx, desc.step.as_ref(), "step")?;
+ let start = parse_idx(loc, ctx.clone(), desc.start.as_ref(), "start")?;
+ let end = parse_idx(loc, ctx.clone(), desc.end.as_ref(), "end")?;
+ let step = parse_idx(loc, ctx, desc.step.as_ref(), "step")?;
IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?
}
@@ -681,18 +649,21 @@
bail!("computed imports are not supported")
};
let tmp = loc.clone().0;
- let s = ctx.state();
- let resolved_path = s.resolve_from(tmp.source_path(), path)?;
- match i {
- Import(_) => in_frame(
- CallLocation::new(&loc),
- || format!("import {:?}", path.clone()),
- || s.import_resolved(resolved_path),
- )?,
- ImportStr(_) => Val::string(s.import_resolved_str(resolved_path)?),
- ImportBin(_) => Val::Arr(ArrValue::bytes(s.import_resolved_bin(resolved_path)?)),
- _ => unreachable!(),
- }
+ with_state(|s| {
+ let resolved_path = s.resolve_from(tmp.source_path(), path)?;
+ Ok(match i {
+ Import(_) => in_frame(
+ CallLocation::new(&loc),
+ || format!("import {:?}", path.clone()),
+ || s.import_resolved(resolved_path),
+ )?,
+ ImportStr(_) => Val::string(s.import_resolved_str(resolved_path)?),
+ ImportBin(_) => {
+ Val::Arr(ArrValue::bytes(s.import_resolved_bin(resolved_path)?))
+ }
+ _ => unreachable!(),
+ }) as Result<Val>
+ })?
}
})
}
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -40,7 +40,7 @@
}
/// Represents Jsonnet function defined in code.
-#[derive(Debug, PartialEq, Trace)]
+#[derive(Debug, Trace, PartialEq)]
pub struct FuncDesc {
/// # Example
///
crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -129,11 +129,11 @@
}
Ok(body_ctx
- .extend(passed_args, None, None, None)
- .extend(defaults, None, None, None)
+ .extend_bindings(passed_args)
+ .extend_bindings(defaults)
.into_future(fctx))
} else {
- let body_ctx = body_ctx.extend(passed_args, None, None, None);
+ let body_ctx = body_ctx.extend_bindings(passed_args);
Ok(body_ctx)
}
}
@@ -257,7 +257,5 @@
}
}
- Ok(body_ctx
- .extend(bindings, None, None, None)
- .into_future(fctx))
+ Ok(body_ctx.extend_bindings(bindings).into_future(fctx))
}
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -28,8 +28,10 @@
any::Any,
cell::{RefCell, RefMut},
collections::hash_map::Entry,
+ clone::Clone,
fmt::{self, Debug},
rc::Rc,
+ marker::PhantomData,
};
pub use ctx::*;
@@ -65,7 +67,7 @@
/// Type of value after object context is bound
type Bound;
/// Create value bound to specified object context
- fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Self::Bound>;
+ fn bind(&self, sup_this: SupThis) -> Result<Self::Bound>;
}
/// Object fields may, or may not depend on `this`/`super`, this enum allows cheaper reuse of object-independent fields for native code
@@ -85,9 +87,9 @@
}
impl MaybeUnbound {
/// Attach object context to value, if required
- pub fn evaluate(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {
+ pub fn evaluate(&self, sup_this: SupThis) -> Result<Val> {
match self {
- Self::Unbound(v) => v.0.bind(sup, this),
+ Self::Unbound(v) => v.0.bind(sup_this),
Self::Bound(v) => Ok(v.evaluate()?),
}
}
@@ -105,8 +107,8 @@
/// Initialize default file context.
/// Has default implementation, which calls `populate`.
/// Prefer to always implement `populate` instead.
- fn initialize(&self, state: State, for_file: Source) -> Context {
- let mut builder = ContextBuilder::with_capacity(state, self.reserve_vars());
+ fn initialize(&self, for_file: Source) -> Context {
+ let mut builder = ContextBuilder::with_capacity(self.reserve_vars());
self.populate(for_file, &mut builder);
builder.build()
}
@@ -130,11 +132,11 @@
where
T: ContextInitializer,
{
- fn initialize(&self, state: State, for_file: Source) -> Context {
+ fn initialize(&self, for_file: Source) -> Context {
if let Some(ctx) = self {
- ctx.initialize(state, for_file)
+ ctx.initialize(for_file)
} else {
- ().initialize(state, for_file)
+ ().initialize(for_file)
}
}
@@ -237,7 +239,40 @@
#[derive(Clone, Trace)]
pub struct State(Cc<EvaluationStateInternals>);
+thread_local! {
+ pub static DEFAULT_STATE: State = State::builder().build();
+ pub static STATE: RefCell<Option<State>> = const {RefCell::new(None)};
+}
+pub struct StateEnterGuard(PhantomData<()>);
+impl Drop for StateEnterGuard {
+ fn drop(&mut self) {
+ STATE.with_borrow_mut(|v| *v = None);
+ }
+}
+
+pub fn with_state<V>(v: impl FnOnce(State) -> V) -> V {
+ if let Some(state) = STATE.with_borrow(Clone::clone) {
+ v(state)
+ } else {
+ let s = DEFAULT_STATE.with(Clone::clone);
+ v(s)
+ }
+}
+
impl State {
+ pub fn enter(&self) -> StateEnterGuard {
+ self.try_enter().expect("entered state already exists")
+ }
+ pub fn try_enter(&self) -> Option<StateEnterGuard> {
+ STATE.with_borrow_mut(|v| {
+ if v.is_none() {
+ *v = Some(self.clone());
+ Some(StateEnterGuard(PhantomData))
+ } else {
+ None
+ }
+ })
+ }
/// Should only be called with path retrieved from [`resolve_path`], may panic otherwise
pub fn import_resolved_str(&self, path: SourcePath) -> Result<IStr> {
let mut file_cache = self.file_cache();
@@ -359,7 +394,7 @@
/// Creates context with all passed global variables
pub fn create_default_context(&self, source: Source) -> Context {
- self.context_initializer().initialize(self.clone(), source)
+ self.context_initializer().initialize(source)
}
/// Creates context with all passed global variables, calling custom modifier
@@ -370,7 +405,6 @@
) -> Context {
let default_initializer = self.context_initializer();
let mut builder = ContextBuilder::with_capacity(
- self.clone(),
default_initializer.reserve_vars() + context_initializer.reserve_vars(),
);
default_initializer.populate(source.clone(), &mut builder);
crates/jrsonnet-evaluator/src/map.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/map.rs
+++ b/crates/jrsonnet-evaluator/src/map.rs
@@ -4,14 +4,14 @@
use crate::{gc::WithCapacityExt as _, Thunk, Val};
-#[derive(Trace)]
+#[derive(Trace, Debug)]
#[trace(tracking(force))]
pub struct LayeredHashMapInternals {
parent: Option<LayeredHashMap>,
current: FxHashMap<IStr, Thunk<Val>>,
}
-#[derive(Trace)]
+#[derive(Trace, Debug)]
pub struct LayeredHashMap(Cc<LayeredHashMapInternals>);
impl LayeredHashMap {
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1,12 +1,9 @@
use std::{
- any::Any,
- cell::RefCell,
- fmt::Debug,
- hash::{Hash, Hasher},
- ptr::addr_of,
+ any::Any, cell::{Cell, RefCell}, collections::hash_map::Entry, fmt::{self, Debug}, hash::{Hash, Hasher}
};
use jrsonnet_gcmodule::{cc_dyn, Cc, Trace, Weak};
+use educe::Educe;
use jrsonnet_interner::IStr;
use jrsonnet_parser::{Span, Visibility};
use rustc_hash::{FxHashMap, FxHashSet};
@@ -14,10 +11,11 @@
use crate::{
arr::{PickObjectKeyValues, PickObjectValues},
bail,
- error::{suggest_object_fields, Error, ErrorKind::*},
+ error::{suggest_object_fields, ErrorKind::*},
function::{CallLocation, FuncVal},
gc::WithCapacityExt as _,
in_frame,
+ identity_hash,
operator::evaluate_add_op,
val::ArrValue,
CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
@@ -43,12 +41,10 @@
#[derive(Clone, Copy, Default, Debug, Trace)]
pub struct SuperDepth(());
impl SuperDepth {
- pub const fn deeper(self) -> Self {
- Self(())
- }
+ pub(super) fn deepen(self) {}
}
- #[derive(Clone, Copy)]
+ #[derive(Clone, Copy, Debug)]
pub struct FieldSortKey(());
impl FieldSortKey {
pub const fn new(_: SuperDepth, _: FieldIndex) -> Self {
@@ -74,8 +70,8 @@
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct SuperDepth(u32);
impl SuperDepth {
- pub fn deeper(self) -> Self {
- Self(self.0 + 1)
+ pub(super) fn deepen(&mut self) {
+ *self.0 += 1
}
}
@@ -120,7 +116,7 @@
}
}
impl Debug for ObjFieldFlags {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ObjFieldFlags")
.field("add", &self.add())
.field("visibility", &self.visibility())
@@ -140,34 +136,29 @@
cc_dyn!(CcObjectAssertion, ObjectAssertion);
pub trait ObjectAssertion: Trace {
- fn run(&self, super_obj: Option<ObjValue>, this: Option<ObjValue>) -> Result<()>;
+ fn run(&self, sup_this: SupThis) -> Result<()>;
}
// Field => This
-#[derive(Trace)]
+#[derive(Trace, Debug)]
enum CacheValue {
- Cached(Val),
- NotFound,
+ Cached(Result<Option<Val>>),
Pending,
- Errored(Error),
}
#[allow(clippy::module_name_repetitions)]
#[derive(Trace)]
#[trace(tracking(force))]
pub struct OopObject {
- sup: Option<ObjValue>,
// this: Option<ObjValue>,
assertions: Cc<Vec<CcObjectAssertion>>,
- assertions_ran: RefCell<FxHashSet<ObjValue>>,
this_entries: Cc<FxHashMap<IStr, ObjMember>>,
value_cache: RefCell<FxHashMap<(IStr, Option<WeakObjValue>), CacheValue>>,
}
impl Debug for OopObject {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("OopObject")
- .field("sup", &self.sup)
// .field("assertions", &self.assertions)
// .field("assertions_ran", &self.assertions_ran)
.field("this_entries", &self.this_entries)
@@ -178,32 +169,36 @@
type EnumFieldsHandler<'a> = dyn FnMut(SuperDepth, FieldIndex, IStr, Visibility) -> bool + 'a;
-pub trait ObjectLike: Trace + Any + Debug {
- fn extend_from(&self, sup: ObjValue) -> ObjValue;
- /// When using standalone super in object, `this.super_obj.with_this(this)` is executed
- fn with_this(&self, me: ObjValue, this: ObjValue) -> ObjValue {
- ObjValue::new(ThisOverride { inner: me, this })
- }
- fn this(&self) -> Option<ObjValue> {
- None
- }
- fn len(&self) -> usize;
- fn is_empty(&self) -> bool;
- // If callback returns false, iteration stops
- fn enum_fields(&self, depth: SuperDepth, handler: &mut EnumFieldsHandler<'_>) -> bool;
+#[derive(Trace, Clone)]
+pub enum ValueProcess {
+ None,
+ SuperPlus,
+}
+
+pub trait ObjectCore: Trace + Any + Debug {
+ // If callback returns false, iteration stops, and this call returns false.
+ fn enum_fields_core(
+ &self,
+ super_depth: &mut SuperDepth,
+ handler: &mut EnumFieldsHandler<'_>,
+ ) -> bool;
fn has_field_include_hidden(&self, name: IStr) -> bool;
- fn has_field(&self, name: IStr) -> bool;
- fn get_for(&self, key: IStr, this: ObjValue) -> Result<Option<Val>>;
- fn get_for_uncached(&self, key: IStr, this: ObjValue) -> Result<Option<Val>>;
+ fn get_for(&self, key: IStr, sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>>;
+ // fn get_for_uncached(&self, key: IStr, this: ObjValue) -> Result<Option<(Val, ValueProcess)>>;
fn field_visibility(&self, field: IStr) -> Option<Visibility>;
- fn run_assertions_raw(&self, this: ObjValue) -> Result<()>;
+ fn run_assertions_raw(&self, sup_this: SupThis) -> Result<()>;
}
#[derive(Clone, Trace)]
-pub struct WeakObjValue(#[trace(skip)] pub(crate) Weak<dyn ObjectLike>);
+pub struct WeakObjValue(#[trace(skip)] Weak<ObjValueInner>);
+impl Debug for WeakObjValue {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_tuple("WeakObjValue").finish()
+ }
+}
impl PartialEq for WeakObjValue {
fn eq(&self, other: &Self) -> bool {
@@ -222,50 +217,97 @@
cc_dyn!(
#[derive(Clone, Debug)]
- ObjValue, ObjectLike,
+ ObjCore, ObjectCore,
pub fn new() {...}
);
+#[derive(Trace, Educe)]
+#[educe(Debug)]
+struct ObjValueInner {
+ cores: Vec<ObjCore>,
+ assertions_ran: Cell<bool>,
+ value_cache: RefCell<FxHashMap<(IStr, CoreIdx), CacheValue>>,
+}
-#[derive(Debug, Trace)]
-struct EmptyObject;
-impl ObjectLike for EmptyObject {
- fn extend_from(&self, sup: ObjValue) -> ObjValue {
- // obj + {} == obj
- sup
+thread_local! {
+ static RUNNING_ASSERTIONS: RefCell<FxHashSet<ObjValue>> = RefCell::default();
+}
+fn is_asserting(obj: &ObjValue) -> bool {
+ RUNNING_ASSERTIONS.with_borrow(|v| v.contains(obj))
+}
+/// Returns false if already asserting
+fn start_asserting(obj: &ObjValue) -> bool {
+ RUNNING_ASSERTIONS.with_borrow_mut(|v| v.insert(obj.clone()))
+}
+fn finish_asserting(obj: &ObjValue) {
+ RUNNING_ASSERTIONS.with_borrow_mut(|v| {
+ let r = v.remove(obj);
+ debug_assert!(
+ r,
+ "finish_asserting was called before start_asserting or twice"
+ );
+ });
+}
+
+#[allow(clippy::module_name_repetitions)]
+#[derive(Clone, Trace, Debug, Educe)]
+#[educe(PartialEq, Hash, Eq)]
+pub struct ObjValue(
+ #[educe(PartialEq(method(Cc::ptr_eq)), Hash(method(identity_hash)))] Cc<ObjValueInner>,
+);
+
+#[derive(Trace, Debug)]
+struct StandaloneSuperCore {
+ sup: CoreIdx,
+ this: ObjValue,
+}
+impl ObjectCore for StandaloneSuperCore {
+ fn enum_fields_core(
+ &self,
+ super_depth: &mut SuperDepth,
+ handler: &mut EnumFieldsHandler<'_>,
+ ) -> bool {
+ self.this
+ .enum_fields_internal(super_depth, handler, self.sup)
}
- fn this(&self) -> Option<ObjValue> {
- None
+ fn has_field_include_hidden(&self, name: IStr) -> bool {
+ self.this.has_field_include_hidden_idx(name, self.sup)
}
- fn len(&self) -> usize {
- 0
+ fn get_for(&self, key: IStr, _sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>> {
+ let v = self.this.get_idx(key, self.sup)?;
+ Ok(v.map(|v| (v, ValueProcess::None)))
}
- fn is_empty(&self) -> bool {
- true
+ fn field_visibility(&self, field: IStr) -> Option<Visibility> {
+ self.this.field_visibility_idx(field, self.sup)
}
- fn enum_fields(&self, _depth: SuperDepth, _handler: &mut EnumFieldsHandler<'_>) -> bool {
- false
+ fn run_assertions_raw(&self, _sup_this: SupThis) -> Result<()> {
+ self.this.run_assertions()
}
+}
- fn has_field_include_hidden(&self, _name: IStr) -> bool {
- false
+#[derive(Debug, Trace)]
+struct EmptyObject;
+impl ObjectCore for EmptyObject {
+ fn enum_fields_core(
+ &self,
+ _super_depth: &mut SuperDepth,
+ _handler: &mut EnumFieldsHandler<'_>,
+ ) -> bool {
+ true
}
- fn has_field(&self, _name: IStr) -> bool {
+ fn has_field_include_hidden(&self, _name: IStr) -> bool {
false
}
- fn get_for(&self, _key: IStr, _this: ObjValue) -> Result<Option<Val>> {
- Ok(None)
- }
- fn get_for_uncached(&self, _key: IStr, _this: ObjValue) -> Result<Option<Val>> {
+ fn get_for(&self, _key: IStr, _sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>> {
Ok(None)
}
- fn run_assertions_raw(&self, _this: ObjValue) -> Result<()> {
+ fn run_assertions_raw(&self, _sup_this: SupThis) -> Result<()> {
Ok(())
}
@@ -274,65 +316,79 @@
}
}
-#[derive(Trace, Debug)]
-struct ThisOverride {
- inner: ObjValue,
- this: ObjValue,
+#[derive(Hash, PartialEq, Eq, Trace, Clone, Copy, Debug)]
+struct CoreIdx {
+ idx: usize,
}
-impl ObjectLike for ThisOverride {
- fn with_this(&self, _me: ObjValue, this: ObjValue) -> ObjValue {
- ObjValue::new(Self {
- inner: self.inner.clone(),
- this,
- })
+impl CoreIdx {
+ fn super_exists(self) -> bool {
+ self.idx != 0
}
-
- fn extend_from(&self, sup: ObjValue) -> ObjValue {
- self.inner.extend_from(sup).with_this(self.this.clone())
+}
+#[derive(Trace, Clone, PartialEq, Eq, Hash, Debug)]
+pub struct SupThis {
+ sup: CoreIdx,
+ this: ObjValue,
+}
+impl SupThis {
+ pub fn has_super(&self) -> bool {
+ self.sup.super_exists()
}
-
- fn this(&self) -> Option<ObjValue> {
- Some(self.this.clone())
+ /// Implementation of `"field" in super` operation,
+ /// works faster than standalone super path.
+ ///
+ /// In case of no `super` existence, returns false.
+ pub fn field_in_super(&self, field: IStr) -> bool {
+ self.this.has_field_include_hidden_idx(field, self.sup)
}
-
- fn len(&self) -> usize {
- self.inner.len()
+ /// Implementation of `super.field` operation,
+ /// works faster than standalone super path.
+ ///
+ /// In case of no `super` existence, returns `NoSuperFound`
+ pub fn get_super(&self, field: IStr) -> Result<Option<Val>> {
+ if !self.sup.super_exists() {
+ bail!(NoSuperFound);
+ }
+ self.this.get_idx(field, self.sup)
}
-
- fn is_empty(&self) -> bool {
- self.inner.is_empty()
+ /// `super` with `self` overriden for top-level lookups.
+ /// Exists when super appears outside of `super.field`/`"field" in super` expressions
+ /// Exclusive to jrsonnet.
+ ///
+ /// Might return `NoSuperFound` error.
+ pub fn standalone_super(&self) -> Result<ObjValue> {
+ if !self.sup.super_exists() {
+ bail!(NoSuperFound)
+ }
+ Ok(ObjValue::new(StandaloneSuperCore {
+ sup: self.sup,
+ this: self.this.clone(),
+ }))
}
-
- fn enum_fields(&self, depth: SuperDepth, handler: &mut EnumFieldsHandler<'_>) -> bool {
- self.inner.enum_fields(depth, handler)
+ pub fn this(&self) -> &ObjValue {
+ &self.this
}
-
- fn has_field_include_hidden(&self, name: IStr) -> bool {
- self.inner.has_field_include_hidden(name)
- }
-
- fn has_field(&self, name: IStr) -> bool {
- self.inner.has_field(name)
+ pub fn downgrade(self) -> WeakSupThis {
+ WeakSupThis {
+ sup: self.sup,
+ this: self.this.downgrade(),
+ }
}
-
- fn get_for(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
- self.inner.get_for(key, this)
- }
-
- fn get_for_uncached(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
- self.inner.get_raw(key, this)
- }
-
- fn field_visibility(&self, field: IStr) -> Option<Visibility> {
- self.inner.field_visibility(field)
- }
-
- fn run_assertions_raw(&self, this: ObjValue) -> Result<()> {
- self.inner.run_assertions_raw(this)
- }
}
+#[derive(Trace, PartialEq, Eq, Hash, Debug)]
+pub struct WeakSupThis {
+ sup: CoreIdx,
+ this: WeakObjValue,
+}
impl ObjValue {
+ pub fn new(v: impl ObjectCore) -> Self {
+ Self(Cc::new(ObjValueInner {
+ cores: vec![ObjCore::new(v)],
+ assertions_ran: Cell::new(false),
+ value_cache: RefCell::new(FxHashMap::new()),
+ }))
+ }
pub fn new_empty() -> Self {
Self::new(EmptyObject)
}
@@ -363,27 +419,77 @@
#[must_use]
pub fn extend_from(&self, sup: Self) -> Self {
- self.0.extend_from(sup)
+ let mut cores = sup.0.cores.clone();
+ cores.extend(self.0.cores.iter().cloned());
+ ObjValue(Cc::new(ObjValueInner {
+ cores,
+ value_cache: RefCell::default(),
+ assertions_ran: Cell::new(false),
+ }))
}
- #[must_use]
- pub fn with_this(&self, this: Self) -> Self {
- self.0.with_this(self.clone(), this)
- }
+ // #[must_use]
+ // pub fn with_this(&self, this: Self) -> Self {
+ // self.0.with_this(self.clone(), this)
+ // }
+ /// Returns amount of visible object fields
+ /// If object only contains hidden fields - may return zero.
pub fn len(&self) -> usize {
- self.0.len()
+ self.fields_visibility()
+ .iter()
+ .filter(|(_, (visible, _))| *visible)
+ .count()
}
pub fn is_empty(&self) -> bool {
- self.0.is_empty()
+ self.len() == 0
+ }
+ /// For each field, calls callback.
+ /// If callback returns false - ends iteration prematurely.
+ ///
+ /// Returns false if ended prematurely
+ pub fn enum_fields(&self, handler: &mut EnumFieldsHandler<'_>) -> bool {
+ let mut super_depth = SuperDepth::default();
+ self.enum_fields_internal(
+ &mut super_depth,
+ handler,
+ CoreIdx {
+ idx: self.0.cores.len(),
+ },
+ )
}
- pub fn enum_fields(&self, depth: SuperDepth, handler: &mut EnumFieldsHandler<'_>) -> bool {
- self.0.enum_fields(depth, handler)
+ fn enum_fields_internal(
+ &self,
+ super_depth: &mut SuperDepth,
+ handler: &mut EnumFieldsHandler<'_>,
+ idx: CoreIdx,
+ ) -> bool {
+ for core in self.0.cores[..idx.idx].iter() {
+ if !core.0.enum_fields_core(super_depth, handler) {
+ return false;
+ }
+ super_depth.deepen();
+ }
+ true
}
pub fn has_field_include_hidden(&self, name: IStr) -> bool {
- self.0.has_field_include_hidden(name)
+ self.has_field_include_hidden_idx(
+ name,
+ CoreIdx {
+ idx: self.0.cores.len(),
+ },
+ )
+ }
+ fn has_field_include_hidden_idx(&self, name: IStr, core: CoreIdx) -> bool {
+ self.0.cores[..core.idx]
+ .iter()
+ .rev()
+ .any(|v| v.0.has_field_include_hidden(name.clone()))
}
pub fn has_field(&self, name: IStr) -> bool {
- self.0.has_field(name)
+ match self.field_visibility(name) {
+ Some(Visibility::Unhide | Visibility::Normal) => true,
+ Some(Visibility::Hidden) | None => false,
+ }
}
pub fn has_field_ex(&self, name: IStr, include_hidden: bool) -> bool {
if include_hidden {
@@ -392,14 +498,78 @@
self.has_field(name)
}
}
+ pub fn get(&self, key: IStr) -> Result<Option<Val>> {
+ self.get_idx(
+ key,
+ CoreIdx {
+ idx: self.0.cores.len(),
+ },
+ )
+ }
- pub fn get(&self, key: IStr) -> Result<Option<Val>> {
- self.run_assertions()?;
- self.get_for(key, self.0.this().unwrap_or_else(|| self.clone()))
+ fn get_idx(&self, key: IStr, core: CoreIdx) -> Result<Option<Val>> {
+ let cache_key = (key.clone(), core);
+ {
+ let mut cache = self.0.value_cache.borrow_mut();
+ // entry_ref candidate?
+ match cache.entry(cache_key.clone()) {
+ Entry::Occupied(v) => match v.get() {
+ CacheValue::Cached(v) => return v.clone(),
+ CacheValue::Pending => {
+ if !is_asserting(self) {
+ bail!(InfiniteRecursionDetected);
+ }
+ }
+ },
+ Entry::Vacant(v) => {
+ v.insert(CacheValue::Pending);
+ }
+ };
+ }
+ let result = self.get_idx_uncached(key, core);
+ {
+ let mut cache = self.0.value_cache.borrow_mut();
+ cache.insert(cache_key, CacheValue::Cached(result.clone()));
+ }
+ result
}
+ fn get_idx_uncached(&self, key: IStr, core: CoreIdx) -> Result<Option<Val>> {
+ self.run_assertions()?;
+ let mut add_stack = Vec::with_capacity(2);
+ for (sup, core) in self.0.cores[..core.idx].iter().enumerate().rev() {
+ let sup_this = SupThis {
+ sup: CoreIdx { idx: sup },
+ this: self.clone(),
+ };
+ if let Some((val, proc)) = core.0.get_for(key.clone(), sup_this)? {
+ match proc {
+ ValueProcess::None if add_stack.is_empty() => return Ok(Some(val)),
+ ValueProcess::None => {
+ add_stack.push(val);
+ break;
+ }
+ ValueProcess::SuperPlus => {
+ add_stack.push(val);
+ }
+ }
+ }
+ }
+ if add_stack.is_empty() {
+ // None of layers had this field
+ return Ok(None);
+ } else if add_stack.len() == 1 {
+ // A layer had this field, but it wanted this field to be added with super.
+ // However, no super had this field, fail-safe
+ return Ok(Some(add_stack.pop().expect("single element on stack")));
+ }
+ let mut values = add_stack.into_iter().rev();
+ let init = values.next().expect("at least 2 elements");
- pub fn get_for(&self, key: IStr, this: Self) -> Result<Option<Val>> {
- self.0.get_for(key, this)
+ values
+ .try_fold(init, |a, b| evaluate_add_op(&a, &b))
+ .map(Some)
+
+ // self.0.get_raw(key, this)
}
pub fn get_or_bail(&self, key: IStr) -> Result<Val> {
@@ -408,22 +578,48 @@
bail!(NoSuchField(key, suggestions))
};
Ok(value)
- }
-
- fn get_raw(&self, key: IStr, this: Self) -> Result<Option<Val>> {
- self.0.get_for_uncached(key, this)
}
fn field_visibility(&self, field: IStr) -> Option<Visibility> {
- self.0.field_visibility(field)
+ self.field_visibility_idx(
+ field,
+ CoreIdx {
+ idx: self.0.cores.len(),
+ },
+ )
}
+ fn field_visibility_idx(&self, field: IStr, core: CoreIdx) -> Option<Visibility> {
+ let mut exists = false;
+ for ele in self.0.cores[..core.idx].iter().rev() {
+ let vis = ele.0.field_visibility(field.clone());
+ match vis {
+ Some(Visibility::Unhide | Visibility::Hidden) => return vis,
+ Some(Visibility::Normal) => exists = true,
+ None => {}
+ }
+ }
+ exists.then_some(Visibility::Normal)
+ }
pub fn run_assertions(&self) -> Result<()> {
- // FIXME: Should it use `self.0.this()` in case of standalone super?
- self.run_assertions_raw(self.clone())
- }
- fn run_assertions_raw(&self, this: Self) -> Result<()> {
- self.0.run_assertions_raw(this)
+ if self.0.assertions_ran.get() {
+ return Ok(());
+ }
+ if !start_asserting(self) {
+ return Ok(());
+ }
+ for (idx, ele) in self.0.cores.iter().enumerate() {
+ let sup_this = SupThis {
+ sup: CoreIdx { idx },
+ this: self.clone(),
+ };
+ ele.0.run_assertions_raw(sup_this).inspect_err(|_e| {
+ finish_asserting(self);
+ })?;
+ }
+ finish_asserting(self);
+ self.0.assertions_ran.set(true);
+ Ok(())
}
pub fn iter(
@@ -462,24 +658,22 @@
}
fn fields_visibility(&self) -> FxHashMap<IStr, (bool, FieldSortKey)> {
let mut out = FxHashMap::default();
- self.enum_fields(
- SuperDepth::default(),
- &mut |depth, index, name, visibility| {
- let new_sort_key = FieldSortKey::new(depth, index);
- let entry = out.entry(name);
- let (visible, _) = entry.or_insert((true, new_sort_key));
- match visibility {
- Visibility::Normal => {}
- Visibility::Hidden => {
- *visible = false;
- }
- Visibility::Unhide => {
- *visible = true;
- }
- };
- false
- },
- );
+ self.enum_fields(&mut |depth, index, name, visibility| {
+ dbg!(&name, visibility);
+ let new_sort_key = FieldSortKey::new(depth, index);
+ let entry = out.entry(name);
+ let (visible, _) = entry.or_insert((true, new_sort_key));
+ match visibility {
+ Visibility::Normal => {}
+ Visibility::Hidden => {
+ *visible = false;
+ }
+ Visibility::Unhide => {
+ *visible = true;
+ }
+ };
+ false
+ });
out
}
pub fn fields_ex(
@@ -515,8 +709,8 @@
return fields;
}
- let mut fields: Vec<_> = self
- .fields_visibility()
+ let mut fields: Vec<_> = dbg!(self
+ .fields_visibility())
.into_iter()
.filter(|(_, (visible, _))| include_hidden || *visible)
.map(|(k, _)| k)
@@ -580,210 +774,65 @@
impl OopObject {
pub fn new(
- sup: Option<ObjValue>,
this_entries: Cc<FxHashMap<IStr, ObjMember>>,
assertions: Cc<Vec<CcObjectAssertion>>,
) -> Self {
Self {
- sup,
- // this: None,
- assertions,
- assertions_ran: RefCell::new(FxHashSet::new()),
this_entries,
value_cache: RefCell::new(FxHashMap::new()),
+ assertions,
}
}
-
- fn evaluate_this(&self, v: &ObjMember, real_this: ObjValue) -> Result<Val> {
- v.invoke.evaluate(self.sup.clone(), Some(real_this))
- }
-
- // FIXME: Duplication between ObjValue and OopObject
- fn fields_visibility(&self) -> FxHashMap<IStr, (bool, FieldSortKey)> {
- let mut out = FxHashMap::default();
- self.enum_fields(
- SuperDepth::default(),
- &mut |depth, index, name, visibility| {
- let new_sort_key = FieldSortKey::new(depth, index);
- let entry = out.entry(name);
- let (visible, _) = entry.or_insert((true, new_sort_key));
- match visibility {
- Visibility::Normal => {}
- Visibility::Hidden => {
- *visible = false;
- }
- Visibility::Unhide => {
- *visible = true;
- }
- };
- false
- },
- );
- out
- }
}
-impl ObjectLike for OopObject {
- fn extend_from(&self, sup: ObjValue) -> ObjValue {
- ObjValue::new(match &self.sup {
- None => Self::new(
- Some(sup),
- self.this_entries.clone(),
- self.assertions.clone(),
- ),
- Some(v) => Self::new(
- Some(v.extend_from(sup)),
- self.this_entries.clone(),
- self.assertions.clone(),
- ),
- })
- }
-
- fn len(&self) -> usize {
- // Maybe it will be better to not compute sort key here?
- self.fields_visibility()
- .into_iter()
- .filter(|(_, (visible, _))| *visible)
- .count()
- }
-
- /// Returns false only if there is any visible entry.
- ///
- /// Note that object with hidden fields `{a:: 1}` will be reported as empty here.
- fn is_empty(&self) -> bool {
- self.len() == 0
- }
-
- /// Run callback for every field found in object
- ///
- /// Returns true if ended prematurely
- fn enum_fields(&self, depth: SuperDepth, handler: &mut EnumFieldsHandler<'_>) -> bool {
- if let Some(s) = &self.sup {
- if s.enum_fields(depth.deeper(), handler) {
- return true;
- }
- }
+impl ObjectCore for OopObject {
+ fn enum_fields_core(
+ &self,
+ super_depth: &mut SuperDepth,
+ handler: &mut EnumFieldsHandler<'_>,
+ ) -> bool {
for (name, member) in self.this_entries.iter() {
if handler(
- depth,
+ *super_depth,
member.original_index,
name.clone(),
member.flags.visibility(),
) {
- return true;
+ return false;
}
}
- false
+ true
}
fn has_field_include_hidden(&self, name: IStr) -> bool {
- if self.this_entries.contains_key(&name) {
- true
- } else if let Some(super_obj) = &self.sup {
- super_obj.has_field_include_hidden(name)
- } else {
- false
- }
+ self.this_entries.contains_key(&name)
}
- fn has_field(&self, name: IStr) -> bool {
- self.field_visibility(name)
- .map_or(false, |v| v.is_visible())
- }
- fn get_for(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
- let cache_key = (key.clone(), Some(this.clone().downgrade()));
- if let Some(v) = self.value_cache.borrow().get(&cache_key) {
- return Ok(match v {
- CacheValue::Cached(v) => Some(v.clone()),
- CacheValue::NotFound => None,
- CacheValue::Pending => bail!(InfiniteRecursionDetected),
- CacheValue::Errored(e) => return Err(e.clone()),
- });
- }
- self.value_cache
- .borrow_mut()
- .insert(cache_key.clone(), CacheValue::Pending);
- let value = self.get_for_uncached(key, this).inspect_err(|e| {
- self.value_cache
- .borrow_mut()
- .insert(cache_key.clone(), CacheValue::Errored(e.clone()));
- })?;
- self.value_cache.borrow_mut().insert(
- cache_key,
- value
- .as_ref()
- .map_or(CacheValue::NotFound, |v| CacheValue::Cached(v.clone())),
- );
- Ok(value)
- }
- fn get_for_uncached(&self, key: IStr, real_this: ObjValue) -> Result<Option<Val>> {
- match (self.this_entries.get(&key), &self.sup) {
- (Some(k), None) => Ok(Some(self.evaluate_this(k, real_this)?)),
- (Some(k), Some(super_obj)) => {
- let our = self.evaluate_this(k, real_this.clone())?;
+ fn get_for(&self, key: IStr, sup_this: SupThis) -> Result<Option<(Val, ValueProcess)>> {
+ match self.this_entries.get(&key) {
+ Some(k) => Ok(Some((
+ k.invoke.evaluate(sup_this)?,
if k.flags.add() {
- super_obj
- .get_raw(key, real_this)?
- .map_or(Ok(Some(our.clone())), |v| {
- Ok(Some(evaluate_add_op(&v, &our)?))
- })
+ ValueProcess::SuperPlus
} else {
- Ok(Some(our))
- }
- }
- (None, Some(super_obj)) => super_obj.get_raw(key, real_this),
- (None, None) => Ok(None),
+ ValueProcess::None
+ },
+ ))),
+ None => Ok(None),
}
}
fn field_visibility(&self, name: IStr) -> Option<Visibility> {
- if let Some(m) = self.this_entries.get(&name) {
- Some(match &m.flags.visibility() {
- Visibility::Normal => self
- .sup
- .as_ref()
- .and_then(|super_obj| super_obj.field_visibility(name))
- .unwrap_or(Visibility::Normal),
- v => *v,
- })
- } else if let Some(super_obj) = &self.sup {
- super_obj.field_visibility(name)
- } else {
- None
- }
+ Some(self.this_entries.get(&name)?.flags.visibility())
}
- fn run_assertions_raw(&self, real_this: ObjValue) -> Result<()> {
+ fn run_assertions_raw(&self, sup_this: SupThis) -> Result<()> {
if self.assertions.is_empty() {
- if let Some(super_obj) = &self.sup {
- super_obj.run_assertions_raw(real_this)?;
- }
return Ok(());
}
- if self.assertions_ran.borrow_mut().insert(real_this.clone()) {
- for assertion in self.assertions.iter() {
- if let Err(e) = assertion.0.run(self.sup.clone(), Some(real_this.clone())) {
- self.assertions_ran.borrow_mut().remove(&real_this);
- return Err(e);
- }
- }
- if let Some(super_obj) = &self.sup {
- super_obj.run_assertions_raw(real_this)?;
- }
+ for assertion in self.assertions.iter() {
+ assertion.0.run(sup_this.clone())?;
}
Ok(())
- }
-}
-
-impl PartialEq for ObjValue {
- fn eq(&self, other: &Self) -> bool {
- Cc::ptr_eq(&self.0, &other.0)
- }
-}
-
-impl Eq for ObjValue {}
-impl Hash for ObjValue {
- fn hash<H: Hasher>(&self, hasher: &mut H) {
- hasher.write_usize(addr_of!(*self.0).expose_provenance() as usize);
}
}
@@ -845,11 +894,8 @@
if self.sup.is_none() && self.map.is_empty() && self.assertions.is_empty() {
return ObjValue::new_empty();
}
- ObjValue::new(OopObject::new(
- self.sup,
- Cc::new(self.map),
- Cc::new(self.assertions),
- ))
+ let res = ObjValue::new(OopObject::new(Cc::new(self.map), Cc::new(self.assertions)));
+ self.sup.map(|sup| res.extend_from(sup)).unwrap_or(res)
}
}
impl Default for ObjValueBuilder {
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -23,7 +23,7 @@
gc::WithCapacityExt as _,
manifest::{ManifestFormat, ToStringFormat},
typed::{BoundedUsize, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER},
- ObjValue, Result, Unbound, WeakObjValue,
+ ObjValue, Result, SupThis, Unbound, WeakSupThis,
};
pub trait ThunkValue: Trace {
@@ -167,8 +167,6 @@
Self::evaluated(T::default())
}
}
-
-type CacheKey = (Option<WeakObjValue>, Option<WeakObjValue>);
#[derive(Trace, Clone)]
pub struct CachedUnbound<I, T>
@@ -176,7 +174,7 @@
I: Unbound<Bound = T>,
T: Trace,
{
- cache: Cc<RefCell<FxHashMap<CacheKey, T>>>,
+ cache: Cc<RefCell<FxHashMap<WeakSupThis, T>>>,
value: I,
}
impl<I: Unbound<Bound = T>, T: Trace> CachedUnbound<I, T> {
@@ -189,17 +187,14 @@
}
impl<I: Unbound<Bound = T>, T: Clone + Trace> Unbound for CachedUnbound<I, T> {
type Bound = T;
- fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<T> {
- let cache_key = (
- sup.as_ref().map(|s| s.clone().downgrade()),
- this.as_ref().map(|t| t.clone().downgrade()),
- );
+ fn bind(&self, sup_this: SupThis) -> Result<T> {
+ let cache_key = sup_this.clone().downgrade();
{
if let Some(t) = self.cache.borrow().get(&cache_key) {
return Ok(t.clone());
}
}
- let bound = self.value.bind(sup, this)?;
+ let bound = self.value.bind(sup_this)?;
{
let mut cache = self.cache.borrow_mut();
tests/cpp_test_suite_golden_override/error.static_error_self.jsonnet.goldendiffbeforeafterboth--- a/tests/cpp_test_suite_golden_override/error.static_error_self.jsonnet.golden
+++ b/tests/cpp_test_suite_golden_override/error.static_error_self.jsonnet.golden
@@ -1,2 +1,2 @@
-self is only usable inside objects
+self/super/$ are only usable inside objects
elem <0> evaluation
\ No newline at end of file
tests/cpp_test_suite_golden_override/error.static_error_super.jsonnet.goldendiffbeforeafterboth--- a/tests/cpp_test_suite_golden_override/error.static_error_super.jsonnet.golden
+++ b/tests/cpp_test_suite_golden_override/error.static_error_super.jsonnet.golden
@@ -1,2 +1,2 @@
-no super found
+self/super/$ are only usable inside objects
elem <0> evaluation
\ No newline at end of file
tests/golden/issue195.jsonnetdiffbeforeafterboth--- /dev/null
+++ b/tests/golden/issue195.jsonnet
@@ -0,0 +1 @@
+{ x: 42 } { y: { "false": "x" in super } }
tests/golden/issue195.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/golden/issue195.jsonnet.golden
@@ -0,0 +1,6 @@
+{
+ "x": 42,
+ "y": {
+ "false": false
+ }
+}
\ No newline at end of file
tests/tests/cpp_test_suite.rsdiffbeforeafterboth--- a/tests/tests/cpp_test_suite.rs
+++ b/tests/tests/cpp_test_suite.rs
@@ -30,6 +30,8 @@
.import_resolver(FileImportResolver::default());
let s = s.build();
+ let _entered = s.enter();
+
let trace_format = CompactFormat {
resolver: PathResolver::FileName,
max_trace: 20,
@@ -61,7 +63,7 @@
Val::Obj(o.build())
}),
);
- v = apply_tla(s, &args, v).expect("failed to apply tla");
+ v = apply_tla(&args, v).expect("failed to apply tla");
}
match v.manifest(JsonFormat::default()) {
tests/tests/golden.rsdiffbeforeafterboth--- a/tests/tests/golden.rs
+++ b/tests/tests/golden.rs
@@ -21,6 +21,8 @@
.import_resolver(FileImportResolver::default());
let s = s.build();
+ let _entered = s.enter();
+
let trace_format = CompactFormat {
resolver: PathResolver::FileName,
max_trace: 20,