Add JsonLogic public entry point; full fixture contract green on all targets - #10
Merged
Merged
Conversation
Ports JsonLogic.java's surface with two deliberate deviations: no unbounded parse cache (parsing is now explicit via parse()/apply overloads) and no lazily-nulled evaluator field (addOperation rebuilds the complete evaluator snapshot eagerly, so applying is race-free without synchronization). Registers the same 34 default operations in the same order and preserves upstream's last-registration-wins behavior for duplicate operator keys. Adds a commonTest suite that replays the entire fixture corpus (289 value fixtures, 46 error fixtures) through a default-configuration engine on every KMP target, plus API tests covering both addOperation overloads, duplicate-key resolution, parse+apply round trips, the truthy companion, and undefined-operation error parity.
The prior wording promised a visibility guarantee and a "never half-built" property for concurrent addOperation/apply use that the plain MutableMap + lateinit var evaluator fields do not provide. Rewrites the paragraph to state the actual contract: configure on a single thread, then safely publish before concurrent apply use; concurrent addOperation (with itself or with apply) is unsupported and can race. Also drops the public KDoc's link to the internal valueToJsonElement symbol.
The class KDoc's safe-publication example named a Kotlin val, which only prevents reassignment and establishes no happens-before edge for the evaluator writes addOperation performs after construction. Replaces it with mechanisms that actually publish across threads. addOperation(JsonLogicExpression)'s method KDoc still claimed the instance was race-free to apply against "as soon as this call returns"; qualifies that to same-thread visibility only, pointing to the class KDoc for what cross-thread visibility requires.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WS-G — public entry point + full fixture replay
What was done
Workstream WS-G of KMP-MIGRATION.md: the public
JsonLogicclass, and the migration's acceptance milestone — the complete fixture contract running unfiltered on every target.JsonLogic.ktportsJsonLogic.java's surface with the two sanctioned design fixes (no behavior change to any evaluation result):ConcurrentHashMap): explicitparse(String)plus threeapplyoverloads (String/JsonElement/ pre-parsedJsonLogicNode), all funneling through the node overload, root path$.addOperationrebuilds the complete evaluator snapshot eagerly and returnsthis; duplicate keys resolve last-registration-wins, pinned by tests both between custom ops and overriding a default (+), matching the Java'sMap.put.JsonLogic.java:21-54, same order.truthyre-exposed on the companion. The lambdaaddOperationconvenience adapted from Java'sObject[]to the port'sList<Any?>.JsonLogicException, called out explicitly), configure-then-share thread-safety with genuine safe-publication guidance, and the Infinity/NaN re-encoding sharp edge.JsonLogicFixtureReplayTest— all fixtures, no operator filter, exact counts asserted;JsonLogicApiTest— 13 API tests.How it was validated
Independently by the orchestrator; the milestone numbers:
jvmTesttestAndroidHostTestwasmJsNodeTestiosSimulatorArm64TestZero fence-gated fixes were needed — the assembled engine passed its entire correctness contract on the first full run, on all four targets. Head
fee20ce(branch on currentorigin/main; the two commits after the lane run are KDoc-only).JsonLogic.kt+ two test files; nothing else; tree clean.Codex adversarial review (2 rounds + orchestrator verification)
lateinitrebuild cannot deliver (concurrent registrations can publish a stale snapshot)valhand-off) doesn't establish happens-before; method KDoc still overclaimedThis PR also flips WS-G's tracking-doc checkbox.