-
Notifications
You must be signed in to change notification settings - Fork 463
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
Add support for in operator #7342
base: master
Are you sure you want to change the base?
Conversation
Ready for review |
The JavaScript I'm not 100% sure about its semantics, but we should avoid confusing it with If it intended to be matched with JS' |
If this is just for implementing stdlib, we can use it as an internal primitive (e.g. |
I just saw #7313 If this is for record types, @unboxed
type rec t = Any('a): t
let hasOwn: (t, string) => bool = %raw(
"Object.hasOwn || Object.bind.call(Object.hasOwnProperty)"
)
let a = hasOwn(Any(dict{}), "toString")
Console.log(a) // => `false` |
I think it might be useful to expose to users as well for JS compat. I can see cases where it might be useful. Also, the Ideally after this PR is merged to add
|
The prototype concept does not exist in the ReScript, so the first-class syntax appears to be confusing. E.g. type t = {
toString?: ...
} If you need it for the purpose of very specific reason, like perf, |
Also, the fact that The results may change over time. This commonly happens with relatively recently added features. I'd recommend testing it on other engines like Firefox and Safari |
IMO, the I'm fine with adding compiler primitives where they're needed to support some low-level JS codes, but I'd like to avoid adding first-class syntax or promoting it to users. |
@cometkim I've made changes based on your comments. It now uses In my opinion, |
( "__proto__" | "toString" | "toLocaleString" | "valueOf" | ||
| "hasOwnProperty" | "isPrototypeOf" | "propertyIsEnumerable" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Record semantics are close to Object.create(null)
and it was actually used in the output of the earlier versions. As we're using object literals for compactness now, this would be a minimal safe guard for the codes with external types.
My previous opinion was that it is not general and safe enough to introduce as a syntax. Having an unsafe primitive for emitting in
is perfectly. It might be better to prefix with "unsafe"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor
too? / __proto__
is so deprecated, no need to cover
}; | ||
} | ||
|
||
if (Object.hasOwn(dict, "toString") !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think usinghasOwnProperty
or pritmitive runtime is better to us. Introducing Object.hasOwn
would significantly increase the target requirement.
Well, it is easier to optimize by simple inlining. compiler's choice IMO. |
@cometkim After a second thought I actually think that we shouldn't use The case:
It is legit, but it's broken even now. And it's possible to fix it with the |
The problem with |
My point is that it's meaningless to worry about |
Although it may be unsafe if additional assumptions are provided by the user like in FFIs the compiler should produce output that is at least as safe as possible, assuming that the given types are true. If it weren't for that now, it would be treated as a bug and should be fixed. The problem with the new operation is it could produce false positives with no custom assumptions. Or it's not a bug, depending on the definitions. Since we support So my question is, is it for dicts or records? if it's only for dicts, how it should be defined in the dict semantics? Regardless, adding a compiler primitive is fine. We can discuss it further when applying it to compiler internals. |
In my mind, any record type is closer to The |
Agree about
The PR introduces the |
No description provided.