-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Clarify intended semantics of isize, usize, and regex types #505
Comments
I need to find where I put this, but I wrote about
My personal expectation, and what I think should be the expectation of most users and implementors, is for As with those types, if you're using these types, you should probably take appropriate caution. We could decide not to reserve them on the basis of "KDL should be predictable and cross-platform), but that would not prevent people from using them. This way, we at least set some ground rules about what they're intended to be instead of ignoring them so folks can shove anything they want in there without anyone potentially giving them a fair warning about it. |
Also I like the idea of expanding regex reservations a bit to be:
At the same time: I think a more prudent approach is to say |
I think that if it's documented that Maybe if it's too lengthy to add multiple regex types, there could be a general suggestion of a naming scheme to follow, just to encourage people to name their new type I personally don't think those three are too lengthy, but that's a weakly held opinion too. Perhaps this belongs in a comment on #486 instead, but if I think I'd also prefer that there at least be some sort of warning in the spec that It might deserve a "Security Considerations" subsection, though I suppose similar overflow-related issues apply to many JSON implementations and the JSON RFC doesn't mention it in its Security Considerations section. ¯\_(ツ)_/¯ |
Other than the
isize
,usize
, andregex
types, all of the reserved types in the spec have a simple consumer-independent procedure for checking whether a node is of that type: checking if it is in a certain fixed range for integer types or checking if it meets some regex for string types.Because of this, it seems very sensible for a parser to reject a node like
(u8)300
or(ipv4)"example.com"
, and for editor tooling to warn humans writing KDL documents when they are writing them that the nodes are malformed.These three reserved types lack that property:
isize
andusize
depends on whether the producer or consumer's platform was intended, and the details of that platform.It feels like there should be multiple regex types for the different regex standards; e.g.
ere-regex
for POSIX extended regular expressions orpcre-regex
for the PCRE library's flavor.Unfortunately, there are so many flavors that most probably shouldn't get reserved names, but giving the ones that do get reserved names makes it more clear what the intended semantics are, and makes it less likely that a parser consuming a KDL document accidentally parses a regex as being of the wrong flavor.
(If I had to pick and choose, I'd reserve/standardize
ecma-regex
andere-regex
today and leave the others, but this is a weakly held opinion.)For
isize
andusize
, I think the question comes down to the semantics of type annotations in general; I don't think I understand how they are supposed to interact with the intended data model.In particular, are the following pairs of values treated as equivalent in the intended data model (and which if any of them should-in-a-SHOULD-sense be errors):
(non-reserved-type)#true
and#true
(u8)300
and300
(u8)300
and(u8)44
(usize)100
and(u32)100
(usize)100
and(u64)100
(usize)1000000000000
and(usize)3567587328
(usize)1000000000000
and(u32)1000000000000
Personally, I think standardizing the
isize
andusize
types would be a mistake; it doesn't seem like a good choice to depend on the specifics of either the producer's or consumer's platform, and on many platforms (for example Common Lisp, JavaScript, OCaml, or Python, all for different reasons) the nearest "natural" semantics don't necessarily correspond to something one would expect from the Rustisize
andusize
types, or from the Csize_t
.The text was updated successfully, but these errors were encountered: