Skip to content
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

Deserialization for VarZeroVec<VarZeroSlice>, take 2 #3649

Merged
merged 3 commits into from
Jul 10, 2023

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Jul 7, 2023

#3643

I noticed that the error included Rust slices ([T]):

error[E0275]: overflow evaluating the requirement `Box<[_]>: Deserialize<'_>`
   --> utils/zerovec/src/varzerovec/serde.rs:103:66
    |
103 |             let deserialized: VarZeroVec<'a, T, F> = VarZeroVec::deserialize(deserializer)?;
    |                                                                  ^^^^^^^^^^^
    |
    = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`zerovec`)
note: required for `Box<varzerovec::slice::VarZeroSlice<[_], _>>` to implement `Deserialize<'_>`
   --> utils/zerovec/src/varzerovec/serde.rs:117:21

which should absolutely not be getting introduced at any point here. The trait resolver is getting sufficiently confused when looking for an impl and it goes and looks at the Box<[T]>: Deserialize from the serde crate. It then continues to confuse itself. I think this is a trait resolver bug.

The fix is to be very specific about which deserialize impl is being called within these impls.

@Manishearth Manishearth requested a review from sffc as a code owner July 7, 2023 13:43
@Manishearth Manishearth requested review from robertbastian and skius and removed request for sffc July 7, 2023 13:43
Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were wondering where the slice came from

@@ -154,7 +72,7 @@ where
where
D: Deserializer<'de>,
{
let visitor: VarZeroVecVisitor<T, F> = VarZeroVecVisitor::default();
let visitor = VarZeroVecVisitor::<T, F>::default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually different code 👀?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, the former still runs some type resolution in picking a deserialize impl. It picked wrong.

@@ -167,6 +85,7 @@ where
impl<'de, 'a, T, F> Deserialize<'de> for &'a VarZeroSlice<T, F>
where
T: VarULE + ?Sized,
Box<T>: Deserialize<'de>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use a VarZeroSliceRefVisitor, we can get rid of this bound entirely. Not sure if that's worth an entirely separate Visitor, though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fair; I think it[s fine because it ought to be pretty rare to want to deserialize this anyway. It's kinda a code smell to not support human readable deserialization, and the code optimizes away anyway since the choice is known at compile time.

@Manishearth Manishearth merged commit 7465509 into unicode-org:main Jul 10, 2023
23 checks passed
@Manishearth Manishearth deleted the varzeroslice branch July 10, 2023 20:58
@Manishearth Manishearth mentioned this pull request Sep 21, 2023
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants