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

Enable trust_return_value_nullability #2791

Merged
merged 6 commits into from
Mar 17, 2023

Conversation

cgwalters
Copy link
Member

@cgwalters cgwalters commented Dec 1, 2022

Enable trust_return_value_nullability

Several commonly used APIs currently unnecessarily return
Option<T>, like ostree_deployment_get_csum().

Flip the gir flag for this to on; I think our annotations are
correct.


Add docs and fix annotations for ostree-repo-file.c

The code here is not great, embarassing we've gone this
long without docs for some of these public API functions too.

I think this is right though.


@openshift-ci
Copy link

openshift-ci bot commented Dec 1, 2022

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@cgwalters
Copy link
Member Author

From chat on Matrix:

yes, you need to set (nullable) on those
I believe (not nullable) is useless and should be dropped as an annotation
the problem is a lot of APIs lack the nullable annotations, that is why the default is to assume everything returned by the C apis is nullable
so you have to carefully review all the API changes

So basically we need to go over the API surfaces affected here and choose whether they do need nullable.

@cgwalters
Copy link
Member Author

OK rebased this on #2814 and lifting draft.

@cgwalters cgwalters force-pushed the enable-trust-return-nullability branch 3 times, most recently from c499526 to b3780e8 Compare March 14, 2023 23:51
Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Looks sane to me, though I didn't review the nullability of all the APIs.

@jlebon
Copy link
Member

jlebon commented Mar 15, 2023

What's the behaviour if an API we thought was not nullable actually is? Does the Rust code panic on encountering the null?

@cgwalters
Copy link
Member Author

Does the Rust code panic on encountering the null?

Hmm I was going to say yes, but apparently the answer is no?
https://docs.rs/glib/0.17.5/src/glib/shared.rs.html#550
That's not great...
I guess we could try to add enable_trust_but_verify_return_value_nullability = true to change debug_assert! -> assert!?

@jlebon
Copy link
Member

jlebon commented Mar 15, 2023

Does the Rust code panic on encountering the null?

Hmm I was going to say yes, but apparently the answer is no? docs.rs/glib/0.17.5/src/glib/shared.rs.html#550 That's not great... I guess we could try to add enable_trust_but_verify_return_value_nullability = true to change debug_assert! -> assert!?

Could be interesting. I guess it depends how much we trust the current annotations to be correct? I think they should be too, but I haven't had to pay close attention to them before. I wouldn't be surprised if there's at least one or two that needs tweaking.

It doesn't look like there's that many APIs being changed, so I'm happy to split it up and sanity-check their nullability if you'd like. Otherwise, I'd vote to just ship this and do any fixups as follow-ups. At least it's early in the development cycle.

Several commonly used APIs currently unnecessarily return
`Option<T>`, like `ostree_deployment_get_csum()`.

Flip the gir flag for this to on; I think our annotations are
correct.
The code here is not great, embarassing we've gone this
long without docs for some of these public API functions too.

I think this is right though.
Since we did a bunch of API changes due to nullability and
other introspection cleanups.
- commit parents are optional
- remote URLs are optional
Unfortunately, the nullability of the output value here is
dependent on whether the `default_value` parameter is provided.  There's
no way to express this in introspection or Rust.
To pick up the latest introspection changes.
@cgwalters cgwalters force-pushed the enable-trust-return-nullability branch from b3780e8 to 61a4a83 Compare March 17, 2023 12:27
@cgwalters
Copy link
Member Author

OK. I did a full audit and found a few more APIs that did need nullable. I think this is now good to go! It will be a nice ergonomic improvement in some cases, biggest one is Sysroot::repo() now correctly just giving Repo.

@jlebon jlebon enabled auto-merge March 17, 2023 13:22
@jlebon jlebon merged commit 7e93837 into ostreedev:main Mar 17, 2023
cgwalters added a commit to cgwalters/ostree-rs-ext that referenced this pull request Mar 17, 2023
This adapts to the changes from ostreedev/ostree#2791
in particular.
@cgwalters
Copy link
Member Author

Yep this made things better ostreedev/ostree-rs-ext#467

@@ -982,7 +982,7 @@ _ostree_repo_remote_name_is_file (const char *remote_name)
* underneath that group, or @default_value if the remote exists but not the
* option name. If an error is returned, @out_value will be set to %NULL.
*
* Returns: %TRUE on success, otherwise %FALSE with @error set
* Returns: (nullable): %TRUE on success, otherwise %FALSE with @error set
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't be null as it is a gboolean

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I messed this up; PR incoming

Copy link
Member Author

Choose a reason for hiding this comment

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

cgwalters added a commit to cgwalters/ostree-rs-ext that referenced this pull request May 1, 2023
This adapts to the changes from ostreedev/ostree#2791
in particular.
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.

5 participants