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

Model: Unify PartialEq #311

Closed
wants to merge 2 commits into from
Closed

Conversation

hunger
Copy link
Member

@hunger hunger commented Jul 10, 2021

Implement PartialEq for Rc and use that for ModelHandle as well
as Value

Wrap a Rc into a SharedModel and implement PartialEq for that.

Wrap Option into the ModuleHandle as well as Value::Model.

@tronical
Copy link
Member

I think that while this change is source incompatible, it is good - especially the centralization of the ptr_eq.

This sheds a bit of light on the fact that there are quite some ways of constructing a modelhandle :). Is that why you removed the From?

@hunger
Copy link
Member Author

hunger commented Jul 10, 2021

@tronical: Yes, this definitely needs some thinking before it can go in.

Is there some documentation on the cpp_cmake parts somewhere? Looks like I broke those.

@tronical
Copy link
Member

It seems to fail deep in the interpreter api through the cmake build. I’ll try to write something about how that plays together on Monday. Sorry about this can of worms :)

@tronical
Copy link
Member

I think the heart of the error is this:

Error: api/sixtyfps-cpp/generated_include/sixtyfps_interpreter_internal.h:177:9: error: ‘SharedModel’ does not name a type

which indicates that the new Value variant holding SharedModel is failing because SharedModel is not a type known in C++.

@tronical
Copy link
Member

I think the heart of the error is this:

Error: api/sixtyfps-cpp/generated_include/sixtyfps_interpreter_internal.h:177:9: error: ‘SharedModel’ does not name a type

which indicates that the new Value variant holding SharedModel is failing because SharedModel is not a type known in C++.

Ah, but Value should not be exposed in the generated headers in the first place.

tronical added a commit that referenced this pull request Jul 12, 2021
Make sure to never export the Value enum. It might drag in all sorts of
unrelated types (as it happened in #311). We have ValueOpaque for that,
so exclude Value from the export config explicitly. However since we
expose the Value *pointers* for the struct iterators, at least provide a
forward declaration.
@tronical
Copy link
Member

tronical commented Jul 12, 2021

Yeah, somehow this patch triggered that cbindgen thought that Value is a dependency needed. Commit 2d3ae83 fixes that. If you rebase then the CI should be green. I also started adding some docs to docs/development.md.

@hunger
Copy link
Member Author

hunger commented Jul 12, 2021

@tronical: Ok, just did a fresh push, let's see what happens.

@tronical
Copy link
Member

@tronical: Ok, just did a fresh push, let's see what happens.

Yay, it’s green now. Only two things left IMO:

(1) typo in the commit message (Hanlde-> Handle)
(2) either break public API but mention in the commit message why (or edit changelog), or keep it - regarding the From impl

@ogoffart ogoffart added the breaking change Anything that probably require a semver bump label Jul 13, 2021
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

I've tagged the change as breaking_change since this change the public API.

The changes here are overall good. But we haven't decide if the next release of the sixtyfps crate will be 0.1.1 or 0.2.

I guess we should wait a bit to see if we have other reasons to break the source compatibility before merging this.

Also changes to public API deserve a changelog entry.

(It would be nice if there was a CI check that could tell if we are breaking semver or touching the public API)

sixtyfps_runtime/corelib/model.rs Show resolved Hide resolved
#[derive(
PartialEq, derive_more::Deref, derive_more::DerefMut, derive_more::From, derive_more::Into,
)]
pub struct ModelHandle<T>(pub Option<SharedModel<T>>);
Copy link
Member

Choose a reason for hiding this comment

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

i wonder if there is a way to remove the inner pub

Anyway, this is a public API breakage.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I added something about this to the CHANGELOG now.

// We can get:
// * false positives: Two different `Model`s get considered the same, even though they are not.
// For this the `self` pointer need to point to the same place. That can only happen if
// `Self` is `()`, which does not make sense for a `Model`. So we ignore this case.
Copy link
Member

Choose a reason for hiding this comment

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

Self could very well be ().

We could imagine for example a impl Model for () that always returns 0 elements.

or a struct MyStaticModel; impl Model for MyStaticModel { ... }.

But anyway, this cannot happen that two different model are considered the same, because the Rc adds an allocation for the refcounts and always allocates. so the data pointer will always be different anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ogoffart: You are way deeper in this rabbit hole than me, so did I understand this correctly?

But I think you are right, this lint might actually be wrong: I went ahead and filed rust-lang/rust-clippy#7461 with my current understanding. I am pretty sure I missed something, but maybe some improvement to the explanation of that clippy lint will fall out of this:-)

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the text, I hope it is a bit better now.

sixtyfps_runtime/corelib/model.rs Show resolved Hide resolved
sixtyfps_runtime/interpreter/api.rs Show resolved Hide resolved
Implement PartialEq for Rc<Model> and use that for ModelHandle as well
as Value<Model>

Wrap a Rc<Model> into a SharedModel and implement PartialEq for that.

Wrap Option<SharedModel> into the ModuleHandle as well as Value::Model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Anything that probably require a semver bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants