Skip to content

Remove PyObjectPayload enum #653

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

Merged
merged 5 commits into from
Mar 11, 2019
Merged

Remove PyObjectPayload enum #653

merged 5 commits into from
Mar 11, 2019

Conversation

OddCoincidence
Copy link
Contributor

This removes the PyObjectPayload enum, and places the Box<dyn Any> directly in PyObject.

PyObjectPayload2 trait is renamed to PyValue to better reflect the purpose it serves.

@coolreader18
Copy link
Member

It looks like you still need to remove a use ...::PyObjectPayload; from rustpython_wasm.

pub payload: Box<dyn Any>,
}

impl Default for PyObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

in what circumstances do we need a default PyObject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was already there, it just can't be automatically derived anymore. It's used in the _nothing() method that it used for the dict, object, and type types. There's a lot of weirdness there that'll need some work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I introduced it for defaulting of the new attributes method, and got to simplify _nothing as a side benefit. (I'm not sure I ended up using it for attributes in the end.) It's probably easy to drop Default and just put the default value in _nothing.

@codecov-io
Copy link

codecov-io commented Mar 10, 2019

Codecov Report

Merging #653 into master will decrease coverage by 0.07%.
The diff coverage is 48.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #653      +/-   ##
==========================================
- Coverage   41.01%   40.93%   -0.08%     
==========================================
  Files          78       77       -1     
  Lines       17586    17439     -147     
  Branches     4509     4561      +52     
==========================================
- Hits         7213     7139      -74     
+ Misses       8473     8391      -82     
- Partials     1900     1909       +9
Impacted Files Coverage Δ
vm/src/obj/objweakref.rs 78.26% <ø> (ø) ⬆️
vm/src/obj/objmodule.rs 81.25% <ø> (ø) ⬆️
vm/src/obj/objbuiltinfunc.rs 33.33% <ø> (ø) ⬆️
vm/src/obj/objnone.rs 57.57% <ø> (ø) ⬆️
vm/src/obj/objmemory.rs 26.08% <0%> (+3.01%) ⬆️
vm/src/obj/objcode.rs 31.57% <0%> (ø) ⬆️
wasm/lib/src/browser_module.rs 0% <0%> (ø) ⬆️
vm/src/obj/objfunction.rs 35.86% <0%> (ø) ⬆️
vm/src/obj/objstr.rs 34.87% <0%> (-0.57%) ⬇️
vm/src/obj/objzip.rs 38.09% <100%> (+0.88%) ⬆️
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf659b8...053ceb1. Read the comment docs.

@coolreader18
Copy link
Member

I'm just realizing near the end of this process that this would have been a good thing to keep a project or milestone for. Oh well, next time! 😆

@OddCoincidence OddCoincidence force-pushed the joey/pyobject-2.0-prep branch from 5ac0864 to 053ceb1 Compare March 11, 2019 03:19
@OddCoincidence OddCoincidence changed the title New object representation part 1 / prep Remove PyObjectPayload enum Mar 11, 2019
@OddCoincidence OddCoincidence changed the title Remove PyObjectPayload enum Remove PyObjectPayload enum Mar 11, 2019
@@ -181,7 +181,7 @@ pub struct Frame {
pub lasti: RefCell<usize>, // index of last instruction ran
}

impl PyObjectPayload2 for Frame {
impl PyValue for Frame {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find myself mixed on this changed - probably just because I'm used to Payload now. I'm sure I'll get used to PyValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that this would be easier to understand for project newcomers - e.g. it feels like it'd be easier to explain that a PyRef is a reference to some type that is a PyValue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm always attached to old names :), but I also feel PyPayload better reflects the fact that it is not a Python value, but a rust inner data for a Python value. That being said, we can always change it later.

@cthulahoops
Copy link
Collaborator

We should look at breaking up pyobject.rs. It has because somewhat unwieldy again. PyContext is probably the most obvious thing to move.

@adrian17
Copy link
Contributor

IntoPyNativeFunc and some of the wrappers like OptionalArg could probably be moved to function.rs/util.rs/function_util.rs.

elements.to_vec().get_slice_items(vm, &subscript)?,
)),
}
if sequence.payload::<PyList>().is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use isinstance to check on types, not on payload. But we can fix this in another PR.

impl PyObject {
pub fn new(payload: PyObjectPayload, typ: PyObjectRef) -> PyObjectRef {
pub fn new<T: PyValue>(payload: T, typ: PyObjectRef) -> PyObjectRef {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be a good idea to swap the order of payload and type here.

@windelbouwman windelbouwman merged commit b8aa38d into master Mar 11, 2019
@windelbouwman
Copy link
Contributor

Well, that was a whole lot of changes!

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.

6 participants