google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.31k stars 1.15k forks source link

Extern definitions for WebGPU #4145

Open kainino0x opened 5 months ago

kainino0x commented 5 months ago

Closure doesn't yet have extern definitions for WebGPU. Over in Emscripten, we are finally switching to externs instead of doing ["this"] everywhere (except everywhere we forgot and so it's broken). https://github.com/emscripten-core/emscripten/pull/21144

There you can see some barebones externs I generated from the WebGPU spec's WebIDL. I think it's enough for minification to work correctly(?) but it doesn't provide much else - no function arguments, in particular.

Would there be interest in bringing this into Closure as-is, or would it need more complete definitions?

frigus02 commented 5 months ago

Link for easy reference: https://github.com/emscripten-core/emscripten/blob/fb4bdc78cf3b99d634838418882f199e18309a5c/src/closure-externs/webgpu-externs.js

Thanks for the offer. On first glance I'd say they look nice. I'm going to check with the team if we want to include them as is.

kainino0x commented 5 months ago

If it helps, both Safari and Firefox have made strong signals about the API - Chrome shipped with positive signals from other browsers (the only caveat being that they hadn't/haven't finished implementing). Firefox has had it on Nightly for a while (not yet shipping to stable): https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API#browser_compatibility Safari recently enabled it behind a flag in Safari Technology Preview: https://www.webkit.org/blog/14885/release-notes-for-safari-technology-preview-185/

frigus02 commented 5 months ago

We talked internally. We'd rather not include the externs with JSCompiler by default, yet, because the API is currently only live Chrome.

Related: We're also thinking about generating externs using tsickle from TypeScript typings. That way we'd get better about adding new browser APIs to externs. But at the same time we'd only get them once at least 2 browser engines implement them, since that seems to be TS' policy.

I hope that makes sense. I'd kinda like to keep the issue open, though. We do need to add WebGPU externs eventually.

kainino0x commented 5 months ago

Sounds good! We're happy to use our own externs in Emscripten for now. Hopefully if anyone is searching they'll find this issue and be able to copy them.

We're currently maintaining TypeScript types for WebGPU outside of upstream TypeScript: https://github.com/gpuweb/types We've considered pushing to get them upstream, but since we're currently maintaining extra features over what TypeScript's generated types would look like (documentation pulled from the WebGPU spec, and some extra strictness), there hasn't been much pressure. And I'm sure TypeScript will add them themselves once it reaches whatever their threshold is.