-
Notifications
You must be signed in to change notification settings - Fork 276
Add builtin replacements for some Json functions #5706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Replacements are for Json.toText and Json.unconsText, using Aeson and some related libraries - Expanded function replacement system to allow for specific indexes into mutual recursion, because one of the Json functions is not index 0 - Fixed some other infrastructure * `matchBoolVal` and `BoolVal` pattern were backwards * `decodeVal` for `Seq Val` was implemented wrong, uncaught due to unsafe coercion and a lack of use
Fixes #5691 |
5342499
to
f677b41
Compare
f677b41
to
489275d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!!
You can merge once CI passes, can you just verify that the tests all pass in unison/json if you haven't already?
@@ -581,7 +581,7 @@ pattern IntVal i <- (matchIntVal -> Just i) | |||
|
|||
matchBoolVal :: Val -> Maybe Bool | |||
matchBoolVal = \case | |||
(BoxedVal (Enum r t)) | r == Ty.booleanRef -> Just (t == TT.falseTag) | |||
(BoxedVal (Enum r t)) | r == Ty.booleanRef -> Just (t == TT.trueTag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this was flipped, how come it wasn't noticed before? Was this code just unused until now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, probably not used in this mode.
An annoying thing we just noticed is different handling of duplicate keys. Aeson sticks the keys of an object into a map, which orders and dedupes them. But the current Unison library doesn't do this. We're not yet sure how we'd like to handle. The reordering is okay IMO but I'm not a fan of the silent deduping behavior (even though the spec allows it). It's one of those things where if you have an application that needs it, silent deduping is the worst thing since the duplicate is gone before your decoder even sees it. So your application cannot react to the situation in any way. |
Okay, I replaced the aeson usage with a port of the
I'm going to add a replacement for |
Okay, with
|
One idea is: I don't see many completely randomly generated tests. Maybe it'd be a good idea to write something that randomly generates both good and bad strings, and tests:
I.E. test the replacement against the original implementation, both good and bad cases. |
Nice!! I added some property-based tests to Everything looks good, but a property test based on the
Be sure to |
Okay, yeah. I actually intentionally made both those changes because I thought the unison one didn't make sense. I also changed the array parser to say it was parsing an array, not an object. I'll update the unison implementation. |
Okay, I added a contribution to The tests didn't find any other inconsistencies. |
Sweet! Thanks @dolio You can cut a release of |
matchBoolVal
andBoolVal
pattern were backwardsdecodeVal
forSeq Val
was implemented wrong, uncaught due to unsafe coercion and a lack of useRequires
@unison/json
version 1.3.2 to operate.In
@pchiusano/misc-benchmarks
So, roughly 10x faster.