-
Notifications
You must be signed in to change notification settings - Fork 161
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
Should EnforceRange be allowed on consts and return types? #842
Comments
If specification text returns an out-of-range number for a getter or method, would that trigger an assert or should it be coerced? |
I think that should be a spec error in any case, even if EnforceRange isn't present. |
That seems fine for this case (and let's assert for it in IDL). (I think sometimes coercion or some flexibility around types makes sense, but I agree that for clearly erroneous cases it would be better to assert.) |
I would strongly prefer not to allow these sorts of no-op extended attributes. They muddle the purpose of the extended attribute, which is to operate on inputs by changing how JS type conversions are done. |
Well, that's still the use case, but they want to reuse that "type" for other purposes. |
I don't quite understand; can you give an example of a case where you cannot remove the extended attribute when using it as a return value or const? |
OP gave an example of |
In that case I would suggest using |
In WebGPU, we want the strongest possible typing on every input integer, because any kind of coercion would be extremely confusing to developers. I don't find it easier to read if we have to pepper If WebIDL won't allow Could we get text in the spec about consts/return types/anything else, and ideally more validation checks (that would run in bikeshed) for invalid usages of |
We are trying to figure out whether we should comply with this hypothetical rule (that FWIW, I think that we (the WebGPU editors) still would prefer if typedefs containing |
Here's a PR where we were making the change: gpuweb/gpuweb#928 |
Consider it resolved! When we have editing bandwidth we can add it to the spec proper. (A pull request would also be lovely.) |
Thanks for the quick reply! |
Just to clarify, we should consider it resolved that |
I can't determine from this thread which way it was resolved. Do you think you could clarify? As an aside: Having to have two sibling typedefs, one with |
Correct! |
In general I find the extensive use of typedefs in the Web GL specs pretty bad for clarity. They're working against the Web IDL type system, which assumes everyone will use a common vocabulary for things like |
Is there a better solution to represent bitsets? |
Using the original types, e.g. |
That breaks down when there are multiple bitsets. A function that takes an |
I think that's pretty misleading, because in JavaScript, there's no distinction between those different types of bitsets. You could easily write code that assigns a |
Not a JS dev by any means, but I thought you can write a lot of weird code in JS. Can't you pass the same object where different WebIDL dictionary types are required, for example? Does that make it less valuable to define different dictionary types then? |
If you made multiple dictionaries with the exact same members, then yes, I agree that would be just as misleading and against the grain of Web IDL.
I wouldn't really put it that way. In particular, Web IDL defines, and allows specs to define, conversion rules for how to turn JavaScript values into Web IDL values. Having, e.g., different dictionary types (which generate different conversion rules), or different integer types (e.g. But if you define two exact same conversion rules under different names, that's generally confusing for readers, causing them to dig through your indirection to realize what conversion rules are actually in place. Sometimes there's a brevity benefit, especially around typedefing large unions or deeply-nested generic structures, which outweighs this confusion; that's generally why typdefs exist. But they don't exist so that you can express "perform ToNumber, round to an integer, and take the value modulo 2**32" in several different ways. We have a canonical way to do that, namely To be clear, I'm not saying that we should disallow typedefing primitives, or other "simple" types, in the Web IDL spec. Where to use typdefs, and make the indirection tradeoff, is a choice that individual specification editors should make. Instead, I'm just explaining why when you attempt to use them in this way, you'll run into issues like the ones discussed in this thread. |
WebIDL specifies that a
[EnforceRange]
types are not valid forreadonly attribute
s. However, it doesn't seem to specify whether they are valid for:const
s (seeGPUBufferUsageFlags
andGPUBufferUsage.*
)GPUFenceValue
)It seems like all 3 should be the same.
That said, I would argue that
EnforceRange
be valid in all of these cases, just that it would have no effect. This makes sense because: (a) it allows atypedef
of an[EnforceRange]
integer type to be used consistently and (b) it matches the behavior of reading from a non-readonlyattribute
([EnforceRange]
is meaningless/ignored).The text was updated successfully, but these errors were encountered: