-
Notifications
You must be signed in to change notification settings - Fork 165
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
BREAKING: Convert the unrestricted
keyword into an extended attribute
#857
BREAKING: Convert the unrestricted
keyword into an extended attribute
#857
Conversation
unrestricted
keyword into an extended attributeunrestricted
keyword into an extended attribute
unrestricted
keyword into an extended attributeunrestricted
keyword into an extended attribute
I don't think that rationale holds. |
As a high-level comment, I suspect that before merging this we should also have a PR against HTML and perhaps some infrastructure PRs? I'm not entirely sure what will break if we make this kind of change. Are unknown extended attributes generally fine? |
ReSpec will throw when unknown extattrs appear. |
Should we get buy-in from various bindings teams that they are interested in this churn? |
We should. If it helps, I think it's worth doing as the main reason we have unrestricted is because extended attributes were not type-bound back in the day. Moving to JavaScript-aligned type names for floats and integers will be similar churn, but also well worth doing readability-wise. (E.g., that IDL's byte is not Infra's byte is super confusing.) |
3e26690
to
ea24af3
Compare
So in terms of implementer interest, I guess it would be good to hear from @yuki3 (Chrome), @EdgarChen (Firefox), @plinss (widlparser, somewhat critical for a lot of standards), @cdumez (WebKit; not entirely sure Chris is the right person, but he'd know the right person), @saschanaz (webidl2.js, somewhat critical for WPT). Both for this change and the proposed renaming of numeric types in #843. Then, if there's implementer support, before making this particular change I think we should at least patch HTML and do a quick grep to see what other specifications are impacted (WebGL?). |
https://github.com/tidoust/reffy-reports seems to indicate that 29 specs use the |
Thanks, I guess for specifications we really need @saschanaz onboard then as their bot can update specifications automatically (well, up to the point of review). |
I'll write an update when we get a consensus to land this. |
Personally I like the both ideas, but I'd like to see the entire type system before moving on. For example, what do we do for In other words, I don't yet understand the (ultimate) goal of these proposals. If we'll keep |
We turn Also, |
It's not clear there's anything "simplifying" about moving from working code to new code. |
I assume this is mainly to ease migration for #843, as we currently can't define a typedef with a space e.g. |
It’s not just that we can’t define a |
I think that specific problem can be solved by modifying existing syntax, though? |
As a thought experiment, we could turn everything into type-annotation:
As another thought experiment, we can turn all numeric types into a single type:
Why don't we do these things? Intuitively bad? I expect that we can explain why we define If this proposal were just a patchwork fix, I'm not convinced. Maybe it's better to fix typedef. Maybe it's expected that you cannot write As long as we have consensus about the type system and it's clear what should be type and what should be annotated type, we should be able to discuss whether this proposal is aligned to the guideline/policy/etc or not. Note that I'm not objecting to this proposal. My intuitiveness supports this way. But I also see lack of justification/rationale behind the proposal. |
Very well put @yuki3. First, I think it's worth separating primitives from all other types, for this discussion. I am reasonably happy with our non-primitive type system, e.g. dictionaries, enums, callbacks, sequences, records, promises, etc. So I think this is mostly about primitives. In particular: numeric types, (Edited to add: I guess enums are a kind of string type, if you think about it. Hmm!) Of those, numeric types and string types are basically what we're discussing. The rest are straightforward mappings to JS primitives. One potential framework we could work toward is saying that types should correspond to JavaScript types, and extended attributes should modify the conversion algorithms. This would argue for turning all numeric types into a single type. This would have a benefit of corresponding IDL better to JS-ecosystem things like TypeScript or MDN documentation. However, for numeric types especially, this is more cumbersome for spec authors and implementers. Another potential framework is to try to match some sort of consensus-type-system of C++/Rust, i.e. implementer languages. This is fuzzier, both because of differences between C++ and Rust, and because of differences in C++ dialects (e.g. different string types). For numeric types, I think the result would be similar to #843. For strings, its unclear which direction this would lean. One issue with a C++/Rust type approach is that those languages don't have an idiomatic type for "double/float but not Infinity or NaN", and it's currently an explicit goal of Web IDL to make the easy path for spec authors not require thinking about those. That is, unrestricted behavior is opt-in in Web IDL, both currently and with this PR. Whereas if we took a principled C++/Rust approach, it would be opt-out. A third possibility would be something in between. For example, we could try to be "JS first", but add conveniences or concessions to make spec-writing easier. It's super-common to want to accept only nonnegative integers, so forcing people to write (As an aside, people may enjoy my 2014-era proposal in #33 for reforming the numeric types. I don't really like it any more, but it illustrates somewhat similar thinking, of trying to be "JavaScript first" and not treating C++ boundaries like 232 or 0 as special. #33 (comment) is a 2019-era update on my thinking to be more spec-author friendly, but it is definitely not prinicipled in the way @yuki3 describes.) |
IMO this part should be decided before landing #843, as it will be way harder to migrate from |
Agreed @saschanaz. Which reminds me that I kind of forgot a conclusion to my post. Unfortunately the conclusion is basically pessimistic: I cannot think of any principled framework for this space which accomplishes the goals of:
Maybe there is some other guiding principle besides grounding our primitive type system in an existing one? |
BTW, my intuition says an extended attribute for a type is for slightly modifying the condition, e.g. |
For numeric types, I'm thinking about the following suggestion from Domenic.
It looks good/reasonable to me to put memory layout and bit pattern interpretation as key principles of the type system of primitive types. I agree that [Restricted] looks more natural and consistent with others. (We should choose a better name for [Restricted], though. For example, [DisallowNanAndInf] looks clearer to me.) # I'm okay to add typedefs for [Restricted] float to make spec authors' lives easier. |
I tried to come up with some things I value in IDL that I think largely overlap with prior points made here:
In the end some of these decisions will have to be tradeoffs, but as long as try to maximize the benefit for these different audiences we'll be fine I think. |
88a0822
to
a375817
Compare
a375817
to
5659a2c
Compare
There was a lot of good discussion happening, but I think it's clear that the idea needs some more time to bake. I'll close this PR for now. |
Very late to this, but in case it were to return: Currently extended attributes are described like this:
And the extended attributes defined by Web IDL are described like this:
That description doesn’t outright preclude the possibility that the “built-in” EAs could also be applicable to other language bindings — but it’s notable that if so, it would not be due to anything the spec states on the matter. Certain EAs seem like they surely ought to have significance to other bindings, but the current definitions of EAs stay true to the text quoted above: all of their effects and associated algorithms are specific to ECMAScript. CrossOriginIsolated, for example, is not defined in terms of its abstract effects but its concrete effects on the initialization of Web IDL constructs in a new ECMAScript realm. Most non-exposure-related EAS don’t have an “intuitive” applicability outside of JS though. Looking at the existing applicable-to-numeric-types EAs, would there be any reason to believe that [Clamp] or [EnforceRange] should have significance for other language bindings? Their defined behavior appears pretty specific to ES’s Number type. In new bindings for a language with a native u64 type, it would be a bit odd if setting a To me this makes it seem a lot like This PR does (or would have) addressed this since this sentence is unqualified by anything specific to ES:
If this is still bubbling, I’d suggest that having a clearer model of the intended scope of EA effects first would be helpful, and that the EA introduction would need to be updated to make it explicit that some, like [Unrestricted], are not binding-specific. However I also suspect this wouldn’t be a positive change and that it’s actually desirable for EAs, at least those applicable to types, to remain controls over binding-specific effects. |
Pre‑requisite for #843 (PR #856).
I decided to go with[UnrestrictedFloat]
instead of[LegacyUnrestricted]
, as the latter implies that it applies to non‑floating‑point types as well.That and there are valid non‑legacy reasons to allow non‑finite floating point values, specifically for Math APIs.
After #857 (comment), I’ve changed it to just be
[Unrestricted]
.Depends on:
Preview | Diff