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

Nullability attributes need some love #190

Open
8 tasks
litherum opened this issue Jun 3, 2023 · 4 comments
Open
8 tasks

Nullability attributes need some love #190

litherum opened this issue Jun 3, 2023 · 4 comments
Labels
has resolution Issue is resolved, just needs to be done non-breaking Does not require a breaking change (that would block V1.0)

Comments

@litherum
Copy link

litherum commented Jun 3, 2023

I had to make quite a bit of changes to make the nullability attributes actually compile. I eventually got them to work in https://github.com/WebKit/WebKit/pull/14652/files#diff-1a3f28db146a69a5330a62cca964426d2794d35086c2d2e9f9a23e493a54d433

  • The attribute is in the wrong place. Right: char const * WGPU_NULLABLE label; Wrong: WGPU_NULLABLE char const * label;
  • You probably want to add a place to stick _Pragma("clang assume_nonnull begin") and _Pragma("clang assume_nonnull end") so you don't have to annotate literally everything
  • Even when using assume_nonnull, there are still some places that need an explicit WGPU_NONNULL. I don't quite understand why. The docs say "More complex pointer types ... must be explicitly annotated."
  • wgpuAdapterEnumerateFeatures() and wgpuDeviceEnumerateFeatures() need to have their argument be nullable. These functions are designed to be called twice: once to let the caller know how much storage to allocate, and then a second time with the actual store. That first call needs to support nullptr.

On the upside, though, after getting these attributes to compile, they found 2 real bugs in our implementation!


Original issue: #119

EDIT(kainino0x): adding onto that list from #182 (review) and others:

  • ChainedStruct pointers should be nullable
  • Typedef'd pointer types (like callback types) should be annotated
  • Objects types (which are opaque pointers) should be annotated
  • Return types should be annotated (like wgpuCreateInstance())
litherum added a commit to litherum/WebKit that referenced this issue Jun 3, 2023
https://bugs.webkit.org/show_bug.cgi?id=257675
rdar://110202947

Reviewed by NOBODY (OOPS!).

WebGPU.h already has macros to specify nullability. This patch hooks them up to the
appropriate clang attributes.

WebGPU.h's macros don't work out of the box; I opened
webgpu-native/webgpu-headers#190 about fixing the problems
with it.

* Source/WebCore/PAL/Configurations/PAL.xcconfig:
* Source/WebGPU/Configurations/Base.xcconfig:
* Source/WebGPU/Configurations/WebGPU.xcconfig:
* Source/WebGPU/WebGPU/Instance.mm:
(wgpuInstanceRequestAdapter):
* Source/WebGPU/WebGPU/WebGPU.h:
@kainino0x kainino0x added the has resolution Issue is resolved, just needs to be done label Aug 1, 2023
@kainino0x
Copy link
Collaborator

  • You probably want to add a place to stick _Pragma("clang assume_nonnull begin") and _Pragma("clang assume_nonnull end") so you don't have to annotate literally everything
  • Even when using assume_nonnull, there are still some places that need an explicit WGPU_NONNULL. I don't quite understand why. The docs say "More complex pointer types ... must be explicitly annotated."

Since we're generating the header anyway I kind of prefer annotating everything. It's noisy but I think it's better than having to go learn the rules about exactly what is and isn't affected by assume_nonnull...

@kainino0x
Copy link
Collaborator

kainino0x commented Nov 7, 2024

Nullability attributes are broken so they can't be used at all right now. It is quite a bit of work to get them fully working so I would like to declare this non-breaking, can be fixed after 1.0.

@kainino0x kainino0x added !discuss Needs discussion (at meeting or online) non-breaking Does not require a breaking change (that would block V1.0) and removed !discuss Needs discussion (at meeting or online) labels Nov 7, 2024
@kainino0x
Copy link
Collaborator

kainino0x commented Nov 21, 2024

This is basically the same as the WGPU_*_ATTRIBUTE macros which are missing in a few places (at least WGPUStringView) but we've decided don't need to work for 1.0 (#179).

@kainino0x
Copy link
Collaborator

Dec 12 meeting:

  • Fixing WGPU_NULLABLE, introducing WGPU_NON_NULL, and also fixing some WGPU_*_ATTRIBUTEs. Postpone to after 1.0?
  • KN: The attributes in particular will require someone to actually write obj-c bindings to make sure that they're working correctly. But nullability also not very important for c/c++ users.
  • OK

@kainino0x kainino0x removed the !discuss Needs discussion (at meeting or online) label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has resolution Issue is resolved, just needs to be done non-breaking Does not require a breaking change (that would block V1.0)
Projects
None yet
Development

No branches or pull requests

3 participants