-
Notifications
You must be signed in to change notification settings - Fork 575
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
Update simd-json to make serenity compile again #2536
Conversation
And fix an unsoundness (lol)
After reading #2474 (comment), I realize serenity actually re-exports the raw serialization and deserialization functions from the underlying JSON library in serenity::json::prelude. As such, any upgrade to serde-json or simd-json is a breaking change >:( We could hack around this unfortunate decision by replacing the re-exported simd_json::from_str with a custom impl that keeps the old signature (at the cost of a soundness hole, that probably no one ever will encounter because this is such a niche serenity API). We should also maybe deprecate the re-exports from the underlying JSON libraries? |
Is changing the trait bound to |
serenity::json::from_str isn't public API! Only serenity::json::prelude::from_str is. The two differ in that the public one is directly re-exported from serde_json or simd_json, whereas the private one is a wrapper function around serde_json or simd_json I have another hack idea to fix the semver issue: depend on both simd_json 0.4 and 0.10 - use 0.10 internally, re-export 0.4. It's silly but it's a silly solution to a silly problem (namely, serenity publicly re-exporting implementation details) |
// Have to clone the argument because simd_json mutates the argument | ||
// And we can't just take &mut str either because simd_json mutates the string such that it may | ||
// not be UTF-8 afterwards, which is unsound | ||
Ok(simd_json::from_slice(&mut s.as_bytes().to_vec())?) |
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.
Does from_slice
work with multi-byte characters? I think that passing in a &mut s.to_string()
would still be fine here, since even if the string becomes invalid UTF-8, it gets dropped immediately afterward.
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.
Does from_slice work with multi-byte characters?
I think that passing in a &mut s.to_string() would still be fine here, since even if the string becomes invalid UTF-8, it gets dropped immediately afterward.
I originally thought the mere existence of a non UTF-8 str is instant UB but I looked it up and it seems you're right
Still, that would need an unsafe block. Using from_slice
needs no unsafe block and has no performance penalty (I expect?
As per arqunis' / acdenis' request. Also add a feature gated compile_error! to make sure people don't accidentally enable simd-json instead of simd_json again
Ok, turns out this approach doesn't entirely work because having things like Considering that the The other fixes in this PR (like the feature flag typo fix) are fine and can be left in. |
Any updates on this? |
I'm currently not motivated to implement that separate prelude thing, and pushing breaking changes into |
If you'd like, we can close this and split it into separate PRs. |
Split into what PRs? What would they do? |
Replacing the uses of the incorrect |
More trouble than its worth tbh. That replacing is a "pick up a piece of litter in your way" level of change |
And fix an unsoundness (lol)
I found out that serenity doesn't compile with the simd_json feature in poise https://github.com/serenity-rs/poise/actions/runs/6158123854/job/16710276804