Skip to content

Implement IncrementalNewlineDecoder in rust - #5443

Merged
coolreader18 merged 1 commit into
RustPython:mainfrom
coolreader18:incremental-newline-decoder
Dec 3, 2024
Merged

coolreader18 merged 1 commit into
RustPython:mainfrom
coolreader18:incremental-newline-decoder

Conversation

@coolreader18

Copy link
Copy Markdown
Member

No description provided.

@coolreader18
coolreader18 force-pushed the incremental-newline-decoder branch from 1d8c3e8 to fbd0c7a Compare November 15, 2024 05:06

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, finally we have rust implementation of newline decoder.
Please check comment if you need TryFromBorrowedObject for PyObject.


let name = field.ident.as_ref();
let name_string = name.map(Ident::to_string);
let name_string = name.map(|ident| ident.unraw().to_string());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Comment thread vm/src/builtins/tuple.rs
}
}

// TODO: figure out a way to let PyObjectRef implement TryFromBorrowedObject, and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PyObjectRef cannot, but PyObject can. Since PyObject can always be borrowed from PyObjectRef, I expect it has same effect.

impl<'a> TryFromBorrowedObject<'a> for &'a PyObject {
    fn try_from_borrowed_object(_vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
        Ok(obj)
    }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That is possible, but not allowing PyObjectRef to be extracted isn't ideal, and I'd rather allow that and disallow &PyObject than the other way around.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you explain more about it?
For me, it doesn't seem possible without increasing refcount. And increasing a refcount is something not expected from TryFromBorrowedObject

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I didn't realize that was part of the contract for TryFromBorrowedObject. It seems useful to me to have some way of generalizing over a type that can be extracted from a borrowed pyobj, but doesn't necessarily have to borrow from it - like serde's Deserialize vs DeserializeOwned. Like this case - the T in extract_tuple() should be able to borrow from the pyobjectref in the tuple, but there's no reason we should enforce it - a (PyObjectRef,) is a perfectly reasonable thing to put there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, I think I am going to catch up.

@coolreader18
coolreader18 merged commit adc05e6 into RustPython:main Dec 3, 2024
@coolreader18
coolreader18 deleted the incremental-newline-decoder branch December 3, 2024 22:28
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.

2 participants